cpython: f0fbc6071d7e (original) (raw)

--- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -1196,41 +1196,21 @@ insertdict(PyDictObject *mp, PyObject k } / -Internal routine used by dictresize() to insert an item which is -known to be absent from the dict. This routine also assumes that -the dict contains no deleted entries. Besides the performance benefit, -using insertdict() in dictresize() is dangerous (SF bug #1456209). -Note that no refcounts are changed by this routine; if needed, the caller -is responsible for incref'ing key and value. -Neither mp->ma_used nor k->dk_usable are modified by this routine; the caller -must set them correctly +Internal routine used by dictresize() to buid a hashtable of entries. */ static void -insertdict_clean(PyDictObject *mp, PyObject *key, Py_hash_t hash,

+build_indices(PyDictKeysObject *keys, PyDictKeyEntry *ep, Py_ssize_t n) {

-

} /* @@ -1246,10 +1226,10 @@ but can be resplit by make_keys_shared() static int dictresize(PyDictObject *mp, Py_ssize_t minused) {

/* Find the smallest table size > minused. */ for (newsize = PyDict_MINSIZE; @@ -1260,8 +1240,14 @@ dictresize(PyDictObject *mp, Py_ssize_t PyErr_NoMemory(); return -1; } + oldkeys = mp->ma_keys;

+

+ /* Allocate a new table. */ mp->ma_keys = new_keys_object(newsize); if (mp->ma_keys == NULL) { @@ -1270,42 +1256,59 @@ dictresize(PyDictObject *mp, Py_ssize_t } if (oldkeys->dk_lookup == lookdict) mp->ma_keys->dk_lookup = lookdict;

+

+ DK_DECREF(oldkeys);

+ assert(oldkeys->dk_lookup != lookdict_split); assert(oldkeys->dk_refcnt == 1);