[Top][All Lists]

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

POSIX behavior of define

From: Eric Blake
Subject: POSIX behavior of define
Date: Wed, 28 Feb 2007 07:37:10 -0700
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: Gecko/20061207 Thunderbird/ Mnenhy/

Hash: SHA1

The Austin Group approved XCU ERN 118:

Add to SD5 for D2R

Add to end of 'define' on page 581 22455

It is unspecified whether the 'define' macro deletes all prior
definitions of the macro named by its first argument or preserves all
but the current definition of the macro.

 Add a paragraph to Application Usage, just after line 22567:

 When a macro has been multiply defined via the pushdef macro, it is
 unspecified whether the define macro will alter only the most recent
 definition (as though by popdef and pushdef), or replace the entire
 stack of definitions with a single definition (as though by undefine
 and pushdef).  An application desiring particular behavior for the
 define macro in this case can redefine it accordingly.

As a result, I'm adding this patch to head, and a similar doc patch to the
branch.  (The deletion of 'eval' changes in NEWS is a reflection of the
fact that that change was backported to the branch).

2007-02-28  Eric Blake  <address@hidden>

        POSIX XCU ERN 118 was approved.
        * modules/m4.c (define): Kill posixly_correct distinction in
        define behavior, since POSIX says GNU behavior complies.
        * tests/builtins.at (define): Restore original semantics.
        * doc/m4.texinfo (Pushdef): Document portability issues with
        (Incompatibilities): Clean up wording of what POSIX requires.
        * NEWS: Document this.

- --
Don't work too hard, make some time for fun as well!

Eric Blake             address@hidden
Version: GnuPG v1.4.5 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

Index: NEWS
RCS file: /sources/m4/m4/NEWS,v
retrieving revision 1.38
diff -u -p -r1.38 NEWS
--- NEWS        23 Jan 2007 14:28:22 -0000      1.38
+++ NEWS        28 Feb 2007 14:33:19 -0000
@@ -84,17 +84,9 @@ promoted to 2.0.
 ** POSIX conformance
-*** POSIXLY_CORRECT and `m4 --traditional' now makes the `define' builtin
-  replace all `pushdef'ed values of a macro.
-  - FIXME: The Austin group clarified that this was never a POSIX
-  requirement; consider reverting this change.
 *** The `defn' builtin now allows any number of arguments, as POSIX requires.
   - FIXME: This still doesn't work with concatenating builtins with text.
-*** The `eval' builtin now follows C precedence rules.  Additionally,
-    short-circuit operators correctly short-circuit division by zero.
   - FIXME: POSIX recommends using ${10} instead of $10 for the tenth
   positional argument.  We should deprecate $10.
@@ -107,7 +99,7 @@ promoted to 2.0.
 ** New builtins
-*** New `changeresyntax' builtin allows programmtic setting of the default
+*** New `changeresyntax' builtin allows programmatic setting of the default
     regular expression flavor, to match `-r'/`--regexp-syntax' command-line
@@ -139,9 +131,6 @@ promoted to 2.0.
 ** Changed behavior of builtins
-*** The '$' syntax class to the `changeresyntax' builtin is now enabled.
-    See the manual for examples.
 *** The `builtin' builtin now has a special form, where if the first
     argument is exactly the special token representing defn(`builtin'), the
     expansion is the special token representing the builtin named in the
@@ -155,9 +144,9 @@ promoted to 2.0.
 *** The `changesyntax' builtin has been improved, to make it easier to add
     and remove characters from a syntax class without having to specify the
-    entire set of characters in that class.  It also supports two new
-    syntax categories, `{' and `}', for extended argument handling in macro
-    definitions.
+    entire set of characters in that class.  It also supports new syntax
+    categories, `$', `{' and `}', for extended argument handling in macro
+    definitions.  See the manual for more examples.
 *** New `m' flag to `-d'/`--debug' command-line option or `debugmode'
     builtin traces actions related to module loading and unloading, and
Index: doc/m4.texinfo
RCS file: /sources/m4/m4/doc/m4.texinfo,v
retrieving revision 1.96
diff -u -p -r1.96 m4.texinfo
--- doc/m4.texinfo      5 Feb 2007 17:31:10 -0000       1.96
+++ doc/m4.texinfo      28 Feb 2007 14:33:21 -0000
@@ -2265,7 +2265,12 @@ foo
 If a macro with several definitions is redefined with @code{define}, the
 topmost definition is @emph{replaced} with the new definition.  If it is
 removed with @code{undefine}, @emph{all} the definitions are removed,
-and not only the topmost one.
+and not only the topmost one.  However, @acronym{POSIX} allows other
+implementations that treat @code{define} as replacing an entire stack
+of definitions with a single new definition, so to be portable to other
+implementations, it may be worth explicitly using @code{popdef} and
address@hidden rather than relying on the @acronym{GNU} behavior of
 define(`foo', `Expansion one.')
@@ -7311,13 +7316,11 @@ avoided through careful programming, a l
 in traditional programming languages.
-Some implementations of @code{m4} (Solaris for example) conform to
address@hidden, which requires @code{define(@var{macro})} to behave
-like @code{undefine(@var{macro})pushdef(@var{macro})}.  Other
-implementations, including GNU @code{m4} without the @samp{-G} option
-and without @env{POSIXLY_CORRECT} set, treat
address@hidden(@var{macro})} as
+Traditional implementations handle @code{define(`f',`1')} (@pxref{Define})
+by undefining the entire stack of previous definitions, and if doing
address@hidden(`f')} first.  @acronym{GNU} @code{m4} replaces just the top
+definition on the stack, as if doing @code{popdef(`f')} followed by
address@hidden(`f',`1')}.  @acronym{POSIX} allows either behavior.
 @acronym{POSIX} states that only unquoted leading newlines and blanks
Index: modules/m4.c
RCS file: /sources/m4/m4/modules/m4.c,v
retrieving revision 1.102
diff -u -p -r1.102 m4.c
--- modules/m4.c        27 Jan 2007 00:25:14 -0000      1.102
+++ modules/m4.c        28 Feb 2007 14:33:21 -0000
@@ -1,5 +1,6 @@
 /* GNU m4 -- A simple macro processor
-   Copyright (C) 2000, 2002, 2003, 2004, 2006, 2007 Free Software Foundation, 
+   Copyright (C) 2000, 2002, 2003, 2004, 2006, 2007 Free Software
+   Foundation, Inc.
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -180,9 +181,6 @@ M4BUILTIN_HANDLER (define)
        m4_symbol_value_copy (value, argv[2]);
-      if (m4_get_posixly_correct_opt (context))
-       m4_symbol_delete (M4SYMTAB, M4ARG (1));
       m4_symbol_define (M4SYMTAB, M4ARG (1), value);
Index: tests/builtins.at
RCS file: /sources/m4/m4/tests/builtins.at,v
retrieving revision 1.37
diff -u -p -r1.37 builtins.at
--- tests/builtins.at   15 Jan 2007 14:04:27 -0000      1.37
+++ tests/builtins.at   28 Feb 2007 14:33:21 -0000
@@ -150,10 +150,9 @@ base value.
 AT_CHECK_M4([--traditional define.m4], 0,
 [[new value.
+hello, world.
+base value.
 ]], [[m4:define.m4:1: Warning: undefine: undefined macro `macro'
-m4:define.m4:9: Warning: popdef: undefined macro `macro'

reply via email to

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