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

Convert C pointers to Go pointers #16

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

dominikh
Copy link
Contributor

Instead of wrapping C pointers in Go structs, wrap C values in Go
structs, then convert C pointers to Go pointers. This lets us use
actual pointers in the API, simplifying things like nil pointer
checks.

We use the notinheap hint for some added safety around C pointer
rules (i.e. users can't accidentally allocate their own wrappers on
the Go heap and pass them to C) and for some added performance (as the
compiler can avoid generating barriers and whatnot when accessing
these pointers.)

Note that this still won't let us set finalizers, as the pointers
aren't managed by Go and thus don't get garbage collected.

Instead of wrapping C pointers in Go structs, wrap C values in Go
structs, then convert C pointers to Go pointers. This lets us use
actual pointers in the API, simplifying things like nil pointer
checks.

We use the notinheap hint for some added safety around C pointer
rules (i.e. users can't accidentally allocate their own wrappers on
the Go heap and pass them to C) and for some added performance (as the
compiler can avoid generating barriers and whatnot when accessing
these pointers.)

Note that this still won't let us set finalizers, as the pointers
aren't managed by Go and thus don't get garbage collected.
@diamondburned
Copy link

I think this PR conflicts with #2. If we pass around C pointers (as Go
pointers), then we cannot attach finalizers on them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants