Permalink
Browse files

Change start_interp from static to extern so that it can be called by…

… the

Postmaster during startup. This allows PL/R and R itself to be loaded and
initialized before backends are forked, saving the startup time for each
backend.

Check for R_HOME defined in the environment and refuse to start if it isn't.
If we don't, R will, and when it unexpectedly exits, we segfault.
  • Loading branch information...
1 parent b24c203 commit ca45a88bd6e8bac9e271d54556627b69fb1674e8 postgres committed Feb 13, 2003
Showing with 9 additions and 2 deletions.
  1. +8 −2 plr.c
  2. +1 −0 plr.h
View
10 plr.c
@@ -198,7 +198,6 @@ typedef struct plr_hashent
/*
* static declarations
*/
-static void start_interp(void);
static void plr_init_interp(Oid funcid);
static void plr_init_all(Oid funcid);
static void plr_init_load_modules(void);
@@ -284,16 +283,23 @@ load_r_cmd(const char *cmd)
/*
* start_interp() - start embedded R
*/
-static void
+void
start_interp(void)
{
+ char *r_home;
int argc;
char *argv[] = {"PL/R", "--gui=none", "--silent", "--no-save"};
/* refuse to start more than once */
if (plr_interp_started == true)
return;
+ /* refuse to start if R_HOME is not defined */
+ r_home = getenv("R_HOME");
+ if (r_home == NULL)
+ elog(ERROR, "plr: cannot start interpreter unless R_HOME " \
+ "environment variable is defined");
+
argc = sizeof(argv)/sizeof(argv[0]);
Rf_initEmbeddedR(argc, argv);
plr_interp_started = true;
View
1 plr.h
@@ -151,6 +151,7 @@ extern int Rf_initEmbeddedR(int argc, char **argv);
/* PL/R language handler */
extern Datum plr_call_handler(PG_FUNCTION_ARGS);
+extern void start_interp(void);
extern void load_r_cmd(const char *cmd);
extern SEXP call_r_func(SEXP fun, SEXP rargs);

0 comments on commit ca45a88

Please sign in to comment.