From 5c612e4822e55b05cb006c5cc1419db3d98480c5 Mon Sep 17 00:00:00 2001 From: Lukas Stadler <lukas.stadler@oracle.com> Date: Wed, 30 Sep 2015 11:28:12 +0200 Subject: [PATCH] implement R_chk_free, vmaxget/set and DUPLICATE_ATTRIB --- .../fficall/jni/src/alloc.c | 16 +++++++++++++--- .../fficall/jni/src/attrib.c | 9 ++++++--- .../r/runtime/ffi/jnr/CallRFFIHelper.java | 9 +++++++++ 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/com.oracle.truffle.r.native/fficall/jni/src/alloc.c b/com.oracle.truffle.r.native/fficall/jni/src/alloc.c index 3217c993e8..d8aeadae4b 100644 --- a/com.oracle.truffle.r.native/fficall/jni/src/alloc.c +++ b/com.oracle.truffle.r.native/fficall/jni/src/alloc.c @@ -76,15 +76,24 @@ void *R_chk_realloc(void *p, size_t size) { } void R_chk_free(void *p) { - unimplemented("R_chk_free"); + if(p) { + free(p); + } } +int VMAX_MAGIC = 1234; + void* vmaxget(void) { - unimplemented("vmaxget"); +// unimplemented("vmaxget"); + // ignored + return &VMAX_MAGIC; } void vmaxset(const void * x) { - unimplemented("vmaxget"); +// unimplemented("vmaxget"); + if (x != &VMAX_MAGIC) { + unimplemented("vmaxset with different value"); + } } void R_gc(void) { @@ -95,3 +104,4 @@ int R_gc_running() { unimplemented("R_gc_running"); return 0; } + diff --git a/com.oracle.truffle.r.native/fficall/jni/src/attrib.c b/com.oracle.truffle.r.native/fficall/jni/src/attrib.c index f72186fcbc..2d357d13a7 100644 --- a/com.oracle.truffle.r.native/fficall/jni/src/attrib.c +++ b/com.oracle.truffle.r.native/fficall/jni/src/attrib.c @@ -25,16 +25,18 @@ static jclass SEXPTYPEClass; static jmethodID gnuRCodeForObjectMethodID; static jmethodID NAMED_MethodID; +static jmethodID DUPLICATE_ATTRIB_MethodID; void init_attrib(JNIEnv *env) { SEXPTYPEClass = checkFindClass(env, "com/oracle/truffle/r/runtime/gnur/SEXPTYPE"); gnuRCodeForObjectMethodID = checkGetMethodID(env, SEXPTYPEClass, "gnuRCodeForObject", "(Ljava/lang/Object;)I", 1); NAMED_MethodID = checkGetMethodID(env, CallRFFIHelperClass, "NAMED", "(Ljava/lang/Object;)I", 1); + DUPLICATE_ATTRIB_MethodID = checkGetMethodID(env, CallRFFIHelperClass, "DUPLICATE_ATTRIB", "(Ljava/lang/Object;Ljava/lang/Object;)V", 1); } int TYPEOF(SEXP x) { - JNIEnv *thisenv = getEnv(); - return (*thisenv)->CallStaticIntMethod(thisenv, SEXPTYPEClass, gnuRCodeForObjectMethodID, x); + JNIEnv *thisenv = getEnv(); + return (*thisenv)->CallStaticIntMethod(thisenv, SEXPTYPEClass, gnuRCodeForObjectMethodID, x); } SEXP ATTRIB(SEXP x){ @@ -79,6 +81,7 @@ void SET_ATTRIB(SEXP x, SEXP v){ } void DUPLICATE_ATTRIB(SEXP to, SEXP from){ - unimplemented("DUPLICATE_ATTRIB"); + JNIEnv *thisenv = getEnv(); + (*thisenv)->CallStaticVoidMethod(thisenv, CallRFFIHelperClass, DUPLICATE_ATTRIB_MethodID, to, from); } diff --git a/com.oracle.truffle.r.runtime.ffi/src/com/oracle/truffle/r/runtime/ffi/jnr/CallRFFIHelper.java b/com.oracle.truffle.r.runtime.ffi/src/com/oracle/truffle/r/runtime/ffi/jnr/CallRFFIHelper.java index 5a0572fb4e..2501963a3b 100644 --- a/com.oracle.truffle.r.runtime.ffi/src/com/oracle/truffle/r/runtime/ffi/jnr/CallRFFIHelper.java +++ b/com.oracle.truffle.r.runtime.ffi/src/com/oracle/truffle/r/runtime/ffi/jnr/CallRFFIHelper.java @@ -472,6 +472,15 @@ public class CallRFFIHelper { } } + static void DUPLICATE_ATTRIB(Object to, Object from) { + if (from instanceof RAttributable) { + guaranteeInstanceOf(to, RAttributable.class); + RAttributes attributes = ((RAttributable) from).getAttributes(); + ((RAttributable) to).initAttributes(attributes == null ? null : attributes.copy()); + } + // TODO: copy OBJECT? and S4 attributes + } + // Checkstyle: resume method name check static Object validate(Object x) { -- GitLab