Re: [PATCH 3/3] autoconf: refine quadrigraph test in _AC_DEFINE_UNQUOTED

Eric Blake <[email protected]>
Newsgroups gmane.comp.sysutils.autoconf.patches
Organization Red Hat, Inc.
Message-ID <[email protected]>
On 10/31/2016 06:39 AM, Paolo Bonzini wrote:
> It is a very common case that a quadrigraph appears in the argument of
> _AC_DEFINE_UNQUOTED, because "#define" is expanded through a quadrigraph.
> Therefore, restrict the quadrigraph tests to "$" (for "$(" and "${")
> and "(" (for "$(").
> 
> At the same time, "#" should not be used inside AC_ECHO because it confuses
> m4's comment parsing.  This pre-existing latent bug is caught by test 251:
> 
>    AC_DEFINE_UNQUOTED([bar], [[%!_!# X]])
> 
> Previously the quadrigraph in "@%:@define bar %!_!# X" made Autoconf fall back
> to cat anyway.  Now that Autoconf is not fooled by the quadrigraph, the test
> catches that "#" is not special-cased.  Kudos to Eric for coming up with it!
> 
> * lib/autoconf/general (_AC_DEFINE_UNQUOTED): Do not blindly
> use cat on all quadrigraphs.
> 
> Signed-off-by: Paolo Bonzini <[email protected]>
> ---
>  lib/autoconf/general.m4 | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)

ACK.

> 
> diff --git a/lib/autoconf/general.m4 b/lib/autoconf/general.m4
> index c15fb13..ef6285d 100644
> --- a/lib/autoconf/general.m4
> +++ b/lib/autoconf/general.m4
> @@ -2167,9 +2167,11 @@ m4_define([AC_DEFINE_UNQUOTED], [_AC_DEFINE_Q([_$0], $@)])
>  # 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.
> +# substitution (taking into account quadrigraphs as well).  Also
> +# avoid AS_ECHO if "#" is present to avoid confusing m4 with comments,
> +# but quadrigraphs are fine in that case.
>  m4_define([_AC_DEFINE_UNQUOTED],
> -[m4_if(m4_bregexp([$1], [\\\|`\|\$(\|\${\|@]), [-1],
> +[m4_if(m4_bregexp([$1], [#\|\\\|`\|\(\$\|@S|@\)\((|{|@{:@\)]), [-1],

Line noise for the win!

>         [AS_ECHO(["AS_ESCAPE([$1], [""])"]) >>confdefs.h],
>         [cat >>confdefs.h <<_ACEOF
>  [$1]
> 

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
signature.asc (application/pgp-signature, 604 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2
Comment: Public key at http://people.redhat.com/eblake/eblake.gpg
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQEcBAEBCAAGBQJYF2WoAAoJEKeha0olJ0Nq9CgH/iRc3dFXjVk/lB40w27yZAbm
02FtE5eaH7TJ3+yXaMUHk6vy+099/PUtwFd2jogvtZMQDKa0lLsSVCkzKesSFfgE
UgdEwHoK3mV8289kmbLNA3ptXELdPlFWSTuIObHR1N+xds7Hxsdu1qT177Rj7aXZ
x+/8sAIKyhis+CksnnJse7aXxLdRtOA9UBsIrCT5xh5KUjSdwnhSYa13vETno1oc
sU2GtCENcKIgQSfjAU6HEElqvKV23gmMOTg/ryahhQ0Be5Jy6bQzEylllcXvOT+1
K8G+AqctzBh87s3wpJYBceqke15kd6X+Bntw8TDamWI+ZoqD5r7/7zLOr/zLJBo=
=EtZ8
-----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.