Skip to content

Commit 2f7e022

Browse files
Move next_dict_keys_version to _PyRuntimeState.
1 parent e874c2f commit 2f7e022

File tree

5 files changed

+11
-5
lines changed

5 files changed

+11
-5
lines changed

Include/internal/pycore_dict.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ extern void _PyDict_Fini(PyInterpreterState *interp);
1717

1818
/* other API */
1919

20+
struct _Py_dict_runtime_state {
21+
uint32_t next_keys_version;
22+
};
23+
2024
#ifndef WITH_FREELISTS
2125
// without freelists
2226
# define PyDict_MAXFREELIST 0

Include/internal/pycore_runtime.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ extern "C" {
99
#endif
1010

1111
#include "pycore_atomic.h" /* _Py_atomic_address */
12+
#include "pycore_dict.h" // struct _Py_dict_runtime_state
1213
#include "pycore_gil.h" // struct _gil_runtime_state
1314
#include "pycore_global_objects.h" // struct _Py_global_objects
1415
#include "pycore_import.h" // struct _import_runtime_state
@@ -135,6 +136,7 @@ typedef struct pyruntimestate {
135136
_Py_AuditHookEntry *audit_hook_head;
136137

137138
struct _Py_unicode_runtime_ids unicode_ids;
139+
struct _Py_dict_runtime_state dict_state;
138140

139141
struct {
140142
/* Used to set PyTypeObject.tp_version_tag */

Include/internal/pycore_runtime_init.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ extern "C" {
3636
until _PyInterpreterState_Enable() is called. */ \
3737
.next_id = -1, \
3838
}, \
39+
.dict_state = { \
40+
.next_keys_version = 2, \
41+
}, \
3942
.types = { \
4043
.next_version_tag = 1, \
4144
}, \

Objects/dictobject.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5661,17 +5661,15 @@ _PyDictKeys_DecRef(PyDictKeysObject *keys)
56615661
dictkeys_decref(keys);
56625662
}
56635663

5664-
static uint32_t next_dict_keys_version = 2;
5665-
56665664
uint32_t _PyDictKeys_GetVersionForCurrentState(PyDictKeysObject *dictkeys)
56675665
{
56685666
if (dictkeys->dk_version != 0) {
56695667
return dictkeys->dk_version;
56705668
}
5671-
if (next_dict_keys_version == 0) {
5669+
if (_PyRuntime.dict_state.next_keys_version == 0) {
56725670
return 0;
56735671
}
5674-
uint32_t v = next_dict_keys_version++;
5672+
uint32_t v = _PyRuntime.dict_state.next_keys_version++;
56755673
dictkeys->dk_version = v;
56765674
return v;
56775675
}

Tools/c-analyzer/cpython/globals-to-fix.tsv

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,6 @@ Python/getargs.c - static_arg_parsers -
417417

418418
# other
419419
Objects/dictobject.c - _pydict_global_version -
420-
Objects/dictobject.c - next_dict_keys_version -
421420
Objects/funcobject.c - next_func_version -
422421
Objects/object.c - _Py_RefTotal -
423422
Python/perf_trampoline.c - perf_status -

0 commit comments

Comments
 (0)