autoconf-patches
[Top][All Lists]
Advanced

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

Re: m4_defun_init


From: Eric Blake
Subject: Re: m4_defun_init
Date: Fri, 24 Oct 2008 17:40:57 +0000 (UTC)
User-agent: Loom/3.14 (http://gmane.org/)

Eric Blake <ebb9 <at> byu.net> writes:

> Phooey.  _AC_*_IFELSE aren't currently one-shot (when you use multiple 
> languages, they create multiple ac_func_*_try_* shell functions across 
separate 
> invocations).  But maybe AC_LANG_PUSH could be made to help out, by copying 
the 
> basic _AC_*_IFELSE implementation as part of AC_LANG(lang), so that each 
> language gets its own one-shot initializer copy.  I'm still playing with it...

To begin with, m4_defun_init([_AC_RUN_IFELSE(C)], [...], [...]) fails 
miserably, without this patch to make m4_defun_init more robust.  Now that I am 
considering copying defun'd macros, the expansion stack should use the copied 
name, not the original name.  In turn, when copying a defun'd macro, the copy 
needs a location, hence m4_copy needs to be smarter.  Writing a macro that in 
turn defines another macro with a literal $0 is tough.

Committing this:

From: Eric Blake <address@hidden>
Date: Fri, 24 Oct 2008 11:24:32 -0600
Subject: [PATCH] Make m4_defun_init more robust.

* lib/m4sugar/m4sugar.m4 (m4_defun_init): Handle indirect macro
names, and correct number of arguments.
(m4_copy): Also set up location of the copy.
(m4_defun): When copied, use current macro name, not original.
* tests/m4sugar.at (m4@&address@hidden: one-shot initialization):
Update test.

Signed-off-by: Eric Blake <address@hidden>
---
 ChangeLog              |    8 ++++++++
 lib/m4sugar/m4sugar.m4 |   12 +++++++-----
 tests/m4sugar.at       |   10 +++++++++-
 3 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index ac48cd9..18ac8e0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2008-10-24  Eric Blake  <address@hidden>
 
+       Make m4_defun_init more robust.
+       * lib/m4sugar/m4sugar.m4 (m4_defun_init): Handle indirect macro
+       names, and correct number of arguments.
+       (m4_copy): Also set up location of the copy.
+       (m4_defun): When copied, use current macro name, not original.
+       * tests/m4sugar.at (m4@&address@hidden: one-shot initialization):
+       Update test.
+
        Optimize clients of AS_REQUIRE.
        * lib/m4sugar/m4sugar.m4 (m4_defun): Add undocumented third
        argument.
diff --git a/lib/m4sugar/m4sugar.m4 b/lib/m4sugar/m4sugar.m4
index 13a1ddb..22c38e8 100644
--- a/lib/m4sugar/m4sugar.m4
+++ b/lib/m4sugar/m4sugar.m4
@@ -544,7 +544,8 @@ m4_define([_m4_bpatsubsts],
 m4_define([m4_copy],
 [m4_ifdef([$2], [m4_fatal([$0: won't overwrite defined macro: $2])],
          [_$0([$1], [m4_tmp])_$0([m4_tmp], [$2],
-  [m4_pushdef([$1], _m4_defn([m4_tmp]))])])])
+  [m4_pushdef([$1], _m4_defn([m4_tmp]))])m4_ifdef([m4_location($1)],
+  [m4_define([m4_location($2)], m4_location)])])])
 m4_define([_m4_copy],
 [m4_ifdef([$1], [m4_pushdef([$2], _m4_defn([$1]))$3[]_m4_popdef([$1])$0($@)])])
 
@@ -1662,9 +1663,9 @@ m4_define([m4_divert_require],
 # previously m4_define'd definition so that subsequent use of the
 # macro is faster.
 m4_define([m4_defun],
-[m4_define([m4_location($1)], m4_location)dnl
-m4_default([$3], [m4_define])([$1],
-         [_m4_defun_pro([$1])$2[]_m4_defun_epi([$1])])])
+[m4_define([m4_location($1)], m4_location)]dnl
+[m4_default([$3], [m4_define])([$1],
+  [_m4_defun_pro(]m4_dquote($[0])[)$2[]_m4_defun_epi(]m4_dquote($[0])[)])])
 
 
 # m4_defun_init(NAME, INIT, COMMON)
@@ -1683,7 +1684,8 @@ m4_default([$3], [m4_define])([$1],
 # to m4_defun.
 m4_define([m4_defun_init],
 [m4_define([$1], [$3])m4_defun([$1],
-   [$2[]_m4_popdef(]m4_dquote([$][0])[)$][0($][@)], [m4_pushdef])])
+   [$2[]_m4_popdef(]m4_dquote($[0])[)m4_indir(]m4_dquote($[0])dnl
+[m4_if(]m4_dquote($[#])[, [0], [], ]m4_dquote([,$]@)[))], [m4_pushdef])])
 
 
 # m4_defun_once(NAME, EXPANSION)
diff --git a/tests/m4sugar.at b/tests/m4sugar.at
index cfaed3b..959b209 100644
--- a/tests/m4sugar.at
+++ b/tests/m4sugar.at
@@ -200,7 +200,7 @@ AT_CLEANUP
 ## ---------------------- ##
 
 AT_SETUP([m4@&address@hidden: one-shot initialization])
-AT_KEYWORDS([m4@&address@hidden)
+AT_KEYWORDS([m4@&address@hidden m4@&address@hidden)
 
 AT_CHECK_M4SUGAR_TEXT([[
 m4_defun_init([a], [[init a
@@ -210,12 +210,20 @@ m4_defun([c], [[c]m4_require([a])])dnl
 b
 c
 a
+m4_defun_init([-], [hello, ], [m4_if([$#], [0], [world], [[$1]])])dnl
+m4_copy([-], [.])dnl
+m4_indir([.])
+m4_indir([.], [goodbye])
+m4_indir([-], [again])
 ]], [[
 init a
 common a
 b
 c
 common a
+hello, world
+goodbye
+hello, again
 ]])
 AT_CLEANUP
 
-- 
1.6.0.2







reply via email to

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