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
Previously the `set_boxed_mut_ptr()` and `set_arc_mut_ptr()` helper fns
used for assigning out parameters across the FFI boundary took `*mut
*mut C` and `*mut *const C` for the destination argument `dst`. Using
these safely required callers always verify that `dst != NULL`. In
practice it's very easy to forget to do this and danger lurks!
We could modify these helpers to do the check itself, but we tend to use
these fns near the end of a function to assign a result in a success
case and we would prefer `NULL` checking happen at the beginning of the
function.
One proposed solution is to modify these setter functions to take `&mut
*mut C` and `&mut *const C`. By using new helper fns to carefully
construct a `&mut` from the input double pointer we can front-load
the `NULL` check and the assignment in the set fns can proceed knowing
there's no possibility for a `NULL` outer pointer.
This commit implements this strategy, updating the argument type of
`set_boxed_mut_ptr` and `set_arc_mut_ptr` to take `&mut (*const|*mut)
C`. New `try_mut_from_ptr_ptr` and `try_ref_from_ptr_ptr` macros allow
converting from `*mut *mut C` and `*mut *const C` to the reference
types, bailing early for `NULL`.
0 commit comments