diff --git a/ase/awk/Awk.java b/ase/awk/Awk.java index a24c3826..e5644d75 100644 --- a/ase/awk/Awk.java +++ b/ase/awk/Awk.java @@ -1,5 +1,5 @@ /* - * $Id: Awk.java,v 1.19 2007-01-23 14:23:17 bacon Exp $ + * $Id: Awk.java,v 1.20 2007-01-24 11:54:15 bacon Exp $ */ package ase.awk; @@ -71,11 +71,14 @@ public abstract class Awk private native int getmaxdepth (int id); private native int setmaxdepth (int id, int depth); - private native void addbfn (String name, int min_args, int max_args) throws Exception; + private native void addbfn ( + String name, int min_args, int max_args) throws Exception; private native void delbfn (String name) throws Exception; - private native int setfilename (long runid, String name); - private native int setofilename (long runid, String name); + private native void setfilename ( + long runid, String name) throws Exception; + private native void setofilename ( + long runid, String name) throws Exception; private native Object strtonum (long runid, String str); private native String valtostr (long runid, Object obj); @@ -181,18 +184,12 @@ public abstract class Awk /* TODO: setfilename is not safe. for example, it can * crash the program if runid is invalid. so this wrapper * needs to do some sanity check. */ - if (setfilename (extio.getRunId(), name) == -1) - { - throw new Exception ("cannot set console input name"); - } + setfilename (extio.getRunId(), name); } protected void setConsoleOutputName (Extio extio, String name) throws Exception { - if (setofilename (extio.getRunId(), name) == -1) - { - throw new Exception ("cannot set console output name"); - } + setofilename (extio.getRunId(), name); } /* == depth limiting == */ diff --git a/ase/awk/jni.c b/ase/awk/jni.c index 5bb3716f..8bcf0730 100644 --- a/ase/awk/jni.c +++ b/ase/awk/jni.c @@ -1,5 +1,5 @@ /* - * $Id: jni.c,v 1.51 2007-01-23 14:23:18 bacon Exp $ + * $Id: jni.c,v 1.52 2007-01-24 11:54:16 bacon Exp $ */ #include @@ -1487,7 +1487,7 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_setmaxdepth ( ase_awk_setmaxdepth (awk, ids, depth); } -JNIEXPORT jint JNICALL Java_ase_awk_Awk_setfilename ( +JNIEXPORT void JNICALL Java_ase_awk_Awk_setfilename ( JNIEnv* env, jobject obj, jlong runid, jstring name) { ase_awk_run_t* run = (ase_awk_run_t*)runid; @@ -1497,7 +1497,15 @@ JNIEXPORT jint JNICALL Java_ase_awk_Awk_setfilename ( len = (*env)->GetStringLength (env, name); ptr = (*env)->GetStringChars (env, name, JNI_FALSE); - if (ptr == NULL) return -1; + if (ptr == NULL) + { + throw_exception ( + env, + ASE_T("out of memory"), + ASE_AWK_ENOMEM, + 0); + return; + } if (ASE_SIZEOF(jchar) != ASE_SIZEOF(ase_char_t)) { @@ -1507,8 +1515,13 @@ JNIEXPORT jint JNICALL Java_ase_awk_Awk_setfilename ( if (tmp == ASE_NULL) { (*env)->ReleaseStringChars (env, name, ptr); - ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM); - return -1; + + throw_exception ( + env, + ASE_T("out of memory"), + ASE_AWK_ENOMEM, + 0); + return; } for (i = 0; i < len; i++) tmp[i] = (ase_char_t)ptr[i]; @@ -1521,10 +1534,18 @@ JNIEXPORT jint JNICALL Java_ase_awk_Awk_setfilename ( } (*env)->ReleaseStringChars (env, name, ptr); - return n; + + if (n == -1) + { + throw_exception ( + env, + ase_awk_getrunerrmsg(run), + ase_awk_getrunerrnum(run), + ase_awk_getrunerrlin(run)); + } } -JNIEXPORT jint JNICALL Java_ase_awk_Awk_setofilename ( +JNIEXPORT void JNICALL Java_ase_awk_Awk_setofilename ( JNIEnv* env, jobject obj, jlong runid, jstring name) { ase_awk_run_t* run = (ase_awk_run_t*)runid; @@ -1534,7 +1555,15 @@ JNIEXPORT jint JNICALL Java_ase_awk_Awk_setofilename ( len = (*env)->GetStringLength (env, name); ptr = (*env)->GetStringChars (env, name, JNI_FALSE); - if (ptr == NULL) return -1; + if (ptr == NULL) + { + throw_exception ( + env, + ASE_T("out of memory"), + ASE_AWK_ENOMEM, + 0); + return; + } if (ASE_SIZEOF(jchar) != ASE_SIZEOF(ase_char_t)) { @@ -1544,8 +1573,13 @@ JNIEXPORT jint JNICALL Java_ase_awk_Awk_setofilename ( if (tmp == ASE_NULL) { (*env)->ReleaseStringChars (env, name, ptr); - ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM); - return -1; + + throw_exception ( + env, + ASE_T("out of memory"), + ASE_AWK_ENOMEM, + 0); + return; } for (i = 0; i < len; i++) tmp[i] = (ase_char_t)ptr[i]; @@ -1558,7 +1592,15 @@ JNIEXPORT jint JNICALL Java_ase_awk_Awk_setofilename ( } (*env)->ReleaseStringChars (env, name, ptr); - return n; + + if (n == -1) + { + throw_exception ( + env, + ase_awk_getrunerrmsg(run), + ase_awk_getrunerrnum(run), + ase_awk_getrunerrlin(run)); + } } JNIEXPORT jobject JNICALL Java_ase_awk_Awk_strtonum ( diff --git a/ase/awk/jni.h b/ase/awk/jni.h index 256e9277..eef6fa76 100644 --- a/ase/awk/jni.h +++ b/ase/awk/jni.h @@ -1,5 +1,5 @@ /* - * $Id: jni.h,v 1.15 2007-01-23 14:23:18 bacon Exp $ + * $Id: jni.h,v 1.16 2007-01-24 11:54:16 bacon Exp $ */ #ifndef _ASE_AWK_JNI_H_ @@ -26,9 +26,9 @@ JNIEXPORT jint JNICALL Java_ase_awk_Awk_getmaxdepth ( JNIEXPORT void JNICALL Java_ase_awk_Awk_setmaxdepth ( JNIEnv* env, jobject obj, jint ids, jint depth); -JNIEXPORT jint JNICALL Java_ase_awk_Awk_setfilename ( +JNIEXPORT void JNICALL Java_ase_awk_Awk_setfilename ( JNIEnv* env, jobject obj, jlong runid, jstring name); -JNIEXPORT jint JNICALL Java_ase_awk_Awk_setofilename ( +JNIEXPORT void JNICALL Java_ase_awk_Awk_setofilename ( JNIEnv* env, jobject obj, jlong runid, jstring name); JNIEXPORT jobject JNICALL Java_ase_awk_Awk_strtonum ( JNIEnv* env, jobject obj, jlong runid, jstring str);