8000 gh-104252: Immortalize Py_EMPTY_KEYS by ericsnowcurrently · Pull Request #104253 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-104252: Immortalize Py_EMPTY_KEYS #104253

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Prev Previous commit
Clarify the comment about dictkeys_incref() and dictkeys_decref().
  • Loading branch information
ericsnowcurrently committed May 9, 2023
commit 5aabfd77b1bba5de8b5ff1a5fbac9a6e32e82dd6
11 changes: 6 additions & 5 deletions Objects/dictobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,11 +300,12 @@ _PyDict_DebugMallocStats(FILE *out)

static void free_keys_object(PyInterpreterState *interp, PyDictKeysObject *keys);

/* We might consider modifying PyDictKeysObject so we could use
Py_INCREF() instead of dictkeys_incref() (and likewise with
Py_DECREF() and dictkeys_decref()). However, there doesn't
seem to be enough benefit (performance or otherwise) to justify
the change. */
/* PyDictKeysObject has refcounts like PyObject does, so we have the
following two functions to mirror what Py_INCREF() and Py_DECREF() do.
(Keep in mind that PyDictKeysObject isn't actually a PyObject.)
Likewise a PyDictKeysObject can be immortal (e.g. Py_EMPTY_KEYS),
so we apply a naive version of what Py_INCREF() and Py_DECREF() do
for immortal objects. */

static inline void
dictkeys_incref(PyDictKeysObject *dk)
Expand Down
0