diff options
| author | kr.angelov <kr.angelov@gmail.com> | 2013-05-28 13:32:32 +0000 |
|---|---|---|
| committer | kr.angelov <kr.angelov@gmail.com> | 2013-05-28 13:32:32 +0000 |
| commit | bae05df3b040c56f87d331a3f7b58529b1e8a014 (patch) | |
| tree | 44dcd9c116c9f938d713f645e7e556f3ada74a95 /src/runtime/java/jpgf.c | |
| parent | 3147e164536ab6d5221302f09ccab627638f84be (diff) | |
added a test class for the Java API plus a small refinement in the implementation for the binding
Diffstat (limited to 'src/runtime/java/jpgf.c')
| -rw-r--r-- | src/runtime/java/jpgf.c | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/src/runtime/java/jpgf.c b/src/runtime/java/jpgf.c index 4796e32dd..44b72d269 100644 --- a/src/runtime/java/jpgf.c +++ b/src/runtime/java/jpgf.c @@ -4,17 +4,20 @@ JNIEXPORT jobject JNICALL Java_org_grammaticalframework_PGF_readPGF(JNIEnv *env, jclass cls, jstring s) -{ - const char *fpath = (*env)->GetStringUTFChars(env, s, 0); - +{ GuPool* pool = gu_new_pool(); GuPool* tmp_pool = gu_local_pool(); // Create an exception frame that catches all errors. GuExn* err = gu_new_exn(NULL, gu_kind(type), tmp_pool); + const char *fpath = (*env)->GetStringUTFChars(env, s, 0); + // Read the PGF grammar. PgfPGF* pgf = pgf_read(fpath, pool, err); + + (*env)->ReleaseStringUTFChars(env, s, fpath); + if (!gu_ok(err)) { gu_pool_free(pool); gu_pool_free(tmp_pool); @@ -23,9 +26,13 @@ Java_org_grammaticalframework_PGF_readPGF(JNIEnv *env, jclass cls, jstring s) gu_pool_free(tmp_pool); - (*env)->ReleaseStringUTFChars(env, s, fpath); + jmethodID constrId = (*env)->GetMethodID(env, cls, "<init>", "(JJ)V"); - jmethodID constrId = (*env)->GetMethodID(env, cls, "<init>", "(II)V"); + return (*env)->NewObject(env, cls, constrId, (long) pool, (long) pgf); +} - return (*env)->NewObject(env, cls, constrId, (int) pool, (int) pgf); +JNIEXPORT void JNICALL +Java_org_grammaticalframework_PGF_free(JNIEnv* env, jclass cls, jlong pool) +{ + gu_pool_free((GuPool*) pool); } |
