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
Closed

cmd/cgo: add ability to run C function pointers in Go #17096

stgleb opened this issue Sep 14, 2016 · 5 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@stgleb
Copy link
Contributor

stgleb 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
Copy link
Contributor

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
Copy link
Contributor Author

stgleb 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.

@bradfitz bradfitz added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Sep 14, 2016
@quentinmit
Copy link
Contributor

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
Copy link
Contributor Author

stgleb 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
Copy link
Contributor Author

stgleb commented Sep 23, 2016

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

@stgleb stgleb closed this as completed 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.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

5 participants