Mail Archives: djgpp-workers/2003/02/27/09:35:36
Hello.
Below is a patch that fixes POSIX::WEXITSTATUS for the DJGPP port
of Perl 5.6.1. ext/POSIX/POSIX.xs is the only code that uses
WEXITSTATUS, so it's safe to put it in the program-wide header
"dosish.h".
If there are no objections, I will upload new packages of Perl 5.6.1
to DJ in a couple of days.
I also looked at changing the WEXITSTATUS macro in <sys/wait.h>
to be more Unixy. But on further thought: Perl messed up the return code,
so it should cope with it, rather than us changing DJGPP. So I think
the fix to dosish.h, below, is the only change we should make.
Here's a quick test program, if you want to check that the bug is fixed:
perl -e 'use POSIX; system "false"; print $?."\n".POSIX::WEXITSTATUS($?)."\n";'
You should get the following:
DJGPP port of Perl 5.6.1 release 2:
256
0
DJGPP port of Perl 5.6.1 release 2 + patch below:
256
1
Bye, Rich =]
--- dosish.h.orig 2002-10-16 13:02:28.000000000 +0000
+++ dosish.h 2003-02-27 14:10:04.000000000 +0000
@@ -116,3 +116,48 @@
# define HAS_WAIT
# define HAS_CHOWN
#endif /* WIN32 */
+
+/*
+ * <rich AT phekda DOT freeserve DOT co DOT uk>: The DJGPP port has code that converts
+ * the return code of system() into the form that Unixy wait usually
+ * returns:
+ *
+ * - signal number in bits 0-6;
+ * - core dump flag in bit 7;
+ * - exit code in bits 8-15.
+ *
+ * Bits 0-7 are always zero for DJGPP, because it uses system().
+ * See djgpp.c.
+ *
+ * POSIX::W* use the W* macros from <sys/wait.h> to decode
+ * the return code. Unfortunately the W* macros for DJGPP use
+ * a different format than Unixy wait does. So there's a mismatch
+ * and, say, WEXITSTATUS($?) will return bogus values.
+ *
+ * So here we add hack to redefine the W* macros from DJGPP's <sys/wait.h>
+ * to work with our return-code conversion.
+ */
+
+#ifdef DJGPP
+
+#include <sys/wait.h>
+
+#undef WEXITSTATUS
+#undef WIFEXITED
+#undef WIFSIGNALED
+#undef WIFSTOPPED
+#undef WNOHANG
+#undef WSTOPSIG
+#undef WTERMSIG
+#undef WUNTRACED
+
+#define WEXITSTATUS(stat_val) ((stat_val) >> 8)
+#define WIFEXITED(stat_val) 0
+#define WIFSIGNALED(stat_val) 0
+#define WIFSTOPPED(stat_val) 0
+#define WNOHANG 0
+#define WSTOPSIG(stat_val) 0
+#define WTERMSIG(stat_val) 0
+#define WUNTRACED 0
+
+#endif
- Raw text -