bug-bash
[Top][All Lists]
Advanced

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

Re: Variable references (declare -n, "nameref") are limited to a depth o


From: Chet Ramey
Subject: Re: Variable references (declare -n, "nameref") are limited to a depth of 8.
Date: Mon, 27 Apr 2020 11:42:08 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Thunderbird/68.7.0

On 4/25/20 11:46 PM, Andrej Podzimek wrote:
>>> Description:
>>>
>>>   While looking for a way to share a "cache" array with a recursive function
>>>   call stack (using local -n (nameref)), I hit a well-known problem with
>>>   "circular name reference" (which has been around for a long time). 
>>
>> Yes, that's how it does loop detection.
> 
> There are, however, no loops involved in my $a … $k example; it is merely a 
> chain of declare -n references starting from a regular variable $a. The chain 
> breaks unexpectedly and silently after 8 links ($j and $k appear to be empty).
> 
> Better options, IMHO, would include:
> 
> (a) An unlimited number of declare -n resolution steps (as long as there are 
> no cycles, i.e., no variable name(*) is encountered twice). This may have 
> performance consequences when abused, but it would be better than unexpected 
> empty values after >8 steps.
> 
> (b) An error message when trying to dereference $j or $k (links No. 9 and 10 
> in the chain example), saying e.g. “maximum nameref depth (8) exceeded”. This 
> would at least make the problem obvious and easy to debug.

I would welcome patches that did either one of these things.

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/



reply via email to

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