From 326c7b707de55c6dd0a2661374cc86d2f297fa09 Mon Sep 17 00:00:00 2001 From: shikokuchuo <53399081+shikokuchuo@users.noreply.github.com> Date: Tue, 3 Sep 2024 16:09:33 +0100 Subject: [PATCH] restrict scope of eval parse result --- src/server.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/server.c b/src/server.c index 978fb4ec8..f6bce6c22 100644 --- a/src/server.c +++ b/src/server.c @@ -237,10 +237,10 @@ void rest_start(void *arg) { } -SEXP nano_eval_res; +static SEXP nano_parse_eval_res; void parse_eval_safe(void *data) { - nano_eval_res = R_ParseEvalString((const char *) data, R_GlobalEnv); + nano_parse_eval_res = R_ParseEvalString((const char *) data, R_GlobalEnv); } void inproc_server(const char* url) { @@ -252,8 +252,6 @@ void inproc_server(const char* url) { if ((xc = nng_rep0_open(&s)) || (xc = nng_listen(s, url, NULL, 0))) fatal("unable to set up inproc", xc); - nano_eval_res = R_BlankScalarString; - for (;;) { if ((xc = nng_recvmsg(s, &msg, 0))) fatal("inproc recvmsg", xc); @@ -261,18 +259,18 @@ void inproc_server(const char* url) { const char *body = nng_msg_body(msg); nano_buf buf; + nano_parse_eval_res = R_BlankScalarString; R_ToplevelExec(parse_eval_safe, (void *) body); - if (TYPEOF(nano_eval_res) == STRSXP) { - const char *string = NANO_STRING(nano_eval_res); + if (TYPEOF(nano_parse_eval_res) == STRSXP) { + const char *string = NANO_STRING(nano_parse_eval_res); buf.buf = (unsigned char *) string; buf.cur = strlen(string); } else { - nano_serialize(&buf, nano_eval_res, R_NilValue); + nano_serialize(&buf, nano_parse_eval_res, R_NilValue); } nng_msg_clear(msg); nng_msg_append(msg, buf.buf, buf.cur); - nano_eval_res = R_BlankScalarString; if ((xc = nng_sendmsg(s, msg, 0))) fatal("inproc sendmsg", xc);