summaryrefslogtreecommitdiff
path: root/src/runtime/java/jpgf.c
diff options
context:
space:
mode:
authorkrasimir <krasimir@chalmers.se>2015-09-03 13:52:32 +0000
committerkrasimir <krasimir@chalmers.se>2015-09-03 13:52:32 +0000
commit3328dd1f8dc784021e6bc0350cabc93b44b582c4 (patch)
tree20be3a100fe3274c942aafaf58e7ea159ad0e982 /src/runtime/java/jpgf.c
parentc322e686a0f59ae633918853c1c434fc11fc49ae (diff)
Java API for opening/closing SG databases
Diffstat (limited to 'src/runtime/java/jpgf.c')
-rw-r--r--src/runtime/java/jpgf.c91
1 files changed, 1 insertions, 90 deletions
diff --git a/src/runtime/java/jpgf.c b/src/runtime/java/jpgf.c
index 875f41e80..db7765551 100644
--- a/src/runtime/java/jpgf.c
+++ b/src/runtime/java/jpgf.c
@@ -2,98 +2,9 @@
#include <pgf/linearizer.h>
#include <gu/mem.h>
#include <gu/exn.h>
-#include <gu/utf8.h>
#include <math.h>
#include <jni.h>
-#ifndef __MINGW32__
-#include <alloca.h>
-#else
-#include <malloc.h>
-#endif
-
-#define l2p(x) ((void*) (intptr_t) (x))
-#define p2l(x) ((jlong) (intptr_t) (x))
-
-static jstring
-gu2j_string(JNIEnv *env, GuString s) {
- const char* utf8 = s;
- size_t len = strlen(s);
-
- jchar* utf16 = alloca(len*sizeof(jchar));
- jchar* dst = utf16;
- while (s-utf8 < len) {
- GuUCS ucs = gu_utf8_decode((const uint8_t**) &s);
-
- if (ucs <= 0xFFFF) {
- *dst++ = ucs;
- } else {
- ucs -= 0x10000;
- *dst++ = 0xD800+((ucs >> 10) & 0x3FF);
- *dst++ = 0xDC00+(ucs & 0x3FF);
- }
- }
-
- return (*env)->NewString(env, utf16, dst-utf16);
-}
-
-static GuString
-j2gu_string(JNIEnv *env, jstring s, GuPool* pool) {
- GuString str = (*env)->GetStringUTFChars(env, s, 0);
- GuString copy = gu_string_copy(str, pool);
- (*env)->ReleaseStringUTFChars(env, s, str);
- return copy;
-}
-
-static size_t
-gu2j_string_offset(GuString s, size_t offset) {
- const char* utf8 = s;
- size_t joffset = 0;
- while (utf8-s < offset) {
- gu_utf8_decode((const uint8_t**) &utf8);
- joffset++;
- }
- return joffset;
-}
-
-static size_t
-j2gu_string_offset(GuString s, size_t joffset) {
- const char* utf8 = s;
- while (joffset > 0) {
- gu_utf8_decode((const uint8_t**) &utf8);
- joffset--;
- }
- return utf8-s;
-}
-
-static void*
-get_ref(JNIEnv *env, jobject self) {
- jfieldID refId = (*env)->GetFieldID(env, (*env)->GetObjectClass(env, self), "ref", "J");
- return l2p((*env)->GetLongField(env, self, refId));
-}
-
-static void
-throw_jstring_exception(JNIEnv *env, const char* class_name, jstring msg)
-{
- jclass exception_class = (*env)->FindClass(env, class_name);
- if (!exception_class)
- return;
- jmethodID constrId = (*env)->GetMethodID(env, exception_class, "<init>", "(Ljava/lang/String;)V");
- if (!constrId)
- return;
- jobject exception = (*env)->NewObject(env, exception_class, constrId, msg);
- if (!exception)
- return;
- (*env)->Throw(env, exception);
-}
-
-static void
-throw_string_exception(JNIEnv *env, const char* class_name, const char* msg)
-{
- jstring jmsg = (*env)->NewStringUTF(env, msg);
- if (!jmsg)
- return;
- throw_jstring_exception(env, class_name, jmsg);
-}
+#include "jni_utils.h"
static JavaVM* cachedJVM;