Skip to content

Commit c49cc36

Browse files
committed
Custom parser or igzip_lib.decompress
1 parent 8aa80d1 commit c49cc36

File tree

1 file changed

+10
-68
lines changed

1 file changed

+10
-68
lines changed

src/isal/igzip_lib.c

Lines changed: 10 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -356,83 +356,25 @@ PyDoc_STRVAR(igzip_lib_decompress__doc__,
356356
" The initial output buffer size.");
357357

358358
#define IGZIP_LIB_DECOMPRESS_METHODDEF \
359-
{"decompress", (PyCFunction)(void(*)(void))igzip_lib_decompress, METH_FASTCALL|METH_KEYWORDS, igzip_lib_decompress__doc__}
359+
{"decompress", (PyCFunction)(void(*)(void))igzip_lib_decompress, METH_VARARGS|METH_KEYWORDS, igzip_lib_decompress__doc__}
360360

361361
static PyObject *
362-
igzip_lib_decompress(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
362+
igzip_lib_decompress(PyObject *module, PyObject *args, PyObject *kwargs)
363363
{
364-
PyObject *return_value = NULL;
365-
static const char * const _keywords[] = {"", "flag", "hist_bits", "bufsize", NULL};
366-
static _PyArg_Parser _parser = {NULL, _keywords, "decompress", 0};
367-
PyObject *argsbuf[4];
368-
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
364+
static const char *keywords[] = {"", "flag", "hist_bits", "bufsize", NULL};
365+
char *format ="y*|iin:decompress";
369366
Py_buffer data = {NULL, NULL};
370367
int flag = DECOMP_DEFLATE;
371368
int hist_bits = ISAL_DEF_MAX_HIST_BITS;
372369
Py_ssize_t bufsize = DEF_BUF_SIZE;
373370

374-
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 4, 0, argsbuf);
375-
if (!args) {
376-
goto exit;
377-
}
378-
if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
379-
goto exit;
380-
}
381-
if (!PyBuffer_IsContiguous(&data, 'C')) {
382-
_PyArg_BadArgument("decompress", "argument 1", "contiguous buffer", args[0]);
383-
goto exit;
384-
}
385-
if (!noptargs) {
386-
goto skip_optional_pos;
387-
}
388-
if (args[1]) {
389-
flag = _PyLong_AsInt(args[1]);
390-
if (flag == -1 && PyErr_Occurred()) {
391-
goto exit;
392-
}
393-
if (!--noptargs) {
394-
goto skip_optional_pos;
395-
}
396-
}
397-
if (args[2]) {
398-
hist_bits = _PyLong_AsInt(args[2]);
399-
if (hist_bits == -1 && PyErr_Occurred()) {
400-
goto exit;
401-
}
402-
if (!--noptargs) {
403-
goto skip_optional_pos;
404-
}
405-
}
406-
if (args[2]) {
407-
flag = _PyLong_AsInt(args[2]);
408-
if (flag == -1 && PyErr_Occurred()) {
409-
goto exit;
410-
}
411-
if (!--noptargs) {
412-
goto skip_optional_pos;
413-
}
414-
}
415-
{
416-
Py_ssize_t ival = -1;
417-
PyObject *iobj = PyNumber_Index(args[3]);
418-
if (iobj != NULL) {
419-
ival = PyLong_AsSsize_t(iobj);
420-
Py_DECREF(iobj);
421-
}
422-
if (ival == -1 && PyErr_Occurred()) {
423-
goto exit;
424-
}
425-
bufsize = ival;
426-
}
427-
skip_optional_pos:
428-
return_value = igzip_lib_decompress_impl(&data, flag, hist_bits, bufsize);
429-
430-
exit:
431-
/* Cleanup for data */
432-
if (data.obj) {
433-
PyBuffer_Release(&data);
371+
if (!PyArg_ParseTupleAndKeywords(
372+
args, kwargs, format, keywords,
373+
&data, &flag, &hist_bits, &bufsize)) {
374+
return NULL;
434375
}
435-
376+
PyObject * return_value = igzip_lib_decompress_impl(&data, flag, hist_bits, bufsize);
377+
PyBuffer_Release(&data);
436378
return return_value;
437379
}
438380

0 commit comments

Comments
 (0)