Skip to content

Commit 560a581

Browse files
committed
address comments.
Signed-off-by: doujiang24 <[email protected]>
1 parent 418b1ad commit 560a581

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/runtime/pinner.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,8 @@ type Pinner struct {
2525
// objects, these objects must be pinned separately if they are going to be
2626
// accessed from C code.
2727
//
28-
// The argument must be a pointer of any type or an
29-
// unsafe.Pointer. It must be the result of calling new,
30-
// taking the address of a composite literal, or taking the address of a
31-
// local variable. If one of these conditions is not met, Pin will panic.
28+
// The argument must be a pointer of any type or an unsafe.Pointer.
29+
// It's safe to call Pin on non-Go pointers, in which case Pin will do nothing.
3230
func (p *Pinner) Pin(pointer any) {
3331
if p.pinner == nil {
3432
// Check the pinner cache first.
@@ -144,14 +142,17 @@ func isPinned(ptr unsafe.Pointer) bool {
144142
return pinState.isPinned()
145143
}
146144

147-
// setPinned marks or unmarks a Go pointer as pinned.
145+
// setPinned marks or unmarks a Go pointer as pinned, when the ptr is a Go pointer.
146+
// It will be ignored while try to pin a non-Go pointer,
147+
// and it will be panic while try to unpin a non-Go pointer,
148+
// which should not happen in normal usage.
148149
func setPinned(ptr unsafe.Pointer, pin bool) bool {
149150
span := spanOfHeap(uintptr(ptr))
150151
if span == nil {
151152
if !pin {
152-
panic(errorString("runtime.Pinner.Unpin: unexpected non Go pointer"))
153+
panic(errorString("tried to unpin non-Go pointer"))
153154
}
154-
// this is a linker-allocated, zero size object or other object,
155+
// This is a linker-allocated, zero size object or other object,
155156
// nothing to do, silently ignore it.
156157
return false
157158
}

0 commit comments

Comments
 (0)