@@ -129,6 +129,9 @@ typedef struct {
129
129
PyThread_type_lock lock ;
130
130
} BZ2Decompressor ;
131
131
132
+ #define _BZ2Compressor_CAST (op ) ((BZ2Compressor *)(op))
133
+ #define _BZ2Decompressor_CAST (op ) ((BZ2Decompressor *)(op))
134
+
132
135
/* Helper functions. */
133
136
134
137
static int
@@ -376,19 +379,21 @@ _bz2_BZ2Compressor_impl(PyTypeObject *type, int compresslevel)
376
379
}
377
380
378
381
static void
379
- BZ2Compressor_dealloc (BZ2Compressor * self )
382
+ BZ2Compressor_dealloc (PyObject * op )
380
383
{
384
+ PyTypeObject * tp = Py_TYPE (op );
385
+ PyObject_GC_UnTrack (op );
386
+ BZ2Compressor * self = _BZ2Compressor_CAST (op );
381
387
BZ2_bzCompressEnd (& self -> bzs );
382
388
if (self -> lock != NULL ) {
383
389
PyThread_free_lock (self -> lock );
384
390
}
385
- PyTypeObject * tp = Py_TYPE (self );
386
- tp -> tp_free ((PyObject * )self );
391
+ tp -> tp_free (self );
387
392
Py_DECREF (tp );
388
393
}
389
394
390
395
static int
391
- BZ2Compressor_traverse (BZ2Compressor * self , visitproc visit , void * arg )
396
+ BZ2Compressor_traverse (PyObject * self , visitproc visit , void * arg )
392
397
{
393
398
Py_VISIT (Py_TYPE (self ));
394
399
return 0 ;
@@ -416,7 +421,7 @@ static PyType_Spec bz2_compressor_type_spec = {
416
421
// bz2_compressor_type_spec does not have Py_TPFLAGS_BASETYPE flag
417
422
// which prevents to create a subclass.
418
423
// So calling PyType_GetModuleState() in this file is always safe.
419
- .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE ),
424
+ .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE | Py_TPFLAGS_HAVE_GC ),
420
425
.slots = bz2_compressor_type_slots ,
421
426
};
422
427
@@ -680,8 +685,11 @@ _bz2_BZ2Decompressor_impl(PyTypeObject *type)
680
685
}
681
686
682
687
static void
683
- BZ2Decompressor_dealloc (BZ2Decompressor * self )
688
+ BZ2Decompressor_dealloc (PyObject * op )
684
689
{
690
+ PyTypeObject * tp = Py_TYPE (op );
691
+ PyObject_GC_UnTrack (op );
692
+ BZ2Decompressor * self = _BZ2Decompressor_CAST (op );
685
693
if (self -> input_buffer != NULL ) {
686
694
PyMem_Free (self -> input_buffer );
687
695
}
@@ -690,14 +698,12 @@ BZ2Decompressor_dealloc(BZ2Decompressor *self)
690
698
if (self -> lock != NULL ) {
691
699
PyThread_free_lock (self -> lock );
692
700
}
693
-
694
- PyTypeObject * tp = Py_TYPE (self );
695
- tp -> tp_free ((PyObject * )self );
701
+ tp -> tp_free (self );
696
702
Py_DECREF (tp );
697
703
}
698
704
699
705
static int
700
- BZ2Decompressor_traverse (BZ2Decompressor * self , visitproc visit , void * arg )
706
+ BZ2Decompressor_traverse (PyObject * self , visitproc visit , void * arg )
701
707
{
702
708
Py_VISIT (Py_TYPE (self ));
703
709
return 0 ;
@@ -744,7 +750,7 @@ static PyType_Spec bz2_decompressor_type_spec = {
744
750
// bz2_decompressor_type_spec does not have Py_TPFLAGS_BASETYPE flag
745
751
// which prevents to create a subclass.
746
752
// So calling PyType_GetModuleState() in this file is always safe.
747
- .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE ),
753
+ .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE | Py_TPFLAGS_HAVE_GC ),
748
754
.slots = bz2_decompressor_type_slots ,
749
755
};
750
756
0 commit comments