@@ -454,20 +454,17 @@ class _ctypes.CType_Type "PyObject *" "clinic_state()->CType_Type"
454454static int
455455CType_Type_traverse (PyObject * self , visitproc visit , void * arg )
456456{
457- ctypes_state * st = get_module_state_by_def_final (Py_TYPE (self ));
458- if (st && st -> PyCType_Type ) {
459- StgInfo * info ;
460- if (PyStgInfo_FromType (st , self , & info ) < 0 ) {
461- PyErr_WriteUnraisable (self );
462- }
463- if (info ) {
464- Py_VISIT (info -> proto );
465- Py_VISIT (info -> argtypes );
466- Py_VISIT (info -> converters );
467- Py_VISIT (info -> restype );
468- Py_VISIT (info -> checker );
469- Py_VISIT (info -> module );
470- }
457+ StgInfo * info = _PyStgInfo_FromType_NoState (self );
458+ if (!info ) {
459+ PyErr_WriteUnraisable (self );
460+ }
461+ if (info ) {
462+ Py_VISIT (info -> proto );
463+ Py_VISIT (info -> argtypes );
464+ Py_VISIT (info -> converters );
465+ Py_VISIT (info -> restype );
466+ Py_VISIT (info -> checker );
467+ Py_VISIT (info -> module );
471468 }
472469 Py_VISIT (Py_TYPE (self ));
473470 return PyType_Type .tp_traverse (self , visit , arg );
@@ -488,38 +485,33 @@ ctype_clear_stginfo(StgInfo *info)
488485static int
489486CType_Type_clear (PyObject * self )
490487{
491- ctypes_state * st = get_module_state_by_def_final (Py_TYPE (self ));
492- if (st && st -> PyCType_Type ) {
493- StgInfo * info ;
494- if (PyStgInfo_FromType (st , self , & info ) < 0 ) {
495- PyErr_WriteUnraisable (self );
496- }
497- if (info ) {
498- ctype_clear_stginfo (info );
499- }
488+ StgInfo * info = _PyStgInfo_FromType_NoState (self );
489+ if (!info ) {
490+ PyErr_WriteUnraisable (self );
491+ }
492+ if (info ) {
493+ ctype_clear_stginfo (info );
500494 }
501495 return PyType_Type .tp_clear (self );
502496}
503497
504498static void
505499CType_Type_dealloc (PyObject * self )
506500{
507- ctypes_state * st = get_module_state_by_def_final (Py_TYPE (self ));
508- if (st && st -> PyCType_Type ) {
509- StgInfo * info ;
510- if (PyStgInfo_FromType (st , self , & info ) < 0 ) {
511- PyErr_WriteUnraisable (self );
512- }
513- if (info ) {
514- PyMem_Free (info -> ffi_type_pointer .elements );
515- info -> ffi_type_pointer .elements = NULL ;
516- PyMem_Free (info -> format );
517- info -> format = NULL ;
518- PyMem_Free (info -> shape );
519- info -> shape = NULL ;
520- ctype_clear_stginfo (info );
521- }
501+ StgInfo * info = _PyStgInfo_FromType_NoState (self );
502+ if (!info ) {
503+ PyErr_WriteUnraisable (self );
504+ }
505+ if (info ) {
506+ PyMem_Free (info -> ffi_type_pointer .elements );
507+ info -> ffi_type_pointer .elements = NULL ;
508+ PyMem_Free (info -> format );
509+ info -> format = NULL ;
510+ PyMem_Free (info -> shape );
511+ info -> shape = NULL ;
512+ ctype_clear_stginfo (info );
522513 }
514+
523515 PyTypeObject * tp = Py_TYPE (self );
524516 PyType_Type .tp_dealloc (self );
525517 Py_DECREF (tp );
@@ -5947,7 +5939,7 @@ module_free(void *module)
59475939
59485940static PyModuleDef_Slot module_slots [] = {
59495941 {Py_mod_exec , _ctypes_mod_exec },
5950- {Py_mod_multiple_interpreters , Py_MOD_MULTIPLE_INTERPRETERS_NOT_SUPPORTED },
5942+ {Py_mod_multiple_interpreters , Py_MOD_MULTIPLE_INTERPRETERS_SUPPORTED },
59515943 {Py_mod_gil , Py_MOD_GIL_NOT_USED },
59525944 {0 , NULL }
59535945};
0 commit comments