m4-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

branch-1_4 - platform recognition macro


From: Eric Blake
Subject: branch-1_4 - platform recognition macro
Date: Fri, 30 Jun 2006 09:05:51 -0600
User-agent: Thunderbird 1.5.0.4 (Windows/20060516)

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

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.

2006-06-30  Eric Blake  <address@hidden>

        * src/m4.h (UNIX, W32_NATIVE): Improve platform detection macros.
        * src/freeze.c (produce_frozen_state): Use new spelling of
        platform macro.
        * src/builtin.c (predefined_tab): Add __windows__ on non-unix
        platforms.
        (m4_syscmd, m4_esyscmd): The empty command is successful.
        * doc/m4.texinfo (Shell commands): Rename from UNIX commands.
        Document platform-dependence of system().
        (Syscmd): Add example.
        (Esyscmd): Make example more robust, and actually demonstrate
        rescanning.
        (Sysval): Expand test to cover esyscmd code path, and to check
        that empty command is successful.  Add conditional check for
        signal behavior.
        (Other Incompatibilities): Move platform macros from here...
        (Platform macros): ...to this new node.  Add windows macro.
        Check that exactly one platform macro is provided.
        * checks/check-them: Improve trap cleanup.  Tolerate dirname and
        .exe in error messages.  Allow for skipping checks.
        * configure.ac (HAVE_EFGCVT): Kill dead configure check.
        * NEWS: Document platform macros.

- --
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

