@@ -441,19 +441,35 @@ static PyType_Spec structparam_spec = {
441
441
static int
442
442
CType_Type_traverse (PyObject * self , visitproc visit , void * arg )
443
443
{
444
+ ctypes_state * st = GLOBAL_STATE ();
445
+ if (st && st -> PyCType_Type ) {
446
+ StgInfo * info ;
447
+ if (PyStgInfo_FromType (st , self , & info ) < 0 ) {
448
+ PyErr_WriteUnraisable (self );
449
+ }
450
+ if (info ) {
451
+ Py_VISIT (info -> proto );
452
+ Py_VISIT (info -> argtypes );
453
+ Py_VISIT (info -> converters );
454
+ Py_VISIT (info -> restype );
455
+ Py_VISIT (info -> checker );
456
+ Py_VISIT (info -> module );
457
+ }
458
+ }
444
459
Py_VISIT (Py_TYPE (self ));
445
- return 0 ;
460
+ return PyType_Type . tp_traverse ( self , visit , arg ) ;
446
461
}
447
462
448
- static void
449
- _ctype_clear_stginfo (StgInfo * info )
463
+ void
464
+ ctype_clear_stginfo (StgInfo * info )
450
465
{
451
466
assert (info );
452
467
Py_CLEAR (info -> proto );
453
468
Py_CLEAR (info -> argtypes );
454
469
Py_CLEAR (info -> converters );
455
470
Py_CLEAR (info -> restype );
456
471
Py_CLEAR (info -> checker );
472
+ Py_CLEAR (info -> module );
457
473
}
458
474
459
475
static int
@@ -463,13 +479,13 @@ CType_Type_clear(PyObject *self)
463
479
if (st && st -> PyCType_Type ) {
464
480
StgInfo * info ;
465
481
if (PyStgInfo_FromType (st , self , & info ) < 0 ) {
466
- return -1 ;
482
+ PyErr_WriteUnraisable ( self ) ;
467
483
}
468
484
if (info ) {
469
- _ctype_clear_stginfo (info );
485
+ ctype_clear_stginfo (info );
470
486
}
471
487
}
472
- return 0 ;
488
+ return PyType_Type . tp_clear ( self ) ;
473
489
}
474
490
475
491
static void
@@ -489,7 +505,7 @@ CType_Type_dealloc(PyObject *self)
489
505
info -> format = NULL ;
490
506
PyMem_Free (info -> shape );
491
507
info -> shape = NULL ;
492
- _ctype_clear_stginfo (info );
508
+ ctype_clear_stginfo (info );
493
509
}
494
510
}
495
511
@@ -522,6 +538,10 @@ CType_Type_sizeof(PyObject *self)
522
538
return PyLong_FromSsize_t (size );
523
539
}
524
540
541
+ static PyObject *
542
+ CType_Type_repeat (PyObject * self , Py_ssize_t length );
543
+
544
+
525
545
static PyMethodDef ctype_methods [] = {
526
546
{"__sizeof__" , _PyCFunction_CAST (CType_Type_sizeof ),
527
547
METH_NOARGS , PyDoc_STR ("Return memory consumption of the type object." )},
@@ -533,6 +553,8 @@ static PyType_Slot ctype_type_slots[] = {
533
553
{Py_tp_clear , CType_Type_clear },
534
554
{Py_tp_dealloc , CType_Type_dealloc },
535
555
{Py_tp_methods , ctype_methods },
556
+ // Sequence protocol.
557
+ {Py_sq_repeat , CType_Type_repeat },
536
558
{0 , NULL },
537
559
};
538
560
@@ -978,7 +1000,7 @@ static PyMethodDef CDataType_methods[] = {
978
1000
};
979
1001
980
1002
static PyObject *
981
- CDataType_repeat (PyObject * self , Py_ssize_t length )
1003
+ CType_Type_repeat (PyObject * self , Py_ssize_t length )
982
1004
{
983
1005
if (length < 0 )
984
1006
return PyErr_Format (PyExc_ValueError ,
@@ -988,35 +1010,6 @@ CDataType_repeat(PyObject *self, Py_ssize_t length)
988
1010
return PyCArrayType_from_ctype (st , self , length );
989
1011
}
990
1012
991
- static int
992
- CDataType_clear (PyTypeObject * self )
993
- {
994
- ctypes_state * st = GLOBAL_STATE ();
995
- StgInfo * info ;
996
- if (PyStgInfo_FromType (st , (PyObject * )self , & info ) < 0 ) {
997
- return -1 ;
998
- }
999
- if (info ) {
1000
- Py_CLEAR (info -> proto );
1001
- }
1002
- return PyType_Type .tp_clear ((PyObject * )self );
1003
- }
1004
-
1005
- static int
1006
- CDataType_traverse (PyTypeObject * self , visitproc visit , void * arg )
1007
- {
1008
- ctypes_state * st = GLOBAL_STATE ();
1009
- StgInfo * info ;
1010
- if (PyStgInfo_FromType (st , (PyObject * )self , & info ) < 0 ) {
1011
- return -1 ;
1012
- }
1013
- if (info ) {
1014
- Py_VISIT (info -> proto );
1015
- }
1016
- Py_VISIT (Py_TYPE (self ));
1017
- return PyType_Type .tp_traverse ((PyObject * )self , visit , arg );
1018
- }
1019
-
1020
1013
static int
1021
1014
PyCStructType_setattro (PyObject * self , PyObject * key , PyObject * value )
1022
1015
{
@@ -1047,39 +1040,29 @@ UnionType_setattro(PyObject *self, PyObject *key, PyObject *value)
1047
1040
static PyType_Slot pycstruct_type_slots [] = {
1048
1041
{Py_tp_setattro , PyCStructType_setattro },
1049
1042
{Py_tp_doc , PyDoc_STR ("metatype for the CData Objects" )},
1050
- {Py_tp_traverse , CDataType_traverse },
1051
- {Py_tp_clear , CDataType_clear },
1052
1043
{Py_tp_methods , CDataType_methods },
1053
1044
{Py_tp_init , PyCStructType_init },
1054
-
1055
- // Sequence protocol.
1056
- {Py_sq_repeat , CDataType_repeat },
1057
1045
{0 , NULL },
1058
1046
};
1059
1047
1060
1048
static PyType_Spec pycstruct_type_spec = {
1061
1049
.name = "_ctypes.PyCStructType" ,
1062
- .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC |
1050
+ .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE |
1063
1051
Py_TPFLAGS_IMMUTABLETYPE ),
1064
1052
.slots = pycstruct_type_slots ,
1065
1053
};
1066
1054
1067
1055
static PyType_Slot union_type_slots [] = {
1068
1056
{Py_tp_setattro , UnionType_setattro },
1069
1057
{Py_tp_doc , PyDoc_STR ("metatype for the Union Objects" )},
1070
- {Py_tp_traverse , CDataType_traverse },
1071
- {Py_tp_clear , CDataType_clear },
1072
1058
{Py_tp_methods , CDataType_methods },
1073
1059
{Py_tp_init , UnionType_init },
1074
-
1075
- // Sequence protocol.
1076
- {Py_sq_repeat , CDataType_repeat },
1077
1060
{0 , NULL },
1078
1061
};
1079
1062
1080
1063
static PyType_Spec union_type_spec = {
1081
1064
.name = "_ctypes.UnionType" ,
1082
- .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC |
1065
+ .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE |
1083
1066
Py_TPFLAGS_IMMUTABLETYPE ),
1084
1067
.slots = union_type_slots ,
1085
1068
};
@@ -1305,19 +1288,14 @@ static PyMethodDef PyCPointerType_methods[] = {
1305
1288
1306
1289
static PyType_Slot pycpointer_type_slots [] = {
1307
1290
{Py_tp_doc , PyDoc_STR ("metatype for the Pointer Objects" )},
1308
- {Py_tp_traverse , CDataType_traverse },
1309
- {Py_tp_clear , CDataType_clear },
1310
1291
{Py_tp_methods , PyCPointerType_methods },
1311
1292
{Py_tp_init , PyCPointerType_init },
1312
-
1313
- // Sequence protocol.
1314
- {Py_sq_repeat , CDataType_repeat },
1315
1293
{0 , NULL },
1316
1294
};
1317
1295
1318
1296
static PyType_Spec pycpointer_type_spec = {
1319
1297
.name = "_ctypes.PyCPointerType" ,
1320
- .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC |
1298
+ .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE |
1321
1299
Py_TPFLAGS_IMMUTABLETYPE ),
1322
1300
.slots = pycpointer_type_slots ,
1323
1301
};
@@ -1640,19 +1618,14 @@ PyCArrayType_init(PyObject *self, PyObject *args, PyObject *kwds)
1640
1618
1641
1619
static PyType_Slot pycarray_type_slots [] = {
1642
1620
{Py_tp_doc , PyDoc_STR ("metatype for the Array Objects" )},
1643
- {Py_tp_traverse , CDataType_traverse },
1644
1621
{Py_tp_methods , CDataType_methods },
1645
1622
{Py_tp_init , PyCArrayType_init },
1646
- {Py_tp_clear , CDataType_clear },
1647
-
1648
- // Sequence protocol.
1649
- {Py_sq_repeat , CDataType_repeat },
1650
1623
{0 , NULL },
1651
1624
};
1652
1625
1653
1626
static PyType_Spec pycarray_type_spec = {
1654
1627
.name = "_ctypes.PyCArrayType" ,
1655
- .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC |
1628
+ .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE |
1656
1629
Py_TPFLAGS_IMMUTABLETYPE ),
1657
1630
.slots = pycarray_type_slots ,
1658
1631
};
@@ -2315,17 +2288,12 @@ static PyType_Slot pycsimple_type_slots[] = {
2315
2288
{Py_tp_doc , PyDoc_STR ("metatype for the PyCSimpleType Objects" )},
2316
2289
{Py_tp_methods , PyCSimpleType_methods },
2317
2290
{Py_tp_init , PyCSimpleType_init },
2318
- {Py_tp_traverse , CDataType_traverse },
2319
- {Py_tp_clear , CDataType_clear },
2320
-
2321
- // Sequence protocol.
2322
- {Py_sq_repeat , CDataType_repeat },
2323
2291
{0 , NULL },
2324
2292
};
2325
2293
2326
2294
static PyType_Spec pycsimple_type_spec = {
2327
2295
.name = "_ctypes.PyCSimpleType" ,
2328
- .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC |
2296
+ .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE |
2329
2297
Py_TPFLAGS_IMMUTABLETYPE ),
2330
2298
.slots = pycsimple_type_slots ,
2331
2299
};
@@ -2570,19 +2538,14 @@ PyCFuncPtrType_init(PyObject *self, PyObject *args, PyObject *kwds)
2570
2538
2571
2539
static PyType_Slot pycfuncptr_type_slots [] = {
2572
2540
{Py_tp_doc , PyDoc_STR ("metatype for C function pointers" )},
2573
- {Py_tp_traverse , CDataType_traverse },
2574
- {Py_tp_clear , CDataType_clear },
2575
2541
{Py_tp_methods , CDataType_methods },
2576
2542
{Py_tp_init , PyCFuncPtrType_init },
2577
-
2578
- // Sequence protocol.
2579
- {Py_sq_repeat , CDataType_repeat },
2580
2543
{0 , NULL },
2581
2544
};
2582
2545
2583
2546
static PyType_Spec pycfuncptr_type_spec = {
2584
2547
.name = "_ctypes.PyCFuncPtrType" ,
2585
- .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC |
2548
+ .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE |
2586
2549
Py_TPFLAGS_IMMUTABLETYPE ),
2587
2550
.slots = pycfuncptr_type_slots ,
2588
2551
};
0 commit comments