2
2
3
3
#include "Python.h"
4
4
#include "pycore_call.h"
5
+ #include "pycore_initconfig.h"
5
6
#include "pycore_object.h"
6
7
#include "pycore_pyerrors.h"
7
8
#include "pycore_pystate.h"
@@ -6932,7 +6933,8 @@ which incorporates the additional structures used for numbers, sequences and
6932
6933
mappings. Note that multiple names may map to the same slot (e.g. __eq__,
6933
6934
__ne__ etc. all map to tp_richcompare) and one name may map to multiple slots
6934
6935
(e.g. __str__ affects tp_str as well as tp_repr). The table is terminated with
6935
- an all-zero entry. (This table is further initialized in init_slotdefs().)
6936
+ an all-zero entry. (This table is further initialized in
6937
+ _PyTypes_InitSlotDefs().)
6936
6938
*/
6937
6939
6938
6940
typedef struct wrapperbase slotdef ;
@@ -7423,28 +7425,29 @@ update_slots_callback(PyTypeObject *type, void *data)
7423
7425
static int slotdefs_initialized = 0 ;
7424
7426
/* Initialize the slotdefs table by adding interned string objects for the
7425
7427
names. */
7426
- static void
7427
- init_slotdefs (void )
7428
+ PyStatus
7429
+ _PyTypes_InitSlotDefs (void )
7428
7430
{
7429
- slotdef * p ;
7431
+ if (slotdefs_initialized ) {
7432
+ return _PyStatus_OK ();
7433
+ }
7430
7434
7431
- if (slotdefs_initialized )
7432
- return ;
7433
- for (p = slotdefs ; p -> name ; p ++ ) {
7435
+ for (slotdef * p = slotdefs ; p -> name ; p ++ ) {
7434
7436
/* Slots must be ordered by their offset in the PyHeapTypeObject. */
7435
7437
assert (!p [1 ].name || p -> offset <= p [1 ].offset );
7436
7438
p -> name_strobj = PyUnicode_InternFromString (p -> name );
7437
- if (!p -> name_strobj || !PyUnicode_CHECK_INTERNED (p -> name_strobj ))
7438
- Py_FatalError ("Out of memory interning slotdef names" );
7439
+ if (!p -> name_strobj || !PyUnicode_CHECK_INTERNED (p -> name_strobj )) {
7440
+ return _PyStatus_NO_MEMORY ();
7441
+ }
7439
7442
}
7440
7443
slotdefs_initialized = 1 ;
7444
+ return _PyStatus_OK ();
7441
7445
}
7442
7446
7443
- /* Undo init_slotdefs , releasing the interned strings. */
7447
+ /* Undo _PyTypes_InitSlotDefs() , releasing the interned strings. */
7444
7448
static void clear_slotdefs (void )
7445
7449
{
7446
- slotdef * p ;
7447
- for (p = slotdefs ; p -> name ; p ++ ) {
7450
+ for (slotdef * p = slotdefs ; p -> name ; p ++ ) {
7448
7451
Py_CLEAR (p -> name_strobj );
7449
7452
}
7450
7453
slotdefs_initialized = 0 ;
@@ -7462,7 +7465,7 @@ update_slot(PyTypeObject *type, PyObject *name)
7462
7465
assert (PyUnicode_CheckExact (name ));
7463
7466
assert (PyUnicode_CHECK_INTERNED (name ));
7464
7467
7465
- init_slotdefs ( );
7468
+ assert ( slotdefs_initialized );
7466
7469
pp = ptrs ;
7467
7470
for (p = slotdefs ; p -> name ; p ++ ) {
7468
7471
if (p -> name_strobj == name )
@@ -7490,7 +7493,7 @@ fixup_slot_dispatchers(PyTypeObject *type)
7490
7493
{
7491
7494
slotdef * p ;
7492
7495
7493
- init_slotdefs ( );
7496
+ assert ( slotdefs_initialized );
7494
7497
for (p = slotdefs ; p -> name ; )
7495
7498
p = update_one_slot (type , p );
7496
7499
}
@@ -7503,7 +7506,7 @@ update_all_slots(PyTypeObject* type)
7503
7506
/* Clear the VALID_VERSION flag of 'type' and all its subclasses. */
7504
7507
PyType_Modified (type );
7505
7508
7506
- init_slotdefs ( );
7509
+ assert ( slotdefs_initialized );
7507
7510
for (p = slotdefs ; p -> name ; p ++ ) {
7508
7511
/* update_slot returns int but can't actually fail */
7509
7512
update_slot (type , p -> name_strobj );
@@ -7663,7 +7666,7 @@ add_operators(PyTypeObject *type)
7663
7666
PyObject * descr ;
7664
7667
void * * ptr ;
7665
7668
7666
- init_slotdefs ( );
7669
+ assert ( slotdefs_initialized );
7667
7670
for (p = slotdefs ; p -> name ; p ++ ) {
7668
7671
if (p -> wrapper == NULL )
7669
7672
continue ;
0 commit comments