I am reading R sources and trying to learn about the Heap Structure. I'm looking for the definition of PROTECT(), but I've founded:
$ grep -rn "#define PROTECT(" *
src/include/Rinternals.h:642:#define PROTECT(s) Rf_protect(s)
and then
$ grep -rn "Rf_protect(" *
src/include/Rinternals.h:803:SEXP Rf_protect(SEXP);
src/include/Rinternals.h:1267:SEXP Rf_protect(SEXP);
But I didn't find Rf_protect()'s definition.
Thanks.
The Rf_
prefix is a common idiom giving this plain C code the resemblance of a namespace. So you want to look for protect(...)
instead:
/usr/share/R/include/Rinternals.h:#define protect Rf_protect
And given how 'core' this, you may as well start in src/main
where a quick grep -c
leads you to src/main/memory.c
. Et voila on lines 3075 to 3081
SEXP protect(SEXP s)
{
if (R_PPStackTop >= R_PPStackSize)
R_signal_protect_error();
R_PPStack[R_PPStackTop++] = CHK(s);
return s;
}
Now that said, you probably want to pay attention to most of the file and not just this function.
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