*** empty log message ***

This commit is contained in:
hyung-hwan 2006-11-29 11:41:15 +00:00
parent 60fbc6c172
commit e7d6a32428
3 changed files with 100 additions and 46 deletions

View File

@ -1,5 +1,5 @@
/* /*
* $Id: jni.c,v 1.32 2006-11-29 03:18:18 bacon Exp $ * $Id: jni.c,v 1.33 2006-11-29 11:41:14 bacon Exp $
*/ */
#include <ase/awk/jni.h> #include <ase/awk/jni.h>
@ -64,6 +64,11 @@ struct run_data_t
{ {
JNIEnv* env; JNIEnv* env;
jobject obj; jobject obj;
jclass string_class;
jclass integer_class;
jclass double_class;
jclass object_class;
}; };
static void* __awk_malloc (ase_size_t n, void* custom_data) static void* __awk_malloc (ase_size_t n, void* custom_data)
@ -347,6 +352,17 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_run (JNIEnv* env, jobject obj)
run_data.env = env; run_data.env = env;
run_data.obj = obj; run_data.obj = obj;
/* would global reference be necessary? */
run_data.string_class = (*env)->FindClass (env, "java/lang/String");
run_data.integer_class = (*env)->FindClass (env, "java/lang/Integer");
run_data.double_class = (*env)->FindClass (env, "java/lang/Double");
run_data.object_class = (*env)->FindClass (env, "java/lang/Object");
ASE_AWK_ASSERT (awk, run_data.string_class != NULL);
ASE_AWK_ASSERT (awk, run_data.integer_class != NULL);
ASE_AWK_ASSERT (awk, run_data.double_class != NULL);
ASE_AWK_ASSERT (awk, run_data.object_class != NULL);
runio_data.env = env; runio_data.env = env;
runio_data.obj = obj; runio_data.obj = obj;
@ -366,8 +382,6 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_run (JNIEnv* env, jobject obj)
char msg[MSG_SIZE]; char msg[MSG_SIZE];
int n; int n;
(*env)->DeleteLocalRef (env, class);
except = (*env)->FindClass (env, CLASS_EXCEPTION); except = (*env)->FindClass (env, CLASS_EXCEPTION);
if (except == NULL) return; /* exception thrown */ if (except == NULL) return; /* exception thrown */
@ -377,10 +391,18 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_run (JNIEnv* env, jobject obj)
(*env)->ThrowNew (env, except, msg); (*env)->ThrowNew (env, except, msg);
(*env)->DeleteLocalRef (env, except); (*env)->DeleteLocalRef (env, except);
(*env)->DeleteLocalRef (env, run_data.integer_class);
(*env)->DeleteLocalRef (env, run_data.double_class);
(*env)->DeleteLocalRef (env, run_data.string_class);
(*env)->DeleteLocalRef (env, run_data.object_class);
return; return;
} }
(*env)->DeleteLocalRef (env, class); (*env)->DeleteLocalRef (env, run_data.integer_class);
(*env)->DeleteLocalRef (env, run_data.double_class);
(*env)->DeleteLocalRef (env, run_data.string_class);
(*env)->DeleteLocalRef (env, run_data.object_class);
} }
static ase_ssize_t __java_open_source (JNIEnv* env, jobject obj, int mode) static ase_ssize_t __java_open_source (JNIEnv* env, jobject obj, int mode)
@ -591,6 +613,13 @@ static ase_ssize_t __java_open_extio (
* ret == 0 opened the stream and reached its end * ret == 0 opened the stream and reached its end
* ret == 1 opened the stream. */ * ret == 1 opened the stream. */
extio->handle = (*env)->NewGlobalRef (env, extio_object); extio->handle = (*env)->NewGlobalRef (env, extio_object);
/* TODO: close it...
if (extio->handle == NULL)
{
close it again...
ret = -1;
}
*/
} }
(*env)->DeleteLocalRef (env, extio_object); (*env)->DeleteLocalRef (env, extio_object);
@ -874,18 +903,21 @@ static int __handle_bfn (
ase_awk_run_t* run, const ase_char_t* fnm, ase_size_t fnl) ase_awk_run_t* run, const ase_char_t* fnm, ase_size_t fnl)
{ {
jclass class; jclass class;
jmethodID method; jmethodID method, init;
jthrowable thrown; jthrowable thrown;
jstring name; jstring name;
const char* name_utf; const char* name_utf;
run_data_t* run_data; run_data_t* run_data;
JNIEnv* env; JNIEnv* env;
jobject obj; jobject obj;
jint ret, i, j, nargs; jint i, nargs;
jobjectArray args; jobjectArray args;
jobject arg; jobject arg, ret;
ase_awk_t* awk;
ase_awk_val_t* v; ase_awk_val_t* v;
awk = ase_awk_getrunawk (run);
run_data = ase_awk_getruncustomdata (run); run_data = ase_awk_getruncustomdata (run);
nargs = ase_awk_getnargs (run); nargs = ase_awk_getnargs (run);
@ -919,35 +951,43 @@ static int __handle_bfn (
return -1; return -1;
} }
class = (*env)->FindClass (env, "java/lang/Object"); args = (*env)->NewObjectArray (
if (class == NULL) env, nargs, run_data->object_class, NULL);
{
ase_awk_setrunerrnum (run, ASE_AWK_EINTERNAL);
return -1;
}
args = (*env)->NewObjectArray (env, nargs, class, NULL);
(*env)->DeleteLocalRef (env, class);
if (args == NULL) if (args == NULL)
{ {
ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM); ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM);
return -1; return -1;
} }
/* A LOT OF TODO's HERE */
for (i = 0; i < nargs; i++) for (i = 0; i < nargs; i++)
{ {
v = ase_awk_getarg (run, i); v = ase_awk_getarg (run, i);
if (v->type == ASE_AWK_VAL_NIL) arg = NULL;
{
} if (v->type == ASE_AWK_VAL_INT)
else if (v->type == ASE_AWK_VAL_INT)
{ {
jint jv;
init = (*env)->GetMethodID (env,
run_data->integer_class, "<init>", "(I)V");
ASE_AWK_ASSERT (awk, init != NULL);
jv = ((ase_awk_val_int_t*)v)->val;
arg = (*env)->NewObject (env,
run_data->integer_class, init, jv);
} }
else if (v->type == ASE_AWK_VAL_REAL) else if (v->type == ASE_AWK_VAL_REAL)
{ {
jdouble jv;
init = (*env)->GetMethodID (env,
run_data->double_class, "<init>", "(D)V");
ASE_AWK_ASSERT (awk, init != NULL);
jv = ((ase_awk_val_real_t*)v)->val;
arg = (*env)->NewObject (env,
run_data->double_class, init, jv);
} }
else if (v->type == ASE_AWK_VAL_STR) else if (v->type == ASE_AWK_VAL_STR)
{ {
@ -955,39 +995,45 @@ static int __handle_bfn (
((ase_awk_val_str_t*)v)->buf, ((ase_awk_val_str_t*)v)->buf,
((ase_awk_val_str_t*)v)->len); ((ase_awk_val_str_t*)v)->len);
} }
else
{
/* something wrong ... */
}
if (arg == NULL) if (v->type != ASE_AWK_VAL_NIL && arg == NULL)
{ {
/* unwinde the local references */ (*env)->DeleteLocalRef (env, args);
for (j = 0; j < i; j++) ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM);
{
arg = (*env)->GetObjectArrayElement (env, args, i);
if (arg != NULL) (*env)->DeleteLocalRef (env, arg);
}
/* TODO... */
return -1; return -1;
} }
(*env)->SetObjectArrayElement (env, args, i, arg); (*env)->SetObjectArrayElement (env, args, i, arg);
if (arg != NULL) (*env)->DeleteLocalRef (env, arg);
} }
ret = (*env)->CallObjectMethod (env, obj, method, args); ret = (*env)->CallObjectMethod (env, obj, method, args);
thrown = (*env)->ExceptionOccurred (env); thrown = (*env)->ExceptionOccurred (env);
if (thrown) if (thrown)
{ {
(*env)->ExceptionDescribe (env);
(*env)->ExceptionClear (env); (*env)->ExceptionClear (env);
(*env)->DeleteLocalRef (env, args); (*env)->DeleteLocalRef (env, args);
ase_awk_setrunerrnum (run, ASE_AWK_EINTERNAL); ase_awk_setrunerrnum (run, ASE_AWK_EINTERNAL);
return -1; return -1;
} }
/* TODO ... */
if ((*env)->IsInstanceOf (env, ret, run_data->string_class))
{
ase_awk_setretval (...);
}
else if ((*env)->IsInstanceOf (env, ret, run_data->integer_class))
{
ase_awk_setretval (...);
}
else if ((*env)->IsInstanceOf (env, ret, run_data->double_class))
{
ase_awk_setretval (...);
}
(*env)->DeleteLocalRef (env, args); (*env)->DeleteLocalRef (env, args);
return ret; return 0;
} }
JNIEXPORT void JNICALL Java_ase_awk_Awk_addbfn ( JNIEXPORT void JNICALL Java_ase_awk_Awk_addbfn (

View File

@ -9,22 +9,23 @@ C_OBJS = $(C_SRCS:.c=.obj)
JNI_OBJS = $(JNI_SRCS:.c=.obj) JNI_OBJS = $(JNI_SRCS:.c=.obj)
JAVA_OBJS = $(JAVA_SRCS:.java=.class) JAVA_OBJS = $(JAVA_SRCS:.java=.class)
JNI_INC = \ JNI_INCPATH = \
/I"C:\Program Files\Java\jdk1.5.0_09\include" \ -I"C:\Program Files\Java\jdk1.5.0_09\include" \
/I"C:\Program Files\Java\jdk1.5.0_09\include\win32" -I"C:\Program Files\Java\jdk1.5.0_09\include\win32"
BDS_LIBPATH = -L"c:\program files\borland\bds\4.0\lib"
CC = bcc32 CC = bcc32
LD = ilink32 LD = ilink32
AR = tlib AR = tlib
JAVAC = javac JAVAC = javac
CFLAGS_COMMON = -O2 -WM -WU -RT- -w -I../.. $(JNI_INC) CFLAGS_COMMON = -O2 -WM -WU -RT- -w -q -I../.. $(JNI_INCPATH)
CFLAGS_RELEASE = $(CFLAGS_COMMON) -DNDEBUG CFLAGS_RELEASE = $(CFLAGS_COMMON) -DNDEBUG
CFLAGS_DEBUG = $(CFLAGS_COMMON) -D_DEBUG CFLAGS_DEBUG = $(CFLAGS_COMMON) -D_DEBUG
CFLAGS = $(CFLAGS_DEBUG) CFLAGS = $(CFLAGS_DEBUG)
JAVACFLAGS = -classpath ../.. JAVACFLAGS = -classpath ../..
LDFLAGS = -Tpd -ap -Gn -c -r -L"c:\program files\borland\bds\4.0\lib" LDFLAGS = -Tpd -ap -Gn -c -q $(BDS_LIBPATH)
STARTUP = c0d32w.obj STARTUP = c0d32w.obj
LIBS = import32.lib cw32mt.lib LIBS = import32.lib cw32mt.lib

View File

@ -1,5 +1,5 @@
/* /*
* $Id: Awk.java,v 1.15 2006-11-28 15:09:03 bacon Exp $ * $Id: Awk.java,v 1.16 2006-11-29 11:41:15 bacon Exp $
*/ */
package ase.test.awk; package ase.test.awk;
@ -16,7 +16,7 @@ public class Awk extends ase.awk.StdAwk
{ {
super (); super ();
try { addBuiltinFunction ("sin", 1, 1); } try { addBuiltinFunction ("sin", 1, 10); }
catch (ase.awk.Exception e) { System.out.println (">>>>>> CANNOT ADD sin"); } catch (ase.awk.Exception e) { System.out.println (">>>>>> CANNOT ADD sin"); }
try { addBuiltinFunction ("xxx", 1, 1); } try { addBuiltinFunction ("xxx", 1, 1); }
catch (ase.awk.Exception e) { System.out.println (">>>>>> CANNOT ADD xxx"); } catch (ase.awk.Exception e) { System.out.println (">>>>>> CANNOT ADD xxx"); }
@ -29,8 +29,15 @@ public class Awk extends ase.awk.StdAwk
} }
public Object sin (Object[] args) public Object sin (Object[] args)
{ {
System.out.println ("BFN_SIN: " + (String)args[0]); System.out.println ("<<BFN_SIN>>");
return args[0]; for (int i = 0; i < args.length; i++)
{
System.out.print ("ARG #" + i);
System.out.print (": ");
if (args[i] == null) System.out.println ("nil");
else System.out.println (args[i].toString());
}
return null;
} }
protected String[] getInputConsoleNames () protected String[] getInputConsoleNames ()