*** empty log message ***

This commit is contained in:
hyung-hwan 2007-01-24 14:21:30 +00:00
parent 6525f98cda
commit 99bb5ee025
5 changed files with 115 additions and 83 deletions

View File

@ -1,5 +1,5 @@
/*
* $Id: Awk.java,v 1.20 2007-01-24 11:54:15 bacon Exp $
* $Id: Awk.java,v 1.21 2007-01-24 14:21:29 bacon Exp $
*/
package ase.awk;
@ -57,8 +57,9 @@ public abstract class Awk
}
/* == just in case == */
protected void finalize ()
protected void finalize () throws Throwable
{
super.finalize ();
if (handle != 0) close ();
}
@ -69,7 +70,7 @@ public abstract class Awk
public native void run () throws Exception;
private native int getmaxdepth (int id);
private native int setmaxdepth (int id, int depth);
private native void setmaxdepth (int id, int depth);
private native void addbfn (
String name, int min_args, int max_args) throws Exception;
@ -80,7 +81,8 @@ public abstract class Awk
private native void setofilename (
long runid, String name) throws Exception;
private native Object strtonum (long runid, String str);
private native Object strtonum (
long runid, String str) throws Exception;
private native String valtostr (long runid, Object obj);
/* == builtin functions == */
@ -95,7 +97,8 @@ public abstract class Awk
delbfn (name);
}
protected long builtinFunctionArgumentToLong (long runid, Object obj)
protected long builtinFunctionArgumentToLong (
long runid, Object obj) throws Exception
{
long n;
@ -131,7 +134,8 @@ public abstract class Awk
return n;
}
protected double builtinFunctionArgumentToDouble (long runid, Object obj)
protected double builtinFunctionArgumentToDouble (
long runid, Object obj) throws Exception
{
double n;
@ -167,7 +171,8 @@ public abstract class Awk
return n;
}
protected String builtinFunctionArgumentToString (long runid, Object obj)
protected String builtinFunctionArgumentToString (
long runid, Object obj) throws Exception
{
String str;
@ -179,7 +184,8 @@ public abstract class Awk
}
/* == console name setters == */
protected void setConsoleInputName (Extio extio, String name) throws Exception
protected void setConsoleInputName (
Extio extio, String name) throws Exception
{
/* TODO: setfilename is not safe. for example, it can
* crash the program if runid is invalid. so this wrapper
@ -187,7 +193,8 @@ public abstract class Awk
setfilename (extio.getRunId(), name);
}
protected void setConsoleOutputName (Extio extio, String name) throws Exception
protected void setConsoleOutputName (
Extio extio, String name) throws Exception
{
setofilename (extio.getRunId(), name);
}

View File

@ -62,8 +62,8 @@ public class Extio
return this.handle;
}
protected void finalize ()
protected void finalize () throws Throwable
{
System.out.println ("Extio being finalized....");
super.finalize ();
}
};

View File

@ -1,5 +1,5 @@
/*
* $Id: StdAwk.java,v 1.11 2007-01-23 14:23:18 bacon Exp $
* $Id: StdAwk.java,v 1.12 2007-01-24 14:21:29 bacon Exp $
*/
package ase.awk;
@ -707,44 +707,44 @@ public abstract class StdAwk extends Awk
/* == arithmetic built-in functions */
public Object sin (long runid, Object[] args)
public Object sin (long runid, Object[] args) throws Exception
{
double x = builtinFunctionArgumentToDouble (runid, args[0]);
return new Double (Math.sin(x));
}
public Object cos (long runid, Object[] args)
public Object cos (long runid, Object[] args) throws Exception
{
double x = builtinFunctionArgumentToDouble (runid, args[0]);
return new Double (Math.cos(x));
}
public Object tan (long runid, Object[] args)
public Object tan (long runid, Object[] args) throws Exception
{
double x = builtinFunctionArgumentToDouble (runid, args[0]);
return new Double (Math.tan(x));
}
public Object atan2 (long runid, Object[] args)
public Object atan2 (long runid, Object[] args) throws Exception
{
double y = builtinFunctionArgumentToDouble (runid, args[0]);
double x = builtinFunctionArgumentToDouble (runid, args[1]);
return new Double (Math.atan2(y,x));
}
public Object log (long runid, Object[] args)
public Object log (long runid, Object[] args) throws Exception
{
double x = builtinFunctionArgumentToDouble (runid, args[0]);
return new Double (Math.log(x));
}
public Object exp (long runid, Object[] args)
public Object exp (long runid, Object[] args) throws Exception
{
double x = builtinFunctionArgumentToDouble (runid, args[0]);
return new Double (Math.exp(x));
}
public Object sqrt (long runid, Object[] args)
public Object sqrt (long runid, Object[] args) throws Exception
{
double x = builtinFunctionArgumentToDouble (runid, args[0]);
return new Double (Math.sqrt(x));
@ -755,7 +755,7 @@ public abstract class StdAwk extends Awk
return new Double (random.nextDouble ());
}
public Object srand (long runid, Object[] args)
public Object srand (long runid, Object[] args) throws Exception
{
long prev_seed = seed;
@ -768,7 +768,7 @@ public abstract class StdAwk extends Awk
}
/* miscellaneous built-in functions */
public Object system (long runid, Object[] args)
public Object system (long runid, Object[] args) throws Exception
{
String str = builtinFunctionArgumentToString (runid, args[0]);
Process proc = null;

View File

@ -1,5 +1,5 @@
/*
* $Id: jni.c,v 1.52 2007-01-24 11:54:16 bacon Exp $
* $Id: jni.c,v 1.53 2007-01-24 14:21:29 bacon Exp $
*/
#include <stdio.h>
@ -13,7 +13,6 @@
#include <ase/awk/jni.h>
#include <ase/awk/awk.h>
#include <ase/awk/val.h>
//#include <ase/awk/awk_i.h>
#include "../etc/printf.c"
@ -204,10 +203,13 @@ static void throw_exception (
{
(*env)->DeleteLocalRef (env, except_class);
except_class = (*env)->FindClass (env, CLASS_OUTOFMEMORYERROR);
except_class = (*env)->FindClass (
env, CLASS_OUTOFMEMORYERROR);
if (except_class == NULL) return;
(*env)->ThrowNew (env, except_class, "out of memory");
(*env)->ThrowNew (
env, except_class,
ase_awk_geterrstr(ASE_AWK_ENOMEM));
(*env)->DeleteLocalRef (env, except_class);
return;
}
@ -291,11 +293,9 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_open (JNIEnv* env, jobject obj)
(*env)->DeleteLocalRef (env, class);
if (handle == NULL)
{
throw_exception (
env,
ASE_T("no handle field found"),
ASE_AWK_EINTERN,
0);
/* internal error. no handle field
* NoSuchFieldError, ExceptionInitializerError,
* OutOfMemoryError might occur */
return;
}
@ -318,7 +318,9 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_close (JNIEnv* env, jobject obj)
(*env)->DeleteLocalRef (env, class);
if (handle == NULL)
{
/* internal error. no handle field */
/* internal error. no handle field
* NoSuchFieldError, ExceptionInitializerError,
* OutOfMemoryError might occur */
return;
}
@ -345,11 +347,9 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_parse (JNIEnv* env, jobject obj)
(*env)->DeleteLocalRef (env, class);
if (handle == NULL)
{
throw_exception (
env,
ASE_T("no handle field found"),
ASE_AWK_EINTERN,
0);
/* internal error. no handle field
* NoSuchFieldError, ExceptionInitializerError,
* OutOfMemoryError might occur */
return;
}
@ -397,11 +397,9 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_run (JNIEnv* env, jobject obj)
(*env)->DeleteLocalRef (env, class);
if (handle == 0)
{
throw_exception (
env,
ASE_T("no handle field found"),
ASE_AWK_EINTERN,
0);
/* internal error. no handle field
* NoSuchFieldError, ExceptionInitializerError,
* OutOfMemoryError might occur */
return;
}
@ -627,8 +625,7 @@ static ase_ssize_t __java_write_source (
thrown = (*env)->ExceptionOccurred (env);
if (thrown)
{
/* TODO: remove the following line */
(*env)->ExceptionDescribe (env);
if (awk->debug) (*env)->ExceptionDescribe (env);
(*env)->ExceptionClear (env);
ret = -1;
}
@ -863,7 +860,6 @@ static ase_ssize_t __java_flush_extio (
{
jclass class;
jmethodID mid;
jthrowable thrown;
jint ret;
class = (*env)->GetObjectClass(env, obj);
@ -875,10 +871,9 @@ static ase_ssize_t __java_flush_extio (
}
ret = (*env)->CallIntMethod (env, obj, mid, extio->handle);
thrown = (*env)->ExceptionOccurred (env);
if (thrown)
if ((*env)->ExceptionOccurred (env))
{
(*env)->ExceptionDescribe (env);
if (awk->debug) (*env)->ExceptionDescribe (env);
(*env)->ExceptionClear (env);
ret = -1;
}
@ -891,7 +886,6 @@ static ase_ssize_t __java_next_extio (
{
jclass class;
jmethodID mid;
jthrowable thrown;
jint ret;
class = (*env)->GetObjectClass(env, obj);
@ -903,10 +897,9 @@ static ase_ssize_t __java_next_extio (
}
ret = (*env)->CallIntMethod (env, obj, mid, extio->handle);
thrown = (*env)->ExceptionOccurred (env);
if (thrown)
if ((*env)->ExceptionOccurred (env))
{
(*env)->ExceptionDescribe (env);
if (awk->debug) (*env)->ExceptionDescribe (env);
(*env)->ExceptionClear (env);
ret = -1;
}
@ -1055,9 +1048,7 @@ static int __handle_bfn (
if (name == NULL)
{
if ((*env)->ExceptionOccurred (env))
(*env)->ExceptionClear (env);
(*env)->ExceptionClear (env);
ase_awk_setrunerror (run, ASE_AWK_ENOMEM, 0, msg_nomem);
return -1;
}
@ -1080,8 +1071,7 @@ static int __handle_bfn (
{
/* if the method is not found, the exception is thrown.
* so clear it to prevent it from being thrown */
if ((*env)->ExceptionOccurred (env))
(*env)->ExceptionClear (env);
(*env)->ExceptionClear (env);
ase_awk_setrunerrnum (run, ASE_AWK_EBFNUSER);
return -1;
}
@ -1168,6 +1158,8 @@ static int __handle_bfn (
ret = (*env)->CallObjectMethod (env, obj, method, (jlong)run, args);
if ((*env)->ExceptionOccurred (env))
{
if (awk->debug) (*env)->ExceptionDescribe (env);
(*env)->ExceptionClear (env);
(*env)->DeleteLocalRef (env, args);
ase_awk_setrunerrnum (run, ASE_AWK_EBFNIMPL);
@ -1332,11 +1324,9 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_addbfn (
(*env)->DeleteLocalRef (env, class);
if (handle == NULL)
{
throw_exception (
env,
ASE_T("no handle field found"),
ASE_AWK_EINTERN,
0);
/* internal error. no handle field
* NoSuchFieldError, ExceptionInitializerError,
* OutOfMemoryError might occur */
return;
}
@ -1346,8 +1336,12 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_addbfn (
ptr = (*env)->GetStringChars (env, name, JNI_FALSE);
if (ptr == NULL)
{
if ((*env)->ExceptionOccurred (env)) (*env)->ExceptionClear (env);
throw_exception (env, ASE_T("out of memory"), ASE_AWK_ENOMEM, 0);
(*env)->ExceptionClear (env);
throw_exception (
env,
ase_awk_geterrstr(ASE_AWK_ENOMEM),
ASE_AWK_ENOMEM,
0);
return;
}
@ -1359,7 +1353,11 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_addbfn (
if (tmp == ASE_NULL)
{
(*env)->ReleaseStringChars (env, name, ptr);
throw_exception (env, ASE_T("out of memory"), ASE_AWK_ENOMEM, 0);
throw_exception (
env,
ase_awk_geterrstr(ASE_AWK_ENOMEM),
ASE_AWK_ENOMEM,
0);
return;
}
@ -1403,11 +1401,9 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_delbfn (
(*env)->DeleteLocalRef (env, class);
if (handle == NULL)
{
throw_exception (
env,
ASE_T("no handle field found"),
ASE_AWK_EINTERN,
0);
/* internal error. no handle field
* NoSuchFieldError, ExceptionInitializerError,
* OutOfMemoryError might occur */
return;
}
@ -1417,8 +1413,12 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_delbfn (
ptr = (*env)->GetStringChars (env, name, JNI_FALSE);
if (ptr == NULL)
{
if ((*env)->ExceptionOccurred (env)) (*env)->ExceptionClear (env);
throw_exception (env, ASE_T("out of memory"), ASE_AWK_ENOMEM, 0);
(*env)->ExceptionClear (env);
throw_exception (
env,
ase_awk_geterrstr(ASE_AWK_ENOMEM),
ASE_AWK_ENOMEM,
0);
return;
}
@ -1430,7 +1430,11 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_delbfn (
if (tmp == ASE_NULL)
{
(*env)->ReleaseStringChars (env, name, ptr);
throw_exception (env, ASE_T("out of memory"), ASE_AWK_ENOMEM, 0);
throw_exception (
env,
ase_awk_geterrstr(ASE_AWK_ENOMEM),
ASE_AWK_ENOMEM,
0);
return;
}
@ -1481,7 +1485,13 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_setmaxdepth (
class = (*env)->GetObjectClass(env, obj);
handle = (*env)->GetFieldID (env, class, FIELD_HANDLE, "J");
(*env)->DeleteLocalRef (env, class);
if (handle == NULL) return; /* should never happen */
if (handle == NULL)
{
/* internal error. no handle field
* NoSuchFieldError, ExceptionInitializerError,
* OutOfMemoryError might occur */
return;
}
awk = (ase_awk_t*) (*env)->GetLongField (env, obj, handle);
ase_awk_setmaxdepth (awk, ids, depth);
@ -1499,10 +1509,11 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_setfilename (
ptr = (*env)->GetStringChars (env, name, JNI_FALSE);
if (ptr == NULL)
{
(*env)->ExceptionClear (env);
throw_exception (
env,
ASE_T("out of memory"),
ASE_AWK_ENOMEM,
ase_awk_geterrstr(ASE_AWK_ENOMEM),
ASE_AWK_ENOMEM,
0);
return;
}
@ -1518,7 +1529,7 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_setfilename (
throw_exception (
env,
ASE_T("out of memory"),
ase_awk_geterrstr(ASE_AWK_ENOMEM),
ASE_AWK_ENOMEM,
0);
return;
@ -1557,9 +1568,10 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_setofilename (
ptr = (*env)->GetStringChars (env, name, JNI_FALSE);
if (ptr == NULL)
{
(*env)->ExceptionClear (env);
throw_exception (
env,
ASE_T("out of memory"),
ase_awk_geterrstr(ASE_AWK_ENOMEM),
ASE_AWK_ENOMEM,
0);
return;
@ -1576,7 +1588,7 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_setofilename (
throw_exception (
env,
ASE_T("out of memory"),
ase_awk_geterrstr(ASE_AWK_ENOMEM),
ASE_AWK_ENOMEM,
0);
return;
@ -1616,7 +1628,16 @@ JNIEXPORT jobject JNICALL Java_ase_awk_Awk_strtonum (
len = (*env)->GetStringLength (env, str);
ptr = (*env)->GetStringChars (env, str, JNI_FALSE);
if (ptr == NULL) return NULL;
if (ptr == NULL)
{
(*env)->ExceptionClear (env);
throw_exception (
env,
ase_awk_geterrstr(ASE_AWK_ENOMEM),
ASE_AWK_ENOMEM,
0);
return NULL;
}
if (ASE_SIZEOF(jchar) != ASE_SIZEOF(ase_char_t))
{
@ -1626,8 +1647,12 @@ JNIEXPORT jobject JNICALL Java_ase_awk_Awk_strtonum (
if (tmp == ASE_NULL)
{
(*env)->ReleaseStringChars (env, str, ptr);
ase_awk_setrunerrnum ((ase_awk_run_t*)runid, ASE_AWK_ENOMEM);
return -1;
throw_exception (
env,
ase_awk_geterrstr(ASE_AWK_ENOMEM),
ASE_AWK_ENOMEM,
0);
return NULL;
}
for (i = 0; i < len; i++) tmp[i] = (ase_char_t)ptr[i];

View File

@ -1,5 +1,5 @@
/*
* $Id: Awk.java,v 1.20 2007-01-23 14:23:18 bacon Exp $
* $Id: Awk.java,v 1.21 2007-01-24 14:21:30 bacon Exp $
*/
package ase.test.awk;
@ -26,7 +26,7 @@ public class Awk extends ase.awk.StdAwk
public Object xxx (long runid, Object[] args)
{
System.out.println ("<<BFN_SIN>>");
System.out.println ("<<BFN_XXX>>");
for (int i = 0; i < args.length; i++)
{
System.out.print ("ARG #" + i);