Skip to content

fix(arrayfunc): fix the behavior of assoc=([key]+=value) - #5

Open
akinomyoga wants to merge 1 commit into
develfrom
assoc_append
Open

akinomyoga wants to merge 1 commit into
develfrom
assoc_append

Conversation

@akinomyoga

Copy link
Copy Markdown
Member

No description provided.

@akinomyoga
akinomyoga force-pushed the assoc_append branch 6 times, most recently from c07bdba to 91f5a3f Compare September 8, 2026 07:53
This patch first stores the generated key-value pairs into an
independent hash table NHASH without modifying the old contents of the
associative array, even for the form `assoc+=(...)'.  Then, it merges
the generated key-value pairs into the associative-array variable
finally.

* The new function `make_assoc_var_kvpair ()' (arrayfunc.c) was made
  based on `make_array_variable_value ()' (arrayfunc.c:177), but it
  stores the constructed key-value pair in the argument NHASH instead
  of returning the constructed value as the return value.  Also, when
  retrieving the existing value for `[key]+=rhs', it attempts to check
  NHASH first and then fall back to the old contents of the
  associative array.

* The new function `bind_assoc_kvpairs ()' (arrayfunc.c) was made
  based on `bind_assoc_var_internal ()' (arrayfunc.c:225).  It merges
  the key-value pairs stored in NHASH into the associative array that
  VAR points to, or replaces it with NHASH.  The two XXX comments were
  inherited from `bind_assoc_var_internal ()'.

* To implement this, I have added a utility function `hash_walk_arg
  ()' (hashlib.{h,c}), extending the existing `hash_walk ()'
  (hashlib.c:397).  I have also added `assoc_merge ()' (assoc.{h,c})

  Although it is not included in this patch, `build_hashcmd ()',
  `build_aliasvar ()', and `flatten ()' in variables.c may also be
  rewritten using `hash_walk_arg ()', instead of directly touching the
  internal structures of the hash table.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant