Re: [PATCH 2/3] autoconf: prefer an unrolled loop for trivial AC_CHECK_HEADERS

Paolo Bonzini <[email protected]>
Newsgroups gmane.comp.sysutils.autoconf.patches
Message-ID <[email protected]>

On 31/10/2016 16:32, Eric Blake wrote:
> On 10/31/2016 06:39 AM, Paolo Bonzini wrote:
>> An unrolled loop avoids the cost of spawning sed in AS_TR_SH and
>> AS_TR_CPP.  Prefer it if there is nothing in the second and third
>> argument of AC_CHECK_HEADERS and the first argument is a literal.
>> Modify AC_CHECK_HEADERS_ONCE to avoid the variable indirection too.
>>
>> * lib/autoconf/headers.m4 (AC_CHECK_HEADERS): Unroll loop if safe.
>> (_AC_CHECK_HEADERS): Move basic implementation here.
>> (_AC_CHECK_HEADER_ONCE): Expand AC_CHECK_HEADERS here...
>> (_AC_HEADERS_EXPANSION): ... and not here, so remove.
>> (AC_CHECK_INCLUDES_DEFAULT): Remove unnecessary arguments after the first.
>>
>> Signed-off-by: Paolo Bonzini <[email protected]>
>> ---
>>  lib/autoconf/headers.m4 | 30 +++++++++++++-----------------
>>  1 file changed, 13 insertions(+), 17 deletions(-)
>>
>> diff --git a/lib/autoconf/headers.m4 b/lib/autoconf/headers.m4
>> index 72262c1..e855025 100644
>> --- a/lib/autoconf/headers.m4
>> +++ b/lib/autoconf/headers.m4
>> @@ -182,22 +182,25 @@ m4_define([AH_CHECK_HEADERS],
>>  # header.  Either ACTION may include `break' to stop the search.
>>  AC_DEFUN([AC_CHECK_HEADERS],
>>  [m4_map_args_w([$1], [_AH_CHECK_HEADER(], [)])]dnl
>> -[AS_FOR([AC_header], [ac_header], [$1],
>> -[AC_CHECK_HEADER(AC_header,
>> -		 [AC_DEFINE_UNQUOTED(AS_TR_CPP([HAVE_]AC_header)) $2],
>> -		 [$3], [$4])dnl])
>> +[m4_if([$2$3]AS_LITERAL_IF([$1], [yes], [no]), []yes,
> 
> Again, why []yes instead of [yes]?
> 
>>  
>>  ## --------------------- ##
>> @@ -261,8 +258,7 @@ ac_includes_default="\
>>  #endif"
>>  ])]dnl
>>  [_AC_CHECK_HEADERS_ONCE(
>> -  [sys/types.h sys/stat.h strings.h inttypes.h stdint.h unistd.h],
>> -  [], [], [$ac_includes_default])]dnl
>> +  [sys/types.h sys/stat.h strings.h inttypes.h stdint.h unistd.h])]dnl
> 
> This one, I'm worried about.  $ac_includes_default is a shell variable
> not documented in the manual (so we can probably get away with changing
> it), but doesn't it exist so that projects can redefine the core set of
> default headers to check by default, whereas you are now losing that
> flexibility?

No, the arguments after the first were unused:

AC_DEFUN([_AC_CHECK_HEADERS_ONCE],
  [m4_map_args_w([$1], [_AC_CHECK_HEADER_ONCE(], [)])])


The variable is still used in my patch by _AC_CHECK_HEADER_ONCE:

m4_define([_AC_CHECK_HEADER_ONCE],
[AC_DEFUN([_AC_Header_]m4_translit([[$1]], [./-], [___]),
          [AC_CHECK_HEADERS([$1], [], [], [$ac_includes_default])])
AC_REQUIRE([_AC_Header_]m4_translit([[$1]], [./-], [___]))])


In fact, the whole usage of $ac_includes_default is only there to avoid
recursion between AC_INCLUDES_DEFAULT and AC_CHECK_HEADERS_ONCE: instead
of using AC_INCLUDES_DEFAULT as the fourth argument, we include its
expansion directly.

Now, because AC_CHECK_INCLUDES_DEFAULT is AC_DEFUN_ONCE'd, the mutual
recursion you would not produce an _infinite recursion_; however, you
would still get a bogus warning about m4_requiring a macro that is not
m4_defun'd.

Thanks,

Paolo
signature.asc (application/pgp-signature, 473 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iQEcBAEBCAAGBQJYF2WvAAoJEL/70l94x66D+ycIAKKFpEO7le4GT+aXTpn1p9t7
BbBL4yp142wldEn1flCdDI8m6TQFTi56zOo/q3zf/uXKAmqIzZUZsgxBHkhgw0wA
Eb7eV6wBS2SpUdwAGY8dKRxt3oa7E3BzCk0A/tYG42SA6lXtX0WapLWzbRD/S6sM
kPHo0frhY8G1nXbqVySZ2+n66AeF5vXv1DncqhQFtMtYS2gT+Kf1S/rwpG+Q4F3E
CiCn0E0JoSt8C3wPBhsbGDFfiKZLFhEUT3Am/muXFb91RQY/ER84y5TXQTwpfhEo
Ltfe0ZHhHDSnYZYuyjzir809cA2gs0aBLDxi/XbU9/eqD0rzTCtdMAXIiMftLZ0=
=MVod
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.