diff --git a/com.oracle.truffle.r.native/fficall/src/jni/Rembedded.c b/com.oracle.truffle.r.native/fficall/src/jni/Rembedded.c index 4baebf20759b4d068a874bba6c240e998f184fbe..6c00b921468e8aab0d1eb9567b73024266bfa080 100644 --- a/com.oracle.truffle.r.native/fficall/src/jni/Rembedded.c +++ b/com.oracle.truffle.r.native/fficall/src/jni/Rembedded.c @@ -67,6 +67,38 @@ static char **update_environ_with_java_home(void); static void print_environ(char **env); static char *get_classpath(char *r_home); +# define JMP_BUF sigjmp_buf + +/* Evaluation Context Structure */ +typedef struct RCNTXT { + struct RCNTXT *nextcontext; /* The next context up the chain */ + int callflag; /* The context "type" */ + JMP_BUF cjmpbuf; /* C stack and register information */ + int cstacktop; /* Top of the pointer protection stack */ + int evaldepth; /* evaluation depth at inception */ + SEXP promargs; /* Promises supplied to closure */ + SEXP callfun; /* The closure called */ + SEXP sysparent; /* environment the closure was called from */ + SEXP call; /* The call that effected this context*/ + SEXP cloenv; /* The environment */ + SEXP conexit; /* Interpreted "on.exit" code */ + void (*cend)(void *); /* C "on.exit" thunk */ + void *cenddata; /* data for C "on.exit" thunk */ + void *vmax; /* top of R_alloc stack */ + int intsusp; /* interrupts are suspended */ + SEXP handlerstack; /* condition handler stack */ + SEXP restartstack; /* stack of available restarts */ + void *prstack; /* stack of pending promises */ + void *nodestack; +#ifdef BC_INT_STACK + IStackval *intstack; +#endif + SEXP srcref; /* The source line in effect */ + int browserfinish; /* should browser finish this context without stopping */ + SEXP returnValue; /* only set during on.exit calls */ +} RCNTXT, *context; + + int Rf_initialize_R(int argc, char *argv[]) { if (initialized) { fprintf(stderr, "%s", "R is already initialized\n"); @@ -89,6 +121,14 @@ int Rf_initialize_R(int argc, char *argv[]) { if (stat(jvmdir, &statbuf) == 0) { java_home = jvmdir; } + } else if (strcmp(utsname.sysname, "Darwin") == 0) { + char *jvmdir = "/Library/Java/JavaVirtualMachines/jdk.latest"; + struct stat statbuf; + if (stat(jvmdir, &statbuf) == 0) { + java_home = (char*)malloc(strlen(jvmdir) + 32); + strcpy(java_home, jvmdir); + strcat(java_home, "/Contents/Home"); + } } if (java_home == NULL) { printf("Rf_initialize_R: can't find a JAVA_HOME\n"); @@ -159,6 +199,7 @@ int Rf_initialize_R(int argc, char *argv[]) { (*jniEnv)->SetObjectArrayElement(jniEnv, argsArray, i, arg); } + R_GlobalContext = malloc(sizeof(struct RCNTXT)); engine = checkRef(jniEnv, (*jniEnv)->CallStaticObjectMethod(jniEnv, rembeddedClass, initializeMethod, argsArray)); initialized++; return 0;