You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Go garbage collector does not know Go variable(pointer) used in C world. In Go package source code: https://github.com/golang/go/blob/master/src/net/cgo_unix.go#L47 here is a variable "hints" in Go world which is passed into C function getaddrinfo(). Theoretically, is it possible that the address of "hints" is invalid due to Go garbage collection?
The text was updated successfully, but these errors were encountered:
mikioh
changed the title
Will the variable pointer in Go side be invalid during calling C function due to garbage collection?
runtime: Will the variable pointer in Go side be invalid during calling C function due to garbage collection?
Jun 23, 2015
Pointers passed to C by cgo are live until the end of the cgo call. I don't think this needs to be documented as such, at least not until we actually resolve #8310.
@ianlancetaylor From the discussion of #10303 , it seems that the pointer passed to C function does not escape until the fix in http://golang.org/cl/10814. So the problem I mentioned may be a real problem in current released 1.4.1/1.4.2. Is that true?
The 1.4.x and earlier releases are fine. In those releases, cgo generated C code, and pointers passed to C code always escape. Issue #10303 was reported against tip, after cgo had been changed to generate Go code. The fix was to cause the compiler to treat pointers as always escaping, which is exactly what it did in 1.4 and earlier releases.
Go garbage collector does not know Go variable(pointer) used in C world. In Go package source code:
https://github.com/golang/go/blob/master/src/net/cgo_unix.go#L47 here is a variable "hints" in Go world which is passed into C function getaddrinfo(). Theoretically, is it possible that the address of "hints" is invalid due to Go garbage collection?
The text was updated successfully, but these errors were encountered: