Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions Modules/_bz2module.c
Original file line number Diff line number Diff line change
Expand Up @@ -381,14 +381,13 @@ _bz2_BZ2Compressor_impl(PyTypeObject *type, int compresslevel)
static void
BZ2Compressor_dealloc(PyObject *op)
{
PyTypeObject *tp = Py_TYPE(op);
PyObject_GC_UnTrack(op);
BZ2Compressor *self = _BZ2Compressor_CAST(op);
BZ2_bzCompressEnd(&self->bzs);
if (self->lock != NULL) {
PyThread_free_lock(self->lock);
}
tp->tp_free(self);
PyTypeObject *tp = Py_TYPE(self);
tp->tp_free((PyObject *)self);
Py_DECREF(tp);
}

Expand Down Expand Up @@ -421,7 +420,7 @@ static PyType_Spec bz2_compressor_type_spec = {
// bz2_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 | Py_TPFLAGS_HAVE_GC),
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE),
.slots = bz2_compressor_type_slots,
};

Expand Down Expand Up @@ -688,19 +687,19 @@ _bz2_BZ2Decompressor_impl(PyTypeObject *type)
static void
BZ2Decompressor_dealloc(PyObject *op)
{
PyTypeObject *tp = Py_TYPE(op);
PyObject_GC_UnTrack(op);
BZ2Decompressor *self = _BZ2Decompressor_CAST(op);

if (self->input_buffer != NULL) {
if(self->input_buffer != NULL) {
PyMem_Free(self->input_buffer);
}
BZ2_bzDecompressEnd(&self->bzs);
Py_CLEAR(self->unused_data);
if (self->lock != NULL) {
PyThread_free_lock(self->lock);
}
tp->tp_free(self);

PyTypeObject *tp = Py_TYPE(self);
tp->tp_free((PyObject *)self);
Py_DECREF(tp);
}

Expand Down Expand Up @@ -752,7 +751,7 @@ static PyType_Spec bz2_decompressor_type_spec = {
// bz2_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 | Py_TPFLAGS_HAVE_GC),
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE),
.slots = bz2_decompressor_type_slots,
};

