autoconf-commit
[Top][All Lists]
Advanced

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

[SCM] GNU Autoconf source repository branch, master, updated. v2.63-215-


From: Eric Blake
Subject: [SCM] GNU Autoconf source repository branch, master, updated. v2.63-215-g2d63737
Date: Fri, 21 Nov 2008 01:13:51 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU Autoconf source repository".

http://git.sv.gnu.org/gitweb/?p=autoconf.git;a=commitdiff;h=2d63737afbd39d9029ab8c4448ec31afe80784ee

The branch, master has been updated
       via  2d63737afbd39d9029ab8c4448ec31afe80784ee (commit)
       via  7791129655cc9fd2136fd3816e2eb487c59c7add (commit)
       via  bcef427e185102ad6469614eed402ace2dd9aee8 (commit)
       via  fa506f9116c42bba43e76d87334d177a8e6d8651 (commit)
       via  aa6c52d78a33835cf987274792d6e3f0cf2c6a95 (commit)
      from  644adb9065b1f2521bc46f8ee4b3c13021ddae51 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 2d63737afbd39d9029ab8c4448ec31afe80784ee
Author: Eric Blake <address@hidden>
Date:   Thu Nov 13 21:20:18 2008 -0700

    Reduce forks in AC_DEFINE.
    
    * lib/autoconf/general.m4 (_AC_DEFINE_Q_PRINT): New macro.
    (_AC_DEFINE_Q): Use it to avoid forks for all AC_DEFINE and most
    AC_DEFINE_UNQUOTED.
    * lib/autoconf/fortran.m4 (_AC_FC_WRAPPERS): Properly quote #.
    * tests/torture.at (Substitute and define special characters):
    (Define to a 2000-byte string): Enhance tests to cover
    AC_DEFINE_UNQUOTED.
    (@%:@define header templates): Enhance test to cover #.
    
    Signed-off-by: Eric Blake <address@hidden>

commit 7791129655cc9fd2136fd3816e2eb487c59c7add
Author: Eric Blake <address@hidden>
Date:   Wed Nov 19 11:38:18 2008 -0700

    Improve m4_expand robustness, part 2.
    
    * lib/m4sugar/m4sugar.m4 (m4_expand): Support unterminated
    comments, by wrapping old implementation...
    (_m4_expand): ...as this, and renaming old core...
    (_m4_expand_): ...to this.
    (m4_text_box): Use lighter-weight _m4_expand.
    * lib/m4sugar/m4sh.m4 (_AS_DETECT_EXPAND)
    (_AS_DETECT_BETTER_SHELL, AS_FUNCTION_DESCRIBE): Likewise.
    * lib/autotest/general.m4 (AT_KEYWORDS): Likewise.
    * tests/m4sugar.at (m4@&address@hidden): Enhance test.
    * tests/autotest.at (AT_CHECK_AT_TITLE_CHAR): Likewise.
    * doc/autoconf.texi (Evaluation Macros) <m4_expand>: Mention new
    functionality.
    
    Signed-off-by: Eric Blake <address@hidden>

