traceon(`traceon')

Eric Blake <[email protected]>
Newsgroups gmane.comp.gnu.m4.patches
Message-ID <[email protected]>
Back when I first started contributing to m4, prior to 1.4.4b, I broke a corner 
case of traceon while fixing a memory corruption bug [1].  The symptoms are 
that any attempt to turn on tracing of a macro currently being expanded will 
delete the current definition of that macro.  Or, for an example:

$ m4 <<\EOF
dumpdef(`traceon')dnl
traceon(`traceon')dnl
dumpdef(`traceon')dnl
traceon(`traceoff')
EOF
traceon:	<traceon>
m4:stdin:3: Warning: dumpdef: undefined macro `traceon'
traceon(traceoff)
$

[1] http://git.savannah.gnu.org/gitweb/?p=m4.git;a=commitdiff;h=f15fa#patch4

In the meantime, the workaround for 1.4.4b through 1.4.11 (ie. all m4 versions 
that I've ever released), is to use 'm4 -ttraceon' to trace traceon itself; and 
for all other macros, avoid using traceon inside argument collection of the 
macro that is intended to be traced.

I'll be hiding under a brown bag for a while.  And for the superstitious, the 
date at which I introduced the regression is rather ominous.  Fortunately, the 
master branch never suffered from this bug.


From c8a2c296df00c2e8b1b3b0372cea10d0d0a0b621 Mon Sep 17 00:00:00 2001
From: Eric Blake <[email protected]>
Date: Wed, 7 May 2008 10:55:33 -0600
Subject: [PATCH] Fix traceon regression introduced 2006-06-06.

* src/builtin.m4 (traceon): Only perform insertion if lookup
fails.
* doc/m4.texinfo (Trace): Test for the bug.
* NEWS: Document it.

Signed-off-by: Eric Blake <[email protected]>
---
 ChangeLog      |    8 ++++++++
 NEWS           |    4 ++++
 doc/m4.texinfo |   10 ++++++++++
 src/builtin.c  |    4 +++-
 4 files changed, 25 insertions(+), 1 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 91c1845..d5b23b6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2008-05-07  Eric Blake  <[email protected]>
+
+	Fix traceon regression introduced 2006-06-06.
+	* src/builtin.m4 (traceon): Only perform insertion if lookup
+	fails.
+	* doc/m4.texinfo (Trace): Test for the bug.
+	* NEWS: Document it.
+
 2008-05-05  Eric Blake  <[email protected]>
 
 	Stage 22: allow builtin token concatenation outside $@.
diff --git a/NEWS b/NEWS
index 052cbbc..9bde89c 100644
--- a/NEWS
+++ b/NEWS
@@ -5,6 +5,10 @@ Foundation, Inc.
 * Noteworthy changes in Version 1.6 (????-??-??) [stable]
   Released by ????, based on git version 1.4.10b.x-*
 
+** Fix regression introduced in 1.4.4b where using `traceon' could delete
+   a macro.  This was most noticeable with `traceon(`traceon')', but
+   would also happen in cases such as `foo(traceon(`foo'))'.
+
 ** Fix regression introduced in 1.4.10b (but not present in 1.4.11) where
    using `builtin' or `indir' to perform nested `shift' calls triggered an
    assertion failure.
diff --git a/doc/m4.texinfo b/doc/m4.texinfo
index fd04622..30db58a 100644
--- a/doc/m4.texinfo
+++ b/doc/m4.texinfo
@@ -3708,6 +3708,16 @@ does not transfer tracing status.
 
 @example
 $ @kbd{m4 -d}
+traceon(`traceon')
+@result{}
+traceon(`traceoff')
+@error{}m4trace: -1- traceon(`traceoff')
+@result{}
+traceoff(`traceoff')
+@error{}m4trace: -1- traceoff(`traceoff')
+@result{}
+traceoff(`traceon')
+@result{}
 traceon(`eval', `m4_divnum')
 @result{}
 define(`m4_eval', defn(`eval'))
diff --git a/src/builtin.c b/src/builtin.c
index 8ce6cf7..0549745 100644
--- a/src/builtin.c
+++ b/src/builtin.c
@@ -1672,7 +1672,9 @@ m4_traceon (struct obstack *obs, int argc, 
macro_arguments *argv)
 	    m4_warn (0, me, _("invalid macro name ignored"));
 	    continue;
 	  }
-	s = lookup_symbol (ARG (i), SYMBOL_INSERT);
+	s = lookup_symbol (ARG (i), SYMBOL_LOOKUP);
+	if (!s)
+	  s = lookup_symbol (ARG (i), SYMBOL_INSERT);
 	set_trace (s, obs);
       }
 }
-- 
1.5.5.1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.