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? -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/e6ea1901-bd1e-4c02-85dc-0071b1ad9dbcn%40googlegroups.com.