autoconf-patches
[Top][All Lists]
Advanced

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

[PATCH] Fix AS_REQUIRE buglet


From: Paolo Bonzini
Subject: [PATCH] Fix AS_REQUIRE buglet
Date: Sat, 18 Oct 2008 23:59:13 +0200
User-agent: Thunderbird 2.0.0.17 (Macintosh/20080914)

The problem showed up with nested requires in different diversions (even
if some of them had already been expanded).  The definition of
_m4_divert_desired was overwritten by the nested call, before actually
reaching the point where the argument was used in _m4_require_call.

I could fix it by using m4_pushdef/m4_popdef; instead I elected to
expand the diversion name to a number in m4_divert_require, since this
is a busy path.

It seems pretty obvious so I will push this soon.

Paolo
2008-10-18  Paolo Bonzini  <address@hidden>

        Make sure that nested AS_REQUIRE do not lose the desired diversion.
        * lib/m4sugar/m4sh.m4 (AS_REQUIRE): Expand _m4_divert_desired before
        passing it to m4_divert_require, so that its content is not used
        anymore.
        * tests/m4sh.at (Nested AS_REQUIRE): New testcase.

diff --git a/lib/m4sugar/m4sh.m4 b/lib/m4sugar/m4sh.m4
index c387864..5d1d929 100644
--- a/lib/m4sugar/m4sh.m4
+++ b/lib/m4sugar/m4sh.m4
@@ -309,11 +309,14 @@ AS_REQUIRE([_AS_UNSET_PREPARE])
 # given diversion when expanded (required or not).  The expansion
 # goes in the named diversion or an earlier one.
 #
+# Note: we expand _m4_divert_desired before passing it to m4_divert_require,
+# otherwise we would need to use m4_pushdef and m4_popdef instead of
+# simply m4_define.
 m4_defun([AS_REQUIRE],
 [m4_define([_m4_divert_desired], [m4_default_quoted([$3], [M4SH-INIT])])dnl
 m4_if(m4_eval(_m4_divert(_m4_divert_dump) <= _m4_divert(_m4_divert_desired)), 
1,
       [m4_require([$1], [$2])],
-      [m4_divert_require([_m4_divert_desired], [$1], [$2])])])
+      [m4_divert_require(_m4_divert(_m4_divert_desired), [$1], [$2])])])
 
 
 # AS_REQUIRE_SHELL_FN(NAME-TO-CHECK, COMMENT, BODY-TO-EXPAND,
diff --git a/tests/m4sh.at b/tests/m4sh.at
index 4951fd9..4ecb2fd 100644
--- a/tests/m4sh.at
+++ b/tests/m4sh.at
@@ -536,6 +536,44 @@ AT_CHECK([./script])
 AT_CLEANUP
 
 
+## ------------------- ##
+## Nested AS_REQUIRE.  ##
+## ------------------- ##
+
+# Hypothesis: M4sh expands the requirements of AS_REQUIRE in the
+# requested diversion, even if other AS_REQUIREs are interleaved.
+
+AT_SETUP([Nested AS@&address@hidden)
+AT_KEYWORDS([m4sh])
+
+AT_DATA_M4SH([script.as], [[dnl
+AS_INIT
+
+m4_defun([in_fn_diversion], still_in_m4sh_init_fn=yes)
+m4_defun([not_in_fn_diversion], still_in_m4sh_init_fn=no)
+
+m4_defun([NESTED], [nested_require_in_fn_diversion=$still_in_m4sh_init_fn])
+
+m4_defun([OUTER], [AS_REQUIRE([NESTED])dnl
+outer_require_in_fn_diversion=$still_in_m4sh_init_fn])
+
+m4_defun([test_init], [
+AS_REQUIRE([in_fn_diversion], , [M4SH-INIT-FN])
+AS_REQUIRE([OUTER], , [M4SH-INIT-FN])
+AS_REQUIRE([not_in_fn_diversion], , [M4SH-INIT-FN])
+])
+
+test_init
+if test $outer_require_in_fn_diversion != yes; then AS_EXIT([1]); fi
+if test $nested_require_in_fn_diversion != no; then AS_EXIT([1]); fi
+]])
+
+AT_CHECK_M4SH
+AT_CHECK([./script])
+
+AT_CLEANUP
+
+
 ## ------------------------------------ ##
 ## AS_REQUIRE_SHELL_FN and m4_require.  ##
 ## ------------------------------------ ##

reply via email to

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