On Mon, 2021-11-15 at 15:06 -0800, David Karr wrote: > > I'm pretty new to Go (many years in other languages). I'm trying to > use cgo to use a C library we're using. > > I have the following line of code, which is compiling (that's been > enough of a struggle): > > status = int(C.VeProtect(C.VeObj(fpeProtect), &argsProtect)) > > This is failing at runtime with > ------------------------ > panic serving [::1]:55146: runtime error: cgo argument has Go pointer > to Go pointer > goroutine 20 [running]: > net/http.(*conn).serve.func1() > /usr/local/go/src/net/http/server.go:1801 +0x13a > panic({0xc21cc0, 0xc000093700}) > /usr/local/go/src/runtime/panic.go:1047 +0x262 > voltagems/voltagefuncs.protectAndAccess.func1(0x0, 0xc0000b2960) > /media/sf_winhome/git/voltagego/voltagefuncs/voltagefuncs.go:71 > +0x90 > ------------------------ > > The first thing that's frustrating about this error is that I can't > tell which argument it's talking > about. I would guess it's the first one, as it's more complicated > than the second. > > The type of "fpeProtect" is "C.VeFPE", and "C.VeObj" is an alias for > "void*". > > And "C.VeFPE" is defined as: > > type _Ctype_VeFPE *_Ctype_struct_VeFPE_st > > Any suggestions? >
This is described in https://pkg.go.dev/cmd/cgo#hdr-Passing_pointers. Setting GODEBUG=cgocheck=0 will avoid this, but is probably not what you want to do in the long term. If you can allocate and manage the value manually through C, then this will prevent the check since the runtime knows it doesn't need to care about it. You could at least use that approach to determine which of the parameters is causing the problem. Dan -- 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/0bcf15771cf2b8dca25bb2384c245e3dcacfcb70.camel%40kortschak.io.