autoconf-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: fewer forks in AC_DEFINE [was: Use newer m4_map_args_{w,sep}]


From: Ralf Wildenhues
Subject: Re: fewer forks in AC_DEFINE [was: Use newer m4_map_args_{w,sep}]
Date: Thu, 20 Nov 2008 07:01:57 +0100
User-agent: Mutt/1.5.18 (2008-05-17)

Hi Eric,

* Eric Blake wrote on Wed, Nov 19, 2008 at 11:58:45PM CET:
> Subject: [PATCH] Improve m4_expand robustness, part 1.
> 
> * lib/m4sugar/m4sugar.m4 (_m4_expand): Tolerate unquoted
> unbalanced ).

Please use appropriate language quoting.  Unlike your code, your readers
cannot deal well with underquoted parentheses.  IOW, please make the
above sentence either
  * lib/m4sugar/m4sugar.m4 (_m4_expand): Tolerate unquoted
  unbalanced `)'.

(')' would be ok, too), or
  * lib/m4sugar/m4sugar.m4 (_m4_expand): Tolerate unquoted
  unbalanced closing parenthesis.

Thank you.

> * tests/m4sugar.at (m4@&address@hidden): New test.
> * doc/autoconf.texi (Limitations of Builtins): Document why
> quadrigraph, and not #, should be used as strategic shell

s/as/to introduce a/  ?

> comment.

> --- a/doc/autoconf.texi
> +++ b/doc/autoconf.texi
> @@ -14895,10 +14895,14 @@ Limitations of Builtins
>  The leading @samp{(} can be omitted safely.  In contexts where
>  unbalanced parentheses cause other problems, such as when using a case
>  statement as an argument to an Autoconf macro, you can also resort to
> -creative shell comments to supply the balance:
> +creative shell comments to supply the balance.  Note that you should use
> +the quadrigraph @samp{@@%:@@} and not a literal @samp{#}, because the
> +latter hides the @samp{(} inside an m4 comment, and you would still be
> +presenting m4 with unbalanced parentheses.

But not the human reader of the macro text!  IIUC then as the code
is capable, we *can* use `in #(', which is much more readable than
`in @:@('.  I've never knowingly added the extra opening parenthesis
in order to help M4, only ever in order to help paren matching
algorithms in $EDITORs.

>  The macro @code{AS_CASE}
> +takes care of this automatically.
>  
>  @example
> -case $file_name in #(
> +case $file_name in @@%:@@(
>    *.c) echo "C source code";;
>  esac
>  @end example

> --- a/lib/m4sugar/m4sugar.m4
> +++ b/lib/m4sugar/m4sugar.m4
> @@ -835,9 +835,20 @@ m4_define([m4_echo], address@hidden)
>  # Exploit that extra () will group unquoted commas and the following
>  # whitespace, then convert () to [].  m4_bpatsubst can't handle newlines
>  # inside $1, and m4_substr strips quoting.  So we (ab)use m4_changequote.
> -m4_define([m4_expand], [_$0(-=<{($1)}>=-)])
> +#
> +# Thanks to shell case statements, too many people are prone to pass
> +# underquoted ), so we try to detect that by passing a marker as a

See comment to log entry.  More instances below.

> +# fourth argument; if the marker is not present, then we encountered
> +# an early ), and we re-expand the first argument, but this time with
> +# one more ( in the second argument and in the open-quote delimiter.
> +# We must also ignore the slop from the previous try.  The final macro
> +# is thus half line-noise, half art.
> +m4_define([m4_expand], [_$0([$1], [(], -=<{($1)}>=-, [}>=-])])
> +
>  m4_define([_m4_expand],
> -[m4_changequote([-=<{(], [)}>=-])$1m4_changequote([, ])])
> +[m4_if([$4], [}>=-],
> +       [m4_changequote([-=<{$2], [)}>=-])$3m4_changequote([, ])],
> +       [$0([$1], [($2], -=<{($2$1)}>=-, [}>=-])m4_ignore$2])])

[ reordered ]
> In addition to the previously discussed idea of making m4_expand supply and 
> chomp a trailing newline, in order to handle what would otherwise be an 
> unterminated comment, I managed to figure out a way to handle underquoted 
> shell 
> case statements.  Kudos to you if you manage to figure out my trick on the 
> first read of the new m4_expand implementation.

Well yeah, with changequote you tread along the path to the dark side.
And no, I don't really understand.

I do wonder when quadrigraphs for `(' and `)' will finally be added,
though.

> +# Exploit that extra unquoted () will group unquoted commas and the
> +# following whitespace.  m4_bpatsubst can't handle newlines inside $1,
> +# and m4_substr strips quoting.  So we (ab)use m4_changequote, using
> +# temporary quotes to remove the delimiters that conveniently included
> +# unquoted () prior to the changequote.

I suppose this explains it.

I haven't read nor reviewed nor tested the code bits of the patches.

Cheers,
Ralf




reply via email to

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