bug-bash
[Top][All Lists]
Advanced

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

Re: funcnest and recursion


From: Dan Douglas
Subject: Re: funcnest and recursion
Date: Fri, 23 May 2014 10:05:55 -0500
User-agent: KMail/4.13 (Linux/3.14.0-pf3+; KDE/4.13.0; x86_64; ; )

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.

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

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



reply via email to

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