Skip to content

Commit e472d94

Browse files
Immortalize Py_EMPTY_KEYS.
1 parent 5bc2469 commit e472d94

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

Objects/dictobject.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,18 +300,26 @@ _PyDict_DebugMallocStats(FILE *out)
300300

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

303+
// XXX Switch to Py_INCREF()?
303304
static inline void
304305
dictkeys_incref(PyDictKeysObject *dk)
305306
{
307+
if (dk->dk_refcnt == _Py_IMMORTAL_REFCNT) {
308+
return;
309+
}
306310
#ifdef Py_REF_DEBUG
307311
_Py_IncRefTotal(_PyInterpreterState_GET());
308312
#endif
309313
dk->dk_refcnt++;
310314
}
311315

316+
// XXX Switch to Py_DECREF()?
312317
static inline void
313318
dictkeys_decref(PyInterpreterState *interp, PyDictKeysObject *dk)
314319
{
320+
if (dk->dk_refcnt == _Py_IMMORTAL_REFCNT) {
321+
return;
322+
}
315323
assert(dk->dk_refcnt > 0);
316324
#ifdef Py_REF_DEBUG
317325
_Py_DecRefTotal(_PyInterpreterState_GET());
@@ -447,7 +455,7 @@ estimate_log2_keysize(Py_ssize_t n)
447455
* (which cannot fail and thus can do no allocation).
448456
*/
449457
static PyDictKeysObject empty_keys_struct = {
450-
1, /* dk_refcnt */
458+
_Py_IMMORTAL_REFCNT, /* dk_refcnt */
451459
0, /* dk_log2_size */
452460
0, /* dk_log2_index_bytes */
453461
DICT_KEYS_UNICODE, /* dk_kind */

0 commit comments

Comments
 (0)