Skip to content

Commit c00d1e0

Browse files
Move next_dict_keys_version to _PyRuntimeState.
1 parent 5f55067 commit c00d1e0

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_dtoa.h" // struct _dtoa_runtime_state
1314
#include "pycore_floatobject.h" // struct _Py_float_runtime_state
1415
#include "pycore_gil.h" // struct _gil_runtime_state
@@ -151,6 +152,7 @@ typedef struct pyruntimestate {
151152

152153
struct _Py_float_runtime_state float_state;
153154
struct _Py_unicode_runtime_state unicode_state;
155+
struct _Py_dict_runtime_state dict_state;
154156

155157
struct {
156158
/* 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
@@ -58,6 +58,9 @@ extern "C" {
5858
.float_format = _py_float_format_unknown, \
5959
.double_format = _py_float_format_unknown, \
6060
}, \
61+
.dict_state = { \
62+
.next_keys_version = 2, \
63+
}, \
6164
.types = { \
6265
.next_version_tag = 1, \
6366
}, \

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
@@ -329,7 +329,6 @@ Python/suggestions.c levenshtein_distance buffer -
329329

330330
# other
331331
Objects/dictobject.c - _pydict_global_version -
332-
Objects/dictobject.c - next_dict_keys_version -
333332
Objects/funcobject.c - next_func_version -
334333
Objects/object.c - _Py_RefTotal -
335334
Python/perf_trampoline.c - perf_status -

0 commit comments

Comments
 (0)