[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: Gecko/20080914 Thunderbird/ Mnenhy/

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:
> m4_defun([AS_FROBIT_PREPARE], [frob=1])
> m4_defun([AS_DOIT], [: $1])
> m4_define([XXFOO], [AS_FROBIT(exit 1)])
> 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 -
$ echo 'm4_define([foo],[m4_divert(1)hi
m4_divert(0)])m4_divert[]m4_echo(foo):' | m4 -Ilib m4sugar/m4sugar.m4 -

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
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


reply via email to

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