From 8810198cb84fe1eeffe7bac42b1284bf74fb1a1b Mon Sep 17 00:00:00 2001 From: Simon Urbanek Date: Wed, 7 Apr 2021 14:20:51 +1200 Subject: [PATCH] revert 373fd34c to restore compatibility before R 3.6.0 --- DESCRIPTION | 4 +-- src/rJava.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index e70cfc6..96dd453 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -3,9 +3,9 @@ Version: (populated by mkdist!) Title: Low-Level R to Java Interface Author: Simon Urbanek Maintainer: Simon Urbanek -Depends: R (>= 3.6.0), methods +Depends: R (>= 2.5.0), methods Description: Low-level interface to Java VM very much like .C/.Call and friends. Allows creation of objects, calling methods and accessing fields. -License: LGPL-2.1 +License: GPL-2 URL: http://www.rforge.net/rJava/ SystemRequirements: Java JDK 1.2 or higher (for JRI/REngine JDK 1.4 or higher), GNU make BugReports: https://github.com/s-u/rJava/issues diff --git a/src/rJava.c b/src/rJava.c index 6f0368e..deef799 100644 --- a/src/rJava.c +++ b/src/rJava.c @@ -11,6 +11,9 @@ int use_eenv = 1; /* cached environment. Do NOT use directly! Always use getJNIEnv()! */ JNIEnv *eenv; +/* -- hack to get at the current call from C code using contexts */ +#if ( R_VERSION >= R_Version(3, 6, 0) ) + static SEXP getCurrentCall() { SEXP cexp, sys_calls = PROTECT(install("sys.calls")); cexp = PROTECT(lang1(sys_calls)); @@ -26,6 +29,74 @@ static SEXP getCurrentCall() { return R_NilValue; /* (LENGTH(cl) > 0) ? VECTOR_ELT(cl, 0) : R_NilValue; */ } +#elif ( R_VERSION >= R_Version(1, 7, 0) ) +#include + +/* stuff we need to pull for Windows... */ +#ifdef WIN32 +/* this is from gnuwin32/fixed/h/psignal.h */ +#ifndef _SIGSET_T_ +#define _SIGSET_T_ +typedef int sigset_t; +#endif /* Not _SIGSET_T_ */ +typedef struct +{ + jmp_buf jmpbuf; /* Calling environment. */ + int mask_was_saved; /* Saved the signal mask? */ + sigset_t saved_mask; /* Saved signal mask. */ +} sigjmp_buf[1]; +/* we need to set HAVE_POSIX_SETJMP since we don't have config.h on Win */ +#ifndef HAVE_POSIX_SETJMP +#define HAVE_POSIX_SETJMP +#endif +#endif + +#ifdef HAVE_POSIX_SETJMP +#define JMP_BUF sigjmp_buf +#else +#define JMP_BUF jmp_buf +#endif + +#ifndef CTXT_BUILTIN +#define CTXT_BUILTIN 64 +#endif + +typedef struct RCNTXT { /* this RCNTXT structure is only partial since we need to get at "call" - it is safe form R 1.7.0 on */ + struct RCNTXT *nextcontext; /* The next context up the chain <<-- we use this one to skip the .Call/.External call frame */ + int callflag; /* The context "type" <<<-- we use this one to skip the .Call/.External call frame */ + 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 <<<--- we pass this one to the condition */ + SEXP cloenv; /* The environment */ +} RCNTXT; + +#ifndef LibExtern +#define LibExtern extern +#endif + +LibExtern RCNTXT* R_GlobalContext; + +static SEXP getCurrentCall() { + RCNTXT *ctx = R_GlobalContext; + /* skip the .External/.Call context to get at the underlying call */ + if (ctx->nextcontext && (ctx->callflag & CTXT_BUILTIN)) + ctx = ctx->nextcontext; + /* skip .jcheck */ + if (TYPEOF(ctx->call) == LANGSXP && CAR(ctx->call) == install(".jcheck") && ctx->nextcontext) + ctx = ctx->nextcontext; + return ctx->call; +} +#else +static SEXP getCurrentCall() { + return R_NilValue; +} +#endif +/* -- end of hack */ + /** throw an exception using R condition code. * @param msg - message string * @param jobj - jobjRef object of the exception