From: Eric Blake Date: Tue, 28 Oct 2008 18:14:06 +0000 (-0600) Subject: Override m4 1.4.x dumpdef, as it breaks autom4te. X-Git-Tag: v2.63b~177 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0b08f40fc7956f03209e8c8d7fa72c0e4a3bf32b;p=thirdparty%2Fautoconf.git Override m4 1.4.x dumpdef, as it breaks autom4te. * lib/m4sugar/m4sugar.m4 (m4_dumpdef): New implementation. * doc/autoconf.texi (Redefined M4 Macros) : Mention semantic differences as well as m4_dumpdefs. * NEWS: Likewise. * tests/m4sugar.at (m4@&t@_dumpdef): New test. Signed-off-by: Eric Blake --- diff --git a/ChangeLog b/ChangeLog index 720f4b061..82f3ce372 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2008-10-28 Eric Blake + + Override m4 1.4.x dumpdef, as it breaks autom4te. + * lib/m4sugar/m4sugar.m4 (m4_dumpdef): New implementation. + (m4_copy): Formatting touchup. + * doc/autoconf.texi (Redefined M4 Macros) : Mention + semantic differences as well as m4_dumpdefs. + * NEWS: Likewise. + * tests/m4sugar.at (m4@&t@_dumpdef): New test. + 2008-10-28 Eric Blake Allow m4sugar to be used without autom4te, such as in bison. diff --git a/NEWS b/NEWS index 1f969b13d..e22559ff2 100644 --- a/NEWS +++ b/NEWS @@ -17,7 +17,7 @@ GNU Autoconf NEWS - User visible changes. m4_set_map ** The following m4sugar macros are documented now: - m4_copy m4_rename + m4_copy m4_dumpdefs m4_rename ** The following documented m4sh macros are new: AS_LINENO_PREPARE AS_ME_PREPARE AS_VAR_APPEND AS_VAR_ARITH diff --git a/doc/autoconf.texi b/doc/autoconf.texi index c1427a67d..d315ebbf0 100644 --- a/doc/autoconf.texi +++ b/doc/autoconf.texi @@ -10272,7 +10272,6 @@ define your own macros into these namespaces. @msindex{decr} @msindex{define} @msindex{divnum} -@msindex{dumpdef} @msindex{errprint} @msindex{esyscmd} @msindex{eval} @@ -10304,7 +10303,6 @@ The list of macros unchanged from M4, except for their name, is: @item m4_decr @item m4_define @item m4_divnum -@item m4_dumpdef @item m4_errprint @item m4_esyscmd @item m4_eval @@ -10404,6 +10402,19 @@ m4_divert_pop()m4_divert_push([@var{diversion}]) diversion stack. @end defmac +@defmac m4_dumpdef (@var{name}@dots{}) +@defmacx m4_dumpdefs (@var{name}) +@msindex{dumpdef} +@msindex{dumpdefs} +@code{m4_dumpdef} is like the M4 builtin, except that this version +requires at least one argument, output always goes to standard error +rather than the current debug file, and an error is issued if any +@var{name} is undefined. @code{m4_dumpdefs} is a convenience macro that +takes exactly one @var{name}, and calls @code{m4_dumpdef} for all of the +@code{m4_pushdef} stack of definitions, starting with the current, and +silently does nothing if @var{name} is undefined. +@end defmac + @defmac m4_exit (@var{exit-status}) @msindex{exit} This macro corresponds to @code{m4exit}. diff --git a/lib/m4sugar/m4sugar.m4 b/lib/m4sugar/m4sugar.m4 index a17776c1a..608c2f239 100644 --- a/lib/m4sugar/m4sugar.m4 +++ b/lib/m4sugar/m4sugar.m4 @@ -539,8 +539,8 @@ m4_define([_m4_bpatsubsts], # involved in the implementation of m4_stack_foreach and m4_curry. m4_define([m4_copy], [m4_ifdef([$2], [m4_fatal([$0: won't overwrite defined macro: $2])], - [m4_stack_foreach([$1], [m4_curry([m4_pushdef], [$2])])m4_ifdef([m4_location($1)], -[m4_define([m4_location($2)], m4_location)])])]) + [m4_stack_foreach([$1], [m4_curry([m4_pushdef], [$2])])])]dnl +[m4_ifdef([m4_location($1)], [m4_define([m4_location($2)], m4_location)])]) # m4_define_default(MACRO, VALUE) @@ -596,6 +596,24 @@ m4_define([m4_defn], [m4_foreach([_m4_macro], [$@], [$0(_m4_defn([_m4_macro]))])])]) +# m4_dumpdef(NAME...) +# ------------------- +# In m4 1.4.x, dumpdef writes to the current debugfile, rather than +# stderr. This in turn royally confuses autom4te; so we follow the +# lead of newer m4 and always dump to stderr. Unlike the original, +# this version requires an argument, since there is no convenient way +# in m4 1.4.x to grab the names of all defined macros. Newer m4 +# always dumps to stderr, regardless of the current debugfile; it also +# provides m4symbols as a way to grab all current macro names. But +# dumpdefs is not frequently called, so we don't need to worry about +# conditionally using these newer features. +m4_define([m4_dumpdef], +[m4_if([$#], [0], [m4_fatal([$0: missing argument])], + [$#], [1], [m4_ifdef([$1], [m4_errprintn( + [$1: ]m4_dquote(_m4_defn([$1])))], [m4_fatal([$0: undefined macro: $1])])], + [m4_foreach([_m4_macro], [$@], [$0(_m4_defn([_m4_macro]))])])]) + + # m4_dumpdefs(NAME) # ----------------- # Similar to `m4_dumpdef(NAME)', but if NAME was m4_pushdef'ed, display its @@ -603,8 +621,7 @@ m4_define([m4_defn], # # This macro cheats, because it relies on the current definition of NAME # while the second argument of m4_stack_foreach_lifo is evaluated (which -# would be undefined according to the API). If m4_dumpdef is ever rewritten -# not to use the builtin, revisit this. +# would be undefined according to the API). m4_define([m4_dumpdefs], [m4_stack_foreach_lifo([$1], [m4_dumpdef([$1])m4_ignore])]) diff --git a/tests/m4sugar.at b/tests/m4sugar.at index 10ebbd8be..af4c4d5a8 100644 --- a/tests/m4sugar.at +++ b/tests/m4sugar.at @@ -151,6 +151,42 @@ a b c AT_CLEANUP +## ------------ ## +## m4_dumpdef. ## +## ------------ ## + +AT_SETUP([m4@&t@_dumpdef]) + +AT_KEYWORDS([m4@&t@_dumpdefs]) + +# Ensure that m4sugar dies when dereferencing undefined macros. + +AT_DATA_M4SUGAR([script.4s], +[[m4_define([good], [yep]) +m4_dumpdef([good], [oops]) +]]) + +AT_CHECK_M4SUGAR([-o-], 1, [], [stderr]) +AT_CHECK([grep '^good: \[[yep\]]$' stderr], [0], [ignore]) +AT_CHECK([grep 'm4@&t@_dumpdef: undefined.*oops' stderr], [0], [ignore]) + +# Check that pushdef stacks can be dumped. +AT_CHECK_M4SUGAR_TEXT([[m4_divert_push([KILL]) +m4_pushdef([a], [1]) +m4_pushdef([a], [2]) +m4_dumpdef([a]) +m4_dumpdefs([a]) +m4_dumpdefs([oops]) +m4_divert_pop([KILL])dnl +]], [], +[[a: [2] +a: [2] +a: [1] +]]) + +AT_CLEANUP + + ## --------- ## ## m4_warn. ## ## --------- ##