File tree 6 files changed +25
-22
lines changed
6 files changed +25
-22
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ extern void _PyUnicode_InitState(PyInterpreterState *);
17
17
extern PyStatus _PyUnicode_InitGlobalObjects (PyInterpreterState * );
18
18
extern PyStatus _PyUnicode_InitTypes (PyInterpreterState * );
19
19
extern void _PyUnicode_Fini (PyInterpreterState * );
20
+ extern void _PyUnicode_FiniTypes (PyInterpreterState * );
20
21
21
22
22
23
/* other API */
Original file line number Diff line number Diff line change @@ -3545,12 +3545,6 @@ _PyExc_FiniTypes(PyInterpreterState *interp)
3545
3545
3546
3546
for (Py_ssize_t i = Py_ARRAY_LENGTH (static_exceptions ) - 1 ; i >= 0 ; i -- ) {
3547
3547
PyTypeObject * exc = static_exceptions [i ].exc ;
3548
-
3549
- // Cannot delete a type if it still has subclasses
3550
- if (exc -> tp_subclasses != NULL ) {
3551
- continue ;
3552
- }
3553
-
3554
3548
_PyStaticType_Dealloc (exc );
3555
3549
}
3556
3550
}
Original file line number Diff line number Diff line change @@ -1994,10 +1994,6 @@ _PyTypes_FiniTypes(PyInterpreterState *interp)
1994
1994
// their base classes.
1995
1995
for (Py_ssize_t i = Py_ARRAY_LENGTH (static_types )- 1 ; i >=0 ; i -- ) {
1996
1996
PyTypeObject * type = static_types [i ];
1997
- // Cannot delete a type if it still has subclasses
1998
- if (type -> tp_subclasses != NULL ) {
1999
- continue ;
2000
- }
2001
1997
_PyStaticType_Dealloc (type );
2002
1998
}
2003
1999
}
Original file line number Diff line number Diff line change @@ -4079,10 +4079,12 @@ type_dealloc_common(PyTypeObject *type)
4079
4079
void
4080
4080
_PyStaticType_Dealloc (PyTypeObject * type )
4081
4081
{
4082
- // _PyStaticType_Dealloc() must not be called if a type has subtypes .
4082
+ // If a type still has subtypes, it cannot be deallocated .
4083
4083
// A subtype can inherit attributes and methods of its parent type,
4084
4084
// and a type must no longer be used once it's deallocated.
4085
- assert (type -> tp_subclasses == NULL );
4085
+ if (type -> tp_subclasses != NULL ) {
4086
+ return ;
4087
+ }
4086
4088
4087
4089
type_dealloc_common (type );
4088
4090
Original file line number Diff line number Diff line change @@ -15567,23 +15567,19 @@ _PyUnicode_InitTypes(PyInterpreterState *interp)
15567
15567
return _PyStatus_OK ();
15568
15568
}
15569
15569
15570
- if (PyType_Ready (& PyUnicode_Type ) < 0 ) {
15571
- return _PyStatus_ERR ("Can't initialize unicode type" );
15572
- }
15573
- if (PyType_Ready (& PyUnicodeIter_Type ) < 0 ) {
15574
- return _PyStatus_ERR ("Can't initialize unicode iterator type" );
15575
- }
15576
-
15577
15570
if (PyType_Ready (& EncodingMapType ) < 0 ) {
15578
- return _PyStatus_ERR ( "Can't initialize encoding map type" ) ;
15571
+ goto error ;
15579
15572
}
15580
15573
if (PyType_Ready (& PyFieldNameIter_Type ) < 0 ) {
15581
- return _PyStatus_ERR ( "Can't initialize field name iterator type" ) ;
15574
+ goto error ;
15582
15575
}
15583
15576
if (PyType_Ready (& PyFormatterIter_Type ) < 0 ) {
15584
- return _PyStatus_ERR ( "Can't initialize formatter iter type" ) ;
15577
+ goto error ;
15585
15578
}
15586
15579
return _PyStatus_OK ();
15580
+
15581
+ error :
15582
+ return _PyStatus_ERR ("Can't initialize unicode types" );
15587
15583
}
15588
15584
15589
15585
@@ -16111,6 +16107,19 @@ unicode_is_finalizing(void)
16111
16107
#endif
16112
16108
16113
16109
16110
+ void
16111
+ _PyUnicode_FiniTypes (PyInterpreterState * interp )
16112
+ {
16113
+ if (!_Py_IsMainInterpreter (interp )) {
16114
+ return ;
16115
+ }
16116
+
16117
+ _PyStaticType_Dealloc (& EncodingMapType );
16118
+ _PyStaticType_Dealloc (& PyFieldNameIter_Type );
16119
+ _PyStaticType_Dealloc (& PyFormatterIter_Type );
16120
+ }
16121
+
16122
+
16114
16123
void
16115
16124
_PyUnicode_Fini (PyInterpreterState * interp )
16116
16125
{
Original file line number Diff line number Diff line change @@ -1664,6 +1664,7 @@ flush_std_files(void)
1664
1664
static void
1665
1665
finalize_interp_types (PyInterpreterState * interp )
1666
1666
{
1667
+ _PyUnicode_FiniTypes (interp );
1667
1668
_PySys_Fini (interp );
1668
1669
_PyExc_Fini (interp );
1669
1670
_PyFrame_Fini (interp );
You can’t perform that action at this time.
0 commit comments