8000 Handle other uses of dk_refcnt. · python/cpython@87351e0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 87351e0

Browse files
Handle other uses of dk_refcnt.
1 parent e472d94 commit 87351e0

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

Objects/dictobject.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,7 @@ clone_combined_dict_keys(PyDictObject *orig)
787787
assert(PyDict_Check(orig));
788788
assert(Py_TYPE(orig)->tp_iter == (getiterfunc)dict_iter);
789789
assert(orig->ma_values == NULL);
790+
assert(orig->ma_keys != Py_EMPTY_KEYS);
790791
assert(orig->ma_keys->dk_refcnt == 1);
791792

792793
size_t keys_size = _PyDict_KeysSize(orig->ma_keys);
@@ -1540,11 +1541,7 @@ dictresize(PyInterpreterState *interp, PyDictObject *mp,
15401541
#ifdef Py_REF_DEBUG
15411542
_Py_DecRefTotal(_PyInterpreterState_GET());
15421543
#endif
1543-
if (oldkeys == Py_EMPTY_KEYS) {
1544-
oldkeys->dk_refcnt--;
1545-
assert(oldkeys->dk_refcnt > 0);
1546-
}
1547-
else {
1544+
if (oldkeys != Py_EMPTY_KEYS) {
15481545
assert(oldkeys->dk_kind != DICT_KEYS_SPLIT);
15491546
assert(oldkeys->dk_refcnt == 1);
15501547
#if PyDict_MAXFREELIST > 0
@@ -2088,8 +2085,8 @@ PyDict_Clear(PyObject *op)
20882085
dictkeys_decref(interp, oldkeys);
20892086
}
20902087
else {
2091-
assert(oldkeys->dk_refcnt == 1);
2092-
dictkeys_decref(interp, oldkeys);
2088+
assert(oldkeys->dk_refcnt == 1 || oldkeys == Py_EMPTY_KEYS);
2089+
dictkeys_decref(interp, oldkeys);
20932090
}
20942091
ASSERT_CONSISTENT(mp);
20952092
}
@@ -3573,7 +3570,7 @@ _PyDict_SizeOf(PyDictObject *mp)
35733570
}
35743571
/* If the dictionary is split, the keys portion is accounted-for
35753572
in the type object. */
3576-
if (mp->ma_keys->dk_refcnt == 1) {
3573+
if (mp->ma_keys->dk_refcnt == 1 || mp->ma_keys == Py_EMPTY_KEYS) {
35773574
res += _PyDict_KeysSize(mp->ma_keys);
35783575
}
35793576
assert(res <= (size_t)PY_SSIZE_T_MAX);

0 commit comments

Comments
 (0)
0