[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Disabling automatic assoc rehashing
From: |
Chet Ramey |
Subject: |
Re: Disabling automatic assoc rehashing |
Date: |
Tue, 10 Nov 2020 16:17:10 -0500 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.4.0 |
On 11/10/20 2:16 PM, Tavis Ormandy wrote:
> Hello, I was just checking the new release candidate for compatability with my
> builtin and noticed that assoc arrays are now automatically rehashed on
> insertion.
>
> I knew this day would come :-)
(I confess that I have not looked at your code.)
> I had been (ab)using the fact that if you created the array with
> assoc_create(1), the order of elements would be maintained. This is
> because you were effectively creating a linked list rather than a hash
> table.
Why not just use a list then? The bash code uses lists (WORD_LIST, etc.)
all over the place. Or does something you're doing require associative
arrays?
> I expect the answer is "too bad", but it would be nice if the rehashing could
> be toggled with a flag in the HASH_TABLE, rather than based on the HASH_CREATE
> parameter, what do you think?
Maybe at some point, but not this close to bash-5.1.
> I'm aware not many people use native builtins, my code is here, it
> allows you to use native libraries in bash scripts:
>
> https://github.com/taviso/ctypes.sh
>
> The reason I need assocs that maintain order is so that you can
> manipulate and access C structures in bash. For example, if you had a
> struct stat, you might want to echo ${stat[st_mtim.tv_sec]}. This
> currently works with ctypes.sh, but I think it might not be possible if
> there's no way to disable automatic rehashing.
Hmmm...I see. You could use dynamic variables and construct the array on
the fly. But that would require more work in your builtin.
> Also, I noticed the definition of ARRAY is now ABI incompatible with builtins
> from previous versions because a new member (lastref) was added in the middle
> (rather than at the end).
Bash has never guaranteed ABI compatibility between versions, but I don't
see any problem with rearranging the ARRAY structure before bash-5.1 is
released.
Chet
--
``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/