On 05/23/2014 05:05 PM, Dan Douglas wrote:
On Friday, May 23, 2014 10:48:11 AM Chet Ramey wrote:
On 5/23/14, 10:17 AM, Ondrej Oprala wrote:
Hi, there've recently been a few bug reports against bash on RH BZ,
saying that bash can't handle infinite recursion the way zsh or ksh can.
Looking at execute_cmd.c, there are the funcnest{,_max} variables
and a piece of code using them in execute_function().
Will funcnest_max be set to non-0 in upstream code in the future?
Or is it just there for the downstream maintainers to set it if they
see it fit?
Neither. The funcnest_max variable reflects the value of the FUNCNEST
shell variable.
Oops Chet read your message right... I presumed you were aware of FUNCNEST,
and were talking about setting a non-zero default at compile-time. Can't
remember if that's ever been discussed.
IMHO that's also a possibility. Having a default of e.g. 1024, still of
course
being overriden by FUNCNEST might be more user-friendly than not
controlling it at all.
Users can set the maximum recursion level they want,
without changing the bash code at all, but the default is still as much as
the stack will give you (as it has been all along).
Yup, it's a good feature. Zsh and ksh don't "support infinite recursion", they
have hardcoded limits (1024 ksh93, 1000 zsh).
Yes, I should have written "support" in my first mail :) .
As a random aside... dash somehow has extremely lightweight function calls.
Glad it's not arbitrarily capped at 1k.
$ time dash -c 'f() { echo "$1"; f $(($1 + 1)); }; f 0' | tail -n 1
13776
real 0m0.035s
user 0m0.020s
sys 0m0.033s
$ time bash -c 'f() { echo "$1"; f $(($1 + 1)); }; f 0' | tail -n 1
8308
real 0m3.993s
user 0m4.032s
sys 0m0.165s
Thanks,
Ondrej