extern PyStatus _PyUnicode_InitGlobalObjects(PyInterpreterState *);
extern PyStatus _PyUnicode_InitTypes(PyInterpreterState *);
extern void _PyUnicode_Fini(PyInterpreterState *);
+extern void _PyUnicode_FiniTypes(PyInterpreterState *);
/* other API */
for (Py_ssize_t i=Py_ARRAY_LENGTH(static_exceptions) - 1; i >= 0; i--) {
PyTypeObject *exc = static_exceptions[i].exc;
-
- // Cannot delete a type if it still has subclasses
- if (exc->tp_subclasses != NULL) {
- continue;
- }
-
_PyStaticType_Dealloc(exc);
}
}
// their base classes.
for (Py_ssize_t i=Py_ARRAY_LENGTH(static_types)-1; i>=0; i--) {
PyTypeObject *type = static_types[i];
- // Cannot delete a type if it still has subclasses
- if (type->tp_subclasses != NULL) {
- continue;
- }
_PyStaticType_Dealloc(type);
}
}
void
_PyStaticType_Dealloc(PyTypeObject *type)
{
- // _PyStaticType_Dealloc() must not be called if a type has subtypes.
+ // If a type still has subtypes, it cannot be deallocated.
// A subtype can inherit attributes and methods of its parent type,
// and a type must no longer be used once it's deallocated.
- assert(type->tp_subclasses == NULL);
+ if (type->tp_subclasses != NULL) {
+ return;
+ }
type_dealloc_common(type);
return _PyStatus_OK();
}
- if (PyType_Ready(&PyUnicode_Type) < 0) {
- return _PyStatus_ERR("Can't initialize unicode type");
- }
- if (PyType_Ready(&PyUnicodeIter_Type) < 0) {
- return _PyStatus_ERR("Can't initialize unicode iterator type");
- }
-
if (PyType_Ready(&EncodingMapType) < 0) {
- return _PyStatus_ERR("Can't initialize encoding map type");
+ goto error;
}
if (PyType_Ready(&PyFieldNameIter_Type) < 0) {
- return _PyStatus_ERR("Can't initialize field name iterator type");
+ goto error;
}
if (PyType_Ready(&PyFormatterIter_Type) < 0) {
- return _PyStatus_ERR("Can't initialize formatter iter type");
+ goto error;
}
return _PyStatus_OK();
+
+error:
+ return _PyStatus_ERR("Can't initialize unicode types");
}
#endif
+void
+_PyUnicode_FiniTypes(PyInterpreterState *interp)
+{
+ if (!_Py_IsMainInterpreter(interp)) {
+ return;
+ }
+
+ _PyStaticType_Dealloc(&EncodingMapType);
+ _PyStaticType_Dealloc(&PyFieldNameIter_Type);
+ _PyStaticType_Dealloc(&PyFormatterIter_Type);
+}
+
+
void
_PyUnicode_Fini(PyInterpreterState *interp)
{
static void
finalize_interp_types(PyInterpreterState *interp)
{
+ _PyUnicode_FiniTypes(interp);
_PySys_Fini(interp);
_PyExc_Fini(interp);
_PyFrame_Fini(interp);