@@ -316,17 +316,12 @@ static void
316
316
Dialect_dealloc (DialectObj * self )
317
317
{
318
318
PyTypeObject * tp = Py_TYPE (self );
319
- Py_CLEAR (self -> lineterminator );
320
- tp -> tp_free ((PyObject * )self );
319
+ PyObject_GC_UnTrack (self );
320
+ tp -> tp_clear ((PyObject * )self );
321
+ PyObject_GC_Del (self );
321
322
Py_DECREF (tp );
322
323
}
323
324
324
- static void
325
- Dialect_finalize (DialectObj * self )
326
- {
327
- Py_CLEAR (self -> lineterminator );
328
- }
329
-
330
325
static char * dialect_kws [] = {
331
326
"dialect" ,
332
327
"delimiter" ,
@@ -512,21 +507,37 @@ PyDoc_STRVAR(Dialect_Type_doc,
512
507
"\n"
513
508
"The Dialect type records CSV parsing and generation options.\n" );
514
509
510
+ static int
511
+ Dialect_clear (DialectObj * self )
512
+ {
513
+ Py_CLEAR (self -> lineterminator );
514
+ return 0 ;
515
+ }
516
+
517
+ static int
518
+ Dialect_traverse (DialectObj * self , visitproc visit , void * arg )
519
+ {
520
+ Py_VISIT (self -> lineterminator );
521
+ Py_VISIT (Py_TYPE (self ));
522
+ return 0 ;
523
+ }
524
+
515
525
static PyType_Slot Dialect_Type_slots [] = {
516
526
{Py_tp_doc , (char * )Dialect_Type_doc },
517
527
{Py_tp_members , Dialect_memberlist },
518
528
{Py_tp_getset , Dialect_getsetlist },
519
529
{Py_tp_new , dialect_new },
520
530
{Py_tp_methods , dialect_methods },
521
- {Py_tp_finalize , Dialect_finalize },
522
531
{Py_tp_dealloc , Dialect_dealloc },
532
+ {Py_tp_clear , Dialect_clear },
533
+ {Py_tp_traverse , Dialect_traverse },
523
534
{0 , NULL }
524
535
};
525
536
526
537
PyType_Spec Dialect_Type_spec = {
527
538
.name = "_csv.Dialect" ,
528
539
.basicsize = sizeof (DialectObj ),
529
- .flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE ,
540
+ .flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC ,
530
541
.slots = Dialect_Type_slots ,
531
542
};
532
543
@@ -885,9 +896,7 @@ Reader_dealloc(ReaderObj *self)
885
896
{
886
897
PyTypeObject * tp = Py_TYPE (self );
887
898
PyObject_GC_UnTrack (self );
888
- Py_CLEAR (self -> dialect );
889
- Py_CLEAR (self -> input_iter );
890
- Py_CLEAR (self -> fields );
899
+ tp -> tp_clear ((PyObject * )self );
891
900
if (self -> field != NULL ) {
892
901
PyMem_Free (self -> field );
893
902
self -> field = NULL ;
@@ -896,24 +905,13 @@ Reader_dealloc(ReaderObj *self)
896
905
Py_DECREF (tp );
897
906
}
898
907
899
- static void
900
- Reader_finalize (ReaderObj * self )
901
- {
902
- Py_CLEAR (self -> dialect );
903
- Py_CLEAR (self -> input_iter );
904
- Py_CLEAR (self -> fields );
905
- if (self -> field != NULL ) {
906
- PyMem_Free (self -> field );
907
- self -> field = NULL ;
908
- }
909
- }
910
-
911
908
static int
912
909
Reader_traverse (ReaderObj * self , visitproc visit , void * arg )
913
910
{
914
911
Py_VISIT (self -> dialect );
915
912
Py_VISIT (self -> input_iter );
916
913
Py_VISIT (self -> fields );
914
+ Py_VISIT (Py_TYPE (self ));
917
915
return 0 ;
918
916
}
919
917
@@ -948,12 +946,11 @@ static struct PyMemberDef Reader_memberlist[] = {
948
946
static PyType_Slot Reader_Type_slots [] = {
949
947
{Py_tp_doc , (char * )Reader_Type_doc },
950
948
{Py_tp_traverse , Reader_traverse },
951
- {Py_tp_clear , Reader_clear },
952
949
{Py_tp_iter , PyObject_SelfIter },
953
950
{Py_tp_iternext , Reader_iternext },
954
951
{Py_tp_methods , Reader_methods },
955
952
{Py_tp_members , Reader_memberlist },
956
- {Py_tp_finalize , Reader_finalize },
953
+ {Py_tp_clear , Reader_clear },
957
954
{Py_tp_dealloc , Reader_dealloc },
958
955
{0 , NULL }
959
956
};
@@ -1339,6 +1336,7 @@ Writer_traverse(WriterObj *self, visitproc visit, void *arg)
1339
1336
Py_VISIT (self -> dialect );
1340
1337
Py_VISIT (self -> write );
1341
1338
Py_VISIT (self -> error_obj );
1339
+ Py_VISIT (Py_TYPE (self ));
1342
1340
return 0 ;
1343
1341
}
1344
1342
@@ -1352,12 +1350,16 @@ Writer_clear(WriterObj *self)
1352
1350
}
1353
1351
1354
1352
static void
1355
- Writer_finalize (WriterObj * self )
1353
+ Writer_dealloc (WriterObj * self )
1356
1354
{
1357
- Writer_clear (self );
1355
+ PyTypeObject * tp = Py_TYPE (self );
1356
+ PyObject_GC_UnTrack (self );
1357
+ tp -> tp_clear ((PyObject * )self );
1358
1358
if (self -> rec != NULL ) {
1359
1359
PyMem_Free (self -> rec );
1360
1360
}
1361
+ PyObject_GC_Del (self );
1362
+ Py_DECREF (tp );
1361
1363
}
1362
1364
1363
1365
PyDoc_STRVAR (Writer_Type_doc ,
@@ -1368,10 +1370,10 @@ PyDoc_STRVAR(Writer_Type_doc,
1368
1370
);
1369
1371
1370
1372
static PyType_Slot Writer_Type_slots [] = {
1371
- {Py_tp_finalize , Writer_finalize },
1372
1373
{Py_tp_doc , (char * )Writer_Type_doc },
1373
1374
{Py_tp_traverse , Writer_traverse },
1374
1375
{Py_tp_clear , Writer_clear },
1376
+ {Py_tp_dealloc , Writer_dealloc },
1375
1377
{Py_tp_methods , Writer_methods },
1376
1378
{Py_tp_members , Writer_memberlist },
1377
1379
{0 , NULL }
0 commit comments