From efb27c9db8161beaf88688765bc66b49f637b095 Mon Sep 17 00:00:00 2001 From: Jordan Bancino Date: Fri, 26 May 2023 21:05:06 +0000 Subject: [PATCH] Push Main return value into MainArgs. This prevents weird things from happing on some architectures. --- Cytoplasm/make.sh | 2 +- Cytoplasm/src/RtStub.c | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Cytoplasm/make.sh b/Cytoplasm/make.sh index 581f18f..c3d7388 100755 --- a/Cytoplasm/make.sh +++ b/Cytoplasm/make.sh @@ -36,7 +36,7 @@ addprefix() { : "${LDFLAGS:=-lm -pthread}" if [ "${DEBUG}" = "1" ]; then - CFLAGS="${CFLAGS} -o0 -g" + CFLAGS="${CFLAGS} -O0 -g" LD_EXTRA="" fi diff --git a/Cytoplasm/src/RtStub.c b/Cytoplasm/src/RtStub.c index 25c90e8..a38620a 100644 --- a/Cytoplasm/src/RtStub.c +++ b/Cytoplasm/src/RtStub.c @@ -43,18 +43,18 @@ typedef struct MainArgs { Array *args; HashMap *env; + int ret; } MainArgs; static void * MainThread(void *argp) { - long ret; MainArgs *args = argp; args = argp; - ret = Main(args->args, args->env); + args->ret = Main(args->args, args->env); - return (void *) ret; + return NULL; } int @@ -62,7 +62,6 @@ main(int argc, char **argv) { pthread_t mainThread; size_t i; - int ret; char *key; char *val; @@ -74,13 +73,14 @@ main(int argc, char **argv) args.args = NULL; args.env = NULL; + args.ret = EXIT_FAILURE; args.args = ArrayCreate(); if (!args.args) { Log(LOG_ERR, "Bootstrap error: Unable to allocate memory for arguments."); - ret = EXIT_FAILURE; + args.ret = EXIT_FAILURE; goto finish; } @@ -88,7 +88,7 @@ main(int argc, char **argv) if (!args.env) { Log(LOG_ERR, "Bootstrap error: Unable to allocate memory for environment."); - ret = EXIT_FAILURE; + args.ret = EXIT_FAILURE; goto finish; } @@ -117,15 +117,15 @@ main(int argc, char **argv) if (pthread_create(&mainThread, NULL, MainThread, &args) != 0) { Log(LOG_ERR, "Bootstrap error: Unable to create main thread."); - ret = EXIT_FAILURE; + args.ret = EXIT_FAILURE; goto finish; } - if (pthread_join(mainThread, (void **) &ret) != 0) + if (pthread_join(mainThread, NULL) != 0) { /* Should never happen */ Log(LOG_ERR, "Unable to join main thread."); - ret = EXIT_FAILURE; + args.ret = EXIT_FAILURE; goto finish; } @@ -158,5 +158,5 @@ finish: MemoryFreeAll(); - return ret; + return args.ret; }