-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 According to Ralf Wildenhues on 6/12/2009 12:28 AM: >> Good point. So, back to my other question - would you rather manually >> undefine the pre-existing definitions at all usage points, or would you >> rather that I create a new m4sugar macro m4_rename_force in autoconf 2.64 >> which performs the rename regardless of the defined-ness of the >> destination, at which point your gcc patch would be s/m4_rename/&_force/ >> rather than adding a line of m4_undefine? > > Well, I don't mind to have a m4_rename_force, but I would still add the > m4_undefine everywhere, in order to have consistent code that can also > be reused with older Autoconf (parts of the GCC tree are also used in > other projects such as libffi, without the override code in ../config, > and it is helpful not to have to force Autoconf version bump everywhere > at the same time).
Or backport a definition of m4_rename_force up front for all autoconf versions where it is not defined. At any rate, here's what I'm committing. I am willing to make a slight change in semantics for m4_copy_force, if others want it: m4_copy_force([undefined], [defined]) currently behaves as a synonym for m4_undefine([defined]), but I could see it being useful to error out in this case. m4_copy_force([undefined], [undefined]) will remain a silent no-op, just like m4_copy. This rewrite would be as simple as the following, if others think it is a worthwhile change: m4_define([m4_copy_force], [m4_ifdef([$2], [m4_ifdef([$1], [_m4_undefine([$2])], [m4_fatal([$0: won't overwrite $2 with undefined $1])])])m4_copy($@)]) - -- Don't work too hard, make some time for fun as well! Eric Blake [email protected] -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (Cygwin) Comment: Public key at home.comcast.net/~ericblake/eblake.gpg Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAko2RNQACgkQ84KuGfSFAYCRggCgq8KjWl2jlawyjc0J1sdOeyoV tMkAoLTcx1lqCIR3fwHFPTRBMVMQL/Z3 =1f/i -----END PGP SIGNATURE-----
>From 4297bd715463cb87b0196811e3c51e42f37218a8 Mon Sep 17 00:00:00 2001 From: Eric Blake <[email protected]> Date: Mon, 15 Jun 2009 06:49:58 -0600 Subject: [PATCH] Add m4_copy_force, m4_rename_force. * lib/m4sugar/m4sugar.m4 (m4_copy_force, m4_rename_force): New macros. * tests/m4sugar.at (m4@&t...@_defn): Test them. * doc/autoconf.texi (Redefined M4 Macros) <m4_copy>: Document them. * NEWS: Likewise. Suggested by Ralf Wildenhues. Signed-off-by: Eric Blake <[email protected]> --- ChangeLog | 9 +++++++++ NEWS | 4 ++-- doc/autoconf.texi | 19 +++++++++++++------ lib/m4sugar/m4sugar.m4 | 16 +++++++++++++++- tests/m4sugar.at | 12 +++++++++++- 5 files changed, 50 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0375ff4..f4605db 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,14 @@ 2009-06-15 Eric Blake <[email protected]> + Add m4_copy_force, m4_rename_force. + * lib/m4sugar/m4sugar.m4 (m4_copy_force, m4_rename_force): New + macros. + * tests/m4sugar.at (m4@&t...@_defn): Test them. + * doc/autoconf.texi (Redefined M4 Macros) <m4_copy>: Document + them. + * NEWS: Likewise. + Suggested by Ralf Wildenhues. + Reinstate _AC_CHECK_HEADER_OLD for gcc. * lib/autoconf/headers.m4 (_AC_CHECK_HEADER_NEW) (_AC_CHECK_HEADER_OLD): Provide autoupdate versions, since gcc and diff --git a/NEWS b/NEWS index 82ba635..93a09c9 100644 --- a/NEWS +++ b/NEWS @@ -26,8 +26,8 @@ GNU Autoconf NEWS - User visible changes. AT_CHECK_UNQUOTED ** The following documented m4sugar macros are new: - m4_argn m4_default_nblank m4_default_nblank_quoted m4_ifblank - m4_ifnblank + m4_argn m4_copy_force m4_default_nblank m4_default_nblank_quoted + m4_ifblank m4_ifnblank m4_rename_force * Major changes in Autoconf 2.63b (2009-03-31) [beta] Released by Eric Blake, based on git versions 2.63.*. diff --git a/doc/autoconf.texi b/doc/autoconf.texi index 9e3327e..4b08042 100644 --- a/doc/autoconf.texi +++ b/doc/autoconf.texi @@ -10642,16 +10642,23 @@ Redefined M4 Macros @end defmac @defmac m4_copy (@var{source}, @var{dest}) +...@defmacx m4_copy_force (@var{source}, @var{dest}) @defmacx m4_rename (@var{source}, @var{dest}) +...@defmacx m4_rename_force (@var{source}, @var{dest}) @msindex{copy} +...@msindex{copy_force} @msindex{rename} +...@msindex{rename_force} These macros aren't directly builtins, but are closely related to -...@code{m4_pushdef} and @code{m4_defn}. They both ensure that @var{dest} -is undefined, then proceed to copy the entire pushdef stack of -definitions of @var{source}. @code{m4_copy} preserves the source -(including in the special case where @var{source} is undefined), while -...@code{m4_rename} undefines the original macro name (making it an error -to rename an undefined @var{source}). +...@code{m4_pushdef} and @code{m4_defn}. @code{m4_copy} and +...@code{m4_rename} ensure that @var{dest} is undefined, while +...@code{m4_copy_force} and @code{m4_rename_force} overwrite any existing +definition. All four macros then proceed to copy the entire pushdef +stack of definitions of @var{source} over to @var{dest}. @code{m4_copy} +and @code{m4_copy_force} preserve the source (including in the special +case where @var{source} is undefined), while @code{m4_rename} and +...@code{m4_rename_force} undefine the original macro name (making it an +error to rename an undefined @var{source}). Note that attempting to invoke a renamed macro might not work, since the macro may have a dependence on helper macros accessed via composition of diff --git a/lib/m4sugar/m4sugar.m4 b/lib/m4sugar/m4sugar.m4 index f5a1f1c..83f6dba 100644 --- a/lib/m4sugar/m4sugar.m4 +++ b/lib/m4sugar/m4sugar.m4 @@ -579,7 +579,8 @@ m4_define([_m4_bpatsubsts], # give an error if DST is already defined. This is particularly nice # for copying self-modifying pushdef stacks, where the top definition # includes one-shot initialization that is later popped to the normal -# definition. +# definition. This version intentionally does nothing if SRC is +# undefined. # # Some macros simply can't be renamed with this method: namely, anything # involved in the implementation of m4_stack_foreach_sep. @@ -589,6 +590,19 @@ m4_define([m4_copy], [m4_ifdef([m4_location($1)], [m4_define([m4_location($2)], m4_location)])]) +# m4_copy_force(SRC, DST) +# m4_rename_force(SRC, DST) +# ------------------------- +# Like m4_copy/m4_rename, except blindly overwrite any existing DST. +# Note that m4_copy_force tolerates undefined SRC, while m4_rename_force +# does not. +m4_define([m4_copy_force], +[m4_ifdef([$2], [_m4_undefine([$2])])m4_copy($@)]) + +m4_define([m4_rename_force], +[m4_ifdef([$2], [_m4_undefine([$2])])m4_rename($@)]) + + # m4_define_default(MACRO, VALUE) # ------------------------------- # If MACRO is undefined, set it to VALUE. diff --git a/tests/m4sugar.at b/tests/m4sugar.at index 4bc7bd4..04f06b9 100644 --- a/tests/m4sugar.at +++ b/tests/m4sugar.at @@ -104,7 +104,8 @@ AT_CLEANUP AT_SETUP([m4@&t...@_defn]) -AT_KEYWORDS([m4@&t...@_popdef m4@&t...@_undefine m4@&t...@_copy m4@&t...@_rename]) +AT_KEYWORDS([m4@&t...@_popdef m4@&t...@_undefine m4@&t...@_copy m4@&t...@_rename +m4@&t...@_copy_force m4@&t...@_rename_force]) # Ensure that m4sugar dies when dereferencing undefined macros, whether # this is provided by m4 natively or faked by wrappers in m4sugar. @@ -161,12 +162,21 @@ m4_popdef([b], [c])dnl a b c dnl m4_copy is intentionally a no-op on undefined source m4_copy([oops], [dummy])m4_ifdef([dummy], [[oops]])dnl +dnl allow forceful overwrites +m4_define([d], [4])m4_define([e], [5])m4_define([f], [6])dnl +m4_copy_force([d], [e])dnl +m4_rename_force([d], [f])dnl +d e f +m4_popdef([e], [f])dnl +d e f ]], [[0 b c a 0 c a 0 0 a 2 2 a 1 1 a b c +d 4 4 +d e f ]]) AT_CLEANUP -- 1.6.3.rc3.2.g4b51
