Recovered from cvs revision 2007-10-31 13:56:00
This commit is contained in:
parent
a72a41480a
commit
1debaa5302
@ -1,9 +1,11 @@
|
||||
/*
|
||||
* $Id: Context.java,v 1.7 2007/10/29 15:20:13 bacon Exp $
|
||||
* $Id: Context.java,v 1.8 2007/10/30 15:01:31 bacon Exp $
|
||||
*/
|
||||
|
||||
package ase.awk;
|
||||
|
||||
import java.util.Stack;
|
||||
|
||||
public class Context
|
||||
{
|
||||
public static int GLOBAL_ARGC = 0;
|
||||
@ -24,15 +26,34 @@ public class Context
|
||||
public static int GLOBAL_RSTART = 15;
|
||||
public static int GLOBAL_SUBSEP = 16;
|
||||
|
||||
private Awk awk;
|
||||
private long runid;
|
||||
private Object custom;
|
||||
protected Awk awk;
|
||||
protected long runid;
|
||||
protected Object custom;
|
||||
protected Stack returnStack;
|
||||
|
||||
Context (Awk awk)
|
||||
{
|
||||
this.awk = awk;
|
||||
this.runid = 0;
|
||||
this.custom = null;
|
||||
this.returnStack = new Stack ();
|
||||
}
|
||||
|
||||
void clear ()
|
||||
{
|
||||
Return r;
|
||||
while ((r = popReturn()) != null) r.clear ();
|
||||
}
|
||||
|
||||
void pushReturn (Return ret)
|
||||
{
|
||||
returnStack.push (ret);
|
||||
}
|
||||
|
||||
Return popReturn ()
|
||||
{
|
||||
if (returnStack.empty()) return null;
|
||||
return (Return)returnStack.pop ();
|
||||
}
|
||||
|
||||
public Awk getAwk ()
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: Return.java,v 1.5 2007/10/29 15:20:13 bacon Exp $
|
||||
* $Id: Return.java,v 1.6 2007/10/30 15:01:31 bacon Exp $
|
||||
*/
|
||||
|
||||
package ase.awk;
|
||||
@ -16,6 +16,7 @@ public class Return
|
||||
|
||||
public Return (Context ctx)
|
||||
{
|
||||
ctx.pushReturn (this);
|
||||
this.runid = ctx.getId();
|
||||
this.valid = 0;
|
||||
}
|
||||
@ -136,7 +137,6 @@ public class Return
|
||||
setindexedstrval (this.runid, this.valid, Long.toString(index), v);
|
||||
}
|
||||
|
||||
|
||||
public void clear ()
|
||||
{
|
||||
clearval (this.runid, this.valid);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: jni.c,v 1.41 2007/10/29 15:20:13 bacon Exp $
|
||||
* $Id: jni.c,v 1.42 2007/10/30 15:01:31 bacon Exp $
|
||||
*
|
||||
* {License}
|
||||
*/
|
||||
@ -121,6 +121,8 @@ struct run_data_t
|
||||
jmethodID exception_get_line;
|
||||
jmethodID exception_get_message;
|
||||
|
||||
jmethodID context_clear;
|
||||
|
||||
jfieldID return_valid;
|
||||
|
||||
jobject context_object;
|
||||
@ -725,11 +727,16 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_run (JNIEnv* env, jobject obj, jlong awk
|
||||
env, run_data.exception_class, "getLine", "()I");
|
||||
run_data.exception_get_message = (*env)->GetMethodID (
|
||||
env, run_data.exception_class, "getMessage", "()Ljava/lang/String;");
|
||||
|
||||
|
||||
ASE_ASSERT (run_data.exception_get_code != ASE_NULL);
|
||||
ASE_ASSERT (run_data.exception_get_line != ASE_NULL);
|
||||
ASE_ASSERT (run_data.exception_get_message != ASE_NULL);
|
||||
|
||||
run_data.context_clear = (*env)->GetMethodID (
|
||||
env, run_data.context_class, "clear", "()V");
|
||||
|
||||
ASE_ASSERT (run_data.context_clear != ASE_NULL);
|
||||
|
||||
run_data.return_valid = (*env)->GetFieldID (
|
||||
env, run_data.return_class, FIELD_VALID, "J");
|
||||
if (run_data.return_valid == ASE_NULL)
|
||||
@ -1710,11 +1717,19 @@ static int handle_bfn (
|
||||
if (is_debug(awk)) (*env)->ExceptionDescribe (env);
|
||||
(*env)->ExceptionClear (env);
|
||||
(*env)->DeleteLocalRef (env, args);
|
||||
|
||||
|
||||
/* invoke context.clear */
|
||||
(*env)->CallVoidMethod (env, run_data->context_object, run_data->context_clear);
|
||||
if ((*env)->ExceptionCheck(env))
|
||||
{
|
||||
if (is_debug(awk)) (*env)->ExceptionDescribe (env);
|
||||
(*env)->ExceptionClear (env);
|
||||
}
|
||||
|
||||
/* refdown on ret.valid is needed here */
|
||||
vi = (*env)->GetLongField (env, ret, run_data->return_valid);
|
||||
if (vi != 0) ase_awk_refdownval (run, v);
|
||||
(*env)->SetLongField (env, ret, run_data->return_valid,(jlong)0);
|
||||
(*env)->SetLongField (env, ret, run_data->return_valid ,(jlong)0);
|
||||
|
||||
(*env)->DeleteLocalRef (env, ret);
|
||||
(*env)->DeleteLocalRef (env, name);
|
||||
@ -1798,6 +1813,16 @@ static int handle_bfn (
|
||||
(*env)->DeleteLocalRef (env, ret);
|
||||
(*env)->DeleteLocalRef (env, name);
|
||||
|
||||
(*env)->CallVoidMethod (env, run_data->context_object, run_data->context_clear);
|
||||
if ((*env)->ExceptionCheck(env))
|
||||
{
|
||||
/* TODO #1: if exception is thrown in clear, it seems to end with a lot of memory leask. PLEASE CHECK THIS */
|
||||
if (is_debug(awk)) (*env)->ExceptionDescribe (env);
|
||||
(*env)->ExceptionClear (env);
|
||||
ase_awk_setrunerrnum (run, ASE_AWK_EBFNIMPL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: AseAwkPanel.java,v 1.14 2007/10/29 15:20:13 bacon Exp $
|
||||
* $Id: AseAwkPanel.java,v 1.15 2007/10/30 15:01:31 bacon Exp $
|
||||
*/
|
||||
|
||||
import java.awt.*;
|
||||
@ -114,6 +114,9 @@ public class AseAwkPanel extends Panel
|
||||
|
||||
Return r = new Return (ctx);
|
||||
r.setStringValue ("[[%.6f]]");
|
||||
Return r2 = new Return (ctx);
|
||||
r.setStringValue ("[[%.6f]]");
|
||||
|
||||
ctx.setGlobal (Context.GLOBAL_CONVFMT, ret);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user