Expand Down
51 changes: 10 additions & 41 deletions Modules/_hashopenssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -752,9 +752,7 @@ py_wrapper_EVP_MD_CTX_new(void)
static HASHobject *
new_hash_object(PyTypeObject *type)
{
assert(type != NULL);
assert(type->tp_alloc != NULL);
HASHobject *retval = (HASHobject *)type->tp_alloc(type, 0);
HASHobject *retval = PyObject_New(HASHobject, type);
if (retval == NULL) {
return NULL;
}
Expand Down Expand Up @@ -794,21 +792,13 @@ _hashlib_HASH_hash(HASHobject *self, const void *vp, Py_ssize_t len)
static void
_hashlib_HASH_dealloc(PyObject *op)
{
PyTypeObject *tp = Py_TYPE(op);
PyObject_GC_UnTrack(op);
HASHobject *self = HASHobject_CAST(op);
PyTypeObject *tp = Py_TYPE(self);
EVP_MD_CTX_free(self->ctx);
tp->tp_free(self);
PyObject_Free(self);
Py_DECREF(tp);
}

static int
_hashlib_HASH_traverse(PyObject *op, visitproc visit, void *arg)
{
Py_VISIT(Py_TYPE(op));
return 0;
}

static int
_hashlib_HASH_copy_locked(HASHobject *self, EVP_MD_CTX *new_ctx_p)
{
Expand Down Expand Up @@ -1003,7 +993,6 @@ PyDoc_STRVAR(HASHobject_type_doc,

static PyType_Slot HASHobject_type_slots[] = {
{Py_tp_dealloc, _hashlib_HASH_dealloc},
{Py_tp_traverse, _hashlib_HASH_traverse},
{Py_tp_repr, _hashlib_HASH_repr},
{Py_tp_doc, (char *)HASHobject_type_doc},
{Py_tp_methods, HASH_methods},
Expand All @@ -1019,7 +1008,6 @@ static PyType_Spec HASHobject_type_spec = {
| Py_TPFLAGS_BASETYPE
| Py_TPFLAGS_DISALLOW_INSTANTIATION
| Py_TPFLAGS_IMMUTABLETYPE
| Py_TPFLAGS_HAVE_GC
),
.slots = HASHobject_type_slots
};
Expand Down Expand Up @@ -1177,8 +1165,6 @@ PyDoc_STRVAR(HASHXOFobject_type_doc,
"digest_size -- number of bytes in this hashes output");

static PyType_Slot HASHXOFobject_type_slots[] = {
{Py_tp_dealloc, _hashlib_HASH_dealloc},
{Py_tp_traverse, _hashlib_HASH_traverse},
{Py_tp_doc, (char *)HASHXOFobject_type_doc},
{Py_tp_methods, HASHXOFobject_methods},
{Py_tp_getset, HASHXOFobject_getsets},
Expand All @@ -1193,7 +1179,6 @@ static PyType_Spec HASHXOFobject_type_spec = {
| Py_TPFLAGS_BASETYPE
| Py_TPFLAGS_DISALLOW_INSTANTIATION
| Py_TPFLAGS_IMMUTABLETYPE
| Py_TPFLAGS_HAVE_GC
),
.slots = HASHXOFobject_type_slots
};
Expand Down Expand Up @@ -1917,8 +1902,7 @@ _hashlib_hmac_new_impl(PyObject *module, Py_buffer *key, PyObject *msg_obj,
goto error;
}

assert(state->HMAC_type != NULL);
self = (HMACobject *)state->HMAC_type->tp_alloc(state->HMAC_type, 0);
self = PyObject_New(HMACobject, state->HMAC_type);
if (self == NULL) {
goto error;
}
Expand Down Expand Up @@ -2024,8 +2008,7 @@ _hashlib_HMAC_copy_impl(HMACobject *self)
return NULL;
}

PyTypeObject *type = Py_TYPE(self);
retval = (HMACobject *)type->tp_alloc(type, 0);
retval = PyObject_New(HMACobject, Py_TYPE(self));
if (retval == NULL) {
HMAC_CTX_free(ctx);
return NULL;
Expand All @@ -2039,24 +2022,16 @@ _hashlib_HMAC_copy_impl(HMACobject *self)
static void
_hmac_dealloc(PyObject *op)
{
PyTypeObject *tp = Py_TYPE(op);
PyObject_GC_UnTrack(op);
HMACobject *self = HMACobject_CAST(op);
PyTypeObject *tp = Py_TYPE(self);
if (self->ctx != NULL) {
HMAC_CTX_free(self->ctx);
self->ctx = NULL;
}
tp->tp_free(self);
PyObject_Free(self);
Py_DECREF(tp);
}

static int
_hashlib_HMAC_traverse(PyObject *op, visitproc visit, void *arg)
{
Py_VISIT(Py_TYPE(op));
return 0;
}

static PyObject *
_hmac_repr(PyObject *op)
{
Expand Down Expand Up @@ -2223,21 +2198,15 @@ static PyType_Slot HMACtype_slots[] = {
{Py_tp_doc, (char *)hmactype_doc},
{Py_tp_repr, _hmac_repr},
{Py_tp_dealloc, _hmac_dealloc},
{Py_tp_traverse, _hashlib_HMAC_traverse},
{Py_tp_methods, HMAC_methods},
{Py_tp_getset, HMAC_getset},
{0, NULL}
};

PyType_Spec HMACtype_spec = {
.name = "_hashlib.HMAC",
.basicsize = sizeof(HMACobject),
.flags = (
Py_TPFLAGS_DEFAULT
| Py_TPFLAGS_DISALLOW_INSTANTIATION
| Py_TPFLAGS_IMMUTABLETYPE
| Py_TPFLAGS_HAVE_GC
),
"_hashlib.HMAC", /* name */
sizeof(HMACobject), /* basicsize */
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION | Py_TPFLAGS_IMMUTABLETYPE,
.slots = HMACtype_slots,
};

Expand Down
10 changes: 4 additions & 6 deletions Modules/_lzmamodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -866,13 +866,12 @@ Compressor_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
static void
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(self);
Py_DECREF(tp);
}
Expand Down Expand Up @@ -934,7 +933,7 @@ static PyType_Spec lzma_compressor_type_spec = {
// 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 | Py_TPFLAGS_HAVE_GC),
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE),
.slots = lzma_compressor_type_slots,
};

Expand Down Expand Up @@ -1315,8 +1314,6 @@ _lzma_LZMADecompressor_impl(PyTypeObject *type, int format,
static void
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);
Expand All @@ -1326,6 +1323,7 @@ Decompressor_dealloc(PyObject *op)
if (self->lock != NULL) {
PyThread_free_lock(self->lock);
}
PyTypeObject *tp = Py_TYPE(self);
tp->tp_free(self);
Py_DECREF(tp);
}
Expand Down Expand Up @@ -1383,7 +1381,7 @@ static PyType_Spec lzma_decompressor_type_spec = {
// 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 | Py_TPFLAGS_HAVE_GC),
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE),
.slots = lzma_decompressor_type_slots,
};

Expand Down
Loading