-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
cmd/cgo: function pointers are assignable #7757
Labels
Comments
cgo uses unsafe.Pointer for function pointers. You can make a constant one of those. http://play.golang.org/p/ked5QOYfx8 |
Interesting example in comment #4. Filed issue #7760. |
I don't think we can use Go consts here, because they need to be known at compile-time, whereas a C function's address won't be known at least until link-time (and possibly not until run-time). However, two possible ways to address this problem (both of which ultimately defer to the Go compiler to reject assignments to C.foo): 1. Instead of emitting C.foo as "_Cfpvar_fp_foo", emit it as "unsafe.Pointer(_Cfpvar_fp_foo)". The explicit conversion would make it non-addressable. (I'd probably actually emit as "_Cgo_pointer(_Cfpvar_fp_foo)" and change the "type _ unsafe.Pointer" in _cgo_gotypes.go to "type _Cgo_pointer unsafe.Pointer" to avoid worrying about whether package "import" is available in the user code.) 2. Emit it as a function call like "_Cfpvar_fp_foo()" and change _Cfpvar_fp_foo into a C function that returns the address of 'foo'. |
CL https://golang.org/cl/118690044 mentions this issue. |
This issue was closed by revision 11016f6. Status changed to Fixed. |
wheatman
pushed a commit
to wheatman/go-akaros
that referenced
this issue
Jun 25, 2018
Fixes golang#7757. Fixes golang#8488. LGTM=iant R=iant CC=golang-codereviews https://golang.org/cl/118690044
wheatman
pushed a commit
to wheatman/go-akaros
that referenced
this issue
Jul 9, 2018
Fixes golang#7757. Fixes golang#8488. LGTM=iant R=iant CC=golang-codereviews https://golang.org/cl/118690044
This issue was closed.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
The text was updated successfully, but these errors were encountered: