From abcc217dd0c8f7f6a42126a35df2c4d5ea3ff560 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Sun, 29 Mar 2020 08:05:36 +0000 Subject: [PATCH] changed the point where hawk_rtx_cleario() is called for cleanup --- hawk/lib/Hawk.cpp | 2 -- hawk/lib/run.c | 11 ++++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/hawk/lib/Hawk.cpp b/hawk/lib/Hawk.cpp index 2eac7fe1..224ba62f 100644 --- a/hawk/lib/Hawk.cpp +++ b/hawk/lib/Hawk.cpp @@ -1797,8 +1797,6 @@ int Hawk::exec (Value* ret, const Value* args, hawk_oow_t nargs) int n = (this->runctx.rtx->hawk->parse.pragma.entry[0] != '\0')? this->call(this->runctx.rtx->hawk->parse.pragma.entry, ret, args, nargs): this->loop(ret); - hawk_rtx_cleario (this->runctx.rtx); - #if defined(HAWK_ENABLE_GC) /* i assume this function is a usual hawk program starter. * call garbage collection after a whole program finishes */ diff --git a/hawk/lib/run.c b/hawk/lib/run.c index 5e5b5f5f..95433e84 100644 --- a/hawk/lib/run.c +++ b/hawk/lib/run.c @@ -1671,6 +1671,10 @@ hawk_val_t* hawk_rtx_loop (hawk_rtx_t* rtx) /* reset the exit level */ rtx->exit_level = EXIT_NONE; + + /* clear any pending io's */ + hawk_rtx_cleario (rtx); + return retv; } @@ -1682,8 +1686,6 @@ hawk_val_t* hawk_rtx_execwithucstrarr (hawk_rtx_t* rtx, const hawk_uch_t* args[] hawk_rtx_callwithooucstrarr(rtx, rtx->hawk->parse.pragma.entry, args, nargs): hawk_rtx_loop(rtx); - hawk_rtx_cleario (rtx); - #if defined(HAWK_ENABLE_GC) /* i assume this function is a usual hawk program starter. * call garbage collection after a whole program finishes */ @@ -1811,7 +1813,7 @@ hawk_val_t* hawk_rtx_callfun (hawk_rtx_t* rtx, hawk_fun_t* fun, hawk_val_t* args v = __eval_call(rtx, (hawk_nde_t*)&call, fun, push_arg_from_vals, (void*)&pafv, capture_retval_on_exit, &crdata); - if (!v) + if (HAWK_UNLIKELY(!v)) { /* an error occurred. let's check if it is caused by exit(). * if so, the return value should have been captured into @@ -1827,6 +1829,9 @@ hawk_val_t* hawk_rtx_callfun (hawk_rtx_t* rtx, hawk_fun_t* fun, hawk_val_t* args hawk_rtx_refupval (rtx, v); } + /* clear any pending io's */ + hawk_rtx_cleario (rtx); + /* return the return value with its reference count at least 1. * the caller of this function should count down its reference. */ return v;