From 5969d900088b6f1e5f379d83191765b0636c51a1 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Sat, 18 Oct 2008 15:08:17 +0200 Subject: [PATCH] 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. --- ChangeLog | 8 ++++++++ lib/m4sugar/m4sh.m4 | 5 ++++- tests/m4sh.at | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 25c8826a..5380a507 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2008-10-18 Paolo Bonzini + + 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. + 2008-10-18 Eric Blake Document bugs in { } handling. diff --git a/lib/m4sugar/m4sh.m4 b/lib/m4sugar/m4sh.m4 index 75b8d847..fbce0269 100644 --- a/lib/m4sugar/m4sh.m4 +++ b/lib/m4sugar/m4sh.m4 @@ -314,11 +314,14 @@ m4_divert_pop[]dnl # 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 c39c8c1d..75da8a4d 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@&t@_REQUIRE]) +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. ## ## ------------------------------------ ## -- 2.47.2