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

Eliminate leaks by modeling lifetimes of C API #10

Closed
onelson opened this issue Jun 30, 2019 · 0 comments · Fixed by #11
Closed

Eliminate leaks by modeling lifetimes of C API #10

onelson opened this issue Jun 30, 2019 · 0 comments · Fixed by #11
Assignees
Milestone

Comments

@onelson
Copy link
Owner

onelson commented Jun 30, 2019

Certain functions in the C API "consume" values to produce new ones, others don't. The values represented in C as jv need to be either consumed or freed by the caller, and this has proven to be a challenge for me, even at such a small scale implementation as I have.

It should be possible to apply the newtype pattern to these pointers, allowing us to impl some useful traits. If not newtype, then at least we'd need a struct to act as a "fat pointer."

I'd like to attempt to impl Drop in terms of calling jv_free() so long as the value hasn't been handed off and consumed. Handing off these values so they can be consumed would indicate that the Drop would need to operate optionally, perhaps using Option<JqValue> internally.

Implementing Clone could perform a jv_copy().

New wrapper functions would need to be written to accept and return the newtypes.

With this new wrapper API, the hope is to eliminate all leaks (as reported by valgrind during work on #9) and hopefully clean up much of the control flow since right now there's a bunch of dancing around result types to ensure cleanup happens on certain values at needed types before functions return. Relying on Drop to do this cleanup should be much more reliable and require much less housekeeping.

@onelson onelson self-assigned this Jun 30, 2019
@onelson onelson added this to the v0.3.1 milestone Jun 30, 2019
onelson added a commit that referenced this issue Jul 1, 2019
Fat pointer style structs to more easily control the frees. Fixes #10
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

Successfully merging a pull request may close this issue.

1 participant