Getting "cgo argument has Go pointer to Go pointer"

570 views
Skip to first unread message

David Karr

unread,
Nov 15, 2021, 6:49:20 PM11/15/21
to golang-nuts

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?

David Karr

unread,
Nov 15, 2021, 7:21:15 PM11/15/21
to golang-nuts
Note that all the properties of this structure are set by C functions. All I do is define the variable and pass a pointer to it to functions.

Also, I saw one note that suggesting that setting "GODEBUG=cgocheck=0" might disable this check (not sure if that will help me or not), but I'm using vscode for this, and I don't know how to set the GO environment variables.

Dan Kortschak

unread,
Nov 15, 2021, 8:16:37 PM11/15/21
to golan...@googlegroups.com
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


Reply all
Reply to author
Forward
0 new messages