Functions for safely extracting pointers from R objects while ensuring the R object remains protected from garbage collection.
Details
When passing R objects to C functions via FFI, we need to:
Extract the underlying pointer (SEXP or data pointer)
Prevent R from garbage collecting the object while we use the pointer
Release the protection when we're done
These helpers use R's R_PreserveObject/R_ReleaseObject mechanism
to prevent GC. The returned external pointer includes a finalizer that
automatically releases the protection when the pointer is no longer used.