From 0e1bd47c531ccc09a73a59f9ba95a411cccf7255 Mon Sep 17 00:00:00 2001
From: Mick Jordan <mick.jordan@oracle.com>
Date: Mon, 29 Aug 2016 21:40:04 -0700
Subject: [PATCH] tools:gramRd.c: abstract Java callback implememtation via
 gramRd_fastr.h

---
 mx.fastr/mx_fastr_dists.py    |  2 +-
 mx.fastr/mx_fastr_mkgramrd.py | 17 ++---------------
 2 files changed, 3 insertions(+), 16 deletions(-)

diff --git a/mx.fastr/mx_fastr_dists.py b/mx.fastr/mx_fastr_dists.py
index c6ee9c06eb..303f1569cd 100644
--- a/mx.fastr/mx_fastr_dists.py
+++ b/mx.fastr/mx_fastr_dists.py
@@ -91,7 +91,7 @@ class DelFastRNativeProject(FastRProjectAdapter):
         gnur_tools_src = join(gnur, 'src', 'library', 'tools', 'src')
         for f in ['gramRd.c', 'init.c', 'tools.h']:
             results.append(join(self.dir, gnur_tools_src, f))
-        for f in ['lib.mk', 'Makefile', 'tools/src/tools_dummy.c', 'tools/Makefile']:
+        for f in ['lib.mk', 'Makefile', 'tools/src/tools_dummy.c', 'tools/src/gramRd_fastr.h', 'tools/Makefile']:
             results.append(join(self.dir, 'library', f))
 
         # selected headers from GNU R source
diff --git a/mx.fastr/mx_fastr_mkgramrd.py b/mx.fastr/mx_fastr_mkgramrd.py
index fdbfebbbb8..fba187ff0e 100644
--- a/mx.fastr/mx_fastr_mkgramrd.py
+++ b/mx.fastr/mx_fastr_mkgramrd.py
@@ -56,15 +56,6 @@ static int Rconn_fgetc(Rconnection con) {
     return -1;
 }
 
-extern JNIEnv *getEnv();
-static jmethodID getcMethodID;
-
-'''
-
-    fastr_getc = '''
-    JNIEnv *env = getEnv();
-    jclass klass = (*env)->FindClass(env, "com/oracle/truffle/r/runtime/conn/RConnection");
-    getcMethodID = (*env)->GetMethodID(env, klass, "getc", "()I");
 '''
 
     c_parserd = '''
@@ -123,17 +114,13 @@ SEXP C_parseRd(SEXP con, SEXP source, SEXP verbose, SEXP fragment, SEXP basename
             elif '#include <Rmath.h>' in sline:
                 line = '//' + line
                 f.write(line)
-                f.write('#include <jni.h>\n')
+                f.write('#include "gramRd_fastr.h"\n')
             elif sline == '#include "Rconnections.h"':
                 line = '//' + line
                 f.write(line)
                 f.write(connect_defs)
             elif 'c = Rconn_fgetc(con_parse);' in sline:
-                f.write('    JNIEnv *env = getEnv();\n')
-                f.write('    c = (*env)->CallIntMethod(env, con_parse, getcMethodID, con_parse);\n')
-            elif 'ptr_getc = con_getc;' in line:
-                f.write(fastr_getc)
-                f.write(line)
+                f.write('    c = callGetCMethod(con_parse);\n')
             elif sline == 'static void con_cleanup(void *data)':
                 # skip
                 i = i + 5
-- 
GitLab