You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
Certain functions in the C API "consume" values to produce new ones, others don't. The values represented in C as
jvneed 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
Dropin terms of callingjv_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 theDropwould need to operate optionally, perhaps usingOption<JqValue>internally.Implementing
Clonecould perform ajv_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
valgrindduring 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 onDropto do this cleanup should be much more reliable and require much less housekeeping.The text was updated successfully, but these errors were encountered: