@@ -126,6 +126,9 @@ typedef struct {
126
126
PyThread_type_lock lock ;
127
127
} Decompressor ;
128
128
129
+ #define Compressor_CAST (op ) ((Compressor *)(op))
130
+ #define Decompressor_CAST (op ) ((Decompressor *)(op))
131
+
129
132
/* Helper functions. */
130
133
131
134
static int
@@ -857,14 +860,16 @@ Compressor_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
857
860
}
858
861
859
862
static void
860
- Compressor_dealloc (Compressor * self )
863
+ Compressor_dealloc (PyObject * op )
861
864
{
865
+ PyTypeObject * tp = Py_TYPE (op );
866
+ PyObject_GC_UnTrack (op );
867
+ Compressor * self = Compressor_CAST (op );
862
868
lzma_end (& self -> lzs );
863
869
if (self -> lock != NULL ) {
864
870
PyThread_free_lock (self -> lock );
865
871
}
866
- PyTypeObject * tp = Py_TYPE (self );
867
- tp -> tp_free ((PyObject * )self );
872
+ tp -> tp_free (self );
868
873
Py_DECREF (tp );
869
874
}
870
875
@@ -875,7 +880,7 @@ static PyMethodDef Compressor_methods[] = {
875
880
};
876
881
877
882
static int
878
- Compressor_traverse (Compressor * self , visitproc visit , void * arg )
883
+ Compressor_traverse (PyObject * self , visitproc visit , void * arg )
879
884
{
880
885
Py_VISIT (Py_TYPE (self ));
881
886
return 0 ;
@@ -925,7 +930,7 @@ static PyType_Spec lzma_compressor_type_spec = {
925
930
// lzma_compressor_type_spec does not have Py_TPFLAGS_BASETYPE flag
926
931
// which prevents to create a subclass.
927
932
// So calling PyType_GetModuleState() in this file is always safe.
928
- .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE ),
933
+ .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE | Py_TPFLAGS_HAVE_GC ),
929
934
.slots = lzma_compressor_type_slots ,
930
935
};
931
936
@@ -1304,8 +1309,11 @@ _lzma_LZMADecompressor_impl(PyTypeObject *type, int format,
1304
1309
}
1305
1310
1306
1311
static void
1307
- Decompressor_dealloc (Decompressor * self )
1312
+ Decompressor_dealloc (PyObject * op )
1308
1313
{
1314
+ PyTypeObject * tp = Py_TYPE (op );
1315
+ PyObject_GC_UnTrack (op );
1316
+ Decompressor * self = Decompressor_CAST (op );
1309
1317
if (self -> input_buffer != NULL )
1310
1318
PyMem_Free (self -> input_buffer );
1311
1319
@@ -1314,13 +1322,12 @@ Decompressor_dealloc(Decompressor *self)
1314
1322
if (self -> lock != NULL ) {
1315
1323
PyThread_free_lock (self -> lock );
1316
1324
}
1317
- PyTypeObject * tp = Py_TYPE (self );
1318
- tp -> tp_free ((PyObject * )self );
1325
+ tp -> tp_free (self );
1319
1326
Py_DECREF (tp );
1320
1327
}
1321
1328
1322
1329
static int
1323
- Decompressor_traverse (Decompressor * self , visitproc visit , void * arg )
1330
+ Decompressor_traverse (PyObject * self , visitproc visit , void * arg )
1324
1331
{
1325
1332
Py_VISIT (Py_TYPE (self ));
1326
1333
return 0 ;
@@ -1372,7 +1379,7 @@ static PyType_Spec lzma_decompressor_type_spec = {
1372
1379
// lzma_decompressor_type_spec does not have Py_TPFLAGS_BASETYPE flag
1373
1380
// which prevents to create a subclass.
1374
1381
// So calling PyType_GetModuleState() in this file is always safe.
1375
- .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE ),
1382
+ .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE | Py_TPFLAGS_HAVE_GC ),
1376
1383
.slots = lzma_decompressor_type_slots ,
1377
1384
};
1378
1385
0 commit comments