Skip to content

Commit 66ff374

Browse files
gh-100227: Move func_state.next_version to PyInterpreterState (gh-102334)
#100227
1 parent cbb0aa7 commit 66ff374

File tree

5 files changed

+8
-8
lines changed

5 files changed

+8
-8
lines changed

Include/internal/pycore_function.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ extern "C" {
1010

1111
#define FUNC_MAX_WATCHERS 8
1212

13-
struct _py_func_runtime_state {
13+
struct _py_func_state {
1414
uint32_t next_version;
1515
};
1616

Include/internal/pycore_interp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ struct _is {
141141
struct _Py_float_state float_state;
142142
struct _Py_long_state long_state;
143143
struct _dtoa_state dtoa;
144+
struct _py_func_state func_state;
144145
/* Using a cache is very effective since typically only a single slice is
145146
created and then deleted again. */
146147
PySliceObject *slice_cache;

Include/internal/pycore_runtime.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ extern "C" {
1313
#include "pycore_dict_state.h" // struct _Py_dict_runtime_state
1414
#include "pycore_floatobject.h" // struct _Py_float_runtime_state
1515
#include "pycore_faulthandler.h" // struct _faulthandler_runtime_state
16-
#include "pycore_function.h" // struct _func_runtime_state
1716
#include "pycore_global_objects.h" // struct _Py_global_objects
1817
#include "pycore_import.h" // struct _import_runtime_state
1918
#include "pycore_interp.h" // PyInterpreterState
@@ -155,7 +154,6 @@ typedef struct pyruntimestate {
155154
struct _Py_float_runtime_state float_state;
156155
struct _Py_unicode_runtime_state unicode_state;
157156
struct _Py_dict_runtime_state dict_state;
158-
struct _py_func_runtime_state func_state;
159157

160158
struct {
161159
/* Used to set PyTypeObject.tp_version_tag */

Include/internal/pycore_runtime_init.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,6 @@ extern PyTypeObject _PyExc_MemoryError;
6868
.dict_state = { \
6969
.next_keys_version = 2, \
7070
}, \
71-
.func_state = { \
72-
.next_version = 1, \
73-
}, \
7471
.types = { \
7572
.next_version_tag = 1, \
7673
}, \
@@ -116,6 +113,9 @@ extern PyTypeObject _PyExc_MemoryError;
116113
}, \
117114
}, \
118115
.dtoa = _dtoa_state_INIT(&(INTERP)), \
116+
.func_state = { \
117+
.next_version = 1, \
118+
}, \
119119
.static_objects = { \
120120
.singletons = { \
121121
._not_used = 1, \

Objects/funcobject.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,11 @@ uint32_t _PyFunction_GetVersionForCurrentState(PyFunctionObject *func)
227227
if (func->vectorcall != _PyFunction_Vectorcall) {
228228
return 0;
229229
}
230-
if (_PyRuntime.func_state.next_version == 0) {
230+
PyInterpreterState *interp = _PyInterpreterState_GET();
231+
if (interp->func_state.next_version == 0) {
231232
return 0;
232233
}
233-
uint32_t v = _PyRuntime.func_state.next_version++;
234+
uint32_t v = interp->func_state.next_version++;
234235
func->func_version = v;
235236
return v;
236237
}

0 commit comments

Comments
 (0)