Mercurial > vim
diff src/if_py_both.h @ 21319:fb3dcd8ed14d v8.2.1210
patch 8.2.1210: using ht_used when looping through a hashtab is less reliable
Commit: https://github.com/vim/vim/commit/1f22cc5cdb2da867d6bbf54dd371f279c38a2f56
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Jul 14 21:08:49 2020 +0200
patch 8.2.1210: using ht_used when looping through a hashtab is less reliable
Problem: Using ht_used when looping through a hashtab is less reliable.
Solution: Use ht_changed in a few more places.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 14 Jul 2020 21:15:04 +0200 |
parents | 8531ddd7dd63 |
children | d1a7088c6efe |
line wrap: on
line diff
--- a/src/if_py_both.h +++ b/src/if_py_both.h @@ -1792,11 +1792,10 @@ DictionaryContains(DictionaryObject *sel typedef struct { - hashitem_T *ht_array; - long_u ht_used; - hashtab_T *ht; - hashitem_T *hi; - long_u todo; + int dii_changed; + hashtab_T *dii_ht; + hashitem_T *dii_hi; + long_u dii_todo; } dictiterinfo_T; static PyObject * @@ -1804,23 +1803,22 @@ DictionaryIterNext(dictiterinfo_T **dii) { PyObject *ret; - if (!(*dii)->todo) + if (!(*dii)->dii_todo) return NULL; - if ((*dii)->ht->ht_array != (*dii)->ht_array || - (*dii)->ht->ht_used != (*dii)->ht_used) + if ((*dii)->dii_ht->ht_changed != (*dii)->dii_changed) { PyErr_SET_STRING(PyExc_RuntimeError, N_("hashtab changed during iteration")); return NULL; } - while (((*dii)->todo) && HASHITEM_EMPTY((*dii)->hi)) - ++((*dii)->hi); - - --((*dii)->todo); - - if (!(ret = PyBytes_FromString((char *)(*dii)->hi->hi_key))) + while (((*dii)->dii_todo) && HASHITEM_EMPTY((*dii)->dii_hi)) + ++((*dii)->dii_hi); + + --((*dii)->dii_todo); + + if (!(ret = PyBytes_FromString((char *)(*dii)->dii_hi->hi_key))) return NULL; return ret; @@ -1839,11 +1837,10 @@ DictionaryIter(DictionaryObject *self) } ht = &self->dict->dv_hashtab; - dii->ht_array = ht->ht_array; - dii->ht_used = ht->ht_used; - dii->ht = ht; - dii->hi = dii->ht_array; - dii->todo = dii->ht_used; + dii->dii_changed = ht->ht_changed; + dii->dii_ht = ht; + dii->dii_hi = ht->ht_array; + dii->dii_todo = ht->ht_used; return IterNew(dii, (destructorfun) PyMem_Free, (nextfun) DictionaryIterNext,