[Top][All Lists]

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

Re: bad define semantics in GNU m4

From: Gary V. Vaughan
Subject: Re: bad define semantics in GNU m4
Date: Fri, 27 Jun 2003 11:17:17 +0100
User-agent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.3) Gecko/20030312

Richard Stallman wrote:
In general, we look at standards as guidelines to what users may
expect or want--not as authorities to be obeyed.  To the extent that
users expect compatibility with a certain standard, it is useful to
give them what they want.  But the mere fact that something is labeled
a standard does not require us to obey it.

    On the other hand, I would like to support the standard in some
    way, perhaps changing the behaviour to match the SUS if m4 is
    invoked with --traditional, or if POSIXLY_CORRECT (hmm
    SUSLY_CORRECT...) is set in the environment?

That is a good idea.  I think that --traditional is a more convenient
interface for this particular feature.


In which case, I propose the small attached patch.  Comments?

  ())_. Gary V. Vaughan     gary@(oranda.demon.co.uk|gnu.org)
  ( '/  Research Scientist  http://www.oranda.demon.co.uk       ,_())____
  / )=  GNU Hacker          http://www.gnu.org/software/libtool  \'      `&
`(_~)_  Tech' Author        http://sources.redhat.com/autobook   =`---d__/
Index: ChangeLog
from  Gary V. Vaughan  <address@hidden>

        * modules/m4.c (builtin_define): Smash the value stack in
        traditional mode.
        * tests/builtin.at (define): Test define/pushdef/popdef
        interactions in GNU and traditional modes.
        * doc/m4.texinfo (Define): Mention stack smashing on some UNIX m4
        (Other Incompat): Reference SUSv3, and --traditional behaviour of
        GNU m4 to satisfy it.
        * NEWS: Updated.

Index: NEWS
RCS file: /cvsroot/m4/m4/NEWS,v
retrieving revision 1.8
diff -u -p -u -r1.8 NEWS
--- NEWS 4 Oct 2001 08:03:18 -0000 1.8
+++ NEWS 27 Jun 2003 10:08:20 -0000
@@ -1,6 +1,12 @@
 GNU m4 NEWS - History of user-visible changes.         -*- outline -*-
 Copyright 1992, 1993, 1994, 1998, 2000, 2001 Free Software Foundation, Inc.
+Version beta 1.4r - ???, by ???
+* `m4 --traditional' now makes the `define' builtin behave as specified
+  in http://www.unix.org/single_unix_specification and replace all
+  `pushdef'ed values of a macro.
 Version beta 1.4q - August 2001, by Gary V. Vaughan
 * Support for the experimental `changeword' has been dropped.
Index: doc/m4.texinfo
RCS file: /cvsroot/m4/m4/doc/m4.texinfo,v
retrieving revision 1.15
diff -u -p -u -r1.15 m4.texinfo
--- doc/m4.texinfo 6 Nov 2002 09:35:15 -0000 1.15
+++ doc/m4.texinfo 27 Jun 2003 10:08:33 -0000
@@ -1032,6 +1032,14 @@ a part of the macro definition, and it i
 the output.  This can be avoided by use of the macro @code{dnl}.
 @xref{Dnl}, for details.
address@hidden GNU extensions
+GNU @code{m4} normally replaces only the @emph{topmost} definition of a
+macro if it has several definitions from @code{pushdef}.
address@hidden, , Temporarily redefining macros}, for an explanation of
address@hidden Some other UNIX implementations replace all definitions
+of a macro with @code{define}.
address@hidden Incompat, , Other incompatibilities}, for more details.
 The first argument to @code{define} does not have to be a simple word.
 It can be any text string.  A macro with a non standard name cannot be
 invoked in the normal way, as the name is not recognised.  It can only
@@ -3878,6 +3886,15 @@ 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.
+Some implementations of @code{m4} (Solaris for example) follow the
+Single Unix Specification} which makes @code{define(@var{macro})} behave
+like @code{undefine(@var{macro})pushdef(@var{macro})}. Other
+implementations including GNU @code{m4} without the @samp{-G} option
+treat @code{define(@var{macro})} as
 @findex __gnu__
Index: modules/m4.c
RCS file: /cvsroot/m4/m4/modules/m4.c,v
retrieving revision 1.45
diff -u -p -u -r1.45 m4.c
--- modules/m4.c 26 Jun 2003 14:57:32 -0000 1.45
+++ modules/m4.c 27 Jun 2003 10:08:36 -0000
@@ -161,6 +161,9 @@ M4BUILTIN_HANDLER (define)
        m4_symbol_value_copy (value, argv[2]);
+      if (m4_get_no_gnu_extensions_opt (context))
+       m4_symbol_delete (M4SYMTAB, M4ARG (1));
       m4_symbol_define (M4SYMTAB, M4ARG (1), value);
Index: tests/builtins.at
RCS file: /cvsroot/m4/m4/tests/builtins.at,v
retrieving revision 1.7
diff -u -p -u -r1.7 builtins.at
--- tests/builtins.at 13 Oct 2001 08:55:55 -0000 1.7
+++ tests/builtins.at 27 Jun 2003 10:08:36 -0000
@@ -20,6 +20,44 @@ AT_BANNER([Torturing builtins.])
 ## ------ ##
+## define ##
+## ------ ##
+pushdef(`macro', `base value')dnl
+pushdef(`macro', `hello, world')dnl
+pushdef(`macro', `top value')dnl
+define(`macro', `new value')dnl
+AT_CHECK_M4([define.m4], 0,
+[[new value.
+hello, world.
+base value.
+]], [[m4: define.m4: 1: Warning: undefine: undefined name: macro
+AT_CHECK_M4([--traditional define.m4], 0,
+[[new value.
+]], [[m4: define.m4: 1: Warning: undefine: undefined name: macro
+m4: define.m4: 9: Warning: popdef: undefined name: macro
+## ------ ##
 ## divert ##
 ## ------ ##

reply via email to

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