summaryrefslogtreecommitdiffstats
path: root/src/dict.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-05-10 15:24:44 +0200
committerBram Moolenaar <Bram@vim.org>2020-05-10 15:24:44 +0200
commit89483d40438830fb9e74a5ec6c92d2470b05e4c2 (patch)
treebeb03e9bded5798073787f275b2f3cee63814f8b /src/dict.c
parent69212b11d18d9d8951968f6ca88e6ce046c90675 (diff)
patch 8.2.0729: Vim9: When reloading a script variables are not clearedv8.2.0729
Problem: Vim9: When reloading a script variables are not cleared. Solution: When sourcing a script again clear all script-local variables.
Diffstat (limited to 'src/dict.c')
-rw-r--r--src/dict.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/src/dict.c b/src/dict.c
index 88bd0e21c6..54d3110b02 100644
--- a/src/dict.c
+++ b/src/dict.c
@@ -105,28 +105,37 @@ rettv_dict_set(typval_T *rettv, dict_T *d)
void
dict_free_contents(dict_T *d)
{
+ hashtab_free_contents(&d->dv_hashtab);
+}
+
+/*
+ * Clear hashtab "ht" and dict items it contains.
+ */
+ void
+hashtab_free_contents(hashtab_T *ht)
+{
int todo;
hashitem_T *hi;
dictitem_T *di;
// Lock the hashtab, we don't want it to resize while freeing items.
- hash_lock(&d->dv_hashtab);
- todo = (int)d->dv_hashtab.ht_used;
- for (hi = d->dv_hashtab.ht_array; todo > 0; ++hi)
+ hash_lock(ht);
+ todo = (int)ht->ht_used;
+ for (hi = ht->ht_array; todo > 0; ++hi)
{
if (!HASHITEM_EMPTY(hi))
{
// Remove the item before deleting it, just in case there is
// something recursive causing trouble.
di = HI2DI(hi);
- hash_remove(&d->dv_hashtab, hi);
+ hash_remove(ht, hi);
dictitem_free(di);
--todo;
}
}
- // The hashtab is still locked, it has to be re-initialized anyway
- hash_clear(&d->dv_hashtab);
+ // The hashtab is still locked, it has to be re-initialized anyway.
+ hash_clear(ht);
}
static void