bug-autoconf
[Top][All Lists]
Advanced

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

Re: 2.62 AT_SETUP limitations


From: Eric Blake
Subject: Re: 2.62 AT_SETUP limitations
Date: Wed, 23 Apr 2008 15:34:22 +0000 (UTC)
User-agent: Loom/3.14 (http://gmane.org/)

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

> Looks like it should work - in m4_expand, the () appear as balanced
> parens, but in _m4_expand, they are embedded as part of the longer quote
> strings.  Thanks for the idea!  However, I'd be a bit more comfortable
> adjusting m4_expand and _m4_split to use the same unlikely quotes, so we
> aren't doubling our chances of the user actually clashing with it; I'll
> probably check in something that uses -=<{( and )}>=- as the quote strings
> across both macros.

Like so.

>From 4d953cea64e30ab7cce948fbbae264da537e260e Mon Sep 17 00:00:00 2001
From: Eric Blake <address@hidden>
Date: Wed, 23 Apr 2008 09:24:46 -0600
Subject: [PATCH] Allow unbalanced () in m4_expand.

* lib/m4sugar/m4sugar.m4 (m4_expand, _m4_expand): Use more complex
quotes.
(m4_noquote, _m4_split): Use consistent complex quote.
* tests/autotest.at (Left paren, Right paren): Test this.
(Parentheses): Ensure new quadrigraphs still work.
(AT_CHECK_AT_TITLE_CHAR): All title char tests exercise m4_expand.
* NEWS: Mention the fix.
* doc/autoconf.texi (Quadrigraphs): Revert mention of macros that
require quadrigraphs for ().
(Evaluation Macros) <m4_expand>: Relax the restriction against
unbalanced ().
(Pretty Help Strings) <AS_HELP_STRING>: Likewise.
(Writing Testsuites) <AT_SETUP>: Likewise.
Reported by Joel E. Denny, fix suggested by Noah Misch.

Signed-off-by: Eric Blake <address@hidden>
---
 ChangeLog              |   18 ++++++++++++++++++
 NEWS                   |    8 +++++---
 doc/autoconf.texi      |   20 ++++++++++----------
 lib/m4sugar/m4sugar.m4 |   23 ++++++++++++-----------
 tests/autotest.at      |   10 ++++++----
 5 files changed, 51 insertions(+), 28 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 8dd130c..5bb1e97 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+2008-04-23  Eric Blake  <address@hidden>
+
+       Allow unbalanced () in m4_expand.
+       * lib/m4sugar/m4sugar.m4 (m4_expand, _m4_expand): Use more complex
+       quotes.
+       (m4_noquote, _m4_split): Use consistent complex quote.
+       * tests/autotest.at (Left paren, Right paren): Test this.
+       (Parentheses): Ensure new quadrigraphs still work.
+       (AT_CHECK_AT_TITLE_CHAR): All title char tests exercise m4_expand.
+       * NEWS: Mention the fix.
+       * doc/autoconf.texi (Quadrigraphs): Revert mention of macros that
+       require quadrigraphs for ().
+       (Evaluation Macros) <m4_expand>: Relax the restriction against
+       unbalanced ().
+       (Pretty Help Strings) <AS_HELP_STRING>: Likewise.
+       (Writing Testsuites) <AT_SETUP>: Likewise.
+       Reported by Joel E. Denny, fix suggested by Noah Misch.
+
 2008-04-22  Eric Blake  <address@hidden>
 
        Support unbalanced () in AT_SETUP by adding two new quadrigraphs.
diff --git a/NEWS b/NEWS
index a50759d..183d4f1 100644
--- a/NEWS
+++ b/NEWS
@@ -2,10 +2,12 @@ GNU Autoconf NEWS - User visible changes.
 
 * Major changes in Autoconf 2.62a (2008-??-??)
 
+** Clients of m4_expand, such as AS_HELP_STRING and AT_SETUP, can now
+   handle properly quoted but otherwise unbalanced parentheses (for
+   some macros, this fixes a regression in 2.62).
+
 ** Two new quadrigraphs have been introduced: @{:@ for (, and @:}@ for ),
-   allowing the output of unbalanced parantheses in contexts such as
-   AS_HELP_STRING or AT_SETUP that must determine the length of
-   expanded text.
+   allowing the output of unbalanced parantheses in more contexts.
 
 
 * Major changes in Autoconf 2.62 (2008-04-05) [stable]
diff --git a/doc/autoconf.texi b/doc/autoconf.texi
index 6f72302..b6ae602 100644
--- a/doc/autoconf.texi
+++ b/doc/autoconf.texi
@@ -9627,10 +9627,7 @@ special characters that are difficult
 Autoconf quoting rules.  For example, you may need to output the regular
 expression @samp{[^[]}, which matches any character other than @samp{[}.
 This expression contains unbalanced brackets so it cannot be put easily
-into an M4 macro.  There are also a few macros, such as
address@hidden, @code{AS_HELP_STRING}, or @code{AT_SETUP}, which
-require balanced parentheses, regardless of the quoting, because the
-macro needs to compute the length of the expansion of its arguments.
+into an M4 macro.
 
 You can work around this problem by using one of the following
 @dfn{quadrigraphs}:
@@ -10909,18 +10906,21 @@ m4_expand([active2, active2])
 @result{}ACT, IVE, ACT, IVE
 @end example
 
-Note that @code{m4_expand} cannot parse everything.  The expansion of
address@hidden must not contain literal unbalanced quotes or parentheses;
-however, quadrigraphs can be used to generate unbalanced output.
+Note that @code{m4_expand} cannot handle an @var{arg} that expands to
+literal unbalanced quotes, but that quadrigraphs can be used when
+unbalanced output is necessary.  Likewise, unbalanced parentheses must
+be supplied with double quoting or a quadrigraph.
 
 @example
 m4_define([pattern], [[!@@<:@@]])dnl
 m4_define([bar], [BAR])dnl
 m4_expand([case $foo in
   m4_defn([pattern])@@:@}@@ bar ;;
+  *[)] blah ;;
 esac])
 @result{}case $foo in
 @result{}  [![]) BAR ;;
address@hidden  *) blah ;;
 @result{}esac
 @end example
 @end defmac
