You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to golang-nuts
I'm trying to pass a pointer to an external C library using Go 1.21 and get the following runtime panic: panic: runtime error: cgo argument has Go pointer to unpinned Go pointer
My first attempt was: var bufferSize int = 0 C.external_library(...,(*C.size_t)(unsafe.Pointer(&bufferSize))) I tried to pin the memory using the Pinner type in the runtime library: var bufferSize int = 0 ptr := &bufferSize var p runtime.Pinner p.Pin(ptr)
C.external_library(...,(*C.size_t)(unsafe.Pointer(ptr))) p.Unpin() which resulted in the same error.
I tried creating the pointer in C as follows: var ptr unsafe.Pointer ptr = C.malloc(C.size_t(4))
C.external_library(...,(*C.size_t)(ptr))
bufferSize := *(*int)(ptr) C.free(ptr) but the error persisted.
What am I doing wrong?
Tamás Gulácsi
unread,
Jan 8, 2024, 3:21:34 AM1/8/24
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to golang-nuts
That should work. Are you sure that those ellipses (...) does not contain some other pointers?