@@ -59,8 +59,9 @@ func (p *Pinner) Pin(pointer any) {
59
59
}
60
60
}
61
61
ptr := pinnerGetPtr (& pointer )
62
- setPinned (ptr , true )
63
- p .refs = append (p .refs , ptr )
62
+ if setPinned (ptr , true ) {
63
+ p .refs = append (p .refs , ptr )
64
+ }
64
65
}
65
66
66
67
// Unpin unpins all pinned objects of the Pinner.
@@ -144,14 +145,15 @@ func isPinned(ptr unsafe.Pointer) bool {
144
145
}
145
146
146
147
// setPinned marks or unmarks a Go pointer as pinned.
147
- func setPinned (ptr unsafe.Pointer , pin bool ) {
148
+ func setPinned (ptr unsafe.Pointer , pin bool ) bool {
148
149
span := spanOfHeap (uintptr (ptr ))
149
150
if span == nil {
150
- if isGoPointerWithoutSpan (ptr ) {
151
- // this is a linker-allocated or zero size object, nothing to do.
152
- return
151
+ if ! pin {
152
+ panic (errorString ("runtime.Pinner.Unpin: unexpected non Go pointer" ))
153
153
}
154
- panic (errorString ("runtime.Pinner.Pin: argument is not a Go pointer" ))
154
+ // this is a linker-allocated, zero size object or other object,
155
+ // nothing to do, silently ignore it.
156
+ return false
155
157
}
156
158
157
159
// ensure that the span is swept, b/c sweeping accesses the specials list
@@ -209,7 +211,7 @@ func setPinned(ptr unsafe.Pointer, pin bool) {
209
211
}
210
212
unlock (& span .speciallock )
211
213
releasem (mp )
212
- return
214
+ return true
213
215
}
214
216
215
217
type pinState struct {
0 commit comments