[prev in list] [next in list] [prev in thread] [next in thread] 

List:       autoconf-bug
Subject:    Re: quoting bug in definition of AC_DEFINE and AC_DEFINE_UNQUOTED
From:       Eric Blake <ebb9 () byu ! net>
Date:       2009-07-25 12:02:05
Message-ID: 4A6AF43D.80603 () byu ! net
[Download RAW message or body]

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

According to Bruno Haible on 6/1/2009 4:07 AM:
> Hi,
> 
> The first argument passed to AC_DEFINE or AC_DEFINE_UNQUOTED is subject
> to m4 macro expansion.

Thanks for the report, and sorry it took me two months to do the two-line
fix (half the battle was finding the free time, the other half was finding
the right three lines to fix, but you know how that goes ;)

> $ cat > configure.ac <<\EOF
> AC_INIT
> AC_CONFIG_HEADER([config.h])
> m4_define([PETER], [SIMSALABIM])
> m4_define([PAUL], [OPENSESAME])
> AC_DEFINE([PETER], [10], [Peter's public info])
> AC_DEFINE_UNQUOTED([PAUL], [`expr 4 + 6`], [Paul's public info])
> AC_OUTPUT
> EOF
> $ autoconf
> $ autoheader
> $ grep SIMSALABIM configure config.h.in 
> configure:#define SIMSALABIM 10
> $

At this point, both configure and autoheader should use SIMSALABIM.

- --
Don't work too hard, make some time for fun as well!

Eric Blake             ebb9@byu.net
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkpq9D0ACgkQ84KuGfSFAYAj8gCbB2hvptPmtBbE6h89GjwctMiS
WqUAoJXFo8pCvFhIsnmYC/mVKpsBvRNY
=zdAa
-----END PGP SIGNATURE-----

["autoconf.patch222" (text/plain)]

>From 77350bd98ce38adde4fe3f80cd73f07fd414db58 Mon Sep 17 00:00:00 2001
From: Eric Blake <ebb9@byu.net>
Date: Sat, 25 Jul 2009 06:00:38 -0600
Subject: [PATCH] Let autoheader see through m4 macros in AC_DEFINE.

* lib/autoconf/general.m4 (AC_DEFINE_TRACE): Expand macro before
tracing its name.
* lib/autoconf/autoheader.m4 (AH_VERBATIM, AH_TEMPLATE): Likewise,
for using the macro in a template file.
* tests/tools.at (autoheader and macros): New test.
* NEWS: Mention this.
Reported by Bruno Haible.

Signed-off-by: Eric Blake <ebb9@byu.net>
---
 ChangeLog                  |    9 +++++++++
 NEWS                       |    3 +++
 lib/autoconf/autoheader.m4 |    4 ++--
 lib/autoconf/general.m4    |    2 +-
 tests/tools.at             |   36 ++++++++++++++++++++++++++++++++++++
 5 files changed, 51 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 0b99080..5daef4d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
 2009-07-25  Eric Blake  <ebb9@byu.net>

+	Let autoheader see through m4 macros in AC_DEFINE.
+	* lib/autoconf/general.m4 (AC_DEFINE_TRACE): Expand macro before
+	tracing its name.
+	* lib/autoconf/autoheader.m4 (AH_VERBATIM, AH_TEMPLATE): Likewise,
+	for using the macro in a template file.
+	* tests/tools.at (autoheader and macros): New test.
+	* NEWS: Mention this.
+	Reported by Bruno Haible.
+
 	Improve NEWS wording.
 	* NEWS: Use more accurate statement.
 	Suggestedy by Ralf Wildenhues.
diff --git a/NEWS b/NEWS
index d3662cd..3830fc0 100644
--- a/NEWS
+++ b/NEWS
@@ -9,6 +9,9 @@ GNU Autoconf NEWS - User visible changes.
 ** The following documented autoconf macros are new:
    AC_ERLANG_SUBST_ERTS_VER

+** The autoheader tool now understands m4 macro arguments passed to
+   AC_DEFINE and AC_DEFINE_UNQUOTED.
+
 ** Ensure AT_CHECK can support commands that include a # given with
    proper m4 quoting.  For shell comments, this is a new feature; for
    non-shell comments, this fixes a regression introduced in 2.63b.
diff --git a/lib/autoconf/autoheader.m4 b/lib/autoconf/autoheader.m4
index 8e109cc..99723f2 100644
--- a/lib/autoconf/autoheader.m4
+++ b/lib/autoconf/autoheader.m4
@@ -68,7 +68,7 @@ m4_define([AH_OUTPUT], [])
 # Quote for Perl '' strings, which are those used by Autoheader.
 m4_define([AH_VERBATIM],
 [AS_LITERAL_IF([$1],
-	       [AH_OUTPUT([$1], AS_ESCAPE([[$2]], [\']))])])
+	       [AH_OUTPUT(_m4_expand([$1]), AS_ESCAPE([[$2]], [\']))])])


 # AH_TEMPLATE(KEY, DESCRIPTION)
@@ -78,7 +78,7 @@ m4_define([AH_VERBATIM],
 m4_define([AH_TEMPLATE],
 [AH_VERBATIM([$1],
 	     m4_text_wrap([$2 */], [   ], [/* ])[
-#undef $1])])
+@%:@undef ]_m4_expand([$1]))])


 # AH_TOP(TEXT)
diff --git a/lib/autoconf/general.m4 b/lib/autoconf/general.m4
index e3b69d0..f030c26 100644
--- a/lib/autoconf/general.m4
+++ b/lib/autoconf/general.m4
@@ -2075,7 +2075,7 @@ AS_IDENTIFIER_IF([$1], [],
 # This macro is a wrapper around AC_DEFINE_TRACE_LITERAL which filters
 # out non literal symbols.  CPP-SYMBOL must not include any parameters.
 m4_define([AC_DEFINE_TRACE],
-[AS_LITERAL_IF([$1], [AC_DEFINE_TRACE_LITERAL([$1])])])
+[AS_LITERAL_IF([$1], [AC_DEFINE_TRACE_LITERAL(_m4_expand([$1]))])])


 # AC_DEFINE(VARIABLE, [VALUE], [DESCRIPTION])
diff --git a/tests/tools.at b/tests/tools.at
index 529eb93..e54ed69 100644
--- a/tests/tools.at
+++ b/tests/tools.at
@@ -717,6 +717,42 @@ The Dog in a h@t.
 AT_CLEANUP


+# autoheader should see through m4 macros, just like autoconf
+# http://lists.gnu.org/archive/html/bug-autoconf/2009-06/msg00000.html
+AT_SETUP([autoheader and macros])
+
+AT_DATA([configure.ac],
+[[AC_INIT
+AC_CONFIG_HEADER([config.h])
+m4_define([PETER], [SIMSALABIM])
+m4_define([PAUL], [OPENSESAME])
+AC_DEFINE([PETER], [10], [Peter's public info])
+AC_DEFINE_UNQUOTED([PAUL], [`expr 4 + 6`], [Paul's public info])
+AC_OUTPUT
+]])
+
+AT_CHECK_AUTOCONF
+AT_CHECK_AUTOHEADER
+AT_CHECK([grep -c SIMSALABIM configure config.h.in], [0],
+[[configure:1
+config.h.in:1
+]])
+AT_CHECK([grep -c OPENSESAME configure config.h.in], [0],
+[[configure:1
+config.h.in:1
+]])
+AT_CHECK([grep -c PETER configure config.h.in], [1],
+[[configure:0
+config.h.in:0
+]])
+AT_CHECK([grep -c PAUL configure config.h.in], [1],
+[[configure:0
+config.h.in:0
+]])
+
+AT_CLEANUP
+
+


 ## ------------ ##
-- 
1.6.3.3.334.g916e1



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic