[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] use m4_require to implement AS_REQUIRE
From: |
Eric Blake |
Subject: |
Re: [PATCH] use m4_require to implement AS_REQUIRE |
Date: |
Fri, 17 Oct 2008 06:59:11 -0600 |
User-agent: |
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.17) Gecko/20080914 Thunderbird/2.0.0.17 Mnenhy/0.7.5.666 |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
According to Paolo Bonzini on 10/17/2008 6:41 AM:
> I still cannot understand why the diversion ends up like this though.
>
> Here is an even smaller testcase:
>
> AS_INIT
> m4_defun([AS_FROBIT_PREPARE], [frob=1])
> m4_defun([AS_FROBIT], [AS_REQUIRE([AS_FROBIT_PREPARE])$1])
> m4_defun([AS_DOIT], [: $1])
> m4_define([XXFOO], [AS_FROBIT(exit 1)])
> AS_DOIT(XXFOO)
>
> which gives
>
> : frob=1
> exit 1
>
> as is, and
>
> frob=1
> : exit 1
>
> when XXFOO is quoted.
>
> So, if this is a bug (and it looks like one, though very minor because
> proper quoting works around it) we also have a testcase. :-)
This is a limitation of m4 diversions. Something even simpler:
$ echo 'm4_define([foo],[m4_divert(1)hi
m4_divert(0)])m4_divert[]foo:' | m4 -Ilib m4sugar/m4sugar.m4 -
:
hi
$ echo 'm4_define([foo],[m4_divert(1)hi
m4_divert(0)])m4_divert[]m4_echo(foo):' | m4 -Ilib m4sugar/m4sugar.m4 -
hi
:
The point is that text goes into a diversion only when _you are not doing
argument collection_ - in other words, the macro call must be expanded at
the outermost level. Any macro that potentially changes the current
diversion must be quoted, rather than expanded in advance, when handed as
an argument to another macro; otherwise, the text output while the
diversion change is in effect doesn't go to the changed diversion, but to
the argument collection.
M4 1.6 will add an optional argument to the divert builtin, such that
divert(1,text) places text in diversion 1, regardless of whether it is
being expanded during argument collection. But unfortunately, we cannot
rely on that. Alas, m4 lacks the ability to inform you when a macro is
being expanded during argument collection, so we can't even protect
against these sorts of subtle diversion bugs (maybe I should add a macro
that expands to the current nesting depth?).
- --
Don't work too hard, make some time for fun as well!
Eric Blake address@hidden
-----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
iEYEARECAAYFAkj4jB8ACgkQ84KuGfSFAYCjMwCgnBIjug/gOs5Dczqp7Mk8Dm2L
0qYAnixI6hsUVLiwDDkbLtqNKD2to7d3
=aaR6
-----END PGP SIGNATURE-----
- Re: [PATCH] use m4_require to implement AS_REQUIRE, (continued)
Re: [PATCH] use m4_require to implement AS_REQUIRE, Eric Blake, 2008/10/13
Re: [PATCH] use m4_require to implement AS_REQUIRE, Eric Blake, 2008/10/14
Re: [PATCH] use m4_require to implement AS_REQUIRE, Eric Blake, 2008/10/17