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

Implement structs as a value wrapped around a container type #26

Closed
diamondburned opened this issue Aug 13, 2021 · 0 comments
Closed

Implement structs as a value wrapped around a container type #26

diamondburned opened this issue Aug 13, 2021 · 0 comments

Comments

@diamondburned
Copy link
Owner

Go structs generated should be defined as such:

type Record struct {
	*record
}

type record struct {
	native *C.CType
}

Then, the finalizer can be set like so:

v := &record{native: c}
runtime.SetFinalizer(v, (*record).free)

return &Record{
	record: v,
}

This way, the caller could safely copy Record without worrying about losing
the finalizer. It will also allow the generated Go code to express the same
level of pointers, though this might be trickier than it seems.

The generated record should have a Copy() method explicitly for duplicating
the underlying C value, though, and the method should reset the finalizer, but
some record types already have a _copy() method, so we don't actually need
that.

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

No branches or pull requests

1 participant