Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Detect Rversion and starting with version 1.8.0 eliminate the need to

use declarations from non-exported headers. Part of this involved
replacing the call to Rstd_CleanUp() with local code that just
removes the leftover temp directories.
  • Loading branch information...
commit 67be537bb157517715dbc72bf9bc15aa9a65ad3f 1 parent 1eaf6bc
postgres authored
Showing with 34 additions and 25 deletions.
  1. +16 −3 plr.c
  2. +18 −22 plr.h
View
19 plr.c
@@ -183,7 +183,7 @@ load_r_cmd(const char *cmd)
PROTECT(cmdSexp = NEW_CHARACTER(1));
SET_STRING_ELT(cmdSexp, 0, COPY_TO_USER_STRING(cmd));
- PROTECT(cmdexpr = R_ParseVector(cmdSexp, -1, &status));
+ PROTECT(cmdexpr = R_PARSEVECTOR(cmdSexp, -1, &status));
if (status != PARSE_OK) {
UNPROTECT(2);
if (last_R_error_msg)
@@ -230,7 +230,20 @@ load_r_cmd(const char *cmd)
void
plr_cleanup(void)
{
- Rstd_CleanUp(SA_NOSAVE, 0, FALSE);
+ char *buf;
+ char *tmpdir = getenv("R_SESSION_TMPDIR");
+
+ if(tmpdir)
+ {
+ /*
+ * length needed = 'rm -rf ""' == 9
+ * plus 1 for NULL terminator
+ * plus length of dir string
+ */
+ buf = (char *) palloc(9 + 1 + strlen(tmpdir));
+ sprintf(buf, "rm -rf \"%s\"", tmpdir);
+ system(buf);
+ }
}
/*
@@ -1140,7 +1153,7 @@ plr_parse_func_body(const char *body)
PROTECT(rbody = NEW_CHARACTER(1));
SET_STRING_ELT(rbody, 0, COPY_TO_USER_STRING(body));
- PROTECT(fun = VECTOR_ELT(R_ParseVector(rbody, -1, &status), 0));
+ PROTECT(fun = VECTOR_ELT(R_PARSEVECTOR(rbody, -1, &status), 0));
if (status != PARSE_OK)
{
UNPROTECT(2);
View
40 plr.h
@@ -63,6 +63,7 @@
#include "R.h"
#include "Rinternals.h"
#include "Rdefines.h"
+#include "Rversion.h"
#ifdef ERROR
#undef ERROR
@@ -119,7 +120,14 @@
#define NEXT_STR_ELEMENT " %s"
/*
- * See the no-exported header file ${R_HOME}/src/include/Parse.h
+ * R version is calculated thus:
+ * Maj * 65536 + Minor * 256 + Build * 1
+ * So version 1.8.0 results in:
+ * 1 * 65536 + 8 * 256 + 0 * 1 == 67584
+ */
+#if (R_VERSION < 67584)
+/*
+ * See the non-exported header file ${R_HOME}/src/include/Parse.h
*/
extern SEXP R_ParseVector(SEXP, int, int *);
#define PARSE_NULL 0
@@ -128,26 +136,20 @@ extern SEXP R_ParseVector(SEXP, int, int *);
#define PARSE_ERROR 3
#define PARSE_EOF 4
+#define R_PARSEVECTOR(a_, b_, c_) R_ParseVector(a_, b_, c_)
/*
- * See the no-exported header file ${R_HOME}/src/include/Startup.h
+ * See the non-exported header file ${R_HOME}/src/include/Defn.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;
+extern void R_PreserveObject(SEXP);
+extern void R_ReleaseObject(SEXP);
-/*
- * See the no-exported header file ${R_HOME}/src/unix/Runix.h
- */
-extern void Rstd_CleanUp(SA_TYPE saveact, int status, int runLast);
+#else
+#include "R_ext/Parse.h"
+#define R_PARSEVECTOR(a_, b_, c_) R_ParseVector(a_, b_, (ParseStatus *) c_)
+
+#endif /* R_VERSION */
/* convert C string to text pointer */
#define PG_TEXT_GET_STR(textp_) \
@@ -348,12 +350,6 @@ extern void plr_HashTableDelete(plr_function *function);
extern char *get_load_self_ref_cmd(Oid funcid);
extern void perm_fmgr_info(Oid functionId, FmgrInfo *finfo);
-/*
- * See the no-exported header file ${R_HOME}/src/include/Defn.h
- */
-extern void R_PreserveObject(SEXP);
-extern void R_ReleaseObject(SEXP);
-
#ifndef PG_VERSION_73_COMPAT
/*************************************************************************
* working with postgres 7.4 or greater compatible sources
Please sign in to comment.
Something went wrong with that request. Please try again.