Skip to main content

checked_prot

Function checked_prot 

Source
unsafe fn checked_prot<'a, T: TypedExternal>(
    receiver: SEXP,
    require_live: bool,
) -> (SEXP, Option<&'a RefCell<T>>)
Expand description

The prot list of the external pointer x carries (sidecar_receiver), after checking that it points to a T, and the live T’s RefCell when it still has an address. Allocates nothing for a pointer, a list or an environment receiver.

A live pointer is checked by Any::downcast. A pointer whose address is NULL (restored from a saved session by readRDS() / unserialize()) still holds its sidecar values, so without require_live it is accepted when its stored type ID is T’s; one another version of the crate saved is refused with the classed RESTORED_OTHER_VERSION_CLASS error. With require_live (the field methods of r_data_accessors) every restored pointer is refused through refuse_restored, so a save by this version gets RESTORED_NO_VALUE_CLASS.

§Panics

When x carries no external pointer to a T, or, with require_live, no live one.

§Safety

Must be called from R’s main thread with a valid x.