[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: Tue, 04 Jul 2006 12:42:47 -0600
User-agent: Thunderbird (Windows/20060516)

Hash: SHA1

Hi Andreas,

According to Andreas Büning on 7/1/2006 9:26 AM:
> Done. Then the linker complained about 'gl_va_copy' being an unresolved
> external. Reason is that va_copy is defined to gl_va_copy in config.h.
> gl_va_copy is supposed to be defined in m4/stdarg.m4. I added gl_STDARG_H
> manually to configure.ac but this didn't help because the gl_STDARG_H
> macro in m4/stdarg.m4 uses the AH_VERBATIM macro with an invalid syntax which
> results in a noop. 

OK, that is fixed in gnulib.  Rerun m4's bootstrap (or you could just do
`gnulib-tool --update') to pick up the gnulib fix, then try this patch,
and see if you can get through the testsuite.

I'm still not sure whether I like this idea of using
popen()/insert_file()/pclose() to emulate system(), since in corner cases
like syscmd(`ls'), when m4 was invoked interactively, system() sees a
terminal as stdout, while popen() sees a pipe, and ls behaves differently
for pipes than for terminals.  On the other hand, the m4 documentation is
(now) clear that syscmd is platform-dependent, so we could just define it
to behave like a pipe on OS/2 since that is the only platform where
system() does not do what we want; while still allowing syscmd to at least
detect signals.  The alternative patch is to still use system(), but shift
the value left by 8 if it is not -1; but we then lose the ability to
detect signals.  Does OS/2 even inform you about termination by signals?
Mingw does not, which is why I added the ability to skip that test in the
testsuite when __unix__ is not defined.

>> The question is whether reading \r in a preprocessor, and immediately
>> spitting it back out in binary mode, still leaves a consistent output file
>> with \r\n endings.  My gut feeling (although I have not yet tested it on
>> cygwin text mounts) is that since none of the builtins break their output
>> across lines, that all line breaks in the output come from line breaks in
>> the input, so reading in binary mode should still work.
> This could work on DOS/Win*/OS/2. However, I had vague memories that
> traditional MacOS uses single \r as linefeed (see, e.g,
> http://kb.iu.edu/data/agiz.html). I don't know how relevant this is
> nowadays.

If anyone using a MacOS that old wants a fix, I assume they will speak up.
 Now that modern Mac uses Unix line endings, I'm not sure it is worth
catering to older platforms unless someone requests it and shows that it
is still a viable porting target.

2006-07-04  Eric Blake  <address@hidden>

        * Makefile.am (SUBDIRS): Build . before src, so that autoheader
        runs first.
        * configure.ac (FUNC_SYSTEM_BROKEN): New check for OS/2 bug.
        * src/builtin.c (m4_syscmd): Work around OS/2 bug.

- --
Life is short - so eat dessert first!

Eric Blake             address@hidden
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

Index: Makefile.am
RCS file: /sources/m4/m4/Makefile.am,v
retrieving revision
diff -u -p -r1.25.2.6 Makefile.am
--- Makefile.am 2 Jul 2006 01:34:24 -0000
+++ Makefile.am 4 Jul 2006 18:30:55 -0000
@@ -20,7 +20,7 @@
 ## Written by Gary V. Vaughan <address@hidden>
-SUBDIRS = examples lib src doc checks
+SUBDIRS = . examples lib src doc checks
 EXTRA_DIST = bootstrap c-boxes.el GNUmakefile Makefile.maint \
Index: configure.ac
RCS file: /sources/m4/m4/configure.ac,v
retrieving revision
diff -u -p -r1.36.2.20 configure.ac
--- configure.ac        30 Jun 2006 18:58:11 -0000
+++ configure.ac        4 Jul 2006 18:30:55 -0000
@@ -91,6 +91,38 @@ if test "$M4_cv_use_stackovf" = yes; the
+AC_CACHE_CHECK([if system() agrees with pclose()],
+  [M4_cv_func_system_consistent],
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+], [int i1, i2;
+  FILE *f;
+  i1 = system ("exit 2");
+  if (i1 == -1)
+    return 1;
+  f = popen ("exit 2", "r");
+  if (!f)
+    return 1;
+  i2 = pclose (f);
+  return i1 != i2;])],
+  [M4_cv_func_system_consistent=yes], [M4_cv_func_system_consistent=no],
+/* EMX on OS/2 defines WEXITSTATUS to be (x>>8)&0xff, and uses that for
+   pclose(), but for system() it uses x&0xff instead.  Otherwise, we assume
+   your system is sane and that pclose() and system() are consistent in their
+   values.  If this heuristic is wrong for your platform, report it as a bug
+   to address@hidden  */
+#ifdef __EMX__
+choke me
+], [M4_cv_func_system_consistent=yes], [M4_cv_func_system_consistent=no])])])
+if test "$M4_cv_func_system_consistent" = no ; then
+    [Define to 1 if the return value of system() disagrees with pclose().])
 dnl Don't let changeword get in our way, if bootstrapping with a version of
 dnl m4 that already turned the feature on.
 m4_ifdef([changeword], [m4_undefine([changeword])])dnl
Index: src/builtin.c
RCS file: /sources/m4/m4/src/Attic/builtin.c,v
retrieving revision
diff -u -p -r1. builtin.c
--- src/builtin.c       30 Jun 2006 18:58:11 -0000
+++ src/builtin.c       4 Jul 2006 18:30:55 -0000
@@ -812,7 +812,32 @@ m4_syscmd (struct obstack *obs, int argc
   debug_flush_files ();
   sysval = system (ARG (1));
+  /* OS/2 has a buggy system() that returns exit status in the lowest eight
+     bits, although pclose() and WEXITSTATUS are defined to return exit
+     status in the next eight bits.  Use popen/pclose instead.  Note that
+     applications that care if stdout is a terminal or a pipe, like ls,
+     might behave differently due to this workaround.  */
+  {
+    FILE *pin;
+    errno = 0;
+    pin = popen (ARG (1), "r");
+    if (pin == NULL)
+      {
+        M4ERROR ((warning_status, errno,
+                  "cannot open pipe to command \"%s\"", ARG (1)));
+        sysval = -1;
+      }
+    else
+      {
+        insert_file (pin);
+        sysval = pclose (pin);
+      }
+  }
+#endif /* FUNC_SYSTEM_BROKEN */
 static void

reply via email to

[Prev in Thread] Current Thread [Next in Thread]