Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where do I find the definition of Rf_protect() in R's sources?

Tags:

r

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.

like image 289
nsm Avatar asked Jul 22 '15 17:07

nsm


1 Answers

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.

like image 140
Dirk Eddelbuettel Avatar answered Nov 12 '22 19:11

Dirk Eddelbuettel