Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #16244

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

Path csiph.com!xmission!news.snarked.org!news.linkpendium.com!news.linkpendium.com!panix!usenet.stanford.edu!not-for-mail
From Andrej Podzimek <andrej@podzimek.org>
Newsgroups gnu.bash.bug
Subject Re: Variable references (declare -n, "nameref") are limited to a depth of 8.
Date Sun, 26 Apr 2020 05:46:15 +0200 (GMT+02:00)
Lines 32
Approved bug-bash@gnu.org
Message-ID <mailman.1267.1587872792.3066.bug-bash@gnu.org> (permalink)
References <courier.000000005EA3DECF.0000B702@charon.podzimek.org> <09fac3bd-2d96-c0ee-ac03-f729507af74a@case.edu> <1b9cc5d.a1fea93e.171b497bdae@podzimek.org>
NNTP-Posting-Host lists.gnu.org
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding quoted-printable
X-Trace usenet.stanford.edu 1587872792 5781 209.51.188.17 (26 Apr 2020 03:46:32 GMT)
X-Complaints-To action@cs.stanford.edu
Cc chet.ramey@case.edu
To chet.ramey@case.edu, bug-bash@gnu.org
Envelope-to bug-bash@gnu.org
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=podzimek.org; s=charon; t=1587872780; bh=INsCAGgfDsQkdxP9tgMr5Uh3Y71ONWh2c+0cQBZgbec=; l=1251; h=Date:From:To:Cc:In-Reply-To:References:Subject; b=kvTTDn2CzZHsi1B2bMSCLOFLAyV9iTUZkLLvejViIi0ltHtRcFOkSMUu9E9eZD0iY k6VVYH5d/coaNuJxGz8x2s7Zcz+wGH+CfLSIfwTvCejknNE8vQIudFf19UbUZ8Pgvd Z3WdRHUkFlsdmhTJiOxy24HtNpXZyTzYV96gk4e5TnfY5e5MYo+dZmeu4ehucnzTsh 86gvwFmHZx9RN9q1rE7uTU/8LXvoNZ6MQs974ovy93umGDZNiCqiUtzx55uxGw2hKz jqH7rwmqbCpotBSmfj7TXEnW6kJV45k0RaOBw+4IxRP7khIFVcmAeKvvmbcJJaqgoB ELvzHni3UQfyw==
Authentication-Results podzimek.org; auth=pass (details omitted)
In-Reply-To <09fac3bd-2d96-c0ee-ac03-f729507af74a@case.edu>
X-Mailer R2Mail2
Received-SPF pass client-ip=2a02:168:5cd0::; envelope-from=andrej@podzimek.org; helo=charon.podzimek.org
X-detected-operating-system by eggs.gnu.org: Error: [-] PROGRAM ABORT : Malformed IPv6 address (bad octet value). Location : parse_addr6(), p0f-client.c:67
X-Received-From 2a02:168:5cd0::
X-BeenThere bug-bash@gnu.org
X-Mailman-Version 2.1.23
Precedence list
List-Id Bug reports for the GNU Bourne Again SHell <bug-bash.gnu.org>
List-Unsubscribe <https://lists.gnu.org/mailman/options/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=unsubscribe>
List-Archive <https://lists.gnu.org/archive/html/bug-bash>
List-Post <mailto:bug-bash@gnu.org>
List-Help <mailto:bug-bash-request@gnu.org?subject=help>
List-Subscribe <https://lists.gnu.org/mailman/listinfo/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=subscribe>
X-Mailman-Original-Message-ID <1b9cc5d.a1fea93e.171b497bdae@podzimek.org>
X-Mailman-Original-References <courier.000000005EA3DECF.0000B702@charon.podzimek.org> <09fac3bd-2d96-c0ee-ac03-f729507af74a@case.edu>
Xref csiph.com gnu.bash.bug:16244

Show key headers only | View raw


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

(*) More precisely, this would be [function context, variable name] pairs in case of local variables referenced by declare -n.

Andrej

Back to gnu.bash.bug | Previous | Next | Find similar


Thread

Re: Variable references (declare -n, "nameref") are limited to a depth of 8. Andrej Podzimek <andrej@podzimek.org> - 2020-04-26 05:46 +0200

csiph-web