That should work. Are you sure that those ellipses (...) does not contain some other pointers?
Brent Bailey a következőt írta (2024. január 8., hétfő, 3:06:35 UTC+1): > 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/bc969a5f-e607-470c-8cfd-bee0aa35b7f7n%40googlegroups.com.