commit bcef427e185102ad6469614eed402ace2dd9aee8
Author: Eric Blake <address@hidden>
Date:   Wed Nov 19 09:00:55 2008 -0700

    Improve m4_expand robustness, part 1.
    
    * lib/m4sugar/m4sugar.m4 (_m4_expand): Tolerate unquoted
    unbalanced `)'.
    * tests/m4sugar.at (m4@&address@hidden): New test.
    
    Signed-off-by: Eric Blake <address@hidden>

commit fa506f9116c42bba43e76d87334d177a8e6d8651
Author: Eric Blake <address@hidden>
Date:   Wed Nov 12 21:45:42 2008 -0700

    Add m4_chomp, m4_esyscmd_s.
    
    * lib/m4sugar/m4sugar.m4 (m4_esyscmd_e, m4_chomp, m4_chomp_all):
    New macros.
    * doc/autoconf.texi (Redefined M4 Macros) <m4_esyscmd_s>: Document
    them.
    (Text processing Macros) <m4_chomp>: Likewise.
    * NEWS: Likewise.
    * tests/m4sugar.at (m4@&address@hidden): New test.
    
    Signed-off-by: Eric Blake <address@hidden>

commit aa6c52d78a33835cf987274792d6e3f0cf2c6a95
Author: Eric Blake <address@hidden>
Date:   Wed Nov 12 21:10:35 2008 -0700

    Remove _m4_index.
    
    * lib/m4sugar/m4sugar.m4 (_m4_index): Delete; it is more efficient
    to make callers guarantee a match.
    (m4_init): Adjust caller.
    * lib/autoconf/status.m4 (_AC_CONFIG_COMPUTE_DEST): Likewise.
    * lib/autoconf/general.m4 (_AC_DEFINE_Q): Likewise.
    
    Signed-off-by: Eric Blake <address@hidden>

-----------------------------------------------------------------------

Summary of changes:
 ChangeLog               |   49 ++++++++++++++++++++++
 NEWS                    |    4 +-
 doc/autoconf.texi       |   34 ++++++++++++++-
 lib/autoconf/fortran.m4 |   20 +++++-----
 lib/autoconf/general.m4 |   47 ++++++++++++++++-----
 lib/autoconf/status.m4  |    5 +-
 lib/autotest/general.m4 |    3 +-
 lib/m4sugar/m4sh.m4     |    8 ++--
 lib/m4sugar/m4sugar.m4  |  104 ++++++++++++++++++++++++++++++----------------
 tests/autotest.at       |    7 ++-
 tests/m4sugar.at        |   84 ++++++++++++++++++++++++++++++++++++++
 tests/torture.at        |   44 +++++++++++++++++---
 12 files changed, 329 insertions(+), 80 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 1d5fbf5..8b2986d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,54 @@
 2008-11-20  Eric Blake  <address@hidden>
 
+       Reduce forks in AC_DEFINE.
+       * lib/autoconf/general.m4 (_AC_DEFINE_Q_PRINT): New macro.
+       (_AC_DEFINE_Q): Use it to avoid forks for all AC_DEFINE and most
+       AC_DEFINE_UNQUOTED.
+       * lib/autoconf/fortran.m4 (_AC_FC_WRAPPERS): Properly quote #.
+       * tests/torture.at (Substitute and define special characters):
+       (Define to a 2000-byte string): Enhance tests to cover
+       AC_DEFINE_UNQUOTED.
+       (@%:@define header templates): Enhance test to cover #.
+
+2008-11-20  Eric Blake  <address@hidden>
+
+       Improve m4_expand robustness, part 2.
+       * lib/m4sugar/m4sugar.m4 (m4_expand): Support unterminated
+       comments, by wrapping old implementation...
+       (_m4_expand): ...as this, and renaming old core...
+       (_m4_expand_): ...to this.
+       (m4_text_box): Use lighter-weight _m4_expand.
+       * lib/m4sugar/m4sh.m4 (_AS_DETECT_EXPAND)
+       (_AS_DETECT_BETTER_SHELL, AS_FUNCTION_DESCRIBE): Likewise.
+       * lib/autotest/general.m4 (AT_KEYWORDS): Likewise.
+       * tests/m4sugar.at (m4@&address@hidden): Enhance test.
+       * tests/autotest.at (AT_CHECK_AT_TITLE_CHAR): Likewise.
+       * doc/autoconf.texi (Evaluation Macros) <m4_expand>: Mention new
+       functionality.
+
+       Improve m4_expand robustness, part 1.
+       * lib/m4sugar/m4sugar.m4 (_m4_expand): Tolerate unquoted
+       unbalanced `)'.
+       * tests/m4sugar.at (m4@&address@hidden): New test.
+
+2008-11-20  Eric Blake  <address@hidden>
+
+       Add m4_chomp, m4_esyscmd_s.
+       * lib/m4sugar/m4sugar.m4 (m4_esyscmd_e, m4_chomp, m4_chomp_all):
+       New macros.
+       * doc/autoconf.texi (Redefined M4 Macros) <m4_esyscmd_s>: Document
+       them.
+       (Text processing Macros) <m4_chomp>: Likewise.
+       * NEWS: Likewise.
+       * tests/m4sugar.at (m4@&address@hidden): New test.
+
+       Remove _m4_index.
+       * lib/m4sugar/m4sugar.m4 (_m4_index): Delete; it is more efficient
+       to make callers guarantee a match.
+       (m4_init): Adjust caller.
+       * lib/autoconf/status.m4 (_AC_CONFIG_COMPUTE_DEST): Likewise.
+       * lib/autoconf/general.m4 (_AC_DEFINE_Q): Likewise.
+
        Describe different hacks for balancing ')' in case statements.
        * doc/autoconf.texi (Limitations of Builtins) <case>: Add an
        exposition on various quoting styles.
