Skip to content

Commit b45d14b

Browse files
gh-100227: Move dict_state.global_version to PyInterpreterState (gh-102338)
#100227
1 parent 58d761e commit b45d14b

File tree

6 files changed

+160
-109
lines changed

6 files changed

+160
-109
lines changed

Include/internal/pycore_dict.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ static inline PyDictUnicodeEntry* DK_UNICODE_ENTRIES(PyDictKeysObject *dk) {
149149
#define DICT_VERSION_INCREMENT (1 << DICT_MAX_WATCHERS)
150150
#define DICT_VERSION_MASK (DICT_VERSION_INCREMENT - 1)
151151

152-
#define DICT_NEXT_VERSION() \
153-
(_PyRuntime.dict_state.global_version += DICT_VERSION_INCREMENT)
152+
#define DICT_NEXT_VERSION(INTERP) \
153+
((INTERP)->dict_state.global_version += DICT_VERSION_INCREMENT)
154154

155155
void
156156
_PyDict_SendEvent(int watcher_bits,
@@ -160,7 +160,8 @@ _PyDict_SendEvent(int watcher_bits,
160160
PyObject *value);
161161

162162
static inline uint64_t
163-
_PyDict_NotifyEvent(PyDict_WatchEvent event,
163+
_PyDict_NotifyEvent(PyInterpreterState *interp,
164+
PyDict_WatchEvent event,
164165
PyDictObject *mp,
165166
PyObject *key,
166167
PyObject *value)
@@ -169,9 +170,9 @@ _PyDict_NotifyEvent(PyDict_WatchEvent event,
169170
int watcher_bits = mp->ma_version_tag & DICT_VERSION_MASK;
170171
if (watcher_bits) {
171172
_PyDict_SendEvent(watcher_bits, event, mp, key, value);
172-
return DICT_NEXT_VERSION() | watcher_bits;
173+
return DICT_NEXT_VERSION(interp) | watcher_bits;
173174
}
174-
return DICT_NEXT_VERSION();
175+
return DICT_NEXT_VERSION(interp);
175176
}
176177

177178
extern PyObject *_PyObject_MakeDictFromInstanceAttributes(PyObject *obj, PyDictValues *values);

Include/internal/pycore_dict_state.h

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

1111

12-
struct _Py_dict_runtime_state {
13-
/*Global counter used to set ma_version_tag field of dictionary.
14-
* It is incremented each time that a dictionary is created and each
15-
* time that a dictionary is modified. */
16-
uint64_t global_version;
17-
};
18-
19-
2012
#ifndef WITH_FREELISTS
2113
// without freelists
2214
# define PyDict_MAXFREELIST 0
@@ -29,6 +21,10 @@ struct _Py_dict_runtime_state {
2921
#define DICT_MAX_WATCHERS 8
3022

3123
struct _Py_dict_state {
24+
/*Global counter used to set ma_version_tag field of dictionary.
25+
* It is incremented each time that a dictionary is created and each
26+
* time that a dictionary is modified. */
27+
uint64_t global_version;
3228
uint32_t next_keys_version;
3329

3430
#if PyDict_MAXFREELIST > 0

Include/internal/pycore_runtime.h

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

1111
#include "pycore_atomic.h" /* _Py_atomic_address */
1212
#include "pycore_ceval_state.h" // struct _ceval_runtime_state
13-
#include "pycore_dict_state.h" // struct _Py_dict_runtime_state
1413
#include "pycore_floatobject.h" // struct _Py_float_runtime_state
1514
#include "pycore_faulthandler.h" // struct _faulthandler_runtime_state
1615
#include "pycore_global_objects.h" // struct _Py_global_objects
@@ -153,7 +152,6 @@ typedef struct pyruntimestate {
153152

154153
struct _Py_float_runtime_state float_state;
155154
struct _Py_unicode_runtime_state unicode_state;
156-
struct _Py_dict_runtime_state dict_state;
157155

158156
struct {
159157
/* Used to set PyTypeObject.tp_version_tag */

0 commit comments

Comments
 (0)