@@ -314,6 +314,16 @@ managed_static_type_state_clear(PyInterpreterState *interp, PyTypeObject *self,
314
314
}
315
315
}
316
316
317
+ static PyTypeObject *
318
+ managed_static_type_get_def (PyTypeObject * self , int isbuiltin )
319
+ {
320
+ size_t index = managed_static_type_index_get (self );
321
+ size_t full_index = isbuiltin
322
+ ? index
323
+ : index + _Py_MAX_MANAGED_STATIC_BUILTIN_TYPES ;
324
+ return & _PyRuntime .types .managed_static .types [full_index ].def ;
325
+ }
326
+
317
327
// Also see _PyStaticType_InitBuiltin() and _PyStaticType_FiniBuiltin().
318
328
319
329
/* end static builtin helpers */
@@ -5840,7 +5850,6 @@ fini_static_type(PyInterpreterState *interp, PyTypeObject *type,
5840
5850
5841
5851
_PyStaticType_ClearWeakRefs (interp , type );
5842
5852
managed_static_type_state_clear (interp , type , isbuiltin , final );
5843
- /* We leave _Py_TPFLAGS_STATIC_BUILTIN set on tp_flags. */
5844
5853
}
5845
5854
5846
5855
void
@@ -7850,7 +7859,7 @@ inherit_slots(PyTypeObject *type, PyTypeObject *base)
7850
7859
return 0 ;
7851
7860
}
7852
7861
7853
- static int add_operators (PyTypeObject * );
7862
+ static int add_operators (PyTypeObject * , PyTypeObject * );
7854
7863
static int add_tp_new_wrapper (PyTypeObject * type );
7855
7864
7856
7865
#define COLLECTION_FLAGS (Py_TPFLAGS_SEQUENCE | Py_TPFLAGS_MAPPING)
@@ -8015,10 +8024,10 @@ type_dict_set_doc(PyTypeObject *type)
8015
8024
8016
8025
8017
8026
static int
8018
- type_ready_fill_dict (PyTypeObject * type )
8027
+ type_ready_fill_dict (PyTypeObject * type , PyTypeObject * def )
8019
8028
{
8020
8029
/* Add type-specific descriptors to tp_dict */
8021
- if (add_operators (type ) < 0 ) {
8030
+ if (add_operators (type , def ) < 0 ) {
8022
8031
return -1 ;
8023
8032
}
8024
8033
if (type_add_methods (type ) < 0 ) {
@@ -8337,7 +8346,7 @@ type_ready_post_checks(PyTypeObject *type)
8337
8346
8338
8347
8339
8348
static int
8340
- type_ready (PyTypeObject * type , int initial )
8349
+ type_ready (PyTypeObject * type , PyTypeObject * def , int initial )
8341
8350
{
8342
8351
ASSERT_TYPE_LOCK_HELD ();
8343
8352
@@ -8376,7 +8385,7 @@ type_ready(PyTypeObject *type, int initial)
8376
8385
if (type_ready_set_new (type , initial ) < 0 ) {
8377
8386
goto error ;
8378
8387
}
8379
- if (type_ready_fill_dict (type ) < 0 ) {
8388
+ if (type_ready_fill_dict (type , def ) < 0 ) {
8380
8389
goto error ;
8381
8390
}
8382
8391
if (initial ) {
@@ -8433,7 +8442,7 @@ PyType_Ready(PyTypeObject *type)
8433
8442
int res ;
8434
8443
BEGIN_TYPE_LOCK ();
8435
8444
if (!(type -> tp_flags & Py_TPFLAGS_READY )) {
8436
- res = type_ready (type , 1 );
8445
+ res = type_ready (type , NULL , 1 );
8437
8446
} else {
8438
8447
res = 0 ;
8439
8448
assert (_PyType_CheckConsistency (type ));
@@ -8469,14 +8478,20 @@ init_static_type(PyInterpreterState *interp, PyTypeObject *self,
8469
8478
8470
8479
managed_static_type_state_init (interp , self , isbuiltin , initial );
8471
8480
8481
+ PyTypeObject * def = managed_static_type_get_def (self , isbuiltin );
8482
+ if (initial ) {
8483
+ memcpy (def , self , sizeof (PyTypeObject ));
8484
+ }
8485
+
8472
8486
int res ;
8473
8487
BEGIN_TYPE_LOCK ();
8474
- res = type_ready (self , initial );
8488
+ res = type_ready (self , def , initial );
8475
8489
END_TYPE_LOCK ();
8476
8490
if (res < 0 ) {
8477
8491
_PyStaticType_ClearWeakRefs (interp , self );
8478
8492
managed_static_type_state_clear (interp , self , isbuiltin , initial );
8479
8493
}
8494
+
8480
8495
return res ;
8481
8496
}
8482
8497
@@ -11064,17 +11079,22 @@ recurse_down_subclasses(PyTypeObject *type, PyObject *attr_name,
11064
11079
infinite recursion here.) */
11065
11080
11066
11081
static int
11067
- add_operators (PyTypeObject * type )
11082
+ add_operators (PyTypeObject * type , PyTypeObject * def )
11068
11083
{
11069
11084
PyObject * dict = lookup_tp_dict (type );
11070
11085
pytype_slotdef * p ;
11071
11086
PyObject * descr ;
11072
11087
void * * ptr ;
11073
11088
11089
+ assert (def == NULL || (type -> tp_flags & _Py_TPFLAGS_STATIC_BUILTIN ));
11090
+ if (def == NULL ) {
11091
+ def = type ;
11092
+ }
11093
+
11074
11094
for (p = slotdefs ; p -> name ; p ++ ) {
11075
11095
if (p -> wrapper == NULL )
11076
11096
continue ;
11077
- ptr = slotptr (type , p -> offset );
11097
+ ptr = slotptr (def , p -> offset );
11078
11098
if (!ptr || !* ptr )
11079
11099
continue ;
11080
11100
int r = PyDict_Contains (dict , p -> name_strobj );
0 commit comments