autoconf-patches
[Top][All Lists]
Advanced

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

Re: Multi-Line Definitions


From: Eric Blake-1
Subject: Re: Multi-Line Definitions
Date: Thu, 27 Sep 2007 11:20:05 -0700 (PDT)

> > Ignoring that, and assuming we only care about backslash-newline like in
> > Eric's example, a patch like the one below would be sufficient, but
> > config.h would not be any more readable than if you would not use
> > newlines in the first place.  OK to apply?  AFAICS it's a strict
> > improvement over what we have now.  OTOH I'm not sure what to do with
> > the XFAILing `Define a newline' test we have now in tests/torture.at.
> 
> I agree that your patch is a strict improvement over the current state of
> things.  I also like Ralf Corsepius' analysis that, at least for now,
> AC_DEFINE should only make sense for the C pre-processor.  My take is that
> we could start from this patch, then additionally add some checking that
> if the value argument to AC_DEFINE{,_UNQUOTED} is literal, an error is
> issued if it contains raw newlines.  And if we do that, then the 'Define a
> newline' test should be altered to check that we correctly diagnose
> improper use of newline, while letting \-newline through.

I'm thinking of applying your patch, along with my followup (munged slightly
to avoid raw email addresses), in another day or two, unless someone else
pipes up with a review.

2007-09-27  Eric Blake  <address@hidden>

        Enhance previous patch's handling of raw newlines.
        * lib/autoconf/general.m4 (_AC_RAW_NEWLINE_RE): New macro.
        (AC_DEFINE, AC_DEFINE_UNQUOTED): Die on raw newlines in value.
        * tests/torture.at (Define a newline): Remove XFAIL, and demand
        failure on raw newline.
        * doc/autoconf.texi (Defining Symbols): Document that raw newlines
        cannot be used in AC_DEFINE.
        * THANKS: Update.

2007-09-27  Ralf Wildenhues  <Ralf.Wildenhues AT gmx.de>

        Allow preprocessor line continuation in AC_DEFINE{,_UNQUOTED}.
        * lib/autoconf/status.m4 (_AC_OUTPUT_HEADER, AC_OUTPUT_MAKE_DEFS):
        Remove backslash-newline combinations from define values.
        * doc/autoconf.texi (Defining Symbols): Adjust.
        * NEWS: Update.
        * tests/torture.at (#define header templates): Extend test.
        Suggestion by Eric Lemings.


From: Ralf Wildenhues <Ralf.Wildenhues AT gmx.de>
Date: Tue, 25 Sep 2007 15:56:55 -0600
Subject: [PATCH] Allow preprocessor line continuation in
AC_DEFINE{,_UNQUOTED}.

* lib/autoconf/status.m4 (_AC_OUTPUT_HEADER, AC_OUTPUT_MAKE_DEFS):
Remove backslash-newline combinations from define values.
* doc/autoconf.texi (Defining Symbols): Adjust.
* NEWS: Update.
* tests/torture.at (#define header templates): Extend test.
Suggestion by Eric Lemings.
---
 ChangeLog              |   10 ++++++++++
 NEWS                   |    3 +++
 doc/autoconf.texi      |    9 +++++----
 lib/autoconf/status.m4 |   14 +++++++++++++-
 tests/torture.at       |   10 +++++++++-
 5 files changed, 40 insertions(+), 6 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 772a777..50aebf1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2007-09-27  Ralf Wildenhues  <Ralf.Wildenhues AT gmx.de>
+
+       Allow preprocessor line continuation in AC_DEFINE{,_UNQUOTED}.
+       * lib/autoconf/status.m4 (_AC_OUTPUT_HEADER, AC_OUTPUT_MAKE_DEFS):
+       Remove backslash-newline combinations from define values.
+       * doc/autoconf.texi (Defining Symbols): Adjust.
+       * NEWS: Update.
+       * tests/torture.at (#define header templates): Extend test.
+       Suggestion by Eric Lemings.
+
 2007-09-27  Eric Blake  <address@hidden>
 
        Autotest formatting touchups.
diff --git a/NEWS b/NEWS
index 73ee6e9..fc977ff 100644
--- a/NEWS
+++ b/NEWS
@@ -34,6 +34,9 @@ GNU Autoconf NEWS - User visible changes.
    if found, and it works to link against a file of the same name in
    the source tree, even if both trees coincide.
 
+** AC_DEFINE and AC_DEFINE_UNQUOTED now handle multi-line values, i.e.,
+   backslash-newline combinations are handled correctly.
+
 ** AC_INIT no longer alters $@; regression introduced in 2.60.
 
 ** AC_USE_SYSTEM_EXTENSIONS now defines _ALL_SOURCE for Interix platforms.
diff --git a/doc/autoconf.texi b/doc/autoconf.texi
index 8d41f47..40cf013 100644
--- a/doc/autoconf.texi
+++ b/doc/autoconf.texi
@@ -8494,10 +8494,11 @@ terminated by an ellipsis @samp{...} if C99 syntax
is employed.
 backslash-newlines, universal character names, or address@hidden
 characters.
 
address@hidden should not contain literal newlines, and if you are not
-using @code{AC_CONFIG_HEADERS} it should not contain any @samp{#}
-characters, as @command{make} tends to eat them.  To use a shell variable,
-use @code{AC_DEFINE_UNQUOTED} instead.
address@hidden may contain backslash-escaped newlines; they may be removed
+in the generated header file.  If you are not using
address@hidden, @var{value} should not contain any @samp{#}
+characters, as @command{make} tends to eat them.  To use a shell
+variable, use @code{AC_DEFINE_UNQUOTED} instead.
 @var{description} is only useful if you are using
 @code{AC_CONFIG_HEADERS}.  In this case, @var{description} is put into
 the generated @file{config.h.in} as the comment before the macro define.
diff --git a/lib/autoconf/status.m4 b/lib/autoconf/status.m4
index 5b43e11..9b63bb7 100644
--- a/lib/autoconf/status.m4
+++ b/lib/autoconf/status.m4
@@ -724,7 +724,13 @@ dnl
 dnl The first use of ac_dA has a space prepended, so that the second
 dnl use does not match the initial 's' of $ac_dA.
 [
-uniq confdefs.h |
+sed ':mline
+     /\\$/{
+     N
+     s,\\\n,,
+     b mline
+   }' confdefs.h |
+  uniq |
   sed -n '
        t rset
        :rset
@@ -1611,6 +1617,12 @@ m4_define([AC_OUTPUT_MAKE_DEFS],
 # take arguments), then branch to the quote section.  Otherwise,
 # look for a macro that doesn't take arguments.
 ac_script='
+:mline
+/\\$/{
+ N
+ s,\\\n,,
+ b mline
+}
 t clear
 :clear
 s/^[    ]*#[    ]*define[       ][      ]*\([^  (][^    (]*([^)]*)\)[   
]*\(.*\)/-D\1=\2/g
diff --git a/tests/torture.at b/tests/torture.at
index 268c15b..0bdebf4 100644
--- a/tests/torture.at
+++ b/tests/torture.at
@@ -333,6 +333,12 @@ AC_DEFINE(fubar, tutu)
 AC_DEFINE(a, A)
 AC_DEFINE(aaa, AAA)
 AC_DEFINE(aa, AA)
+
+# backslash-newline combinations
+AC_DEFINE(multiline, line1\
+line2\
+line3 \
+line4)
 AC_CONFIG_FILES(defs)
 
 # Things included in confdefs.h, but which make no sense in
@@ -366,6 +372,7 @@ AT_DATA([config.hin],
 #undef a
 #undef aa
 #undef aaa
+#undef multiline
 ]])
 
 AT_CHECK_AUTOCONF
@@ -383,12 +390,13 @@ AT_DATA([expout],
 #define a A
 #define aa AA
 #define aaa AAA
+#define multiline line1line2line3 line4
 ]])
 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
+[[-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
 ]])
 
 # Because we strip trailing spaces in `testsuite' we can't leave one in
-- 
1.5.3.2


>From 63af984f762540e52e57689f1b5b1555d5d54186 Mon Sep 17 00:00:00 2001
From: Eric Blake <address@hidden>
Date: Wed, 26 Sep 2007 08:56:49 -0600
Subject: [PATCH] Enhance previous patch's handling of raw newlines.

* lib/autoconf/general.m4 (_AC_RAW_NEWLINE_RE): New macro.
(AC_DEFINE, AC_DEFINE_UNQUOTED): Die on raw newlines in value.
* tests/torture.at (Define a newline): Remove XFAIL, and demand
failure on raw newline.
* doc/autoconf.texi (Defining Symbols): Document that raw newlines
cannot be used in AC_DEFINE.
* THANKS: Update.

Signed-off-by: Eric Blake <address@hidden>
---
 ChangeLog               |   11 +++++++++++
 THANKS                  |    1 +
 doc/autoconf.texi       |    6 ++++--
 lib/autoconf/general.m4 |   16 ++++++++++++++--
 tests/torture.at        |   22 ++++++++++++++++------
 5 files changed, 46 insertions(+), 10 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 50aebf1..18f5733 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2007-09-27  Eric Blake  <address@hidden>
+
+       Enhance previous patch's handling of raw newlines.
+       * lib/autoconf/general.m4 (_AC_RAW_NEWLINE_RE): New macro.
+       (AC_DEFINE, AC_DEFINE_UNQUOTED): Die on raw newlines in value.
+       * tests/torture.at (Define a newline): Remove XFAIL, and demand
+       failure on raw newline.
+       * doc/autoconf.texi (Defining Symbols): Document that raw newlines
+       cannot be used in AC_DEFINE.
+       * THANKS: Update.
+
 2007-09-27  Ralf Wildenhues  <Ralf.Wildenhues AT gmx.de>
 
        Allow preprocessor line continuation in AC_DEFINE{,_UNQUOTED}.
diff --git a/THANKS b/THANKS
index 13318e0..862d54f 100644
--- a/THANKS
+++ b/THANKS
diff --git a/doc/autoconf.texi b/doc/autoconf.texi
index 40cf013..a56989b 100644
--- a/doc/autoconf.texi
+++ b/doc/autoconf.texi
@@ -8494,8 +8494,10 @@ terminated by an ellipsis @samp{...} if C99 syntax is
employed.
 backslash-newlines, universal character names, or address@hidden
 characters.
 
address@hidden may contain backslash-escaped newlines; they may be removed
-in the generated header file.  If you are not using
address@hidden may contain backslash-escaped newlines, although they may be
+removed in the generated header file (with no effect on the compilation,
+since the preprocessor sees only one line in the first place).
address@hidden should not contain raw newlines.  If you are not using
 @code{AC_CONFIG_HEADERS}, @var{value} should not contain any @samp{#}
 characters, as @command{make} tends to eat them.  To use a shell
 variable, use @code{AC_DEFINE_UNQUOTED} instead.
diff --git a/lib/autoconf/general.m4 b/lib/autoconf/general.m4
index ce3b48e..b6e0cc8 100644
--- a/lib/autoconf/general.m4
+++ b/lib/autoconf/general.m4
@@ -2002,18 +2002,30 @@ m4_define([AC_DEFINE_TRACE],
 [AS_LITERAL_IF([$1], [AC_DEFINE_TRACE_LITERAL(m4_bpatsubst([[$1]],
[(.*)]))])])
 
 
+# _AC_RAW_NEWLINE_RE
+# ------------------
+# Contains regex that matches a newline not preceded by backslash.
+m4_define([_AC_RAW_NEWLINE_RE], [\(^\|[^\]\)
+])
+
+
 # AC_DEFINE(VARIABLE, [VALUE], [DESCRIPTION])
 # -------------------------------------------
 # 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], [m4_bmatch([[$2]], m4_defn([_AC_RAW_NEWLINE_RE]),
+[AC_FATAL([$0: `$2' is not a valid preprocessor define value])],
+[_AC_DEFINE_Q([\], $@)])])
 
 
 # AC_DEFINE_UNQUOTED(VARIABLE, [VALUE], [DESCRIPTION])
 # ----------------------------------------------------
 # Similar, but perform shell substitutions $ ` \ once on VALUE.
-m4_define([AC_DEFINE_UNQUOTED], [_AC_DEFINE_Q([], $@)])
+m4_define([AC_DEFINE_UNQUOTED],
+[AS_LITERAL_IF([$2], [m4_bmatch([[$2]], m4_defn([_AC_RAW_NEWLINE_RE]),
+[AC_FATAL([$0: `$2' is not a valid preprocessor define value])])])dnl
+_AC_DEFINE_Q([], $@)])
 
 
 # _AC_DEFINE_Q(QUOTE, VARIABLE, [VALUE], [DESCRIPTION])
diff --git a/tests/torture.at b/tests/torture.at
index 0bdebf4..d450e3d 100644
--- a/tests/torture.at
+++ b/tests/torture.at
@@ -737,16 +737,26 @@ AT_CLEANUP
 ## ------------------ ##
 
 AT_SETUP([Define a newline])
-AT_XFAIL_IF(:)
 AT_CONFIGURE_AC([[AC_DEFINE([foo], [one
 two], [This spans two lines.])
 ]])
-AT_CHECK_AUTOCONF
-AT_CHECK_AUTOHEADER
-AT_CHECK_CONFIGURE
-AT_CHECK_DEFINES([[#define foo one
-two
+AT_CHECK_AUTOCONF([], [1], [],
+[[configure.ac:5: error: AC_DEFINE: `one
+two' is not a valid preprocessor define value
+configure.ac:5: the top level
+autom4te: m4 failed with exit status: 1
 ]])
+
+AT_CONFIGURE_AC([[AC_DEFINE_UNQUOTED([foo], [one
+two], [This spans two lines.])
+]])
+AT_CHECK_AUTOCONF([], [1], [],
+[[configure.ac:5: error: AC_DEFINE_UNQUOTED: `one
+two' is not a valid preprocessor define value
+configure.ac:5: the top level
+autom4te: m4 failed with exit status: 1
+]])
+
 AT_CLEANUP
 
 
-- 
1.5.3.2


-- 
View this message in context: 
http://www.nabble.com/Re%3A-Multi-Line-Definitions-tf4476595.html#a12927378
Sent from the Gnu - Autoconf - Patches mailing list archive at Nabble.com.





reply via email to

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