Skip to content

Commit ba9e889

Browse files
Move next_func_version to _PyRuntimeState.
1 parent a937251 commit ba9e889

File tree

5 files changed

+11
-5
lines changed

5 files changed

+11
-5
lines changed

Include/internal/pycore_function.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ extern "C" {
88
# error "this header requires Py_BUILD_CORE define"
99
#endif
1010

11+
struct _py_func_runtime_state {
12+
uint32_t next_version;
13+
};
14+
1115
extern PyFunctionObject* _PyFunction_FromConstructor(PyFrameConstructor *constr);
1216

1317
extern uint32_t _PyFunction_GetVersionForCurrentState(PyFunctionObject *func);

Include/internal/pycore_runtime.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ extern "C" {
1212
#include "pycore_dict_state.h" // struct _Py_dict_runtime_state
1313
#include "pycore_dtoa.h" // struct _dtoa_runtime_state
1414
#include "pycore_floatobject.h" // struct _Py_float_runtime_state
15+
#include "pycore_function.h" // struct _func_runtime_state
1516
#include "pycore_gil.h" // struct _gil_runtime_state
1617
#include "pycore_global_objects.h" // struct _Py_global_objects
1718
#include "pycore_import.h" // struct _import_runtime_state
@@ -153,6 +154,7 @@ typedef struct pyruntimestate {
153154
struct _Py_float_runtime_state float_state;
154155
struct _Py_unicode_runtime_state unicode_state;
155156
struct _Py_dict_runtime_state dict_state;
157+
struct _py_func_runtime_state func_state;
156158

157159
struct {
158160
/* 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
@@ -61,6 +61,9 @@ extern "C" {
6161
.dict_state = { \
6262
.next_keys_version = 2, \
6363
}, \
64+
.func_state = { \
65+
.next_version = 1, \
66+
}, \
6467
.types = { \
6568
.next_version_tag = 1, \
6669
}, \

Objects/funcobject.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
#include "pycore_pyerrors.h" // _PyErr_Occurred()
88
#include "structmember.h" // PyMemberDef
99

10-
static uint32_t next_func_version = 1;
11-
1210
PyFunctionObject *
1311
_PyFunction_FromConstructor(PyFrameConstructor *constr)
1412
{
@@ -129,10 +127,10 @@ uint32_t _PyFunction_GetVersionForCurrentState(PyFunctionObject *func)
129127
if (func->vectorcall != _PyFunction_Vectorcall) {
130128
return 0;
131129
}
132-
if (next_func_version == 0) {
130+
if (_PyRuntime.func_state.next_version == 0) {
133131
return 0;
134132
}
135-
uint32_t v = next_func_version++;
133+
uint32_t v = _PyRuntime.func_state.next_version++;
136134
func->func_version = v;
137135
return v;
138136
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,6 @@ Objects/unicodeobject.c - ucnhash_capi -
328328
Python/suggestions.c levenshtein_distance buffer -
329329

330330
# other
331-
Objects/funcobject.c - next_func_version -
332331
Objects/object.c - _Py_RefTotal -
333332
Python/perf_trampoline.c - perf_status -
334333
Python/perf_trampoline.c - extra_code_index -

0 commit comments

Comments
 (0)