Skip to content

Commit 3ea16f9

Browse files
authored
gh-116946: fully implement GC protocol for lzma objects (#138288)
1 parent 9be91f6 commit 3ea16f9

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

Modules/_lzmamodule.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -866,12 +866,13 @@ Compressor_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
866866
static void
867867
Compressor_dealloc(PyObject *op)
868868
{
869+
PyTypeObject *tp = Py_TYPE(op);
870+
PyObject_GC_UnTrack(op);
869871
Compressor *self = Compressor_CAST(op);
870872
lzma_end(&self->lzs);
871873
if (self->lock != NULL) {
872874
PyThread_free_lock(self->lock);
873875
}
874-
PyTypeObject *tp = Py_TYPE(self);
875876
tp->tp_free(self);
876877
Py_DECREF(tp);
877878
}
@@ -933,7 +934,7 @@ static PyType_Spec lzma_compressor_type_spec = {
933934
// lzma_compressor_type_spec does not have Py_TPFLAGS_BASETYPE flag
934935
// which prevents to create a subclass.
935936
// So calling PyType_GetModuleState() in this file is always safe.
936-
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE),
937+
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE | Py_TPFLAGS_HAVE_GC),
937938
.slots = lzma_compressor_type_slots,
938939
};
939940

@@ -1314,6 +1315,8 @@ _lzma_LZMADecompressor_impl(PyTypeObject *type, int format,
13141315
static void
13151316
Decompressor_dealloc(PyObject *op)
13161317
{
1318+
PyTypeObject *tp = Py_TYPE(op);
1319+
PyObject_GC_UnTrack(op);
13171320
Decompressor *self = Decompressor_CAST(op);
13181321
if(self->input_buffer != NULL)
13191322
PyMem_Free(self->input_buffer);
@@ -1323,7 +1326,6 @@ Decompressor_dealloc(PyObject *op)
13231326
if (self->lock != NULL) {
13241327
PyThread_free_lock(self->lock);
13251328
}
1326-
PyTypeObject *tp = Py_TYPE(self);
13271329
tp->tp_free(self);
13281330
Py_DECREF(tp);
13291331
}
@@ -1381,7 +1383,7 @@ static PyType_Spec lzma_decompressor_type_spec = {
13811383
// lzma_decompressor_type_spec does not have Py_TPFLAGS_BASETYPE flag
13821384
// which prevents to create a subclass.
13831385
// So calling PyType_GetModuleState() in this file is always safe.
1384-
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE),
1386+
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE | Py_TPFLAGS_HAVE_GC),
13851387
.slots = lzma_decompressor_type_slots,
13861388
};
13871389

0 commit comments

Comments
 (0)