go-wlroots icon indicating copy to clipboard operation
go-wlroots copied to clipboard

Convert C pointers to Go pointers

Open dominikh opened this issue 5 years ago • 1 comments

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.

dominikh avatar Sep 23 '20 20:09 dominikh

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

diamondburned avatar Dec 02 '21 00:12 diamondburned