| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent dba7a16 commit 105f22e
13 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -589,7 +589,7 @@ _PyObject_GET_WEAKREFS_LISTPTR(PyObject *op) | |||
| 589 | 589 | if (PyType_Check(op) && | |
| 590 | 590 | ((PyTypeObject *)op)->tp_flags & _Py_TPFLAGS_STATIC_BUILTIN) { | |
| 591 | 591 | PyInterpreterState *interp = _PyInterpreterState_GET(); | |
| 592 | - static_builtin_state *state = _PyStaticType_GetState( | ||
| 592 | + managed_static_type_state *state = _PyStaticType_GetState( | ||
| 593 | 593 | interp, (PyTypeObject *)op); | |
| 594 | 594 | return _PyStaticType_GET_WEAKREFS_LISTPTR(state); | |
| 595 | 595 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -44,10 +44,12 @@ struct type_cache { | |||
| 44 | 44 | ||
| 45 | 45 | /* For now we hard-code this to a value for which we are confident | |
| 46 | 46 | all the static builtin types will fit (for all builds). */ | |
| 47 | - #define _Py_MAX_STATIC_BUILTIN_TYPES 200 | ||
| 47 | + #define _Py_MAX_MANAGED_STATIC_BUILTIN_TYPES 200 | ||
| 48 | + #define _Py_MAX_MANAGED_STATIC_EXT_TYPES 10 | ||
| 48 | 49 | ||
| 49 | 50 | typedef struct { | |
| 50 | 51 | PyTypeObject *type; | |
| 52 | + int isbuiltin; | ||
| 51 | 53 | int readying; | |
| 52 | 54 | int ready; | |
| 53 | 55 | // XXX tp_dict can probably be statically allocated, | |
@@ -59,7 +61,7 @@ typedef struct { | |||
| 59 | 61 | are also some diagnostic uses for the list of weakrefs, | |
| 60 | 62 | so we still keep it. */ | |
| 61 | 63 | PyObject *tp_weaklist; | |
| 62 | - } static_builtin_state; | ||
| 64 | + } managed_static_type_state; | ||
| 63 | 65 | ||
| 64 | 66 | struct types_state { | |
| 65 | 67 | /* Used to set PyTypeObject.tp_version_tag. | |
@@ -105,8 +107,16 @@ struct types_state { | |||
| 105 | 107 | num_builtins_initialized is incremented once for each static | |
| 106 | 108 | builtin type. Once initialization is over for a subinterpreter, | |
| 107 | 109 | the value will be the same as for all other interpreters. */ | |
| 108 | - size_t num_builtins_initialized; | ||
| 109 | - static_builtin_state builtins[_Py_MAX_STATIC_BUILTIN_TYPES]; | ||
| 110 | + struct { | ||
| 111 | + size_t num_initialized; | ||
| 112 | + managed_static_type_state initialized[_Py_MAX_MANAGED_STATIC_BUILTIN_TYPES]; | ||
| 113 | + } builtins; | ||
| 114 | + /* We apply a similar strategy for managed extension modules. */ | ||
| 115 | + struct { | ||
| 116 | + size_t num_initialized; | ||
| 117 | + size_t next_index; | ||
| 118 | + managed_static_type_state initialized[_Py_MAX_MANAGED_STATIC_EXT_TYPES]; | ||
| 119 | + } for_extensions; | ||
| 110 | 120 | PyMutex mutex; | |
| 111 | 121 | }; | |
| 112 | 122 | ||
@@ -130,12 +140,35 @@ typedef struct wrapperbase pytype_slotdef; | |||
| 130 | 140 | ||
| 131 | 141 | ||
| 132 | 142 | static inline PyObject ** | |
| 133 | - _PyStaticType_GET_WEAKREFS_LISTPTR(static_builtin_state *state) | ||
| 143 | + _PyStaticType_GET_WEAKREFS_LISTPTR(managed_static_type_state *state) | ||
| 134 | 144 | { | |
| 135 | 145 | assert(state != NULL); | |
| 136 | 146 | return &state->tp_weaklist; | |
| 137 | 147 | } | |
| 138 | 148 | ||
| 149 | + extern int _PyStaticType_InitBuiltin( | ||
| 150 | + PyInterpreterState *interp, | ||
| 151 | + PyTypeObject *type); | ||
| 152 | + extern void _PyStaticType_FiniBuiltin( | ||
| 153 | + PyInterpreterState *interp, | ||
| 154 | + PyTypeObject *type); | ||
| 155 | + extern void _PyStaticType_ClearWeakRefs( | ||
| 156 | + PyInterpreterState *interp, | ||
| 157 | + PyTypeObject *type); | ||
| 158 | + extern managed_static_type_state * _PyStaticType_GetState( | ||
| 159 | + PyInterpreterState *interp, | ||
| 160 | + PyTypeObject *type); | ||
| 161 | + | ||
| 162 | + // Export for '_datetime' shared extension. | ||
| 163 | + PyAPI_FUNC(int) _PyStaticType_InitForExtension( | ||
| 164 | + PyInterpreterState *interp, | ||
| 165 | + PyTypeObject *self); | ||
| 166 | + PyAPI_FUNC(void) _PyStaticType_FiniForExtension( | ||
| 167 | + PyInterpreterState *interp, | ||
| 168 | + PyTypeObject *self, | ||
| 169 | + int final); | ||
| 170 | + | ||
| 171 | + | ||
| 139 | 172 | /* Like PyType_GetModuleState, but skips verification | |
| 140 | 173 | * that type is a heap type with an associated module */ | |
| 141 | 174 | static inline void * | |
@@ -151,11 +184,6 @@ _PyType_GetModuleState(PyTypeObject *type) | |||
| 151 | 184 | } | |
| 152 | 185 | ||
| 153 | 186 | ||
| 154 | - extern int _PyStaticType_InitBuiltin(PyInterpreterState *, PyTypeObject *type); | ||
| 155 | - extern static_builtin_state * _PyStaticType_GetState(PyInterpreterState *, PyTypeObject *); | ||
| 156 | - extern void _PyStaticType_ClearWeakRefs(PyInterpreterState *, PyTypeObject *type); | ||
| 157 | - extern void _PyStaticType_Dealloc(PyInterpreterState *, PyTypeObject *); | ||
| 158 | - | ||
| 159 | 187 | // Export for 'math' shared extension, used via _PyType_IsReady() static inline | |
| 160 | 188 | // function | |
| 161 | 189 | PyAPI_FUNC(PyObject *) _PyType_GetDict(PyTypeObject *); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,2 @@ | |||
| 1 | + The ``_datetime`` module (C implementation for :mod:`datetime`) now supports | ||
| 2 | + being imported in multiple interpreters. | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments