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 <ebb9@byu.net>
This commit is contained in:
Eric Blake 2008-11-13 21:20:18 -07:00
parent 7791129655
commit 2d63737afb
4 changed files with 90 additions and 26 deletions

View File

@ -1,3 +1,15 @@
2008-11-20 Eric Blake <ebb9@byu.net>
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 <ebb9@byu.net>
Improve m4_expand robustness, part 2.

View File

@ -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])
;;

View File

@ -2060,18 +2060,41 @@ 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_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(QUOTE, VARIABLE, [VALUE], [DESCRIPTION])
# _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
@ -2087,13 +2110,12 @@ m4_define([_AC_DEFINE_Q],
])], [-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
[@%:@define] $2 m4_if([$#], 2, 1, [$3], [], [/**/], [$3])
_ACEOF
[$1(m4_expand([[@%:@define] $2 ]m4_if([$#], 2, 1,
[$3], [], [/**/], [[$3]])))
])

View File

@ -449,6 +449,7 @@ AT_CLEANUP
# problems when a symbol is prefix of another.
AT_SETUP([@%:@define header templates])
AT_KEYWORDS([AC@&t@_DEFINE])
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@&t@_DEFINE AC@&t@_DEFINE_UNQUOTED])
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([@%:@define foo m4_for([n], 1, 100,, ....................)
@%:@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@&t@_DEFINE AC@&t@_DEFINE_UNQUOTED])
AT_DATA([Foo.in], [@foo@
@bar@@notsubsted@@baz@ stray @ and more@@@baz@
@ -800,7 +810,8 @@ AT_DATA([Zardoz.in], [@zardoz@
])
AT_CONFIGURE_AC(
[[foo="AS@&t@_ESCAPE([[X*'[]+ ",& &`\($foo \& \\& \\\& \\\\& \ \\ \\\ !]])"
[[foo="AS@&t@_ESCAPE([[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@@notsubsted@bla stray @ and more@@bla
abc@foo@ @baz@baz@baz
abc@foo@ @baz@blabaz
@ -849,7 +869,16 @@ X@file@
]])
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@&t@_DEFINE AC@&t@_DEFINE_UNQUOTED])
AT_CONFIGURE_AC([[AC_DEFINE([foo], [one
two], [This spans two lines.])
]])