Skip to content

Commit 1915b52

Browse files
committed
Inline newfunc
1 parent 7ba8c5a commit 1915b52

File tree

1 file changed

+45
-50
lines changed

1 file changed

+45
-50
lines changed

src/isal/igzip_libmodule.c

Lines changed: 45 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -44,50 +44,6 @@ IgzipDecompressor_dealloc(IgzipDecompressor *self)
4444
Py_TYPE(self)->tp_free((PyObject *)self);
4545
}
4646

47-
static int
48-
igzip_lib_IgzipDecompressor___init___impl(IgzipDecompressor *self,
49-
int flag,
50-
int hist_bits,
51-
PyObject *zdict)
52-
{
53-
int err;
54-
self->needs_input = 1;
55-
self->avail_in_real = 0;
56-
self->input_buffer = NULL;
57-
self->input_buffer_size = 0;
58-
self->zdict = zdict;
59-
Py_XSETREF(self->unused_data, PyBytes_FromStringAndSize(NULL, 0));
60-
if (self->unused_data == NULL)
61-
goto error;
62-
isal_inflate_init(&(self->state));
63-
self->state.hist_bits = hist_bits;
64-
self->state.crc_flag = flag;
65-
if (self->zdict != NULL){
66-
Py_buffer zdict_buf;
67-
if (PyObject_GetBuffer(self->zdict, &zdict_buf, PyBUF_SIMPLE) == -1) {
68-
goto error;
69-
}
70-
if ((size_t)zdict_buf.len > UINT32_MAX) {
71-
PyErr_SetString(PyExc_OverflowError,
72-
"zdict length does not fit in an unsigned 32-bits int");
73-
PyBuffer_Release(&zdict_buf);
74-
}
75-
err = isal_inflate_set_dict(&(self->state), zdict_buf.buf,
76-
(uint32_t)zdict_buf.len);
77-
PyBuffer_Release(&zdict_buf);
78-
if (err != ISAL_DECOMP_OK) {
79-
isal_inflate_error(err);
80-
goto error;
81-
}
82-
}
83-
return 0;
84-
85-
error:
86-
Py_CLEAR(self->unused_data);
87-
Py_CLEAR(self->zdict);
88-
return -1;
89-
}
90-
9147
/* Decompress data of length d->bzs_avail_in_real in d->state.next_in. The output
9248
buffer is allocated dynamically and returned. At most max_length bytes are
9349
returned, so some of the input may not be consumed. d->state.next_in and
@@ -430,8 +386,10 @@ PyDoc_STRVAR(igzip_lib_IgzipDecompressor___init____doc__,
430386
"\n"
431387
"For one-shot decompression, use the decompress() function instead.");
432388

433-
static int
434-
igzip_lib_IgzipDecompressor___init__(PyObject *self, PyObject *args, PyObject *kwargs)
389+
static PyObject *
390+
igzip_lib_IgzipDecompressor__new__(PyTypeObject *type,
391+
PyObject *args,
392+
PyObject *kwargs)
435393
{
436394
char *keywords[] = {"flag", "hist_bits", "zdict", NULL};
437395
char *format = "|iiO:IgzipDecompressor";
@@ -441,9 +399,47 @@ igzip_lib_IgzipDecompressor___init__(PyObject *self, PyObject *args, PyObject *k
441399

442400
if (!PyArg_ParseTupleAndKeywords(
443401
args, kwargs, format, keywords, &flag, &hist_bits, &zdict)) {
444-
return -1;
402+
return NULL;
403+
}
404+
IgzipDecompressor *self = PyObject_New(IgzipDecompressor, type);
405+
int err;
406+
self->eof = 0;
407+
self->needs_input = 1;
408+
self->avail_in_real = 0;
409+
self->input_buffer = NULL;
410+
self->input_buffer_size = 0;
411+
self->zdict = zdict;
412+
self->unused_data = PyBytes_FromStringAndSize(NULL, 0);
413+
if (self->unused_data == NULL) {
414+
Py_CLEAR(self);
415+
return NULL;
416+
}
417+
isal_inflate_init(&(self->state));
418+
self->state.hist_bits = hist_bits;
419+
self->state.crc_flag = flag;
420+
if (self->zdict != NULL){
421+
Py_buffer zdict_buf;
422+
if (PyObject_GetBuffer(self->zdict, &zdict_buf, PyBUF_SIMPLE) == -1) {
423+
Py_CLEAR(self);
424+
return -1;;
425+
}
426+
if ((size_t)zdict_buf.len > UINT32_MAX) {
427+
PyErr_SetString(PyExc_OverflowError,
428+
"zdict length does not fit in an unsigned 32-bits int");
429+
PyBuffer_Release(&zdict_buf);
430+
Py_CLEAR(self);
431+
return NULL;
432+
}
433+
err = isal_inflate_set_dict(&(self->state), zdict_buf.buf,
434+
(uint32_t)zdict_buf.len);
435+
PyBuffer_Release(&zdict_buf);
436+
if (err != ISAL_DECOMP_OK) {
437+
isal_inflate_error(err);
438+
Py_CLEAR(self);
439+
return NULL;
440+
}
445441
}
446-
return igzip_lib_IgzipDecompressor___init___impl((IgzipDecompressor *)self, flag, hist_bits, zdict);
442+
return (PyObject *)self;
447443
}
448444

449445
static PyMethodDef IgzipDecompressor_methods[] = {
@@ -484,8 +480,7 @@ static PyTypeObject IgzipDecompressor_Type = {
484480
.tp_doc = igzip_lib_IgzipDecompressor___init____doc__,
485481
.tp_methods = IgzipDecompressor_methods,
486482
.tp_members = IgzipDecompressor_members,
487-
.tp_init = igzip_lib_IgzipDecompressor___init__,
488-
.tp_new = PyType_GenericNew,
483+
.tp_new = igzip_lib_IgzipDecompressor__new__,
489484
};
490485

491486
static PyMethodDef IgzipLibMethods[] = {

0 commit comments

Comments
 (0)