[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: |
Mon, 21 Aug 2006 06:48:20 -0600 |
User-agent: |
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.5) Gecko/20060719 Thunderbird/1.5.0.5 Mnenhy/0.7.4.666 |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
According to Eric Blake on 6/30/2006 12:39 PM:
> 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.
Ported this portion of the patch to head as follows. Note that the OS/2
portion, where we added .m4 code to configure to check for a broken
system() call, has not been ported yet (but I'm not even sure how libtool
fares on OS/2, to be worried about that port just yet). I still have
quite a bit of porting to do in m4.texinfo, including the tests that the
branch had that exercise this code.
2006-08-21 Eric Blake <address@hidden>
* configure.ac (AC_CHECK_HEADERS_ONCE): Check for <sys/wait.h>.
* modules/gnu.c (esyscmd): Use -1 for failure. Set sysval to 0
when no arguments are given, but without losing warning about 0
arguments.
* modules/m4.c (syscmd): Likewise.
(includes): Assume C89.
(m4_sysval): Make static.
(M4_SYSVAL_EXITBITS, M4_SYSVAL_TERMSIGBITS): New macros.
(sysval): Port calculation from branch.
- --
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
iD8DBQFE6auT84KuGfSFAYARAgycAKCeufbkECuRabGtLgGEvllQqOAGLACgvXLl
81ruPqAc3LIksLVYYUGg6No=
=RH/3
-----END PGP SIGNATURE-----
Index: configure.ac
===================================================================
RCS file: /sources/m4/m4/configure.ac,v
retrieving revision 1.52
diff -u -p -r1.52 configure.ac
--- configure.ac 9 Aug 2006 13:16:34 -0000 1.52
+++ configure.ac 21 Aug 2006 12:38:48 -0000
@@ -168,7 +168,7 @@ AC_CHECK_SIZEOF([long long int])
## ------------------------- ##
## C headers required by M4. ##
## ------------------------- ##
-AC_CHECK_HEADERS_ONCE([limits.h])
+AC_CHECK_HEADERS_ONCE([limits.h sys/wait.h])
if test $ac_cv_header_stdbool_h = yes; then
INCLUDE_STDBOOL_H='#include <stdbool.h>'
Index: modules/gnu.c
===================================================================
RCS file: /sources/m4/m4/modules/gnu.c,v
retrieving revision 1.48
diff -u -p -r1.48 gnu.c
--- modules/gnu.c 21 Aug 2006 02:37:45 -0000 1.48
+++ modules/gnu.c 21 Aug 2006 12:38:48 -0000
@@ -53,7 +53,7 @@
BUILTIN(changesyntax, false, true, 1, -1 ) \
BUILTIN(debugmode, false, false, 1, 2 ) \
BUILTIN(debugfile, false, false, 1, 2 ) \
- BUILTIN(esyscmd, false, true, 2, 2 ) \
+ BUILTIN(esyscmd, false, true, -1, 2 ) \
BUILTIN(format, false, true, 2, -1 ) \
BUILTIN(indir, false, true, 2, -1 ) \
BUILTIN(patsubst, false, true, 3, 5 ) \
@@ -126,7 +126,7 @@ m4_regexp_compile (m4 *context, const ch
use a static variable. To be reentrant, we would need a mutex in
this method, and we should have a way to free the memory used by
buf when this module is unloaded. */
-
+
static m4_pattern_buffer buf; /* compiled regular expression */
const char *msg; /* error message from re_compile_pattern */
@@ -468,6 +468,16 @@ M4BUILTIN_HANDLER (esyscmd)
FILE *pin;
int ch;
+ /* Calling with no arguments triggers a warning, but must also
+ set sysval to 0 as if the empty command had been executed.
+ Therefore, we must manually check min args ourselves rather
+ than relying on the macro calling engine. */
+ if (m4_bad_argc (context, argc, argv, 2, -1))
+ {
+ m4_set_sysval (0);
+ return;
+ }
+
m4_sysval_flush (context);
errno = 0;
pin = popen (M4ARG (1), "r");
@@ -476,7 +486,7 @@ M4BUILTIN_HANDLER (esyscmd)
m4_error (context, 0, errno,
_("%s: cannot open pipe to command `%s'"),
M4ARG (0), M4ARG (1));
- m4_set_sysval (0xffff);
+ m4_set_sysval (-1);
}
else
{
Index: modules/m4.c
===================================================================
RCS file: /sources/m4/m4/modules/m4.c,v
retrieving revision 1.64
diff -u -p -r1.64 m4.c
--- modules/m4.c 9 Aug 2006 21:33:24 -0000 1.64
+++ modules/m4.c 21 Aug 2006 12:38:48 -0000
@@ -21,20 +21,14 @@
# include <config.h>
#endif
-#if HAVE_STDLIB_H
-# include <stdlib.h>
-#endif
-
-#if HAVE_UNISTD_H
-# include <unistd.h>
-#endif
-
+#include <assert.h>
#include <errno.h>
-#ifndef errno
-extern int errno;
-#endif
+#include <stdlib.h>
+#include <unistd.h>
-#include <assert.h>
+#if HAVE_SYS_WAIT_H
+# include <sys/wait.h>
+#endif
#include <m4module.h>
#include <modules/m4.h>
@@ -92,7 +86,7 @@ extern const char *m4_expand_ranges (con
BUILTIN(shift, false, false, 0, -1 ) \
BUILTIN(sinclude, false, true, 2, 2 ) \
BUILTIN(substr, false, true, 3, 4 ) \
- BUILTIN(syscmd, false, true, 2, 2 ) \
+ BUILTIN(syscmd, false, true, -1, 2 ) \
BUILTIN(sysval, false, false, 0, -1 ) \
BUILTIN(traceoff, false, false, 0, -1 ) \
BUILTIN(traceon, false, false, 0, -1 ) \
@@ -427,11 +421,40 @@ Warning: %s: builtin `%s' requested by f
and "sysval". */
/* Exit code from last "syscmd" command. */
-int m4_sysval = 0;
+/* FIXME - we should preserve this value across freezing. See
+ http://lists.gnu.org/archive/html/bug-m4/2006-06/msg00059.html
+ for ideas on how do to that. */
+static int m4_sysval = 0;
+
+/* Helper macros for readability. */
+#if UNIX || defined WEXITSTATUS
+# define M4_SYSVAL_EXITBITS(status) \
+ (WIFEXITED (status) ? WEXITSTATUS (status) : 0)
+# define M4_SYSVAL_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 M4_SYSVAL_EXITBITS(status) status
+# define M4_SYSVAL_TERMSIGBITS(status) 0
+#endif /* ! UNIX && ! defined WEXITSTATUS */
+/* Fallback definitions if <stdlib.h> or <sys/wait.h> are inadequate. */
+/* FIXME - this may fit better as a gnulib module. */
#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
void
m4_set_sysval (int value)
@@ -451,14 +474,28 @@ m4_sysval_flush (m4 *context)
M4BUILTIN_HANDLER (syscmd)
{
+ /* Calling with no arguments triggers a warning, but must also set
+ sysval to 0 as if the empty command had been executed.
+ Therefore, we must manually check min args ourselves rather than
+ relying on the macro calling engine. */
+ if (m4_bad_argc (context, argc, argv, 2, -1))
+ {
+ m4_set_sysval (0);
+ return;
+ }
m4_sysval_flush (context);
m4_sysval = system (M4ARG (1));
+ /* FIXME - determine if libtool works for OS/2, in which case the
+ FUNC_SYSTEM_BROKEN section on the branch must be ported to work
+ around the bug in their EMX libc system(). */
}
M4BUILTIN_HANDLER (sysval)
{
- m4_shipout_int (obs, WEXITSTATUS (m4_sysval));
+ m4_shipout_int (obs, (m4_sysval == -1 ? 127
+ : (M4_SYSVAL_EXITBITS (m4_sysval)
+ | M4_SYSVAL_TERMSIGBITS (m4_sysval))));
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: branch-1_4 - platform recognition macro,
Eric Blake <=