From 3827f7eceeeca2f57c56e2fdf71c8d097f553ba0 Mon Sep 17 00:00:00 2001 From: felix Date: Sun, 1 Mar 2020 16:25:38 +0100 Subject: [PATCH] Use intermediate variable for process exit status on all platforms WIFEXITSTATUS and friends always assume the argument is an lvalue, but certain compilers seem to optimize the indirection "*((int *)&xxx)" away which resulted in technically incorrect code still to be accepted. Now on all platforms an intermediate temporary variable is used. --- posixunix.scm | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/posixunix.scm b/posixunix.scm index eedf119b..23ff157e 100644 --- a/posixunix.scm +++ b/posixunix.scm @@ -142,22 +142,13 @@ static C_TLS struct stat C_statbuf; #define C_u_i_execvp(f,a) C_fix(execvp(C_c_string(f), (char *const *)C_c_pointer_vector_or_null(a))) #define C_u_i_execve(f,a,e) C_fix(execve(C_c_string(f), (char *const *)C_c_pointer_vector_or_null(a), (char *const *)C_c_pointer_vector_or_null(e))) -#if defined(__FreeBSD__) || defined(C_MACOSX) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__sgi__) || defined(sgi) || defined(__DragonFly__) || defined(__SUNPRO_C) static C_TLS int C_uw; -# define C_WIFEXITED(n) (C_uw = C_unfix(n), C_mk_bool(WIFEXITED(C_uw))) -# define C_WIFSIGNALED(n) (C_uw = C_unfix(n), C_mk_bool(WIFSIGNALED(C_uw))) -# define C_WIFSTOPPED(n) (C_uw = C_unfix(n), C_mk_bool(WIFSTOPPED(C_uw))) -# define C_WEXITSTATUS(n) (C_uw = C_unfix(n), C_fix(WEXITSTATUS(C_uw))) -# define C_WTERMSIG(n) (C_uw = C_unfix(n), C_fix(WTERMSIG(C_uw))) -# define C_WSTOPSIG(n) (C_uw = C_unfix(n), C_fix(WSTOPSIG(C_uw))) -#else -# define C_WIFEXITED(n) C_mk_bool(WIFEXITED(C_unfix(n))) -# define C_WIFSIGNALED(n) C_mk_bool(WIFSIGNALED(C_unfix(n))) -# define C_WIFSTOPPED(n) C_mk_bool(WIFSTOPPED(C_unfix(n))) -# define C_WEXITSTATUS(n) C_fix(WEXITSTATUS(C_unfix(n))) -# define C_WTERMSIG(n) C_fix(WTERMSIG(C_unfix(n))) -# define C_WSTOPSIG(n) C_fix(WSTOPSIG(C_unfix(n))) -#endif +#define C_WIFEXITED(n) (C_uw = C_unfix(n), C_mk_bool(WIFEXITED(C_uw))) +#define C_WIFSIGNALED(n) (C_uw = C_unfix(n), C_mk_bool(WIFSIGNALED(C_uw))) +#define C_WIFSTOPPED(n) (C_uw = C_unfix(n), C_mk_bool(WIFSTOPPED(C_uw))) +#define C_WEXITSTATUS(n) (C_uw = C_unfix(n), C_fix(WEXITSTATUS(C_uw))) +#define C_WTERMSIG(n) (C_uw = C_unfix(n), C_fix(WTERMSIG(C_uw))) +#define C_WSTOPSIG(n) (C_uw = C_unfix(n), C_fix(WSTOPSIG(C_uw))) #ifdef __CYGWIN__ # define C_mkfifo(fn, m) C_fix(-1) -- 2.21.0