Mercurial > vim
diff src/dict.c @ 20347:0e1dfff4f294 v8.2.0729
patch 8.2.0729: Vim9: When reloading a script variables are not cleared
Commit: https://github.com/vim/vim/commit/89483d40438830fb9e74a5ec6c92d2470b05e4c2
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun May 10 15:24:44 2020 +0200
patch 8.2.0729: Vim9: When reloading a script variables are not cleared
Problem: Vim9: When reloading a script variables are not cleared.
Solution: When sourcing a script again clear all script-local variables.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 10 May 2020 15:30:03 +0200 |
parents | 0b35a7ffceb2 |
children | c225be44692a |
line wrap: on
line diff
--- a/src/dict.c +++ b/src/dict.c @@ -105,28 +105,37 @@ rettv_dict_set(typval_T *rettv, dict_T * 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