go-wlroots
go-wlroots copied to clipboard
Convert C pointers to Go pointers
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.
I think this PR conflicts with #2. If we pass around C pointers (as Go pointers), then we cannot attach finalizers on them.