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

Investigate usage of cgo.Handle for callback handling #18

Open
dignifiedquire opened this issue Sep 26, 2023 · 6 comments
Open

Investigate usage of cgo.Handle for callback handling #18

dignifiedquire opened this issue Sep 26, 2023 · 6 comments
Labels
enhancement New feature or request

Comments

@dignifiedquire
Copy link
Contributor

Should look into using https://pkg.go.dev/runtime/[email protected]#Handle for callback handling, which is the recommended way of dealing with callbacks since go 1.17

https://github.com/golang/go/wiki/cgo#function-variables for reference

@arg0d
Copy link
Contributor

arg0d commented Oct 2, 2023

Looks like a good idea. Would allow to get rid of callback table from Go bindings. But I wonder if the semantics of Handle are safe, i.e. use after calling Handle.Delete(), callling Handle.Delete() multiple times. If these are defined behaviors and result in a panic (unlike C where it would be undefined behavior), then I think we can definitely switch to use Handle.

@arg0d arg0d closed this as completed Oct 2, 2023
@dignifiedquire
Copy link
Contributor Author

@arg0d why did you close the issue?

@arg0d arg0d reopened this Oct 2, 2023
@dignifiedquire
Copy link
Contributor Author

But I wonder if the semantics of Handle are safe, i.e. use after calling Handle.Delete(), callling Handle.Delete() multiple times.

It seems these are meant to be safe. From the docs of Delete: "The method panics if the handle is invalid."

@dignifiedquire
Copy link
Contributor Author

And the same for Value:

Value returns the associated Go value for a valid handle.

The method panics if the handle is invalid.

@arg0d
Copy link
Contributor

arg0d commented Oct 2, 2023

😅 I somehow closed it by accident

@dignifiedquire
Copy link
Contributor Author

Implementation of cgo.Handle is done using a global https://pkg.go.dev/sync#Map

@arg0d arg0d added the enhancement New feature or request label Nov 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants