-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/cgo: []byte argument has Go pointer to Go pointer #28606
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
cgo isn't clever enough to look at where the arguments are coming from. It should work if you write it as C.f(unsafe.Pointer(&p[0])) |
Hi @ianlancetaylor . Is this something that does not need to be addressed anymore? If so, can we close the issue. If not, I would love to pick it up as a first issue |
As far as I know, this still happens. The program above still fails in the same way. If you want to look at this, that would be great. But I want to caution you that I don't think this will be easy to fix. At the moment I don't really see how to fix it at all. |
Awesome. I'm delighted to investigate it and try some options. Reproducing it first.. |
@ianlancetaylor sorry I have been unavailable for a while due to some unforeseen circumstances.
That would explain why this is able to work just fine as you mentioned earlier when the expressions are combined.
I would love to also look at how the type conversion is implemented. Can you point me in any direction of where this is? Thanks |
The relevant code here is cmd/cgo/gcc.go, around the method I don't think there is going to be any simple fix here. I think that fixing this will require a significant change to how the cgo tool works. |
I believe I may be seeing a variation of this problem with this message:
However, I don't know how to confirm anything. The offending Code: func (ssp *StaticShaderProgram) SetLights(sphereLights []shaderstate.SphereLight) {
numLights := int32(min(MaxLights, len(sphereLights)))
gl.Uniform1i(ssp.uniformNumLightsLocation, numLights)
if len(sphereLights) > 0 {
gl.BindBufferBase(gl.UNIFORM_BUFFER, ssp.uniformBlockBindingIndexUBLights, ssp.uniformBlockBufferUBLights)
gl.BufferSubData(gl.UNIFORM_BUFFER, 0, ssp.uniformBlockBufferSizeUBLights, unsafe.Pointer(&sphereLights[0].Position[0])) // panic!
}
} No luck using pinner, either: var p runtime.Pinner
ptr := &sphereLights[0].Position[0]
p.Pin(ptr)
gl.BufferSubData(gl.UNIFORM_BUFFER, 0, ssp.uniformBlockBufferSizeUBLights, unsafe.Pointer(ptr)) // still panics
p.Unpin() |
Questions are better asked on a forum. See https://go.dev/wiki/Questions. Thanks. I'm not aware of any comprehensive list of cases where this arises. The basic idea is pretty simple: the cgo tool can't handle complex expressions that take the address of a field in a struct, and so it treats a pointer as a pointer to the entire struct. If that struct has other fields that contain Go pointers, you get the cgo error at run time. The workaround is to simplify the expressions of rearrange the struct so that it doesn't contain Go pointers. Note that addresses passed to cgo always escape. |
With Go 1.11 and HEAD:
go version devel +a2a3dd00c9 Thu Sep 13 09:52:57 2018 +0000 darwin/amd64
, the following program:Panics:
I suspect (but cannot yet show that) this is related to the fact that gzip.Writer is passing a []byte to the Write method made out of an array field of the gzip.Writer struct.
The text was updated successfully, but these errors were encountered: