From 575feda6c4dda61e0292b1c8f5783eb60e3f239c Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Wed, 22 Nov 2023 17:09:46 -0700 Subject: [PATCH] unbreak `system` in a thread that has interrupts disabled (#766) Fixes a mistake in d7cc2cf2e5. This mistake was noticed by some C compilers, but I missed the warnings. --- c/prim5.c | 10 +++++----- mats/unix.ms | 5 +++++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/c/prim5.c b/c/prim5.c index f27cd4e66..90b087f12 100644 --- a/c/prim5.c +++ b/c/prim5.c @@ -711,9 +711,9 @@ static void s_showalloc(IBOOL show_dump, const char *outfn) { static ptr s_system(const char *s) { INT status; - char *s_arg; #ifdef PTHREADS ptr tc = get_thread_context(); + char *s_arg = NULL; #endif #ifdef PTHREADS @@ -725,11 +725,11 @@ static ptr s_system(const char *s) { S_error("system", "malloc failed"); memcpy(s_arg, s, len); deactivate_thread(tc); - } -#else - s_arg = (char *)s; + s = s_arg; + } else + s_arg = NULL; #endif - status = SYSTEM(s_arg); + status = SYSTEM(s); #ifdef PTHREADS if (DISABLECOUNT(tc) == FIX(0)) { reactivate_thread(tc); diff --git a/mats/unix.ms b/mats/unix.ms index 581620ffb..b59c8c6dc 100644 --- a/mats/unix.ms +++ b/mats/unix.ms @@ -708,6 +708,11 @@ (unless (or (windows?) (not (threaded?))) (mat thread-system + + ;; make sure `system` works when interrupts are disabled + (with-interrupts-disabled + (eqv? 0 (system "echo hi"))) + ;; check that when a thread is deactivated during `system`, ;; the command that it's running isn't GCed (let* ([count 50]