diff --git a/NEWS b/NEWS
index 6ef0725..297b3ea 100644
--- a/NEWS
+++ b/NEWS
@@ -23,8 +23,8 @@ GNU Autoconf NEWS - User visible changes.
    `autoreconf -I dir' option.
 
 ** The following documented m4sugar macros are new:
-   m4_curry  m4_default_quoted  m4_map_args  m4_map_args_pair
-   m4_set_map
+   m4_chomp  m4_curry  m4_default_quoted  m4_esyscmd_s  m4_map_args
+   m4_map_args_pair  m4_set_map
 
 ** The following m4sugar macros are documented now:
    m4_copy  m4_dumpdefs  m4_rename
diff --git a/doc/autoconf.texi b/doc/autoconf.texi
index db3f7cc..7a154b7 100644
--- a/doc/autoconf.texi
+++ b/doc/autoconf.texi
@@ -10440,6 +10440,14 @@ calls @code{m4_dumpdef} for all of the
 silently does nothing if @var{name} is undefined.
 @end defmac
 
address@hidden m4_esyscmd_s (@var{command})
address@hidden
+Like @code{m4_esyscmd}, this macro expands to the result of running
address@hidden in a shell.  The difference is that any trailing newlines
+are removed, so that the output behaves more like shell command
+substitution.
address@hidden defmac
+
 @defmac m4_exit (@var{exit-status})
 @msindex{exit}
 This macro corresponds to @code{m4exit}.
@@ -11155,12 +11163,15 @@ discarding whitespace after unquoted commas, this 
macro is a no-op.
 Return the expansion of @var{arg} as a quoted string.  Whereas
 @code{m4_quote} is designed to collect expanded text into a single
 argument, @code{m4_expand} is designed to perform one level of expansion
-on quoted text.  The distinction is in the treatment of whitespace
+on quoted text.  One distinction is in the treatment of whitespace
 following a comma in the original @var{arg}.  Any time multiple
 arguments are collected into one with @code{m4_quote}, the M4 argument
 collection rules discard the whitespace.  However, with @code{m4_expand},
 whitespace is preserved, even after the expansion of macros contained in
address@hidden
address@hidden  Additionally, @code{m4_expand} is able to expand text that
+would involve an unterminated comment, whereas expanding that same text
+as the argument to @code{m4_quote} runs into difficulty in finding the
+end of the argument.
 
 @example
 m4_define([active], [ACT, IVE])dnl
@@ -11173,11 +11184,17 @@ m4_quote(active2, active2)
 @result{}ACT, IVE,ACT, IVE
 m4_expand([active2, active2])
 @result{}ACT, IVE, ACT, IVE
+m4_expand([# m4_echo])
address@hidden m4_echo
+m4_quote(# m4_echo)
+)
address@hidden m4_echo)
address@hidden
 @end example
 
 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
+unbalanced output is necessary.  Likewise, unbalanced parentheses should
 be supplied with double quoting or a quadrigraph.
 
 @example
@@ -11392,6 +11409,17 @@ numbers
 @end example
 @end defmac
 
address@hidden m4_chomp (@var{string})
address@hidden m4_chomp_all (@var{string})
address@hidden
address@hidden
+Output @var{string} in quotes, but without a trailing newline.  The
+macro @code{m4_chomp} is slightly faster, and removes at most one
+newline; the macro @code{m4_chomp_all} removes all consecutive trailing
+newlines.  Unlike @code{m4_flatten}, embedded newlines are left intact,
+and backslash does not influence the result.
address@hidden defmac
+
 @defmac m4_combine (@ovar{separator}, @var{prefix-list}, @ovar{infix}, @
   @var{suffix-1}, @ovar{suffix-2}, @dots{})
 @msindex{combine}
diff --git a/lib/autoconf/fortran.m4 b/lib/autoconf/fortran.m4
index 7aa5bd4..f144c0e 100644
--- a/lib/autoconf/fortran.m4
+++ b/lib/autoconf/fortran.m4
@@ -1032,25 +1032,25 @@ case $ac_cv_[]_AC_LANG_ABBREV[]_mangling in
          AC_DEFINE(_AC_FC[_FUNC_(name,NAME)], [name]) ;;
   "lower case, no underscore, extra underscore")
          AC_DEFINE(_AC_FC[_FUNC(name,NAME)],  [name])
-         AC_DEFINE(_AC_FC[_FUNC_(name,NAME)], [name ## _]) ;;
+         AC_DEFINE(_AC_FC[_FUNC_(name,NAME)], [name [##] _]) ;;
   "lower case, underscore, no extra underscore")
-         AC_DEFINE(_AC_FC[_FUNC(name,NAME)],  [name ## _])
-         AC_DEFINE(_AC_FC[_FUNC_(name,NAME)], [name ## _]) ;;
+         AC_DEFINE(_AC_FC[_FUNC(name,NAME)],  [name [##] _])
+         AC_DEFINE(_AC_FC[_FUNC_(name,NAME)], [name [##] _]) ;;
   "lower case, underscore, extra underscore")
-         AC_DEFINE(_AC_FC[_FUNC(name,NAME)],  [name ## _])
-         AC_DEFINE(_AC_FC[_FUNC_(name,NAME)], [name ## __]) ;;
+         AC_DEFINE(_AC_FC[_FUNC(name,NAME)],  [name [##] _])
+         AC_DEFINE(_AC_FC[_FUNC_(name,NAME)], [name [##] __]) ;;
   "upper case, no underscore, no extra underscore")
          AC_DEFINE(_AC_FC[_FUNC(name,NAME)],  [NAME])
          AC_DEFINE(_AC_FC[_FUNC_(name,NAME)], [NAME]) ;;
   "upper case, no underscore, extra underscore")
          AC_DEFINE(_AC_FC[_FUNC(name,NAME)],  [NAME])
-         AC_DEFINE(_AC_FC[_FUNC_(name,NAME)], [NAME ## _]) ;;
+         AC_DEFINE(_AC_FC[_FUNC_(name,NAME)], [NAME [##] _]) ;;
   "upper case, underscore, no extra underscore")
-         AC_DEFINE(_AC_FC[_FUNC(name,NAME)],  [NAME ## _])
-         AC_DEFINE(_AC_FC[_FUNC_(name,NAME)], [NAME ## _]) ;;
+         AC_DEFINE(_AC_FC[_FUNC(name,NAME)],  [NAME [##] _])
+         AC_DEFINE(_AC_FC[_FUNC_(name,NAME)], [NAME [##] _]) ;;
   "upper case, underscore, extra underscore")
-         AC_DEFINE(_AC_FC[_FUNC(name,NAME)],  [NAME ## _])
-         AC_DEFINE(_AC_FC[_FUNC_(name,NAME)], [NAME ## __]) ;;
+         AC_DEFINE(_AC_FC[_FUNC(name,NAME)],  [NAME [##] _])
+         AC_DEFINE(_AC_FC[_FUNC_(name,NAME)], [NAME [##] __]) ;;
   *)
          AC_MSG_WARN([unknown Fortran name-mangling scheme])
          ;;
diff --git a/lib/autoconf/general.m4 b/lib/autoconf/general.m4
index 2f40f82..50b6eae 100644
--- a/lib/autoconf/general.m4
+++ b/lib/autoconf/general.m4
@@ -2060,39 +2060,62 @@ m4_define([AC_DEFINE_TRACE],
 # Set VARIABLE to VALUE, verbatim, or 1.  Remember the value
 # and if VARIABLE is affected the same VALUE, do nothing, else
 # die.  The third argument is used by autoheader.
-m4_define([AC_DEFINE], [_AC_DEFINE_Q([\], $@)])
+m4_define([AC_DEFINE], [_AC_DEFINE_Q([_$0], $@)])
+
+# _AC_DEFINE(STRING)
+# ------------------
+# Append the pre-expanded STRING and a newline to confdefs.h, as if by
+# a quoted here-doc.
+m4_define([_AC_DEFINE],
+[AS_ECHO(["AS_ESCAPE([[$1]])"]) >>confdefs.h])
 
 
 # AC_DEFINE_UNQUOTED(VARIABLE, [VALUE], [DESCRIPTION])
 # ----------------------------------------------------
-# Similar, but perform shell substitutions $ ` \ once on VALUE.
-m4_define([AC_DEFINE_UNQUOTED], [_AC_DEFINE_Q([], $@)])
-
+# Similar, but perform shell substitutions $ ` \ once on VALUE, as
+# in an unquoted here-doc.
+m4_define([AC_DEFINE_UNQUOTED], [_AC_DEFINE_Q([_$0], $@)])
 
