/// Helper function used by `operations_helper`. Returns a finalizer for custom
/// blocks containing an `Rc<T>`.
Helper function used by `operations_helper`. Returns a finalizer for custom
blocks containing an `Rc`.
Helper function used by ` operations_helper ` . Returns a finalizer for custom blocks containing an ` Rc ` .
extern "C" fn drop_value<T: CamlSerialize>(value: usize) {
    let _: usize = catch_unwind(|| {
        // Safety: We trust here that CustomOperations structs containing this
        // `drop_value` instance will only ever be referenced by custom blocks
        // matching the layout of `CustomBlockOcamlRep`. If that's so, then this
        // function should only be invoked by the OCaml runtime on a pointer to
        // a CustomBlockOcamlRep<T> created by T::to_ocamlrep. Such a pointer
        // would be aligned and valid.
        let custom_block_ptr = value as *mut CustomBlockOcamlRep<T>;
        let custom_block = unsafe { custom_block_ptr.as_mut().unwrap() };
        // The `Rc` will be dropped here, and its reference count will decrease
        // by one (possibly freeing the referenced value).
        // Safety: Since the OCaml runtime will only invoke the finalizer for a
        // value which will never again be used, it is safe to use
        // `drop_in_place` (i.e., our finalizer will only be invoked once, so we
        // won't cause a double-drop).
        unsafe {
            std::ptr::drop_in_place(&mut custom_block.1);
        }
        0
    });
}
extern " " fn drop_value < T : CamlSerialize > ( value : usize ) { let _ : usize = catch_unwind ( | | { // Safety: We trust here that CustomOperations structs containing this // `drop_value` instance will only ever be referenced by custom blocks // matching the layout of `CustomBlockOcamlRep`. If that's so, then this // function should only be invoked by the OCaml runtime on a pointer to // a CustomBlockOcamlRep<T> created by T::to_ocamlrep. Such a pointer // would be aligned and valid. let custom_block_ptr = value as * mut CustomBlockOcamlRep < T > ; let custom_block = unsafe { custom_block_ptr . as_mut ( ) . unwrap ( ) } ; // The `Rc` will be dropped here, and its reference count will decrease // by one (possibly freeing the referenced value). // Safety: Since the OCaml runtime will only invoke the finalizer for a // value which will never again be used, it is safe to use // `drop_in_place` (i.e., our finalizer will only be invoked once, so we // won't cause a double-drop). unsafe { std :: ptr :: drop_in_place ( & mut custom_block . 1 ) ; } 0 } ) ; }
Helper function used by `operations_helper`.
Helper function used by ` operations_helper ` .
value
usize