Visitar URL original
gh-104252: Immortalize Py_EMPTY_KEYS by ericsnowcurrently · Pull Request #104253 · python/cpython · GitHub
Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Handle other uses of dk_refcnt.
  • Loading branch information
ericsnowcurrently committed May 8, 2023
commit 87351e0159fd9b758e715f2033e57cec9165cb5b
13 changes: 5 additions & 8 deletions Objects/dictobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,7 @@ clone_combined_dict_keys(PyDictObject *orig)
assert(PyDict_Check(orig));
assert(Py_TYPE(orig)->tp_iter == (getiterfunc)dict_iter);
assert(orig->ma_values == NULL);
assert(orig->ma_keys != Py_EMPTY_KEYS);
assert(orig->ma_keys->dk_refcnt == 1);

size_t keys_size = _PyDict_KeysSize(orig->ma_keys);
Expand Down Expand Up @@ -1540,11 +1541,7 @@ dictresize(PyInterpreterState *interp, PyDictObject *mp,
#ifdef Py_REF_DEBUG
_Py_DecRefTotal(_PyInterpreterState_GET());
#endif
if (oldkeys == Py_EMPTY_KEYS) {
oldkeys->dk_refcnt--;
assert(oldkeys->dk_refcnt > 0);
}
else {
if (oldkeys != Py_EMPTY_KEYS) {
assert(oldkeys->dk_kind != DICT_KEYS_SPLIT);
assert(oldkeys->dk_refcnt == 1);
#if PyDict_MAXFREELIST > 0
Expand Down Expand Up @@ -2088,8 +2085,8 @@ PyDict_Clear(PyObject *op)
dictkeys_decref(interp, oldkeys);
}
else {
assert(oldkeys->dk_refcnt == 1);
dictkeys_decref(interp, oldkeys);
assert(oldkeys->dk_refcnt == 1 || oldkeys == Py_EMPTY_KEYS);
dictkeys_decref(interp, oldkeys);
Comment thread
sunmy2019 marked this conversation as resolved.
}
ASSERT_CONSISTENT(mp);
}
Expand Down Expand Up @@ -3573,7 +3570,7 @@ _PyDict_SizeOf(PyDictObject *mp)
}
/* If the dictionary is split, the keys portion is accounted-for
in the type object. */
if (mp->ma_keys->dk_refcnt == 1) {
if (mp->ma_keys->dk_refcnt == 1 || mp->ma_keys == Py_EMPTY_KEYS) {
Comment thread
sunmy2019 marked this conversation as resolved.
Outdated
res += _PyDict_KeysSize(mp->ma_keys);
}
assert(res <= (size_t)PY_SSIZE_T_MAX);
Expand Down