@@ -17721,7 +17721,7 @@ Since it is not expanded, it should not
 The @code{AS_HELP_STRING} macro is particularly helpful when the
 @var{left-hand-side} and/or @var{right-hand-side} are composed of macro
 arguments, as shown in the following example.  Be aware that
address@hidden may not contain unbalanced quotes or parentheses,
address@hidden may not expand to unbalanced quotes,
 although quadrigraphs can be used.
 
 @example
@@ -20311,8 +20311,8 @@ isolation.
 This macro starts a group of related tests, all to be executed in the
 same subshell.  It accepts a single argument, which holds a few words
 (no more than about 30 or 40 characters) quickly describing the purpose
-of the test group being started.  @var{test-group-name} must not contain
-unbalanced quotes or parentheses, although quadrigraphs can be used.
+of the test group being started.  @var{test-group-name} must not expand
+to unbalanced quotes, although quadrigraphs can be used.
 @end defmac
 
 @defmac AT_KEYWORDS (@var{keywords})
diff --git a/lib/m4sugar/m4sugar.m4 b/lib/m4sugar/m4sugar.m4
index 841ce72..4f86546 100644
--- a/lib/m4sugar/m4sugar.m4
+++ b/lib/m4sugar/m4sugar.m4
@@ -702,16 +702,17 @@ m4_define([m4_echo], address@hidden)
 #   m4_expand([active, active2])
 #   => ACT, IVE, ACT, IVE
 #
-# Unfortunately, due to limitations in m4, ARG must contain balanced quotes
-# (use quadrigraphs) and balanced parentheses (use creative shell comments
-# when writing shell case statements).
+# Unfortunately, due to limitations in m4, ARG must expand to something
+# with balanced quotes (use quadrigraphs to get around this).  The input
+# is not likely to have unbalanced -=<{(/)}>=- quotes, and it is possible
+# to have unbalanced (), provided it was specified with proper [] quotes.
 #
 # Exploit that extra () will group unquoted commas and the following
 # whitespace, then convert () to [].  m4_bpatsubst can't handle newlines
 # inside $1, and m4_substr strips quoting.  So we (ab)use m4_changequote.
