Having some trouble with R's garbage collection, when passing objects to C++.
We have the following scenario:
.Call()
)SEXP
type) and returnsR_tryEval()
Between steps 2 and 3, the R function object appears to get garbage-collected by R. This leads to a crash because R_tryEval()
tries to execute something that no longer represents a valid R function object. That's fair, as we haven't done anything to tell R that the function object is still in use...
With that in mind:
R_tryEval()
?(As far as I understand, the PROTECT()
/UNPROTECT()
macros are not an option here because those are supposed to balance out within the same scope. As in, we can't call PROTECT()
when the function is first passed to C++ and then later call UNPROTECT()
after it has been executed.)
I think you're looking for
/* preserve objects across GCs */
void R_PreserveObject(SEXP);
void R_ReleaseObject(SEXP);
in the R_internals.h header.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With