PyThread_type_lock lock;
} Decompressor;
+#define Compressor_CAST(op) ((Compressor *)(op))
+#define Decompressor_CAST(op) ((Decompressor *)(op))
+
/* Helper functions. */
static int
}
static void
-Compressor_dealloc(Compressor *self)
+Compressor_dealloc(PyObject *op)
{
+ PyTypeObject *tp = Py_TYPE(op);
+ PyObject_GC_UnTrack(op);
+ Compressor *self = Compressor_CAST(op);
lzma_end(&self->lzs);
if (self->lock != NULL) {
PyThread_free_lock(self->lock);
}
- PyTypeObject *tp = Py_TYPE(self);
- tp->tp_free((PyObject *)self);
+ tp->tp_free(self);
Py_DECREF(tp);
}
};
static int
-Compressor_traverse(Compressor *self, visitproc visit, void *arg)
+Compressor_traverse(PyObject *self, visitproc visit, void *arg)
{
Py_VISIT(Py_TYPE(self));
return 0;
// lzma_compressor_type_spec does not have Py_TPFLAGS_BASETYPE flag
// which prevents to create a subclass.
// So calling PyType_GetModuleState() in this file is always safe.
- .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE),
+ .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE | Py_TPFLAGS_HAVE_GC),
.slots = lzma_compressor_type_slots,
};
}
static void
-Decompressor_dealloc(Decompressor *self)
+Decompressor_dealloc(PyObject *op)
{
+ PyTypeObject *tp = Py_TYPE(op);
+ PyObject_GC_UnTrack(op);
+ Decompressor *self = Decompressor_CAST(op);
if(self->input_buffer != NULL)
PyMem_Free(self->input_buffer);
if (self->lock != NULL) {
PyThread_free_lock(self->lock);
}
- PyTypeObject *tp = Py_TYPE(self);
- tp->tp_free((PyObject *)self);
+ tp->tp_free(self);
Py_DECREF(tp);
}
static int
-Decompressor_traverse(Decompressor *self, visitproc visit, void *arg)
+Decompressor_traverse(PyObject *self, visitproc visit, void *arg)
{
Py_VISIT(Py_TYPE(self));
return 0;
// lzma_decompressor_type_spec does not have Py_TPFLAGS_BASETYPE flag
// which prevents to create a subclass.
// So calling PyType_GetModuleState() in this file is always safe.
- .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE),
+ .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE | Py_TPFLAGS_HAVE_GC),
.slots = lzma_decompressor_type_slots,
};