diff --git a/ase/awk/awk.h b/ase/awk/awk.h index e0df32b6..da678eb1 100644 --- a/ase/awk/awk.h +++ b/ase/awk/awk.h @@ -1,5 +1,5 @@ /* - * $Id: awk.h,v 1.155 2006-11-28 15:09:53 bacon Exp $ + * $Id: awk.h,v 1.156 2006-11-29 02:39:09 bacon Exp $ */ #ifndef _ASE_AWK_AWK_H_ diff --git a/ase/awk/err.c b/ase/awk/err.c index 0047d020..3cfd0cde 100644 --- a/ase/awk/err.c +++ b/ase/awk/err.c @@ -1,5 +1,5 @@ /* - * $Id: err.c,v 1.53 2006-11-28 15:09:53 bacon Exp $ + * $Id: err.c,v 1.54 2006-11-29 02:39:09 bacon Exp $ */ #include diff --git a/ase/awk/func.c b/ase/awk/func.c index cd391226..e68714b6 100644 --- a/ase/awk/func.c +++ b/ase/awk/func.c @@ -1,5 +1,5 @@ /* - * $Id: func.c,v 1.80 2006-11-28 15:09:53 bacon Exp $ + * $Id: func.c,v 1.81 2006-11-29 02:39:09 bacon Exp $ */ #include diff --git a/ase/awk/jni.c b/ase/awk/jni.c index b6fbb0fa..be4519ef 100644 --- a/ase/awk/jni.c +++ b/ase/awk/jni.c @@ -1,5 +1,5 @@ /* - * $Id: jni.c,v 1.30 2006-11-28 15:09:53 bacon Exp $ + * $Id: jni.c,v 1.31 2006-11-29 02:39:09 bacon Exp $ */ #include @@ -17,6 +17,10 @@ #include #endif +#ifdef _MSC_VER +#define snprintf _snprintf +#endif + #ifndef ASE_CHAR_IS_WCHAR #error this module supports ASE_CHAR_IS_WCHAR only #endif @@ -116,8 +120,8 @@ static void __awk_aprintf (const ase_char_t* fmt, ...) va_start (ap, fmt); #if defined(_WIN32) - n = _vsntprintf (buf, ase_countof(buf), fmt, ap); - if (n < 0) buf[ase_countof(buf)-1] = ASE_T('\0'); + n = _vsntprintf (buf, ASE_COUNTOF(buf), fmt, ap); + if (n < 0) buf[ASE_COUNTOF(buf)-1] = ASE_T('\0'); #if defined(_MSC_VER) && (_MSC_VER<1400) MessageBox (NULL, buf, @@ -866,34 +870,6 @@ static ase_ssize_t __process_extio ( return -1; } -JNIEXPORT jint JNICALL Java_ase_awk_Awk_setfilename ( - JNIEnv* env, jobject obj, jlong run_id, jstring name) -{ - ase_awk_run_t* run = (ase_awk_run_t*)run_id; - const jchar* str; - jint len, n; - - str = (*env)->GetStringChars (env, name, JNI_FALSE); - len = (*env)->GetStringLength (env, name); - n = ase_awk_setfilename (run, str, len); - (*env)->ReleaseStringChars (env, name, str); - return n; -} - -JNIEXPORT jint JNICALL Java_ase_awk_Awk_setofilename ( - JNIEnv* env, jobject obj, jlong run_id, jstring name) -{ - ase_awk_run_t* run = (ase_awk_run_t*)run_id; - const jchar* str; - jint len, n; - - str = (*env)->GetStringChars (env, name, JNI_FALSE); - len = (*env)->GetStringLength (env, name); - n = ase_awk_setofilename (run, str, len); - (*env)->ReleaseStringChars (env, name, str); - return n; -} - static int __handle_bfn ( ase_awk_run_t* run, const ase_char_t* fnm, ase_size_t fnl) { @@ -905,7 +881,7 @@ static int __handle_bfn ( run_data_t* run_data; JNIEnv* env; jobject obj; - jint ret, i, nargs; + jint ret, i, j, nargs; jobjectArray args; jobject arg; ase_awk_val_t* v; @@ -984,6 +960,19 @@ static int __handle_bfn ( /* something wrong ... */ } + if (arg == NULL) + { + /* unwinde the local references */ + for (j = 0; j < i; j++) + { + arg = (*env)->GetObjectArrayElement (env, args, i, arg); + if (arg != NULL) (*env)->DeleteLocalRef (env, arg); + } + + /* TODO... */ + return -1; + } + (*env)->SetObjectArrayElement (env, args, i, arg); } @@ -1050,3 +1039,81 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_addbfn ( (*env)->ReleaseStringChars (env, name, str); (*env)->DeleteLocalRef (env, class); } + +JNIEXPORT void JNICALL Java_ase_awk_Awk_delbfn ( + JNIEnv* env, jobject obj, jstring name) +{ + jclass class; + jfieldID fid_handle; + jthrowable except; + + ase_awk_t* awk; + const jchar* str; + jint len; + + class = (*env)->GetObjectClass(env, obj); + + fid_handle = (*env)->GetFieldID (env, class, FIELD_HANDLE, "J"); + if (fid_handle == NULL) + { + (*env)->DeleteLocalRef (env, class); + return; + } + + awk = (ase_awk_t*) (*env)->GetLongField (env, obj, fid_handle); + + str = (*env)->GetStringChars (env, name, JNI_FALSE); + len = (*env)->GetStringLength (env, name); + + if (ase_awk_delbfn (awk, str, len) == -1) + { + char msg[MSG_SIZE]; + int n; + + (*env)->ReleaseStringChars (env, name, str); + (*env)->DeleteLocalRef (env, class); + + except = (*env)->FindClass (env, CLASS_EXCEPTION); + if (except == NULL) return; + + /* TODO: more intuitive message */ + n = snprintf (msg, sizeof(msg), "cannot delete the function"); + if (n < 0 || n >= sizeof(msg)) msg[sizeof(msg)-1] = '\0'; + + (*env)->ThrowNew (env, except, msg); + (*env)->DeleteLocalRef (env, except); + return; + } + + (*env)->ReleaseStringChars (env, name, str); + (*env)->DeleteLocalRef (env, class); +} + +JNIEXPORT jint JNICALL Java_ase_awk_Awk_setfilename ( + JNIEnv* env, jobject obj, jlong run_id, jstring name) +{ + ase_awk_run_t* run = (ase_awk_run_t*)run_id; + const jchar* str; + jint len, n; + + str = (*env)->GetStringChars (env, name, JNI_FALSE); + len = (*env)->GetStringLength (env, name); + n = ase_awk_setfilename (run, str, len); + (*env)->ReleaseStringChars (env, name, str); + return n; +} + +JNIEXPORT jint JNICALL Java_ase_awk_Awk_setofilename ( + JNIEnv* env, jobject obj, jlong run_id, jstring name) +{ + ase_awk_run_t* run = (ase_awk_run_t*)run_id; + const jchar* str; + jint len, n; + + str = (*env)->GetStringChars (env, name, JNI_FALSE); + len = (*env)->GetStringLength (env, name); + n = ase_awk_setofilename (run, str, len); + (*env)->ReleaseStringChars (env, name, str); + return n; +} + diff --git a/ase/awk/jni.def b/ase/awk/jni.def index c5e2d377..9d125961 100644 --- a/ase/awk/jni.def +++ b/ase/awk/jni.def @@ -5,6 +5,8 @@ EXPORTS Java_ase_awk_Awk_close Java_ase_awk_Awk_parse Java_ase_awk_Awk_run + Java_ase_awk_Awk_addbfn + Java_ase_awk_Awk_delbfn Java_ase_awk_Awk_setfilename Java_ase_awk_Awk_setofilename diff --git a/ase/awk/jni.h b/ase/awk/jni.h index 4419a64e..1bbd9d91 100644 --- a/ase/awk/jni.h +++ b/ase/awk/jni.h @@ -1,5 +1,5 @@ /* - * $Id: jni.h,v 1.11 2006-11-27 15:10:34 bacon Exp $ + * $Id: jni.h,v 1.12 2006-11-29 02:39:10 bacon Exp $ */ #ifndef _ASE_AWK_JNI_H_ @@ -18,6 +18,9 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_run (JNIEnv* env, jobject obj); JNIEXPORT void JNICALL Java_ase_awk_Awk_addbfn ( JNIEnv* env, jobject obj, jstring name, jint min_args, jint max_args); +JNIEXPORT void JNICALL Java_ase_awk_Awk_delbfn ( + JNIEnv* env, jobject obj, jstring name); + JNIEXPORT jint JNICALL Java_ase_awk_Awk_setfilename ( JNIEnv* env, jobject obj, jlong run_id, jstring name); JNIEXPORT jint JNICALL Java_ase_awk_Awk_setofilename ( diff --git a/ase/awk/makefile.bcc b/ase/awk/makefile.bcc index 9921ef2d..22131fea 100644 --- a/ase/awk/makefile.bcc +++ b/ase/awk/makefile.bcc @@ -24,7 +24,7 @@ CFLAGS_DEBUG = $(CFLAGS_COMMON) -D_DEBUG CFLAGS = $(CFLAGS_DEBUG) JAVACFLAGS = -classpath ../.. -LDFLAGS = -Tpd -ap -Gn -L"c:\program files\borland\bds\4.0\lib" +LDFLAGS = -Tpd -ap -Gn -c -r -L"c:\program files\borland\bds\4.0\lib" STARTUP = c0d32w.obj LIBS = import32.lib cw32mt.lib @@ -37,7 +37,7 @@ lib: $(C_OBJS) ! jni: $(JNI_OBJS) $(JAVA_OBJS) - $(LD) $(LDFLAGS) $(STARTUP) $(JNI_OBJS),$(OUT).dll,,$(LIBS),, + $(LD) $(LDFLAGS) $(STARTUP) $(JNI_OBJS),$(OUT).dll,,$(LIBS),jni.def, ada: gnatmake -I.. ase-awk diff --git a/ase/awk/makefile.cl b/ase/awk/makefile.cl index 95fee043..a8065006 100644 --- a/ase/awk/makefile.cl +++ b/ase/awk/makefile.cl @@ -17,7 +17,8 @@ CC = cl LD = link JAVAC = javac -CFLAGS = /nologo /O2 /MT /W3 /GR- /Za -I../.. $(JNI_INC) +#CFLAGS = /nologo /O2 /MT /W3 /GR- /Za -I../.. $(JNI_INC) +CFLAGS = /nologo /O2 /MT /W3 /GR- -I../.. $(JNI_INC) JAVACFLAGS = -classpath ../.. all: lib jni @@ -29,7 +30,7 @@ lib: $(C_OBJS) jni: $(JNI_OBJS) $(JAVA_OBJS) $(LD) /dll /def:jni.def /subsystem:windows /version:0.1 /release @<< -/nologo /out:$(OUT).dll $(JNI_OBJS) +/nologo /out:$(OUT).dll $(JNI_OBJS) user32.lib << clean: diff --git a/ase/awk/val.c b/ase/awk/val.c index 0ac3fe45..494b9430 100644 --- a/ase/awk/val.c +++ b/ase/awk/val.c @@ -1,5 +1,5 @@ /* - * $Id: val.c,v 1.93 2006-11-23 14:27:52 bacon Exp $ + * $Id: val.c,v 1.94 2006-11-29 02:39:10 bacon Exp $ */ #include @@ -46,7 +46,7 @@ ase_awk_val_t* ase_awk_makeintval (ase_awk_run_t* run, ase_long_t v) ase_awk_val_int_t* val; if (v >= __awk_int[0].val && - v <= __awk_int[ase_countof(__awk_int)-1].val) + v <= __awk_int[ASE_COUNTOF(__awk_int)-1].val) { return (ase_awk_val_t*)&__awk_int[v-__awk_int[0].val]; } @@ -58,7 +58,7 @@ ase_awk_val_t* ase_awk_makeintval (ase_awk_run_t* run, ase_long_t v) else { val = (ase_awk_val_int_t*) ASE_AWK_MALLOC ( - run->awk, ase_sizeof(ase_awk_val_int_t)); + run->awk, ASE_SIZEOF(ase_awk_val_int_t)); if (val == ASE_NULL) return ASE_NULL; } @@ -82,7 +82,7 @@ ase_awk_val_t* ase_awk_makerealval (ase_awk_run_t* run, ase_real_t v) else { val = (ase_awk_val_real_t*) ASE_AWK_MALLOC ( - run->awk, ase_sizeof(ase_awk_val_real_t)); + run->awk, ASE_SIZEOF(ase_awk_val_real_t)); if (val == ASE_NULL) return ASE_NULL; } @@ -106,7 +106,7 @@ ase_awk_val_t* ase_awk_makestrval ( ase_awk_val_str_t* val; val = (ase_awk_val_str_t*) ASE_AWK_MALLOC ( - run->awk, ase_sizeof(ase_awk_val_str_t)); + run->awk, ASE_SIZEOF(ase_awk_val_str_t)); if (val == ASE_NULL) return ASE_NULL; val->type = ASE_AWK_VAL_STR; @@ -129,7 +129,7 @@ ase_awk_val_t* ase_awk_makestrval_nodup ( ase_awk_val_str_t* val; val = (ase_awk_val_str_t*) ASE_AWK_MALLOC ( - run->awk, ase_sizeof(ase_awk_val_str_t)); + run->awk, ASE_SIZEOF(ase_awk_val_str_t)); if (val == ASE_NULL) return ASE_NULL; val->type = ASE_AWK_VAL_STR; @@ -147,7 +147,7 @@ ase_awk_val_t* ase_awk_makestrval2 ( ase_awk_val_str_t* val; val = (ase_awk_val_str_t*) ASE_AWK_MALLOC ( - run->awk, ase_sizeof(ase_awk_val_str_t)); + run->awk, ASE_SIZEOF(ase_awk_val_str_t)); if (val == ASE_NULL) return ASE_NULL; val->type = ASE_AWK_VAL_STR; @@ -170,7 +170,7 @@ ase_awk_val_t* ase_awk_makerexval ( ase_awk_val_rex_t* val; val = (ase_awk_val_rex_t*) ASE_AWK_MALLOC ( - run->awk, ase_sizeof(ase_awk_val_rex_t)); + run->awk, ASE_SIZEOF(ase_awk_val_rex_t)); if (val == ASE_NULL) return ASE_NULL; val->type = ASE_AWK_VAL_REX; @@ -210,7 +210,7 @@ ase_awk_val_t* ase_awk_makemapval (ase_awk_run_t* run) ase_awk_val_map_t* val; val = (ase_awk_val_map_t*) ASE_AWK_MALLOC ( - run->awk, ase_sizeof(ase_awk_val_map_t)); + run->awk, ASE_SIZEOF(ase_awk_val_map_t)); if (val == ASE_NULL) return ASE_NULL; val->type = ASE_AWK_VAL_MAP; @@ -237,7 +237,7 @@ ase_awk_val_t* ase_awk_makerefval (ase_awk_run_t* run, int id, ase_awk_val_t** a else { val = (ase_awk_val_ref_t*) ASE_AWK_MALLOC ( - run->awk, ase_sizeof(ase_awk_val_ref_t)); + run->awk, ASE_SIZEOF(ase_awk_val_ref_t)); if (val == ASE_NULL) return ASE_NULL; } @@ -258,7 +258,7 @@ ase_bool_t ase_awk_isbuiltinval (ase_awk_val_t* val) val == ase_awk_val_zero || val == ase_awk_val_one || (val >= (ase_awk_val_t*)&__awk_int[0] && - val <= (ase_awk_val_t*)&__awk_int[ase_countof(__awk_int)-1]); + val <= (ase_awk_val_t*)&__awk_int[ASE_COUNTOF(__awk_int)-1]); } void ase_awk_freeval (ase_awk_run_t* run, ase_awk_val_t* val, ase_bool_t cache) @@ -275,7 +275,7 @@ xp_printf (ASE_T("\n"));*/ else if (val->type == ASE_AWK_VAL_INT) { if (cache == ase_true && - run->icache_count < ase_countof(run->icache)) + run->icache_count < ASE_COUNTOF(run->icache)) { run->icache[run->icache_count++] = (ase_awk_val_int_t*)val; @@ -285,7 +285,7 @@ xp_printf (ASE_T("\n"));*/ else if (val->type == ASE_AWK_VAL_REAL) { if (cache == ase_true && - run->rcache_count < ase_countof(run->rcache)) + run->rcache_count < ASE_COUNTOF(run->rcache)) { run->rcache[run->rcache_count++] = (ase_awk_val_real_t*)val; @@ -311,7 +311,7 @@ xp_printf (ASE_T("\n"));*/ else if (val->type == ASE_AWK_VAL_REF) { if (cache == ase_true && - run->fcache_count < ase_countof(run->fcache)) + run->fcache_count < ASE_COUNTOF(run->fcache)) { run->fcache[run->fcache_count++] = (ase_awk_val_ref_t*)val; @@ -511,7 +511,7 @@ static ase_char_t* __val_int_to_str ( if (buf == ASE_NULL) { tmp = ASE_AWK_MALLOC ( - run->awk, 2 * ase_sizeof(ase_char_t)); + run->awk, 2 * ASE_SIZEOF(ase_char_t)); if (tmp == ASE_NULL) { run->errnum = ASE_AWK_ENOMEM; @@ -544,7 +544,7 @@ static ase_char_t* __val_int_to_str ( if (buf == ASE_NULL) { tmp = ASE_AWK_MALLOC ( - run->awk, (l + 1) * ase_sizeof(ase_char_t)); + run->awk, (l + 1) * ASE_SIZEOF(ase_char_t)); if (tmp == ASE_NULL) { run->errnum = ASE_AWK_ENOMEM; diff --git a/ase/macros.h b/ase/macros.h index bcdb0240..9b166892 100644 --- a/ase/macros.h +++ b/ase/macros.h @@ -1,5 +1,5 @@ /* - * $Id: macros.h,v 1.40 2006-11-28 11:47:43 bacon Exp $ + * $Id: macros.h,v 1.41 2006-11-29 02:39:09 bacon Exp $ */ #ifndef _ASE_MACROS_H_ @@ -15,10 +15,11 @@ #endif #define ASE_CHAR_EOF ((ase_cint_t)-1) +#define ASE_UNREFERENCED(x) ((x) = (x)) -#define ase_sizeof(n) (sizeof(n)) -#define ase_countof(n) (sizeof(n) / sizeof(n[0])) -#define ase_offsetof(type,member) ((ase_size_t)&((type*)0)->member) +#define ASE_SIZEOF(n) (sizeof(n)) +#define ASE_COUNTOF(n) (sizeof(n) / sizeof(n[0])) +#define ASE_OFFSETOF(type,member) ((ase_size_t)&((type*)0)->member) #if defined(_WIN32) && defined(ASE_CHAR_IS_WCHAR) && !defined(__LCC__) #define ase_main wmain