Skip to main content

rebuild_restored

Function rebuild_restored 

Source
pub(crate) unsafe fn rebuild_restored<T: TypedExternal>(
    sexp: SEXP,
    receiver: SEXP,
) -> bool
Expand description

Rebuilds the value of sexp, a pointer without an address, when T has a rebuild hook (#[externalptr(rebuild = path)]) and this version of its crate saved it, or another version did and T opts in with any_version (#2187) and the save carries slot names. Installs the value in sexp. Returns whether sexp holds a value now; false leaves the caller to refuse the pointer as before (another version saved it, another type, no hook, or the hook is already running for sexp).

The hook reads the saved Sidecar slots through Saved, by field name. The installed pointer keeps each saved slot whose field T still has, unless the hook’s struct replaces it (Sidecar::replace), and takes the value the hook’s struct holds for a field the save lacks (install_rebuilt). A failing hook (an Err, or a condition it raises) installs nothing and raises the restored refusal of T (its classes, then RESTORED_NO_VALUE_CLASS and RESTORED_CLASS), the cause as e$parent; the next use tries again. Any other unwind (an R error, a plain panic) carries on.

§Safety

On R’s main thread, with sexp a valid EXTPTRSXP whose address is NULL, rooted for the call; receiver is the object the user called on.