iD8DBQFEpT3P84KuGfSFAYARAvCQAJ4/r4qVtyTR5bMmXIXTELjPSADR7wCdGdtL
YvTEbPs71ljauv/yZvKXSqg=
=0k2x
-----END PGP SIGNATURE-----
Index: NEWS
===================================================================
RCS file: /sources/m4/m4/NEWS,v
retrieving revision 1.1.1.1.2.27
diff -u -p -r1.1.1.1.2.27 NEWS
--- NEWS        30 Jun 2006 03:38:48 -0000      1.1.1.1.2.27
+++ NEWS        30 Jun 2006 15:02:47 -0000
@@ -22,6 +22,9 @@ Version 1.4.5 - ?? 2006, by ???  (CVS ve
   zeroes on integers printed with %.0f.  On systems without these
   functions, format is no longer subject to a buffer overflow that
   permitted arbitrary code execution.
+* On Windows builds, the macro __windows__ is provided instead of __unix__.
+  This allows input files to determine when syscmd might behave
+  differently.
 
 Version 1.4.4b - 17 June 2006, by Eric Blake  (CVS version 1.4.4a)
 
Index: configure.ac
===================================================================
RCS file: /sources/m4/m4/configure.ac,v
retrieving revision 1.36.2.18
diff -u -p -r1.36.2.18 configure.ac
--- configure.ac        29 Jun 2006 13:41:49 -0000      1.36.2.18
+++ configure.ac        30 Jun 2006 15:02:47 -0000
@@ -52,18 +52,6 @@ AC_CHECK_FUNCS_ONCE([sigaction sigaltsta
 
 M4_INIT
 
-AC_CACHE_CHECK([ecvt declaration], [M4_cv_have_efgcvt],
-[AC_EGREP_HEADER([ecvt], [stdlib.h],
-  [M4_cv_have_efgcvt=yes], [M4_cv_have_efgcvt=no])])
-if test $M4_cv_have_efgcvt = yes ; then
-  AC_DEFINE([HAVE_EFGCVT], [2],
-     [Define to 1 if you have ecvt(3), fcvt(3) and gcvt(3).  Define to 2 if
-they are declared in stdlib.h])
-else
-  AC_CHECK_FUNCS([ecvt])
-fi
-
-
 # Code from Jim Avera <address@hidden>.
 # stackovf.c requires:
 #  1. Either sigaction with SA_ONSTACK, or sigvec with SV_ONSTACK
Index: checks/check-them
===================================================================
RCS file: /sources/m4/m4/checks/Attic/check-them,v
retrieving revision 1.1.1.1.2.2
diff -u -p -r1.1.1.1.2.2 check-them
--- checks/check-them   11 May 2006 12:56:19 -0000      1.1.1.1.2.2
+++ checks/check-them   30 Jun 2006 15:02:47 -0000
@@ -2,19 +2,45 @@
 # Check GNU m4 against examples from the manual source.
 # Copyright (C) 1992, 2006 Free Software Foundation, Inc.
 
-out=/tmp/m4-out.$$
-err=/tmp/m4-err.$$
-xout=/tmp/m4-xout.$$
-xerr=/tmp/m4-xerr.$$
+# Sanity check what we are testing
+m4 --version
 
-trap "rm -f $out $err $xout $xerr; exit 1" 1 2 15
+# Clean up temp files on exit
+pwd=`pwd`
+tmp=m4-tmp.$$
+trap 'stat=$?; cd $pwd; rm -rf $tmp && exit $stat' 0
+trap '(exit $?); exit $?' 1 2 13 15
+
+# Create scratch dir
+framework_failure=0
+mkdir $tmp || framework_failure=1
+
+if test $framework_failure = 1; then
+  echo "$0: failure in testing framework" 1>&2
+  (exit 1); exit 1
+fi
 
-m4 --version
+out=$tmp/m4-out
+err=$tmp/m4-err
+xout=$tmp/m4-xout
+xerr=$tmp/m4-xerr
+failed=
+skipped=
+
+# Find out how the executable prints argv[0]
+m4=`m4 --help | sed -e 's/Usage: \(.*\) \[OPTION.*/\1/' \
+    -e 's/\\\\/\\\\\\\\/g' -e 1q`
 
+# Run the tests.  This assumes pwd is the checks directory.
 for file
 do
   echo "Checking $file"
-  LC_MESSAGES=C m4 -d $file >$out 2>$err
+  LC_MESSAGES=C m4 -d -I ../examples $file >$out 2>$err
+
+  if test $? == 77 ; then
+    skipped="$skipped $file"
+    continue
+  fi
 
   sed -e '/^dnl @result{}/!d' -e 's///' -e "s/m4.input/$file/" $file > $xout
 
@@ -27,7 +53,8 @@ do
     diff $xout $out
   fi
 
-  sed -e '/^dnl @error{}/!d' -e 's///' -e "s/m4.input/$file/" $file > $xerr
+  sed -e '/^dnl @error{}/!d' -e 's///' -e "s/m4.input/$file/" \
+      -e "s| $m4:| m4:|" $file > $xerr
 
   if cmp -s $err $xerr; then
     :
@@ -43,9 +70,16 @@ done
 rm -f $out $err $xout $xerr
 
 echo
+if test -n "$skipped"; then
+  echo "Skipped checks were:"
+  echo " $skipped"
+fi
 if test -z "$failed"; then
   echo "All checks successful"
+  stat=0
 else
   echo "Failed checks were:"
   echo " $failed"
+  stat=1
 fi
+(exit $stat); exit $stat
Index: doc/m4.texinfo
===================================================================
RCS file: /sources/m4/m4/doc/m4.texinfo,v
retrieving revision 1.1.1.1.2.27
diff -u -p -r1.1.1.1.2.27 m4.texinfo
--- doc/m4.texinfo      30 Jun 2006 03:38:49 -0000      1.1.1.1.2.27
+++ doc/m4.texinfo      30 Jun 2006 15:02:48 -0000
@@ -127,7 +127,7 @@ changeword will go away and you should n
 
 * Text handling::               Macros for text handling
 * Arithmetic::                  Macros for doing arithmetic
-* UNIX commands::               Macros for running UNIX commands
+* Shell commands::              Macros for running shell commands
 * Miscellaneous::               Miscellaneous builtin macros
 * Frozen files::                Fast loading of frozen states
 
@@ -222,8 +222,9 @@ Macros for doing arithmetic
 * Incr::                        Decrement and increment operators
 * Eval::                        Evaluating integer expressions
 
-Running UNIX commands
+Running shell commands
 
+* Platform macros::             Determining the platform
 * Syscmd::                      Executing simple commands
 * Esyscmd::                     Reading the output of commands
 * Sysval::                      Exit codes
@@ -271,7 +272,7 @@ language.
 input to the output, expanding macros as it goes.  Macros are either
 builtin or user-defined, and can take any number of arguments.
 Besides just doing macro expansion, @code{m4} has builtin functions
-for including named files, running UNIX commands, doing integer
+for including named files, running shell commands, doing integer
 arithmetic, manipulating text in various ways, recursion, address@hidden
 @code{m4} can be used either as a front-end to a compiler, or as a
 macro processor in its own right.
@@ -2230,7 +2231,7 @@ Then, the @code{m4} version:
 
 @comment ignore
 @example
-define(a, `errprint(`Hello')')dnl
+define(`a', `errprint(`Hello')')dnl
 changeword(`@@\([_a-zA-Z0-9]*\)')
 @result{}
 @@a
@@ -3007,7 +3008,7 @@ specifiers, and give warnings when probl
 
 The macro @code{format} is recognized only with parameters.
 
address@hidden Arithmetic, UNIX commands, Text handling, Top
address@hidden Arithmetic, Shell commands, Text handling, Top
 @chapter Macros for doing arithmetic
 
 @cindex arithmetic
@@ -3193,24 +3194,91 @@ Take note that @var{radix} cannot be lar
 
 The builtin macro @code{eval} is recognized only when given arguments.
 
address@hidden UNIX commands, Miscellaneous, Arithmetic, Top
address@hidden Running UNIX commands
address@hidden Shell commands, Miscellaneous, Arithmetic, Top
address@hidden Running shell commands
 
 @cindex executing UNIX commands
 @cindex running UNIX commands
 @cindex UNIX commands, running
 @cindex commands, running UNIX
-There are a few builtin macros in @code{m4} that allow you to run UNIX
address@hidden executing shell commands
address@hidden running shell commands
address@hidden shell commands, running
address@hidden commands, running shell
+There are a few builtin macros in @code{m4} that allow you to run shell
 commands from within @code{m4}.
 
+Note that the definition of a valid shell command is system dependent.
+On UNIX systems, this is the typical @code{/bin/sh}.  But on other
+systems, such as native Windows, the shell has a different syntax of
+commands that it understands.  Some examples in this chapter assume
address@hidden/bin/sh}, and also demonstrate how to quit early with a known
+exit value if this is not the case.
+
 @menu
+* Platform macros::             Determining the platform
 * Syscmd::                      Executing simple commands
 * Esyscmd::                     Reading the output of commands
 * Sysval::                      Exit codes
 * Maketemp::                    Making names for temporary files
 @end menu
 
address@hidden Syscmd, Esyscmd, UNIX commands, UNIX commands
address@hidden Platform macros, Syscmd, Shell commands, Shell commands
address@hidden Determining the platform
+
address@hidden platform macros
+Sometimes it is desirable for an input file to know which
+platform @code{m4} is running on.  GNU @code{m4} provides several
+macros that are predefined to expand to the empty string; checking for
+their existence will confirm platform details.
+
address@hidden ignore
address@hidden
+__gnu__
+__unix__
+unix
+__windows__
+windows
address@hidden example
+
address@hidden gnu
+When GNU extensions are in effect (that is, when you did not use the
address@hidden option), GNU @code{m4} will define the macro @code{__gnu__} to
+expand to the empty string.
+
address@hidden
+__gnu__
address@hidden
+ifdef(`__gnu__', `Extensions are active')
address@hidden are active
address@hidden example
+
address@hidden unix
address@hidden platform macro
+On UNIX systems, GNU @code{m4} without the @samp{-G} option will define
+the macro @code{__unix__}, otherwise the macro @code{unix}.  Both will
+expand to the empty string.
+
address@hidden windows
+On native Windows systems, GNU @code{m4} without the @samp{-G} option
+will define the macro @code{__windows__}, otherwise the macro
address@hidden  Both will expand to the empty string.
+
+If GNU @code{m4} does not provide a platform macro for your system,
+please report that as a bug.
+
address@hidden
+define(`provided', `0')
address@hidden
+ifdef(`__gnu__', `define(`provided', incr(provided))')
address@hidden
+ifdef(`__windows__', `define(`provided', incr(provided))')
address@hidden
+provided
address@hidden
address@hidden example
+
address@hidden Syscmd, Esyscmd, Platform macros, Shell commands
 @section Executing simple commands
 
 @findex syscmd
@@ -3233,14 +3301,25 @@ Prior to executing the command, @code{m4
 The default standard input, output and error of @var{shell-command} are
 the same as those of @code{m4}.
 
address@hidden
+define(`foo', `FOO')
address@hidden
+syscmd(`echo foo')
address@hidden
address@hidden
address@hidden example
+
+Note how the expansion of @code{syscmd} keeps the trailing newline of
+the command, as well as using the newline that appeared after the macro.
+
 The builtin macro @code{syscmd} is recognized only when given arguments.
 
address@hidden Esyscmd, Sysval, Syscmd, UNIX commands
address@hidden Esyscmd, Sysval, Syscmd, Shell commands
 @section Reading the output of commands
 
 @findex esyscmd
 @cindex GNU extensions
-If you want @code{m4} to read the output of a UNIX command, use
+If you want @code{m4} to read the output of a shell command, use
 @code{esyscmd}:
 
 @comment ignore
@@ -3258,28 +3337,29 @@ the same as those of @code{m4}.  The err
 is not a part of the expansion: it will appear along with the error
 output of @code{m4}.
 
-Assume you are positioned into the @file{checks} directory of GNU
address@hidden distribution, then:
-
 @example
-define(`vice', `esyscmd(`grep Vice ../COPYING')')
+define(`foo, `FOO')
 @result{}
-vice
address@hidden  Ty Coon, President of Vice
+esyscmd(`echo foo')
address@hidden
 @result{}
 @end example
 
-Note how the expansion of @code{esyscmd} has a trailing newline.
+Note how the expansion of @code{esyscmd} keeps the trailing newline of
+the command, as well as using the newline that appeared after the macro.
 
 The builtin macro @code{esyscmd} is recognized only when given
 arguments.
 
address@hidden Sysval, Maketemp, Esyscmd, UNIX commands
address@hidden Sysval, Maketemp, Esyscmd, Shell commands
 @section Exit codes
 
 @cindex exit code from UNIX commands
 @cindex UNIX commands, exit code from
 @cindex commands, exit code from UNIX
address@hidden exit code from shell commands
address@hidden shell commands, exit code from
address@hidden commands, exit code from shell
 @findex sysval
 To see whether a shell command succeeded, use @code{sysval}:
 
@@ -3297,6 +3377,10 @@ syscmd(`false')
 @result{}
 ifelse(sysval, `0', `zero', `non-zero')
 @result{}non-zero
+syscmd
address@hidden
+sysval
address@hidden
 syscmd(`exit 2')
 @result{}
 sysval
@@ -3305,9 +3389,49 @@ syscmd(`true')
 @result{}
 sysval
 @result{}0
+esyscmd(`false')
address@hidden
+ifelse(sysval, `0', `zero', `non-zero')
address@hidden
+esyscmd
address@hidden
+sysval
address@hidden
+esyscmd(`exit 2')
address@hidden
+sysval
address@hidden
+esyscmd(`true')
address@hidden
+sysval
address@hidden
address@hidden example
+
address@hidden results in 127 if there was a problem executing the
+command, for example, if the system-imposed argument length is exceeded,
+or if there were not enough resources to fork.  It is not possible to
+distinguish between failed execution and successful execution that had
+an exit status of 127.
+
+On UNIX platforms, where it is possible to detect when command execution
+is terminated by a signal, rather than a normal exit, the result is the
+signal number shifted left by eight bits.
+
address@hidden
+dnl This test assumes kill is a shell builtin, and that signals are
+dnl recognizable.
+ifdef(`__unix__', , `m4exit(`77')')dnl
+syscmd(`kill -1 $$')
address@hidden
+sysval
address@hidden
+esyscmd(`kill -9 $$')
address@hidden
+sysval
address@hidden
 @end example
 
address@hidden Maketemp,  , Sysval, UNIX commands
address@hidden Maketemp,  , Sysval, Shell commands
 @section Making names for temporary files
 
 @cindex temporary filenames
@@ -3344,6 +3468,9 @@ maketemp(`/tmp/fooXXXXXX')
 @c This test makes sure maketemp gets testsuite coverage, but is
 @c somewhat complex for use in the manual.
 @example
+dnl This test assumes /tmp is a valid directory name, which is not true
+dnl for native Windows.
+ifdef(`__unix__', , `m4exit(`77')')dnl
 define(`file1', maketemp(`/tmp/fooXXXXXX'))dnl
 define(`file2', maketemp(`/tmp/fooXXXXXX'))dnl
 ifelse(file1, file2, `same', `different')
@@ -3358,7 +3485,7 @@ sysval
 The builtin macro @code{maketemp} is recognized only when given
 arguments.
 
address@hidden Miscellaneous, Frozen files, UNIX commands, Top
address@hidden Miscellaneous, Frozen files, Shell commands, Top
 @chapter Miscellaneous builtin macros
 
 This chapter describes various builtins, that do not really belong in
@@ -3797,7 +3924,7 @@ of the macro is different even if the in
 @item
 @acronym{POSIX} requires @code{changequote(@var{arg})}
 (@pxref{Changequote}) to use newline as the close quote, but GNU
address@hidden uses @samp{'} as the close quote.  Meanwhile,  some
address@hidden uses @samp{'} as the close quote.  Meanwhile, some
 traditional implementations use @var{arg} as the close quote, making it
 impossible to nest quotes.  For predictable results, never call
 changequote with just one argument.
@@ -3884,16 +4011,6 @@ name would be a useless limitation.  Of 
 for the GNU @code{m4} user to hang himself!  Rescanning hangs may be
 avoided through careful programming, a little like for endless loops
 in traditional programming languages.
-
address@hidden
address@hidden gnu
-GNU @code{m4} without @samp{-G} option will define the macro
address@hidden to expand to the empty string.
-
address@hidden unix
-On UNIX systems, GNU @code{m4} without the @samp{-G} option will define
-the macro @code{__unix__}, otherwise the macro @code{unix}.  Both will
-expand to the empty string.
 @end itemize
 
 @node Concept index, Macro index, Compatibility, Top
Index: src/builtin.c
===================================================================
RCS file: /sources/m4/m4/src/Attic/builtin.c,v
retrieving revision 1.1.1.1.2.14
diff -u -p -r1.1.1.1.2.14 builtin.c
--- src/builtin.c       23 Jun 2006 12:58:20 -0000      1.1.1.1.2.14
+++ src/builtin.c       30 Jun 2006 15:02:48 -0000
@@ -148,7 +148,13 @@ builtin_tab[] =
 static predefined const
 predefined_tab[] =
 {
+#if UNIX
   { "unix",    "__unix__",     "" },
+#elif W32_NATIVE
+  { "windows", "__windows__",  "" },
+#else
+# warning Platform macro not provided
+#endif
   { NULL,      "__gnu__",      "" },
 
   { NULL,      NULL,           NULL },
@@ -770,7 +776,11 @@ static void
 m4_syscmd (struct obstack *obs, int argc, token_data **argv)
 {
   if (bad_argc (argv[0], argc, 2, 2))
-    return;
+    {
+      /* The empty command is successful.  */
+      sysval = 0;
+      return;
+    }
 
   debug_flush_files ();
   sysval = system (ARG (1));
@@ -783,7 +793,11 @@ m4_esyscmd (struct obstack *obs, int arg
   int ch;
 
   if (bad_argc (argv[0], argc, 2, 2))
-    return;
+    {
+      /* The empty command is successful.  */
+      sysval = 0;
+      return;
+    }
 
   debug_flush_files ();
   errno = 0;
Index: src/freeze.c
===================================================================
RCS file: /sources/m4/m4/src/freeze.c,v
retrieving revision 1.1.1.1.2.7
diff -u -p -r1.1.1.1.2.7 freeze.c
--- src/freeze.c        23 Jun 2006 13:06:10 -0000      1.1.1.1.2.7
+++ src/freeze.c        30 Jun 2006 15:02:48 -0000
@@ -56,7 +56,7 @@ produce_frozen_state (const char *name)
   symbol *sym;
   const builtin *bp;
 
-#ifdef WIN32
+#ifdef W32_NATIVE
 # define FROZEN_WRITE "wb"
 #else
 # define FROZEN_WRITE "w"
Index: src/m4.h
===================================================================
RCS file: /sources/m4/m4/src/m4.h,v
retrieving revision 1.1.1.1.2.12
diff -u -p -r1.1.1.1.2.12 m4.h
--- src/m4.h    22 Jun 2006 23:17:22 -0000      1.1.1.1.2.12
+++ src/m4.h    30 Jun 2006 15:02:48 -0000
@@ -27,12 +27,15 @@
 # include <config.h>
 #endif
 
-/* Canonicalise Windows and Cygwin recognition macros.  */
-#if defined __CYGWIN32__ && !defined __CYGWIN__
-#  define __CYGWIN__ __CYGWIN32__
+/* Canonicalize UNIX recognition macros.  */
+#if defined unix || defined __unix || defined __unix__ \
+  || defined _POSIX_VERSION || defined _POSIX2_VERSION
+# define UNIX 1
 #endif
-#if defined _WIN32 && !defined WIN32
-#  define WIN32 _WIN32
+
+/* Canonicalize Windows recognition macros.  */
+#if (defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__
+# define W32_NATIVE 1
 #endif
 
 #include <sys/types.h>

reply via email to

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