changed code to prevent buffered output from span across the end of hawk_rtx_execXXX()

This commit is contained in:
hyung-hwan 2020-03-29 06:29:05 +00:00
parent e54537886c
commit cd7873e19a
4 changed files with 20 additions and 6 deletions

View File

@ -1221,11 +1221,6 @@ static HAWK_INLINE int execute_hawk (int argc, hawk_bch_t* argv[])
hawk_rtx_execwithbcstrarr(rtx, (const hawk_bch_t**)arg.icf.ptr, arg.icf.size); hawk_rtx_execwithbcstrarr(rtx, (const hawk_bch_t**)arg.icf.ptr, arg.icf.size);
#endif #endif
/* clear unflushed io data - this is also done by hawk_rtx_close().
* but i restore the SIGPIPE handler to the default in unset_intr_run().
* any output after this restoration may cause the program to terminate for unhandled SIGPIPE */
hawk_rtx_cleario (rtx);
unset_intr_run (); unset_intr_run ();
if (retv) if (retv)

View File

@ -1794,8 +1794,18 @@ int Hawk::call (const hawk_uch_t* name, Value* ret, const Value* args, hawk_oow_
int Hawk::exec (Value* ret, const Value* args, hawk_oow_t nargs) int Hawk::exec (Value* ret, const Value* args, hawk_oow_t nargs)
{ {
return (this->runctx.rtx->hawk->parse.pragma.entry[0] != '\0')? 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); 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 */
hawk_rtx_gc (this->runctx.rtx, HAWK_RTX_GC_GEN_FULL);
#endif
return n;
} }
void Hawk::halt () void Hawk::halt ()

View File

@ -1682,6 +1682,8 @@ 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_callwithooucstrarr(rtx, rtx->hawk->parse.pragma.entry, args, nargs):
hawk_rtx_loop(rtx); hawk_rtx_loop(rtx);
hawk_rtx_cleario (rtx);
#if defined(HAWK_ENABLE_GC) #if defined(HAWK_ENABLE_GC)
/* i assume this function is a usual hawk program starter. /* i assume this function is a usual hawk program starter.
* call garbage collection after a whole program finishes */ * call garbage collection after a whole program finishes */

View File

@ -239,6 +239,11 @@ static void stop_run (int sig)
if (app_hawk) app_hawk->halt (); if (app_hawk) app_hawk->halt ();
errno = e; errno = e;
} }
static void do_nothing (int sig)
{
}
#endif #endif
static void set_signal (void) static void set_signal (void)
@ -248,6 +253,7 @@ static void set_signal (void)
#else #else
/*setsignal (SIGINT, stop_run, 1); TO BE MORE COMPATIBLE WITH WIN32*/ /*setsignal (SIGINT, stop_run, 1); TO BE MORE COMPATIBLE WITH WIN32*/
setsignal (SIGINT, stop_run, 0); setsignal (SIGINT, stop_run, 0);
setsignal (SIGPIPE, do_nothing, 0);
#endif #endif
} }
@ -257,6 +263,7 @@ static void unset_signal (void)
SetConsoleCtrlHandler (stop_run, FALSE); SetConsoleCtrlHandler (stop_run, FALSE);
#else #else
setsignal (SIGINT, SIG_DFL, 1); setsignal (SIGINT, SIG_DFL, 1);
setsignal (SIGPIPE, SIG_DFL, 1);
#endif #endif
} }