]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-100227: Move func_state.next_version to PyInterpreterState (gh-102334)
authorEric Snow <ericsnowcurrently@gmail.com>
Wed, 8 Mar 2023 22:56:36 +0000 (15:56 -0700)
committerGitHub <noreply@github.com>
Wed, 8 Mar 2023 22:56:36 +0000 (15:56 -0700)
https://github.com/python/cpython/issues/100227

Include/internal/pycore_function.h
Include/internal/pycore_interp.h
Include/internal/pycore_runtime.h
Include/internal/pycore_runtime_init.h
Objects/funcobject.c

index 5cedb33d7e3afdb5806dbca0fc950e46b94e01c5..11988149843fefce8ebf5d3b1348b39a012fdeaa 100644 (file)
@@ -10,7 +10,7 @@ extern "C" {
 
 #define FUNC_MAX_WATCHERS 8
 
-struct _py_func_runtime_state {
+struct _py_func_state {
     uint32_t next_version;
 };
 
index 7ef9c40153e4211ec95150976ad495c3d807b6e1..9efed0a1cf90c2781dc897727f58b912cf08452e 100644 (file)
@@ -141,6 +141,7 @@ struct _is {
     struct _Py_float_state float_state;
     struct _Py_long_state long_state;
     struct _dtoa_state dtoa;
+    struct _py_func_state func_state;
     /* Using a cache is very effective since typically only a single slice is
        created and then deleted again. */
     PySliceObject *slice_cache;
index 2350eaab5976cafb3690cc188a3e65aadbaef848..e0e3d4ace0cfde1f974d1c59410d8aaa8643bf97 100644 (file)
@@ -13,7 +13,6 @@ extern "C" {
 #include "pycore_dict_state.h"      // struct _Py_dict_runtime_state
 #include "pycore_floatobject.h"     // struct _Py_float_runtime_state
 #include "pycore_faulthandler.h"    // struct _faulthandler_runtime_state
-#include "pycore_function.h"        // struct _func_runtime_state
 #include "pycore_global_objects.h"  // struct _Py_global_objects
 #include "pycore_import.h"          // struct _import_runtime_state
 #include "pycore_interp.h"          // PyInterpreterState
@@ -155,7 +154,6 @@ typedef struct pyruntimestate {
     struct _Py_float_runtime_state float_state;
     struct _Py_unicode_runtime_state unicode_state;
     struct _Py_dict_runtime_state dict_state;
-    struct _py_func_runtime_state func_state;
 
     struct {
         /* Used to set PyTypeObject.tp_version_tag */
index a2cc7c87c2f3e29e7ad9cbed60df9a6191fc4e90..aeabcfd2b9056ca22e0b897996f0c3f494258593 100644 (file)
@@ -68,9 +68,6 @@ extern PyTypeObject _PyExc_MemoryError;
         .dict_state = { \
             .next_keys_version = 2, \
         }, \
-        .func_state = { \
-            .next_version = 1, \
-        }, \
         .types = { \
             .next_version_tag = 1, \
         }, \
@@ -116,6 +113,9 @@ extern PyTypeObject _PyExc_MemoryError;
             }, \
         }, \
         .dtoa = _dtoa_state_INIT(&(INTERP)), \
+        .func_state = { \
+            .next_version = 1, \
+        }, \
         .static_objects = { \
             .singletons = { \
                 ._not_used = 1, \
index 99048ea41c6c80080ba1ab803688476facd2dda5..ce5d7bda32c0320f1686c3c1d3d2ed3e61eef83d 100644 (file)
@@ -227,10 +227,11 @@ uint32_t _PyFunction_GetVersionForCurrentState(PyFunctionObject *func)
     if (func->vectorcall != _PyFunction_Vectorcall) {
         return 0;
     }
-    if (_PyRuntime.func_state.next_version == 0) {
+    PyInterpreterState *interp = _PyInterpreterState_GET();
+    if (interp->func_state.next_version == 0) {
         return 0;
     }
-    uint32_t v = _PyRuntime.func_state.next_version++;
+    uint32_t v = interp->func_state.next_version++;
     func->func_version = v;
     return v;
 }