Mercurial > vim
comparison 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 |
comparison
equal
deleted
inserted
replaced
20346:cd52b48baba5 | 20347:0e1dfff4f294 |
---|---|
103 * Ignores the reference count. | 103 * Ignores the reference count. |
104 */ | 104 */ |
105 void | 105 void |
106 dict_free_contents(dict_T *d) | 106 dict_free_contents(dict_T *d) |
107 { | 107 { |
108 hashtab_free_contents(&d->dv_hashtab); | |
109 } | |
110 | |
111 /* | |
112 * Clear hashtab "ht" and dict items it contains. | |
113 */ | |
114 void | |
115 hashtab_free_contents(hashtab_T *ht) | |
116 { | |
108 int todo; | 117 int todo; |
109 hashitem_T *hi; | 118 hashitem_T *hi; |
110 dictitem_T *di; | 119 dictitem_T *di; |
111 | 120 |
112 // Lock the hashtab, we don't want it to resize while freeing items. | 121 // Lock the hashtab, we don't want it to resize while freeing items. |
113 hash_lock(&d->dv_hashtab); | 122 hash_lock(ht); |
114 todo = (int)d->dv_hashtab.ht_used; | 123 todo = (int)ht->ht_used; |
115 for (hi = d->dv_hashtab.ht_array; todo > 0; ++hi) | 124 for (hi = ht->ht_array; todo > 0; ++hi) |
116 { | 125 { |
117 if (!HASHITEM_EMPTY(hi)) | 126 if (!HASHITEM_EMPTY(hi)) |
118 { | 127 { |
119 // Remove the item before deleting it, just in case there is | 128 // Remove the item before deleting it, just in case there is |
120 // something recursive causing trouble. | 129 // something recursive causing trouble. |
121 di = HI2DI(hi); | 130 di = HI2DI(hi); |
122 hash_remove(&d->dv_hashtab, hi); | 131 hash_remove(ht, hi); |
123 dictitem_free(di); | 132 dictitem_free(di); |
124 --todo; | 133 --todo; |
125 } | 134 } |
126 } | 135 } |
127 | 136 |
128 // The hashtab is still locked, it has to be re-initialized anyway | 137 // The hashtab is still locked, it has to be re-initialized anyway. |
129 hash_clear(&d->dv_hashtab); | 138 hash_clear(ht); |
130 } | 139 } |
131 | 140 |
132 static void | 141 static void |
133 dict_free_dict(dict_T *d) | 142 dict_free_dict(dict_T *d) |
134 { | 143 { |