-# _AC_DEFINE_Q(QUOTE, VARIABLE, [VALUE], [DESCRIPTION])
+# _AC_DEFINE_UNQUOTED(STRING)
+# ---------------------------
+# Append the pre-expanded STRING and a newline to confdefs.h, as if
+# with an unquoted here-doc, but avoiding a fork in the common case of
+# no backslash, no command substitution, no complex variable
+# substitution, and no quadrigraphs.
+m4_define([_AC_DEFINE_UNQUOTED],
+[m4_if(m4_bregexp([$1], [\\\|`\|\$(\|\${\|@]), [-1],
+       [AS_ECHO(["AS_ESCAPE([$1], [""])"]) >>confdefs.h],
+       [cat >>confdefs.h <<_ACEOF
+[$1]
+_ACEOF])])
+
+
+# _AC_DEFINE_Q(MACRO, VARIABLE, [VALUE], [DESCRIPTION])
 # -----------------------------------------------------
 # Internal function that performs common elements of AC_DEFINE{,_UNQUOTED}.
+# MACRO must take one argument, which is the fully expanded string to
+# append to confdefs.h as if by a possibly-quoted here-doc.
 #
 # m4_index is roughly 5 to 8 times faster than m4_bpatsubst, so we use
 # m4_format rather than regex to grab prefix up to first ().  AC_name
 # is defined with over-quotation, so that we can avoid m4_defn; this
 # is only safe because the name should not contain $.
 #
-# Use _m4_index to avoid a bug in m4_format in older m4.
+# Guarantee a match in m4_index, so as to avoid a bug with precision
+# -1 in m4_format in older m4.
 m4_define([_AC_DEFINE_Q],
-[m4_pushdef([AC_name], m4_format([[[%.*s]]], _m4_index([$2], [(]), [$2]))]dnl
+[m4_pushdef([AC_name], m4_format([[[%.*s]]], m4_index([$2(], [(]), [$2]))]dnl
 [AC_DEFINE_TRACE(AC_name)]dnl
 [m4_cond([m4_index([$3], [
 ])], [-1], [],
        [AS_LITERAL_IF([$3], [m4_bregexp([[$3]], [[^\\]
 ], [-])])], [], [],
-       [m4_warn([syntax], [AC_DEFINE]m4_ifval([$1], [], [[_UNQUOTED]])dnl
-[: `$3' is not a valid preprocessor define value])])]dnl
+       [m4_warn([syntax], [AC_DEFINE]m4_if([$1], [_AC_DEFINE], [],
+  [[_UNQUOTED]])[: `$3' is not a valid preprocessor define value])])]dnl
 [m4_ifval([$4], [AH_TEMPLATE(AC_name, [$4])
 ])_m4_popdef([AC_name])]dnl
-[cat >>confdefs.h <<$1_ACEOF
address@hidden:@define] $2 m4_if([$#], 2, 1, [$3], [], [/**/], [$3])
-_ACEOF
+[$1(m4_expand(address@hidden:@define] $2 ]m4_if([$#], 2, 1,
+  [$3], [], [/**/], [[$3]])))
 ])
 
 
diff --git a/lib/autoconf/status.m4 b/lib/autoconf/status.m4
index fe78358..bfd7a79 100644
--- a/lib/autoconf/status.m4
+++ b/lib/autoconf/status.m4
@@ -247,9 +247,10 @@ m4_define([_AC_CONFIG_FOOS],
 # _AC_CONFIG_COMPUTE_DEST(STRING)
 # -------------------------------
 # Compute the DEST from STRING by stripping any : and following
-# characters.  Use _m4_index to avoid a bug in m4_format in older m4.
+# characters.  Guarantee a match in m4_index, so as to avoid a bug
+# with precision -1 in m4_format in older m4.
 m4_define([_AC_CONFIG_COMPUTE_DEST],
-[m4_format([[%.*s]], _m4_index([$1], [:]), [$1])])
+[m4_format([[%.*s]], m4_index([$1:], [:]), [$1])])
 
 # _AC_CONFIG_REGISTER(MODE, TAG, [COMMANDS])
 # ------------------------------------------
diff --git a/lib/autotest/general.m4 b/lib/autotest/general.m4
index 704dbbf..ebde0b3 100644
--- a/lib/autotest/general.m4
+++ b/lib/autotest/general.m4
@@ -1636,7 +1636,8 @@ m4_case([$1],
 # Since the -k option is case-insensitive, the list is stored in lower case
 # to avoid duplicates that differ only by case.
 _AT_DEFINE_SETUP([AT_KEYWORDS],
-[m4_append_uniq_w([AT_keywords], m4_tolower(m4_dquote(m4_expand([$1]))))])
+[m4_append_uniq_w([AT_keywords], m4_tolower(m4_dquote(_m4_expand([$1
+]))))])
 
 
 # AT_CAPTURE_FILE(FILE)
diff --git a/lib/m4sugar/m4sh.m4 b/lib/m4sugar/m4sh.m4
index 0b32440..4364387 100644
--- a/lib/m4sugar/m4sh.m4
+++ b/lib/m4sugar/m4sh.m4
@@ -165,7 +165,7 @@ $1], [^], address@hidden:@ ])])])
 # we must piece-meal the assignment of VAR such that $LINENO expansion
 # occurs in a single line.
 m4_define([_AS_DETECT_EXPAND],
-[$1="m4_bpatsubst(m4_dquote(AS_ESCAPE(m4_expand(m4_set_contents([$2], [
+[$1="m4_bpatsubst(m4_dquote(AS_ESCAPE(_m4_expand(m4_set_contents([$2], [
 ])))), [\\\$LINENO\(.*\)$], [";$1=$$1$LINENO;$1=$$1"\1])"])
 
 
@@ -219,7 +219,7 @@ dnl Remove any tests from suggested that are also required
 [m4_set_map([_AS_DETECT_SUGGESTED_BODY], [_AS_DETECT_SUGGESTED_PRUNE])]dnl
 [m4_pushdef([AS_EXIT], [exit m4_default([$1], 1)])]dnl
 [if test "x$CONFIG_SHELL" = x; then
-  as_bourne_compatible="AS_ESCAPE(m4_expand([_AS_BOURNE_COMPATIBLE]))"
+  as_bourne_compatible="AS_ESCAPE(_m4_expand([_AS_BOURNE_COMPATIBLE]))"
   _AS_DETECT_EXPAND([as_required], [_AS_DETECT_REQUIRED_BODY])
   _AS_DETECT_EXPAND([as_suggested], [_AS_DETECT_SUGGESTED_BODY])
   AS_IF([_AS_RUN(["$as_required"])],
@@ -1341,8 +1341,8 @@ _ASBOX])
 m4_define([AS_FUNCTION_DESCRIBE],
 address@hidden:@ $1[]m4_ifval([$2], [ $2])
 @%:@ m4_translit(m4_format([%*s],
-                  m4_qlen(m4_expand([$1[]m4_ifval([$2], [ $2])])), []),
-                [ ], [-])
+          m4_decr(m4_qlen(_m4_expand([$1[]m4_ifval([$2], [ $2])
+]))), []), [ ], [-])
 m4_text_wrap([$3], address@hidden:@ ], [], [$4])])
 
 
diff --git a/lib/m4sugar/m4sugar.m4 b/lib/m4sugar/m4sugar.m4
index 8884714..4657995 100644
--- a/lib/m4sugar/m4sugar.m4
+++ b/lib/m4sugar/m4sugar.m4
@@ -624,21 +624,12 @@ m4_define([m4_dumpdefs],
        [$#], [1], [m4_stack_foreach_lifo([$1], [m4_dumpdef([$1])m4_ignore])],
        [m4_map_args([$0], $@)])])
 
-
-# _m4_index(HAYSTACK, NEEDLE)
-# ---------------------------
-# Like the original, except return -2 instead of -1 if NEEDLE is not
-# present in HAYSTACK.  That way, it can be used to work around a bug
-# in m4 1.4.9 and earlier where m4_format did not accept a precision
-# of -1; this macro can be safely used in the idiom:
-#   m4_format([[%.*s]], _m4_index([$1],[$2]), [$1])
-# to grab the prefix of $1 up to but excluding $2, if it was present,
-# otherwise the entire $1.
-m4_define([_m4_index],
-[$0_(m4_index($@))])
-
-m4_define([_m4_index_],
-[m4_if([$1], [-1], [-2], [$1])])
+# m4_esyscmd_s(COMMAND)
+# ---------------------
+# Like m4_esyscmd, except strip any trailing newlines, thus behaving
+# more like shell command substitution.
+m4_define([m4_esyscmd_s],
+[m4_chomp_all(m4_esyscmd([$1]))])
 
 
 # m4_popdef(NAME)
@@ -822,10 +813,12 @@ m4_define([m4_echo], address@hidden)
 
 
 # m4_expand(ARG)
-# --------------
-# Return the expansion of ARG as a single string.  Unlike m4_quote($1), this
-# correctly preserves whitespace following single-quoted commas that appeared
-# within ARG.
+# _m4_expand(ARG)
+# ---------------
+# Return the expansion of ARG as a single string.  Unlike
+# m4_quote($1), this preserves whitespace following single-quoted
+# commas that appear within ARG.  It also deals with shell case
+# statements.
 #
 #   m4_define([active], [ACT, IVE])
 #   m4_define([active2], [[ACT, IVE]])
@@ -834,17 +827,36 @@ m4_define([m4_echo], address@hidden)
 #   m4_expand([active, active2])
 #   => ACT, IVE, ACT, IVE
 #
-# 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],
-[m4_changequote([-=<{(], [)}>=-])$1m4_changequote([, ])])
+# Unfortunately, due to limitations in m4, ARG must expand to
+# something with balanced quotes (use quadrigraphs to get around
+# this), and should not contain the unlikely delimiters -=<{( or
+# )}>=-.  It is possible to have unbalanced quoted `(' or `)', as well
+# as unbalanced unquoted `)'.  m4_expand can handle unterminated
+# comments or dnl on the final line, at the expense of speed, while
+# _m4_expand is faster but must be given a terminated expansion.
+#
+# Exploit that extra unquoted () will group unquoted commas and the
+# following whitespace.  m4_bpatsubst can't handle newlines inside $1,
+# and m4_substr strips quoting.  So we (ab)use m4_changequote, using
+# temporary quotes to remove the delimiters that conveniently included
+# the unquoted () that were added prior to the changequote.
+#
+# Thanks to shell case statements, too many people are prone to pass
+# underquoted `)', so we try to detect that by passing a marker as a
+# fourth argument; if the marker is not present, then we assume that
+# we encountered an early `)', and re-expand the first argument, but
+# this time with one more `(' in the second argument and in the
+# open-quote delimiter.  We must also ignore the slop from the
+# previous try.  The final macro is thus half line-noise, half art.
+m4_define([m4_expand], [m4_chomp(_$0([$1
+]))])
+
+m4_define([_m4_expand], [$0_([$1], [(], -=<{($1)}>=-, [}>=-])])
+
+m4_define([_m4_expand_],
+[m4_if([$4], [}>=-],
+       [m4_changequote([-=<{$2], [)}>=-])$3m4_changequote([, ])],
+       [$0([$1], [($2], -=<{($2$1)}>=-, [}>=-])m4_ignore$2])])
 
 
 # m4_ignore(ARGS)
@@ -2105,6 +2117,28 @@ m4_define([_m4_split],
               -=<{(]$3[)}>=-)]m4_changequote([, ])])
 
 
+# m4_chomp(STRING)
+# m4_chomp_all(STRING)
+# --------------------
+# Return STRING quoted, but without a trailing newline.  m4_chomp
+# removes at most one newline, while m4_chomp_all removes all
+# consecutive trailing newlines.  Embedded newlines are not touched,
+# and a trailing backslash-newline leaves just a trailing backslash.
+#
+# m4_bregexp is slower than m4_index, and we don't always want to
+# remove all newlines; hence the two variants.  We massage characters
+# to give a nicer pattern to match, particularly since m4_bregexp is
+# line-oriented.  Both versions must guarantee a match, to avoid bugs
+# with precision -1 in m4_format in older m4.
+m4_define([m4_chomp],
+[m4_format([[%.*s]], m4_index(m4_translit([[$1]], [
+/.], [/  ])[./.], [/.]), [$1])])
+
+m4_define([m4_chomp_all],
+[m4_format([[%.*s]], m4_bregexp(m4_translit([[$1]], [
+/], [/ ]), [/*$]), [$1])])
+
+
 # m4_flatten(STRING)
 # ------------------
 # If STRING contains end of lines, replace them with spaces.  If there
@@ -2406,9 +2440,9 @@ m4_define([_m4_text_wrap_word],
 # will post-process.
 m4_define([m4_text_box],
 [m4_pushdef([m4_Border],
-           m4_translit(m4_format([%*s], m4_qlen(m4_expand([$1])), []),
-                       [ ], m4_default_quoted([$2], [-])))dnl
-[##] m4_Border [##]
+           m4_translit(m4_format([%*s], m4_decr(m4_qlen(_m4_expand([$1
+]))), []), [ ], m4_default_quoted([$2], [-])))]dnl
+[[##] m4_Border [##]
 [##] $1 [##]
 [##] m4_Border [##]_m4_popdef([m4_Border])])
 
@@ -2991,8 +3025,7 @@ m4_pattern_forbid([^dnl$])
 
 # If __m4_version__ is defined, we assume that we are being run by M4
 # 1.6 or newer, and thus that $@ recursion is linear and debugmode(d)
-# is available for faster checks of dereferencing undefined macros,
-# and we don't need to worry about _m4_format bugs with _m4_index.
+# is available for faster checks of dereferencing undefined macros.
 # But if it is missing, we assume we are being run by M4 1.4.x, that
 # $@ recursion is quadratic, and that we need foreach-based
 # replacement macros.  Use the raw builtin to avoid tripping up
@@ -3001,7 +3034,6 @@ m4_pattern_forbid([^dnl$])
 m4_ifdef([__m4_version__],
 [m4_debugmode([+d])
 m4_define([m4_defn], _m4_defn([_m4_defn]))
-m4_define([_m4_index], _m4_defn([m4_index]))
 m4_define([m4_popdef], _m4_defn([_m4_popdef]))
 m4_define([m4_undefine], _m4_defn([_m4_undefine]))],
 [m4_builtin([include], [m4sugar/foreach.m4])])
diff --git a/tests/autotest.at b/tests/autotest.at
index d674c81..631c0c8 100644
--- a/tests/autotest.at
+++ b/tests/autotest.at
@@ -464,9 +464,10 @@ AT_CHECK_AT_TITLE_CHAR([Backslash],     [\])
 AT_CHECK_AT_TITLE_CHAR([Brackets],   [[[]]], [[]])
 AT_CHECK_AT_TITLE_CHAR([Left bracket],  [@<@&t@:@], [@<:@])
 AT_CHECK_AT_TITLE_CHAR([Right bracket], [@:@&t@>@], [@:>@])
-AT_CHECK_AT_TITLE_CHAR([Pound],       [[#]], [#])
-AT_CHECK_AT_TITLE_CHAR([Quoted comma],[[,]], [,])
-AT_CHECK_AT_TITLE_CHAR([Comma],         [,], [,])
+AT_CHECK_AT_TITLE_CHAR([Quoted pound],  [[#]], [#])
+AT_CHECK_AT_TITLE_CHAR([Pound],         [#])
+AT_CHECK_AT_TITLE_CHAR([Quoted comma],  [[,]], [,])
+AT_CHECK_AT_TITLE_CHAR([Comma],         [,])
 dnl this test also hits quadrigraphs for ()
 AT_CHECK_AT_TITLE_CHAR([Parentheses],   [(@{:@)@:address@hidden, [(())])
 AT_CHECK_AT_TITLE_CHAR([Left paren],    [[(]], [(])
diff --git a/tests/m4sugar.at b/tests/m4sugar.at
index 5a90493..708067b 100644
--- a/tests/m4sugar.at
+++ b/tests/m4sugar.at
@@ -676,6 +676,62 @@ one
 AT_CLEANUP
 
 
+## ----------- ##
+## m4_expand.  ##
+## ----------- ##
+
+AT_SETUP([m4@&address@hidden)
+
+AT_CHECK_M4SUGAR_TEXT(
+[[m4_define([active], [ACTIVE])dnl
+m4_expand([#active
+active])
+m4_expand([[active]])
+dnl properly quoted case statements
+m4_expand([case a in @%:@(
+  *) echo active, ;;
+esac
+case b in
+  *[)] echo active, ;;
+esac])
+dnl unbalanced underquoted `)', but we manage anyway (gasp!)
+m4_expand([case c in #(
+  *) echo active, ;;
+esac
+case d in
+  *) echo active, ;;
+esac])
+dnl unterminated comment/dnl
+m4_expand([active # active])
+m4_expand([a
+dnl])
+m4_expand([a
+-dnl])
+]],
+[[#active
+ACTIVE
+active
+case a in #(
+  *) echo ACTIVE, ;;
+esac
+case b in
+  *) echo ACTIVE, ;;
+esac
+case c in #(
+  *) echo ACTIVE, ;;
+esac
+case d in
+  *) echo ACTIVE, ;;
+esac
+ACTIVE # active
+a
+a
+-
+]])
+
+AT_CLEANUP
+
+
 ## -------------- ##
 ## m4_text_wrap.  ##
 ## -------------- ##
@@ -871,6 +927,34 @@ $1$#$@
 
 AT_CLEANUP
 
+## -------------- ##
+## m4_esyscmd_s.  ##
+## -------------- ##
+
+AT_SETUP([m4@&address@hidden)
+AT_KEYWORDS([m4@&address@hidden m4@&address@hidden)
+
+AT_CHECK_M4SUGAR_TEXT(
+[[m4_define([world], [WORLD])dnl
+m4_chomp([abc])
+m4_chomp([world
+
+])
+m4_esyscmd_s([echo hello world])
+m4_esyscmd_s([echo '[goodbye,
+cruel world
+
+]'])
+]], [[abc
+world
+
+hello WORLD
+goodbye,
+cruel world
+]])
+
+AT_CLEANUP
+
 ## ---------- ##
 ## M4 Loops.  ##
 ## ---------- ##
diff --git a/tests/torture.at b/tests/torture.at
index 586d0f8..1a9ea4f 100644
--- a/tests/torture.at
+++ b/tests/torture.at
@@ -449,6 +449,7 @@ AT_CLEANUP
 # problems when a symbol is prefix of another.
 
 AT_SETUP(address@hidden:@define header templates])
+AT_KEYWORDS([AC@&address@hidden)
 
 AT_DATA([configure.ac],
 [[AC_INIT
@@ -474,6 +475,9 @@ AC_DEFINE([multiline_args(ARG1, ARG2)], [ARG2 \
 ARG1])
 AC_CONFIG_FILES(defs)
 
+# underquoted #
+AC_DEFINE([paste(a,b)], [a##b])
+
 # Things included in confdefs.h, but which make no sense in
 # config.h, nor in $DEFS.
 cat <<\EOF >>confdefs.h
@@ -510,6 +514,7 @@ AT_DATA([config.hin],
 #define aaac(a, aa) aa a
 #undef multiline
 #  undef multiline_args
+#define paste(a,b) a##b
 /* an ugly one: */
 #define str(define) \
 #define
@@ -542,6 +547,7 @@ line3 \
 line4
 #  define multiline_args(ARG1, ARG2) ARG2 \
 ARG1
+#define paste(a,b) a##b
 /* an ugly one: */
 #define str(define) \
 #define
@@ -553,7 +559,7 @@ AT_CHECK([cat config.h], 0, expout)
 
 # Check the value of DEFS.
 AT_DATA([expout],
-[[-DPACKAGE_NAME=\"\" -DPACKAGE_TARNAME=\"\" -DPACKAGE_VERSION=\"\" 
-DPACKAGE_STRING=\"\" -DPACKAGE_BUGREPORT=\"\" -Dfoo=toto -Dbar=tata -Dbaz=titi 
-Dfubar=tutu -Da=A -Daaa=AAA -Daa=AA -Dmultiline=line1line2line3\ line4 
-Dmultiline_args\(ARG1,\ ARG2\)=ARG2\ ARG1
+[[-DPACKAGE_NAME=\"\" -DPACKAGE_TARNAME=\"\" -DPACKAGE_VERSION=\"\" 
-DPACKAGE_STRING=\"\" -DPACKAGE_BUGREPORT=\"\" -Dfoo=toto -Dbar=tata -Dbaz=titi 
-Dfubar=tutu -Da=A -Daaa=AAA -Daa=AA -Dmultiline=line1line2line3\ line4 
-Dmultiline_args\(ARG1,\ ARG2\)=ARG2\ ARG1 -Dpaste\(a,b\)=a\#\#b
 ]])
 
 # Because we strip trailing spaces in `testsuite' we can't leave one in
@@ -756,16 +762,19 @@ AT_CLEANUP
 ## ------------------------------ ##
 
 AT_SETUP([Define to a 2000-byte string])
+AT_KEYWORDS([AC@&address@hidden AC@&address@hidden)
 
 AT_CONFIGURE_AC(
 [[
-AC_DEFINE([foo], ]m4_for([n], 1, 100,, ....................)[, [desc])
+AC_DEFINE_UNQUOTED([foo], ]m4_for([n], 1, 100,, ....................)[, [desc])
+AC_DEFINE([fooq], ]m4_for([n], 1, 100,, ....................)[, [desc])
 ]])
 
 AT_CHECK_AUTOCONF
 AT_CHECK_AUTOHEADER
 AT_CHECK_CONFIGURE
 AT_CHECK_DEFINES(address@hidden:@define foo m4_for([n], 1, 100,, 
....................)
address@hidden:@define fooq m4_for([n], 1, 100,, ....................)
 ])
 AT_CLEANUP
 
@@ -777,6 +786,7 @@ AT_CLEANUP
 # Use characters special to the shell, sed, awk, and M4.
 
 AT_SETUP([Substitute and define special characters])
+AT_KEYWORDS([AC@&address@hidden AC@&address@hidden)
 
 AT_DATA([Foo.in], address@hidden@
 @bar@@notsubsted@@baz@ stray @ and more@@@baz@
@@ -800,7 +810,8 @@ AT_DATA([Zardoz.in], address@hidden@
 ])
 
 AT_CONFIGURE_AC(
-[[foo="AS@&address@hidden([[X*'[]+ ",& &`\($foo \& \\& \\\& \\\\& \ \\ \\\ 
!]])"
+[[foo="AS@&address@hidden([[X*'[]+ ", & &`\($foo \& \\& \\\& \\\\& \ \\ \\\ 
!]])"
+#"
 bar="@foo@ @baz@"
 baz=bla
 ( for i in 0 1 2 3; do
@@ -824,8 +835,17 @@ AC_SUBST([baz])
 AC_SUBST([zardoz])
 file=File
 AC_SUBST_FILE([file])
-AC_DEFINE([foo], [[X*'[]+ ",& &`\($foo !]], [Awful value.])
-AC_DEFINE([bar], [[%!_!# X]], [Value that is used as special delimiter.])
+AC_DEFINE([fooq], [[X*'[]+ ", & &`\($foo !]], [Awful value.])
+AC_DEFINE([barq], [[%!_!# X]], [Value that is used as special delimiter.])
+AC_DEFINE_UNQUOTED([foo], [[X*'[]+ ", & &\`\\(\$foo !]], [Awful value.])
+AC_DEFINE_UNQUOTED([bar], [[%!_!# X]], [Value that is used as special 
delimiter.])
+AC_DEFINE_UNQUOTED([unq1], [$baz], [unquoted, test 1])
+AC_DEFINE_UNQUOTED([unq2], [\$baz], [unquoted, test 2])
+AC_DEFINE_UNQUOTED([unq3], ["$baz"], [unquoted, test 3])
+AC_DEFINE_UNQUOTED([unq4], [${baz+set}], [unquoted, test 4])
+AC_DEFINE_UNQUOTED([unq5], ["${baz+`echo "a b"`}"], [unquoted, test 5])
+AC_DEFINE_UNQUOTED([unq6], [`echo hi`], [unquoted, test 6])
+AC_DEFINE_UNQUOTED([unq7], ['\"'], [unquoted, test 7])
 AC_PROG_AWK
 AC_CONFIG_FILES([Foo Zardoz])]])
 
@@ -834,7 +854,7 @@ AT_CHECK_AUTOHEADER
 # Check both awk and the result of AC_PROG_AWK
 for awk_arg in FOO= AWK=awk; do
   AT_CHECK_CONFIGURE([$awk_arg])
-  AT_CHECK([cat Foo], 0, [[X*'[]+ ",& &`\($foo \& \\& \\\& \\\\& \ \\ \\\ !
+  AT_CHECK([cat Foo], 0, [[X*'[]+ ", & &`\($foo \& \\& \\\& \\\\& \ \\ \\\ !
 @foo@ @baz@@address@hidden stray @ and more@@bla
 address@hidden@ @address@hidden@baz
 address@hidden@ @address@hidden
@@ -849,7 +869,16 @@ address@hidden@
 ]])
   AT_CHECK([cmp allowed-chars Zardoz])
   AT_CHECK_DEFINES([[#define bar %!_!# X
-#define foo X*'[]+ ",& &`\($foo !
+#define barq %!_!# X
+#define foo X*'[]+ ", & &`\($foo !
+#define fooq X*'[]+ ", & &`\($foo !
+#define unq1 bla
+#define unq2 $baz
+#define unq3 "bla"
+#define unq4 set
+#define unq5 "a b"
+#define unq6 hi
+#define unq7 '\"'
 ]])
 done
 AT_CLEANUP
@@ -900,6 +929,7 @@ AT_CLEANUP
 ## ------------------ ##
 
 AT_SETUP([Define a newline])
+AT_KEYWORDS([AC@&address@hidden AC@&address@hidden)
 AT_CONFIGURE_AC([[AC_DEFINE([foo], [one
 two], [This spans two lines.])
 ]])


hooks/post-receive
--
GNU Autoconf source repository




reply via email to

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