Skip to content
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: add ability to run C function pointers in Go #17096

Closed
stgleb opened this issue Sep 14, 2016 · 5 comments

Comments

@stgleb
Copy link
Contributor

commented Sep 14, 2016

Quote from https://golang.org/cmd/cgo/

Calling C function pointers is currently not supported

Is there any plans to add ability to run C function pointers passed to Go code?

@ianlancetaylor ianlancetaylor changed the title Proposal: runtime add ability to run C function pointers in Go cmd/cgo: add ability to run C function pointers in Go Sep 14, 2016

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Sep 14, 2016

If you can work out how to do it safely, then, sure, I don't think anybody would object to adding this feature. I dropped the proposal label because I don't see this as something that needs to go through the proposal process. The problem here is not a concern about whether it is a good idea, but a concern as to whether it is possible at all. A call to a C function needs to change stacks and change the calling convention, so it's not simple.

@stgleb

This comment has been minimized.

Copy link
Contributor Author

commented Sep 14, 2016

@ianlancetaylor Thanks, yep, that might be difficult, i just would like to have it for passing python callbacks wrapped with ctypes.Function to golang code, likewise we can do with C.

@quentinmit

This comment has been minimized.

Copy link
Contributor

commented Sep 14, 2016

If you're willing to write cgo, you can always just write a function in a comment in the cgo file that takes a void* and calls it, no?

@quentinmit quentinmit added this to the Go1.8Maybe milestone Sep 14, 2016

@stgleb

This comment has been minimized.

Copy link
Contributor Author

commented Sep 15, 2016

@quentinmit , do you mean write function signature only? I'm not sure about that, I will be very grateful if you provide a code snippet.

@stgleb

This comment has been minimized.

Copy link
Contributor Author

commented Sep 23, 2016

Thanks, i've found a way to do it, not very straightforward, but works

@stgleb stgleb closed this Sep 23, 2016

@golang golang locked and limited conversation to collaborators Sep 23, 2017

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
5 participants
You can’t perform that action at this time.