[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: branch-1_4 - platform recognition macro
From: |
Eric Blake |
Subject: |
Re: branch-1_4 - platform recognition macro |
Date: |
Fri, 30 Jun 2006 12:39:30 -0600 |
User-agent: |
Thunderbird 1.5.0.4 (Windows/20060516) |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
According to Eric Blake on 6/30/2006 9:05 AM:
> In building for mingw, I realized that we were still defining __unix__,
> which is rather pointless (mingw couldn't be further from Unix if we
> tried); so I borrowed the idea from CVS head of defining __windows__
> instead. With this in place, I can now skip tests that assume UNIX/POSIX
> semantics of syscmd on platforms that do not provide those semantics. My
> next patch will finally be able to clean up sysval from the perspective of
> mingw, which I assume has similar semantics to OS/2. mingw does not
> provide WEXITSTATUS, and the result of system() and pclose() does not need
> shifting, but also cannot report if a signal terminated the process.
And here's my proposal for the sysval issue. I went ahead and committed
it, since I validated that it improves the situation for mingw (at least,
for a cross-compilation with cygwin build and mingw host). Andreas, could
you give some feedback on how 'make check' fares on OS/2 using the latest
CVS on branch-1_4?
Also, in my testing, I noticed that mingw had issues with line endings.
I'm toying with a patch that would force binary processing on all files if
O_BINARY is defined, rather than text processing, to guarantee line
endings. POSIX does say that compliant apps only use m4 on text files,
and I'm not quite sure how things will behave in binary mode. On the
other hand, the autoconf testsuite behaves quite dismally on a cygwin text
mount, and a binary mode m4 would probably help matters there, and
autoconf does tend to be the primary user of m4. Does anyone else have an
opinion on this matter?
2006-06-30 Eric Blake <address@hidden>
For compatibility with other m4 implementations, sysval returns
signal<<8 rather than 0 if syscmd is terminated by a signal.
* configure.ac (AC_CHECK_HEADERS_ONCE): Check for sys/wait.h.
* src/builtin.c (include): Include sys/wait.h when stdlib.h does
not provide wait macros.
(WTERMSIG, WIFSIGNALED, WIFEXITED): More fallback macros.
(M4SYSVAL_EXITBITS, M4SYSVAL_TERMSIGBITS): New helper macros.
(m4_esyscmd): Set sysval to -1 on failure.
(m4_sysval): Print 127 on failure, and accomodate signals if they
are detectable.
* NEWS: Document this change.
* doc/m4.texinfo (Platform macros, Esyscmd, Sysval): Fix typos in
last commit.
* checks/check-them: Likewise.
* src/debug.c (debug_set_file): Work around mingw fstat bug.
- --
Life is short - so eat dessert first!
Eric Blake address@hidden
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.1 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFEpW/h84KuGfSFAYARAnuMAJ0a/YCQpxP4TDfgBTrzL6kYB3NyfgCfUJ1S
x0JLoY3Z4R7NMMPCMXXkWUc=
=kv3p
-----END PGP SIGNATURE-----
Index: NEWS
===================================================================
RCS file: /sources/m4/m4/NEWS,v
retrieving revision 1.1.1.1.2.28
diff -u -p -r1.1.1.1.2.28 NEWS
--- NEWS 30 Jun 2006 15:06:53 -0000 1.1.1.1.2.28
+++ NEWS 30 Jun 2006 18:37:48 -0000
@@ -5,7 +5,9 @@ Foundation, Inc.
Version 1.4.5 - ?? 2006, by ??? (CVS version 1.4.4c)
* Fix sysval on BeOS, OS/2, and other systems that store exit status
- in the low-order byte.
+ in the low-order byte. Additionally, on Unix platforms, if syscmd was
+ terminated by a signal, sysval now displays the signal number shifted
+ left by eight bits, to match traditional m4 implementations.
* The maketemp macro is no longer subject to platform limitations (such as
26 or 32 max files from a given template).
* Frozen files now require that the first directive be V (version), to
Index: configure.ac
===================================================================
RCS file: /sources/m4/m4/configure.ac,v
retrieving revision 1.36.2.19
diff -u -p -r1.36.2.19 configure.ac
--- configure.ac 30 Jun 2006 15:06:53 -0000 1.36.2.19
+++ configure.ac 30 Jun 2006 18:37:48 -0000
@@ -34,7 +34,7 @@ AC_CANONICAL_HOST
AC_PROG_CC
M4_EARLY
-AC_CHECK_HEADERS_ONCE([limits.h siginfo.h])
+AC_CHECK_HEADERS_ONCE([limits.h siginfo.h sys/wait.h])
AC_CHECK_TYPES([siginfo_t], [], [],
[[#include <signal.h>
#if HAVE_SIGINFO_H
Index: checks/check-them
===================================================================
RCS file: /sources/m4/m4/checks/Attic/check-them,v
retrieving revision 1.1.1.1.2.3
diff -u -p -r1.1.1.1.2.3 check-them
--- checks/check-them 30 Jun 2006 15:06:53 -0000 1.1.1.1.2.3
+++ checks/check-them 30 Jun 2006 18:37:48 -0000
@@ -54,7 +54,7 @@ do
fi
sed -e '/^dnl @error{}/!d' -e 's///' -e "s/m4.input/$file/" \
- -e "s| $m4:| m4:|" $file > $xerr
+ -e "s| m4:| $m4:|" $file > $xerr
if cmp -s $err $xerr; then
:
Index: doc/m4.texinfo
===================================================================
RCS file: /sources/m4/m4/doc/m4.texinfo,v
retrieving revision 1.1.1.1.2.28
diff -u -p -r1.1.1.1.2.28 m4.texinfo
--- doc/m4.texinfo 30 Jun 2006 15:06:53 -0000 1.1.1.1.2.28
+++ doc/m4.texinfo 30 Jun 2006 18:37:49 -0000
@@ -3270,7 +3270,7 @@ please report that as a bug.
@example
define(`provided', `0')
@result{}
-ifdef(`__gnu__', `define(`provided', incr(provided))')
+ifdef(`__unix__', `define(`provided', incr(provided))')
@result{}
ifdef(`__windows__', `define(`provided', incr(provided))')
@result{}
@@ -3338,7 +3338,7 @@ is not a part of the expansion: it will
output of @code{m4}.
@example
-define(`foo, `FOO')
+define(`foo', `FOO')
@result{}
esyscmd(`echo foo')
@result{}FOO
@@ -3377,7 +3377,7 @@ syscmd(`false')
@result{}
ifelse(sysval, `0', `zero', `non-zero')
@result{}non-zero
-syscmd
+syscmd()
@result{}
sysval
@result{}0
@@ -3393,7 +3393,7 @@ esyscmd(`false')
@result{}
ifelse(sysval, `0', `zero', `non-zero')
@result{}non-zero
-esyscmd
+esyscmd()
@result{}
sysval
@result{}0
Index: src/builtin.c
===================================================================
RCS file: /sources/m4/m4/src/Attic/builtin.c,v
retrieving revision 1.1.1.1.2.15
diff -u -p -r1.1.1.1.2.15 builtin.c
--- src/builtin.c 30 Jun 2006 15:06:53 -0000 1.1.1.1.2.15
+++ src/builtin.c 30 Jun 2006 18:37:50 -0000
@@ -28,6 +28,10 @@ extern FILE *popen ();
#include "regex.h"
+#if HAVE_SYS_WAIT_H
+# include <sys/wait.h>
+#endif
+
#define ARG(i) (argc > (i) ? TOKEN_DATA_TEXT (argv[i]) : "")
/* Initialisation of builtin and predefined macros. The table
@@ -765,9 +769,34 @@ builtin `%s' requested by frozen file is
| and "sysval". "esyscmd" is GNU specific. |
`------------------------------------------------------------------------*/
+/* Helper macros for readability. */
+#if UNIX || defined WEXITSTATUS
+# define M4SYSVAL_EXITBITS(status) \
+ (WIFEXITED (status) ? WEXITSTATUS (status) : 0)
+# define M4SYSVAL_TERMSIGBITS(status) \
+ (WIFSIGNALED (status) ? WTERMSIG (status) << 8 : 0)
+
+#else /* ! UNIX && ! defined WEXITSTATUS */
+/* Platforms such as mingw do not support the notion of reporting
+ which signal terminated a process. Furthermore if WEXITSTATUS was
+ not provided, then the exit value is in the low eight bits. */
+# define M4SYSVAL_EXITBITS(status) status
+# define M4SYSVAL_TERMSIGBITS(status) 0
+#endif /* ! UNIX && ! defined WEXITSTATUS */
+
+/* Fallback definitions if <stdlib.h> or <sys/wait.h> are inadequate. */
#ifndef WEXITSTATUS
# define WEXITSTATUS(status) (((status) >> 8) & 0xff)
#endif
+#ifndef WTERMSIG
+# define WTERMSIG(status) ((status) & 0x7f)
+#endif
+#ifndef WIFSIGNALED
+# define WIFSIGNALED(status) (WTERMSIG (status) != 0)
+#endif
+#ifndef WIFEXITED
+# define WIFEXITED(status) (WTERMSIG (status) == 0)
+#endif
/* Exit code from last "syscmd" command. */
static int sysval;
@@ -806,7 +835,7 @@ m4_esyscmd (struct obstack *obs, int arg
{
M4ERROR ((warning_status, errno,
"cannot open pipe to command \"%s\"", ARG (1)));
- sysval = 0xffff;
+ sysval = -1;
}
else
{
@@ -819,7 +848,9 @@ m4_esyscmd (struct obstack *obs, int arg
static void
m4_sysval (struct obstack *obs, int argc, token_data **argv)
{
- shipout_int (obs, WEXITSTATUS (sysval));
+ shipout_int (obs, (sysval == -1 ? 127
+ : (M4SYSVAL_EXITBITS (sysval)
+ | M4SYSVAL_TERMSIGBITS (sysval))));
}
/*-------------------------------------------------------------------------.
Index: src/debug.c
===================================================================
RCS file: /sources/m4/m4/src/Attic/debug.c,v
retrieving revision 1.1.1.1.2.3
diff -u -p -r1.1.1.1.2.3 debug.c
--- src/debug.c 23 Jun 2006 13:06:10 -0000 1.1.1.1.2.3
+++ src/debug.c 30 Jun 2006 18:37:50 -0000
@@ -148,8 +148,11 @@ debug_set_file (FILE *fp)
if (fstat (fileno (debug), &debug_stat) < 0)
return;
+ /* mingw has a bug where fstat on a regular file reports st_ino
+ of 0. On normal system, st_ino should never be 0. */
if (stdout_stat.st_ino == debug_stat.st_ino
- && stdout_stat.st_dev == debug_stat.st_dev)
+ && stdout_stat.st_dev == debug_stat.st_dev
+ && stdout_stat.st_ino != 0)
{
if (debug != stderr)
fclose (debug);