summaryrefslogtreecommitdiffstats
path: root/Include
diff options
context:
space:
mode:
authorEric Snow <ericsnowcurrently@gmail.com>2023-04-24 22:30:13 (GMT)
committerGitHub <noreply@github.com>2023-04-24 22:30:13 (GMT)
commit209a0a76552c19088e74b0f27827b9214b6c2cf8 (patch)
tree561e233e1e44bc061a8ee594f4c57fa657ba1d93 /Include
parent0dc8b50d33208e9ca4fc3d959c6798529731f020 (diff)
downloadcpython-209a0a76552c19088e74b0f27827b9214b6c2cf8.zip
cpython-209a0a76552c19088e74b0f27827b9214b6c2cf8.tar.gz
cpython-209a0a76552c19088e74b0f27827b9214b6c2cf8.tar.bz2
gh-95795: Move types.next_version_tag to PyInterpreterState (gh-102343)
Core static types will continue to use the global value. All other types will use the per-interpreter value. They all share the same range, where the global types use values < 2^16 and each interpreter uses values higher than that.
Diffstat (limited to 'Include')
-rw-r--r--Include/internal/pycore_runtime.h9
-rw-r--r--Include/internal/pycore_runtime_init.h3
-rw-r--r--Include/internal/pycore_typeobject.h59
3 files changed, 44 insertions, 27 deletions
diff --git a/Include/internal/pycore_runtime.h b/Include/internal/pycore_runtime.h
index 2a3fd8a..789a1fb 100644
--- a/Include/internal/pycore_runtime.h
+++ b/Include/internal/pycore_runtime.h
@@ -25,6 +25,7 @@ extern "C" {
#include "pycore_signal.h" // struct _signals_runtime_state
#include "pycore_time.h" // struct _time_runtime_state
#include "pycore_tracemalloc.h" // struct _tracemalloc_runtime_state
+#include "pycore_typeobject.h" // struct types_runtime_state
#include "pycore_unicodeobject.h" // struct _Py_unicode_runtime_ids
struct _getargs_runtime_state {
@@ -150,13 +151,7 @@ typedef struct pyruntimestate {
struct _py_object_runtime_state object_state;
struct _Py_float_runtime_state float_state;
struct _Py_unicode_runtime_state unicode_state;
-
- struct {
- /* Used to set PyTypeObject.tp_version_tag */
- // bpo-42745: next_version_tag remains shared by all interpreters
- // because of static types.
- unsigned int next_version_tag;
- } types;
+ struct _types_runtime_state types;
/* All the objects that are shared by the runtime's interpreters. */
struct _Py_static_objects static_objects;
diff --git a/Include/internal/pycore_runtime_init.h b/Include/internal/pycore_runtime_init.h
index d8425b3..843f8a3 100644
--- a/Include/internal/pycore_runtime_init.h
+++ b/Include/internal/pycore_runtime_init.h
@@ -112,6 +112,9 @@ extern PyTypeObject _PyExc_MemoryError;
.func_state = { \
.next_version = 1, \
}, \
+ .types = { \
+ .next_version_tag = _Py_TYPE_BASE_VERSION_TAG, \
+ }, \
.static_objects = { \
.singletons = { \
._not_used = 1, \
diff --git a/Include/internal/pycore_typeobject.h b/Include/internal/pycore_typeobject.h
index 324e500..fa59c53 100644
--- a/Include/internal/pycore_typeobject.h
+++ b/Include/internal/pycore_typeobject.h
@@ -11,22 +11,17 @@ extern "C" {
#endif
-/* runtime lifecycle */
-
-extern PyStatus _PyTypes_InitTypes(PyInterpreterState *);
-extern void _PyTypes_FiniTypes(PyInterpreterState *);
-extern void _PyTypes_Fini(PyInterpreterState *);
-
+/* state */
-/* other API */
-
-/* Length of array of slotdef pointers used to store slots with the
- same __name__. There should be at most MAX_EQUIV-1 slotdef entries with
- the same __name__, for any __name__. Since that's a static property, it is
- appropriate to declare fixed-size arrays for this. */
-#define MAX_EQUIV 10
+#define _Py_TYPE_BASE_VERSION_TAG (2<<16)
+#define _Py_MAX_GLOBAL_TYPE_VERSION_TAG (_Py_TYPE_BASE_VERSION_TAG - 1)
-typedef struct wrapperbase pytype_slotdef;
+struct _types_runtime_state {
+ /* Used to set PyTypeObject.tp_version_tag for core static types. */
+ // bpo-42745: next_version_tag remains shared by all interpreters
+ // because of static types.
+ unsigned int next_version_tag;
+};
// Type attribute lookup cache: speed up attribute and method lookups,
@@ -57,6 +52,36 @@ typedef struct {
PyObject *tp_weaklist;
} static_builtin_state;
+struct types_state {
+ /* Used to set PyTypeObject.tp_version_tag.
+ It starts at _Py_MAX_GLOBAL_TYPE_VERSION_TAG + 1,
+ where all those lower numbers are used for core static types. */
+ unsigned int next_version_tag;
+
+ struct type_cache type_cache;
+ size_t num_builtins_initialized;
+ static_builtin_state builtins[_Py_MAX_STATIC_BUILTIN_TYPES];
+};
+
+
+/* runtime lifecycle */
+
+extern PyStatus _PyTypes_InitTypes(PyInterpreterState *);
+extern void _PyTypes_FiniTypes(PyInterpreterState *);
+extern void _PyTypes_Fini(PyInterpreterState *);
+
+
+/* other API */
+
+/* Length of array of slotdef pointers used to store slots with the
+ same __name__. There should be at most MAX_EQUIV-1 slotdef entries with
+ the same __name__, for any __name__. Since that's a static property, it is
+ appropriate to declare fixed-size arrays for this. */
+#define MAX_EQUIV 10
+
+typedef struct wrapperbase pytype_slotdef;
+
+
static inline PyObject **
_PyStaticType_GET_WEAKREFS_LISTPTR(static_builtin_state *state)
{
@@ -78,12 +103,6 @@ _PyType_GetModuleState(PyTypeObject *type)
return mod->md_state;
}
-struct types_state {
- struct type_cache type_cache;
- size_t num_builtins_initialized;
- static_builtin_state builtins[_Py_MAX_STATIC_BUILTIN_TYPES];
-};
-
extern int _PyStaticType_InitBuiltin(PyTypeObject *type);
extern static_builtin_state * _PyStaticType_GetState(PyTypeObject *);