mirror of
https://github.com/python/cpython.git
synced 2025-08-02 08:02:56 +00:00
gh-94673: Add Per-Interpreter Storage for Static Builtin Types (#95255)
This is the last precursor to storing tp_subclasses (and tp_weaklist) on the interpreter state for static builtin types. Here we add per-type storage on PyInterpreterState, but only for the static builtin types. This involves the following: * add PyInterpreterState.types * move PyInterpreterState.type_cache to it * add a "num_builtins_initialized" field * add a "builtins" field (a static array big enough for all the static builtin types) * add _PyStaticType_GetState() to look up a static builtin type's state * (temporarily) add PyTypeObject.tp_static_builtin_index (to hold the type's index into PyInterpreterState.types.builtins) We will be eliminating tp_static_builtin_index in a later change.
This commit is contained in:
parent
7ac5bb3e6a
commit
47e75a0025
5 changed files with 125 additions and 7 deletions
|
@ -227,6 +227,7 @@ struct _typeobject {
|
|||
|
||||
destructor tp_finalize;
|
||||
vectorcallfunc tp_vectorcall;
|
||||
size_t tp_static_builtin_index; /* 0 means "not initialized" */
|
||||
};
|
||||
|
||||
/* This struct is used by the specializer
|
||||
|
|
|
@ -173,7 +173,7 @@ struct _is {
|
|||
struct _Py_exc_state exc_state;
|
||||
|
||||
struct ast_state ast;
|
||||
struct type_cache type_cache;
|
||||
struct types_state types;
|
||||
struct callable_cache callable_cache;
|
||||
|
||||
/* The following fields are here to avoid allocation during init.
|
||||
|
|
|
@ -39,9 +39,25 @@ struct type_cache {
|
|||
#endif
|
||||
};
|
||||
|
||||
/* For now we hard-code this to a value for which we are confident
|
||||
all the static builtin types will fit (for all builds). */
|
||||
#define _Py_MAX_STATIC_BUILTIN_TYPES 200
|
||||
|
||||
typedef struct {
|
||||
PyTypeObject *type;
|
||||
} static_builtin_state;
|
||||
|
||||
struct types_state {
|
||||
struct type_cache type_cache;
|
||||
size_t num_builtins_initialized;
|
||||
static_builtin_state builtins[_Py_MAX_STATIC_BUILTIN_TYPES];
|
||||
};
|
||||
|
||||
|
||||
extern PyStatus _PyTypes_InitSlotDefs(void);
|
||||
|
||||
extern int _PyStaticType_InitBuiltin(PyTypeObject *type);
|
||||
extern static_builtin_state * _PyStaticType_GetState(PyTypeObject *);
|
||||
extern void _PyStaticType_Dealloc(PyTypeObject *type);
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue