@@ -315,19 +315,13 @@ static PyGetSetDef Dialect_getsetlist[] = {
315315static void
316316Dialect_dealloc (DialectObj * self )
317317{
318- PyObject_GC_UnTrack (self );
319318 PyTypeObject * tp = Py_TYPE (self );
320- Py_CLEAR (self -> lineterminator );
321- tp -> tp_free ((PyObject * )self );
319+ PyObject_GC_UnTrack (self );
320+ tp -> tp_clear ((PyObject * )self );
321+ PyObject_GC_Del (self );
322322 Py_DECREF (tp );
323323}
324324
325- static void
326- Dialect_finalize (DialectObj * self )
327- {
328- Py_CLEAR (self -> lineterminator );
329- }
330-
331325static char * dialect_kws [] = {
332326 "dialect" ,
333327 "delimiter" ,
@@ -514,8 +508,16 @@ PyDoc_STRVAR(Dialect_Type_doc,
514508"The Dialect type records CSV parsing and generation options.\n" );
515509
516510static int
517- Dialect_traverse ( PyObject * self , visitproc visit , void * arg )
511+ Dialect_clear ( DialectObj * self )
518512{
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 );
519521 Py_VISIT (Py_TYPE (self ));
520522 return 0 ;
521523}
@@ -526,8 +528,8 @@ static PyType_Slot Dialect_Type_slots[] = {
526528 {Py_tp_getset , Dialect_getsetlist },
527529 {Py_tp_new , dialect_new },
528530 {Py_tp_methods , dialect_methods },
529- {Py_tp_finalize , Dialect_finalize },
530531 {Py_tp_dealloc , Dialect_dealloc },
532+ {Py_tp_clear , Dialect_clear },
531533 {Py_tp_traverse , Dialect_traverse },
532534 {0 , NULL }
533535};
@@ -894,29 +896,11 @@ Reader_dealloc(ReaderObj *self)
894896{
895897 PyTypeObject * tp = Py_TYPE (self );
896898 PyObject_GC_UnTrack (self );
897- Py_CLEAR (self -> dialect );
898- Py_CLEAR (self -> input_iter );
899- Py_CLEAR (self -> fields );
900- if (self -> field != NULL ) {
901- PyMem_Free (self -> field );
902- self -> field = NULL ;
903- }
899+ tp -> tp_clear ((PyObject * )self );
904900 PyObject_GC_Del (self );
905901 Py_DECREF (tp );
906902}
907903
908- static void
909- Reader_finalize (ReaderObj * self )
910- {
911- Py_CLEAR (self -> dialect );
912- Py_CLEAR (self -> input_iter );
913- Py_CLEAR (self -> fields );
914- if (self -> field != NULL ) {
915- PyMem_Free (self -> field );
916- self -> field = NULL ;
917- }
918- }
919-
920904static int
921905Reader_traverse (ReaderObj * self , visitproc visit , void * arg )
922906{
@@ -933,6 +917,10 @@ Reader_clear(ReaderObj *self)
933917 Py_CLEAR (self -> dialect );
934918 Py_CLEAR (self -> input_iter );
935919 Py_CLEAR (self -> fields );
920+ if (self -> field != NULL ) {
921+ PyMem_Free (self -> field );
922+ self -> field = NULL ;
923+ }
936924 return 0 ;
937925}
938926
@@ -958,12 +946,11 @@ static struct PyMemberDef Reader_memberlist[] = {
958946static PyType_Slot Reader_Type_slots [] = {
959947 {Py_tp_doc , (char * )Reader_Type_doc },
960948 {Py_tp_traverse , Reader_traverse },
961- {Py_tp_clear , Reader_clear },
962949 {Py_tp_iter , PyObject_SelfIter },
963950 {Py_tp_iternext , Reader_iternext },
964951 {Py_tp_methods , Reader_methods },
965952 {Py_tp_members , Reader_memberlist },
966- {Py_tp_finalize , Reader_finalize },
953+ {Py_tp_clear , Reader_clear },
967954 {Py_tp_dealloc , Reader_dealloc },
968955 {0 , NULL }
969956};
@@ -1359,27 +1346,22 @@ Writer_clear(WriterObj *self)
13591346 Py_CLEAR (self -> dialect );
13601347 Py_CLEAR (self -> write );
13611348 Py_CLEAR (self -> error_obj );
1349+ if (self -> rec != NULL ) {
1350+ PyMem_Free (self -> rec );
1351+ }
13621352 return 0 ;
13631353}
13641354
13651355static void
13661356Writer_dealloc (WriterObj * self )
13671357{
1368- PyObject_GC_UnTrack (self );
13691358 PyTypeObject * tp = Py_TYPE (self );
1359+ PyObject_GC_UnTrack (self );
13701360 tp -> tp_clear ((PyObject * )self );
1361+ PyObject_GC_Del (self );
13711362 Py_DECREF (tp );
13721363}
13731364
1374- static void
1375- Writer_finalize (WriterObj * self )
1376- {
1377- Writer_clear (self );
1378- if (self -> rec != NULL ) {
1379- PyMem_Free (self -> rec );
1380- }
1381- }
1382-
13831365PyDoc_STRVAR (Writer_Type_doc ,
13841366"CSV writer\n"
13851367"\n"
@@ -1388,7 +1370,6 @@ PyDoc_STRVAR(Writer_Type_doc,
13881370);
13891371
13901372static PyType_Slot Writer_Type_slots [] = {
1391- {Py_tp_finalize , Writer_finalize },
13921373 {Py_tp_doc , (char * )Writer_Type_doc },
13931374 {Py_tp_traverse , Writer_traverse },
13941375 {Py_tp_clear , Writer_clear },
0 commit comments