Joe Conway
2003-Aug-24 18:57 UTC
[Rd] declarations in non-exported headers and embedding R
Hello, I've been using R embedded in PL/R (R procedural language handler for PostgreSQL, http://www.joeconway.com/plr/) very successfully for several months now. A sincere "thank you" goes to the R development team for such a great product. I have a question I'm hoping someone here can help me with. In order to get the required functionality out of PL/R, I've had to resort to using some defines and declarations that are only available in non-exported headers. There is precedent, of a sort, for most of what I've used in the tests/Embedding source. Below I'll present the header code I've used, where it comes from, why I've used it, and where I saw it used in tests/Embedding. My question is whether there is equivalent exported functionality that I'm missing? Or if not, would a patch be accepted that moves this functionality to an exported header? Thanks, Joe ==========================================================Here are the specifics: ----------------------------------------------------------- From non-exported header file ${R_HOME}/src/include/Parse.h ----------------------------------------------------------- extern SEXP R_ParseVector(SEXP, int, int *); #define PARSE_NULL 0 #define PARSE_OK 1 #define PARSE_INCOMPLETE 2 #define PARSE_ERROR 3 #define PARSE_EOF 4 ----------------------------------------------------------- From non-exported header file ${R_HOME}/src/include/Defn.h ----------------------------------------------------------- extern void R_PreserveObject(SEXP); extern void R_ReleaseObject(SEXP); Use: ------------- The first time a PL/R function is called, the R function is built and parsed using R_ParseVector(), then cached for subsequent calls. Without R_PreserveObject() garbage collection destroys the object while PL/R is still trying to use it. R_ReleaseObject() is needed to release the object for garbage collection if the cached copy becomes invalid. Note: ------------- Similar use of R_ParseVector() found in ${R_HOME}/tests/Embedding/RParseEval.c Similar use of R_PreserveObject() found in ${R_HOME}/tests/Embedding/Rshutdown.c ------------------------------------------------------------- from non-exported header file ${R_HOME}/src/include/Startup.h ------------------------------------------------------------- /* Startup Actions */ typedef enum { SA_NORESTORE,/* = 0 */ SA_RESTORE, SA_DEFAULT,/* was === SA_RESTORE */ SA_NOSAVE, SA_SAVE, SA_SAVEASK, SA_SUICIDE } SA_TYPE; ------------------------------------------------------------- from non-exported header file ${R_HOME}/src/unix/Runix.h ------------------------------------------------------------- extern void Rstd_CleanUp(SA_TYPE saveact, int status, int runLast); Use: ------------- When the PostgreSQL backend process exits, Rstd_CleanUp() is called via registered onexit callback so that the embedded R interpreter can clean up (e.g. to remove the created Rtmp[pid] directory). Note: ------------- Similar use found in ${R_HOME}/tests/Embedding/Rerror.c
Peter Dalgaard BSA
2003-Aug-24 20:19 UTC
[Rd] declarations in non-exported headers and embedding R
Joe Conway <mail@joeconway.com> writes:> Hello, > > I've been using R embedded in PL/R (R procedural language handler for > PostgreSQL, http://www.joeconway.com/plr/) very successfully for > several months now. A sincere "thank you" goes to the R development > team for such a great product. > > I have a question I'm hoping someone here can help me with. In order > to get the required functionality out of PL/R, I've had to resort to > using some defines and declarations that are only available in > non-exported headers. There is precedent, of a sort, for most of what > I've used in the tests/Embedding source. Below I'll present the header > code I've used, where it comes from, why I've used it, and where I saw > it used in tests/Embedding. > > My question is whether there is equivalent exported functionality that > I'm missing? Or if not, would a patch be accepted that moves this > functionality to an exported header?Some of it is certainly a well-known shortcoming of the set of exports. E.g. tcltk.c has had /* From Parse.h -- must find better solution: */ #define PARSE_NULL 0 #define PARSE_OK 1 #define PARSE_INCOMPLETE 2 #define PARSE_ERROR 3 #define PARSE_EOF 4 SEXP R_ParseVector(SEXP, int, int *); for a couple of years (not that it gets much use since that interface is mostly in the opposite direction). Adding an Rembedding.h or so could be a good idea. However, it's not really my field of expertise and a couple ofother R core members might have strong opinions on what should be made available and how... -p -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk) FAX: (+45) 35327907