Skip to content

Commit c155d19

Browse files
committed
reduce diff
1 parent fb60618 commit c155d19

File tree

1 file changed

+14
-18
lines changed

1 file changed

+14
-18
lines changed

Modules/zlibmodule.c

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -273,15 +273,13 @@ static compobject *
273273
newcompobject(PyTypeObject *type)
274274
{
275275
compobject *self;
276-
self = PyObject_GC_New(compobject, type);
277-
if (self == NULL) {
276+
assert(type != NULL && type->tp_alloc != NULL);
277+
self = _compobject_CAST(type->tp_alloc(type, 0));
278+
if (self == NULL)
278279
return NULL;
279-
}
280-
281-
/* Initialize the remaining fields (untouched by PyObject_GC_New()). */
282-
const size_t offset = sizeof(struct { PyObject_HEAD });
283-
memset((char *)self + offset, 0, sizeof(*self) - offset);
284-
280+
self->eof = 0;
281+
self->is_initialised = 0;
282+
self->zdict = NULL;
285283
self->unused_data = Py_GetConstant(Py_CONSTANT_EMPTY_BYTES);
286284
if (self->unused_data == NULL) {
287285
goto error;
@@ -734,7 +732,7 @@ compobject_dealloc_impl(PyObject *op, int (*dealloc)(z_streamp))
734732
Py_XDECREF(self->unused_data);
735733
Py_XDECREF(self->unconsumed_tail);
736734
Py_XDECREF(self->zdict);
737-
PyObject_GC_Del(self);
735+
type->tp_free(self);
738736
Py_DECREF(type);
739737
}
740738

@@ -1404,7 +1402,7 @@ ZlibDecompressor_dealloc(PyObject *op)
14041402
PyMem_Free(self->input_buffer);
14051403
Py_CLEAR(self->unused_data);
14061404
Py_CLEAR(self->zdict);
1407-
PyObject_GC_Del(self);
1405+
type->tp_free(self);
14081406
Py_DECREF(type);
14091407
}
14101408

@@ -1759,25 +1757,23 @@ static PyObject *
17591757
zlib__ZlibDecompressor_impl(PyTypeObject *type, int wbits, PyObject *zdict)
17601758
/*[clinic end generated code: output=1065607df0d33baa input=9ebad0be6de226e2]*/
17611759
{
1760+
assert(type != NULL && type->tp_alloc != NULL);
17621761
zlibstate *state = PyType_GetModuleState(type);
1763-
ZlibDecompressor *self = PyObject_GC_New(ZlibDecompressor, type);
1762+
ZlibDecompressor *self = ZlibDecompressor_CAST(type->tp_alloc(type, 0));
17641763
if (self == NULL) {
17651764
return NULL;
17661765
}
1767-
1768-
/* Initialize the remaining fields (untouched by PyObject_GC_New()). */
1769-
const size_t offset = sizeof(struct { PyObject_HEAD });
1770-
memset((char *)self + offset, 0, sizeof(*self) - offset);
1771-
1766+
self->eof = 0;
17721767
self->needs_input = 1;
1768+
self->avail_in_real = 0;
1769+
self->input_buffer = NULL;
1770+
self->input_buffer_size = 0;
17731771
self->zdict = Py_XNewRef(zdict);
1774-
17751772
self->zst.opaque = NULL;
17761773
self->zst.zalloc = PyZlib_Malloc;
17771774
self->zst.zfree = PyZlib_Free;
17781775
self->zst.next_in = NULL;
17791776
self->zst.avail_in = 0;
1780-
17811777
self->unused_data = PyBytes_FromStringAndSize(NULL, 0);
17821778
if (self->unused_data == NULL) {
17831779
goto error;

0 commit comments

Comments
 (0)