Sarthak-Pandey commented on code in PR #3859:
URL: https://github.com/apache/nuttx-apps/pull/3859#discussion_r4329624089
##########
interpreters/duktape/duk_cmdline.patch:
##########
@@ -2,17 +2,74 @@ diff --color -ur duktape/examples/cmdline/duk_cmdline.c
duktape-2.5.0-modifed/ex
--- duktape/examples/cmdline/duk_cmdline.c 2019-11-25 06:04:27.000000000
+0800
+++ duktape-2.5.0-modifed/examples/cmdline/duk_cmdline.c 2020-08-07
23:20:27.320000000 +0800
@@ -103,7 +103,7 @@
+
#define MEM_LIMIT_NORMAL (128*1024*1024) /* 128 MB */
#define MEM_LIMIT_HIGH (2047*1024*1024) /* ~2 GB */
-#define LINEBUF_SIZE 65536
+#define LINEBUF_SIZE 256
static int main_argc = 0;
static char **main_argv = NULL;
-
-@@ -810,10 +810,12 @@
+@@ -167,14 +167,33 @@ static void set_resource_limits(rlim_t mem_limit_value) {
+ #endif /* DUK_CMDLINE_RLIMIT */
+
+ #if defined(DUK_CMDLINE_SIGNAL)
++#include <signal.h>
++
++static volatile sig_atomic_t g_interrupted = 0;
++static volatile sig_atomic_t g_executing = 0;
++
++duk_bool_t duk_cmdline_timeout_check(void *udata) {
++ (void) udata;
++ if (g_interrupted && g_executing) {
++ g_executing = 0;
++ return 1;
++ }
++ return 0;
++}
++
+ static void my_sighandler(int x) {
+- fprintf(stderr, "Got signal %d\n", x);
+- fflush(stderr);
++ (void) x;
++ g_interrupted = 1;
+ }
+ static void set_sigint_handler(void) {
+ (void) signal(SIGINT, my_sighandler);
+ (void) signal(SIGPIPE, SIG_IGN); /* avoid SIGPIPE killing process */
+ }
++#else
++duk_bool_t duk_cmdline_timeout_check(void *udata) {
++ (void) udata;
++ return 0;
++}
+ #endif /* DUK_CMDLINE_SIGNAL */
+
+ static void cmdline_fatal_handler(void *udata, const char *msg) {
+@@ -284,7 +303,13 @@ static duk_ret_t wrapped_compile_execute(duk_context
*ctx, void *udata) {
+ #endif
+
+ duk_push_global_object(ctx); /* 'this' binding */
++#if defined(DUK_CMDLINE_SIGNAL)
++ g_executing = 1;
Review Comment:
The original intention was to guard the timeout callback so it only aborts
when active bytecode execution (duk_call_method) is taking place, avoiding
unintended aborts if a signal arrived outside the execution phase.
However, since DUK_USE_EXEC_TIMEOUT_CHECK is only ever invoked internally by
Duktape's bytecode interpreter loop during active execution, checking
g_interrupted alone is sufficient. g_executing is indeed redundant—I will
remove it and simplify the check to return g_interrupted;.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]