-m4_define([m4_expand], [_$0(($1))])
+m4_define([m4_expand], [_$0(-=<{($1)}>=-)])
 m4_define([_m4_expand],
-[m4_changequote([(], [)])$1m4_changequote`'m4_changequote(`[', `]')])
+[m4_changequote([-=<{(], [)}>=-])$1m4_changequote([, ])])
 
 
 # m4_ignore(ARGS)
@@ -741,9 +742,9 @@ m4_define([m4_make_list], [m4_join([,
 # and help-strings).  On the other hand, since all quotes are disabled,
 # any macro expanded during this time that relies on nested [] quoting
 # will likely crash and burn.  This macro is seldom useful; consider
-# m4_unquote instead.
+# m4_unquote or m4_expand instead.
 m4_define([m4_noquote],
-[m4_changequote(-=<{,}>=-)$1-=<{}>=-m4_changequote([,])])
+[m4_changequote([-=<{(],[)}>=-])$1-=<{()}>=-m4_changequote([,])])
 
 
 # m4_quote(ARGS)
@@ -1733,7 +1734,7 @@ m4_define([m4_toupper],
 #
 # Also, notice that $1 is quoted twice, since we want the result to
 # be quoted.  Then you should understand that the argument of
-# patsubst is -=<{STRING}>=- (i.e., with additional -=<{ and }>=-).
+# patsubst is -=<{(STRING)}>=- (i.e., with additional -=<{( and )}>=-).
 #
 # This macro is safe on active symbols, i.e.:
 #   m4_define(active, ACTIVE)
@@ -1751,9 +1752,9 @@ m4_define([m4_split],
        [_$0($@)])])
 
 m4_define([_m4_split],
-[m4_changequote(-=<{,}>=-)]dnl
-[[m4_bpatsubst(-=<{-=<{$1}>=-}>=-, -=<{$2}>=-,
-              -=<{], [}>=-)]m4_changequote([, ])])
+[m4_changequote([-=<{(],[)}>=-])]dnl
+[[m4_bpatsubst(-=<{(-=<{($1)}>=-)}>=-, -=<{($2)}>=-,
+              -=<{(], [)}>=-)]m4_changequote([, ])])
 
 
 
diff --git a/tests/autotest.at b/tests/autotest.at
index 27948aa..7db8451 100644
--- a/tests/autotest.at
+++ b/tests/autotest.at
@@ -424,7 +424,8 @@ AT_CLEANUP
 ]], [$4], [], [], [],
 dnl This sed script checks for two things - that the output is properly
 dnl expanded, and that the 'ok' starts on the right column.
-[AT_CHECK([[$CONFIG_SHELL ./micro-suite |
+[AT_KEYWORDS([m4@&address@hidden)
+AT_CHECK([[$CONFIG_SHELL ./micro-suite |
            sed -n '/^  1:/{
 h
 s/[^:]*: \(.*[^         ]\)[    ]*ok.*/\1/p
@@ -458,9 +459,10 @@ AT_CHECK_AT_TITLE_CHAR([Right bracket],
 AT_CHECK_AT_TITLE_CHAR([Pound],       [[#]], [#])
 AT_CHECK_AT_TITLE_CHAR([Quoted comma],[[,]], [,])
 AT_CHECK_AT_TITLE_CHAR([Comma],         [,], [,])
-AT_CHECK_AT_TITLE_CHAR([Parentheses],   [()])
-AT_CHECK_AT_TITLE_CHAR([Left paren],    address@hidden@&t@:@], [(])
-AT_CHECK_AT_TITLE_CHAR([Right paren],   [@:@&address@hidden@], [)])
+dnl this test also hits quadrigraphs for ()
+AT_CHECK_AT_TITLE_CHAR([Parentheses],   [(@{:@)@:address@hidden, [(())])
+AT_CHECK_AT_TITLE_CHAR([Left paren],    [[(]], [(])
+AT_CHECK_AT_TITLE_CHAR([Right paren],   [[)]], [)])
 
 AT_CHECK_AT_TITLE_CHAR([Quoted Macro], [[macro_name]], [macro_name])
 AT_CHECK_AT_TITLE_CHAR([Macro],        [macro_name],   [macro_expanded])
-- 
1.5.5.1








reply via email to

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