From cd7873e19a6900b0f77d201e5230d6c390f6cd05 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Sun, 29 Mar 2020 06:29:05 +0000 Subject: [PATCH] changed code to prevent buffered output from span across the end of hawk_rtx_execXXX() --- hawk/bin/main.c | 5 ----- hawk/lib/Hawk.cpp | 12 +++++++++++- hawk/lib/run.c | 2 ++ hawk/samples/hawk51.cpp | 7 +++++++ 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/hawk/bin/main.c b/hawk/bin/main.c index 9cd20449..20d925e0 100644 --- a/hawk/bin/main.c +++ b/hawk/bin/main.c @@ -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); #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 (); if (retv) diff --git a/hawk/lib/Hawk.cpp b/hawk/lib/Hawk.cpp index b0e983d0..2eac7fe1 100644 --- a/hawk/lib/Hawk.cpp +++ b/hawk/lib/Hawk.cpp @@ -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) { - 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); + + 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 () diff --git a/hawk/lib/run.c b/hawk/lib/run.c index e372bf79..5e5b5f5f 100644 --- a/hawk/lib/run.c +++ b/hawk/lib/run.c @@ -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_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 */ diff --git a/hawk/samples/hawk51.cpp b/hawk/samples/hawk51.cpp index cb7233eb..4161882d 100644 --- a/hawk/samples/hawk51.cpp +++ b/hawk/samples/hawk51.cpp @@ -239,6 +239,11 @@ static void stop_run (int sig) if (app_hawk) app_hawk->halt (); errno = e; } + +static void do_nothing (int sig) +{ +} + #endif static void set_signal (void) @@ -248,6 +253,7 @@ static void set_signal (void) #else /*setsignal (SIGINT, stop_run, 1); TO BE MORE COMPATIBLE WITH WIN32*/ setsignal (SIGINT, stop_run, 0); + setsignal (SIGPIPE, do_nothing, 0); #endif } @@ -257,6 +263,7 @@ static void unset_signal (void) SetConsoleCtrlHandler (stop_run, FALSE); #else setsignal (SIGINT, SIG_DFL, 1); + setsignal (SIGPIPE, SIG_DFL, 1); #endif }