Skip to content

Commit e70b361

Browse files
committed
Custom parser for decompress
1 parent c49cc36 commit e70b361

File tree

1 file changed

+10
-45
lines changed

1 file changed

+10
-45
lines changed

src/isal/igzip_lib.c

Lines changed: 10 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -398,61 +398,26 @@ PyDoc_STRVAR(igzip_lib_IgzipDecompressor_decompress__doc__,
398398
"the unused_data attribute.");
399399

400400
#define IGZIP_LIB_IGZIPDECOMPRESSOR_DECOMPRESS_METHODDEF \
401-
{"decompress", (PyCFunction)(void(*)(void))igzip_lib_IgzipDecompressor_decompress, METH_FASTCALL|METH_KEYWORDS, igzip_lib_IgzipDecompressor_decompress__doc__}
401+
{"decompress", (PyCFunction)(void(*)(void))igzip_lib_IgzipDecompressor_decompress, METH_VARARGS|METH_KEYWORDS, igzip_lib_IgzipDecompressor_decompress__doc__}
402402

403403
static PyObject *
404-
igzip_lib_IgzipDecompressor_decompress(IgzipDecompressor *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
404+
igzip_lib_IgzipDecompressor_decompress(IgzipDecompressor *self, PyObject *args, PyObject *kwargs)
405405
{
406-
PyObject *return_value = NULL;
407-
static const char * const _keywords[] = {"data", "max_length", NULL};
408-
static _PyArg_Parser _parser = {NULL, _keywords, "decompress", 0};
409-
PyObject *argsbuf[2];
410-
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
406+
char *keywords[] = {"", "max_length", NULL};
407+
char *format = "y*|n:decompress";
411408
Py_buffer data = {NULL, NULL};
412409
Py_ssize_t max_length = -1;
413410

414-
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
415-
if (!args) {
416-
goto exit;
417-
}
418-
if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
419-
goto exit;
420-
}
421-
if (!PyBuffer_IsContiguous(&data, 'C')) {
422-
_PyArg_BadArgument("decompress", "argument 'data'", "contiguous buffer", args[0]);
423-
goto exit;
424-
}
425-
if (!noptargs) {
426-
goto skip_optional_pos;
427-
}
428-
if (PyFloat_Check(args[1])) {
429-
PyErr_SetString(PyExc_TypeError,
430-
"integer argument expected, got float" );
431-
goto exit;
432-
}
433-
{
434-
Py_ssize_t ival = -1;
435-
PyObject *iobj = PyNumber_Index(args[1]);
436-
if (iobj != NULL) {
437-
ival = PyLong_AsSsize_t(iobj);
438-
Py_DECREF(iobj);
439-
}
440-
if (ival == -1 && PyErr_Occurred()) {
441-
goto exit;
442-
}
443-
max_length = ival;
444-
}
445-
skip_optional_pos:
446-
return_value = igzip_lib_IgzipDecompressor_decompress_impl(self, &data, max_length);
447-
448-
exit:
449-
/* Cleanup for data */
450-
if (data.obj) {
451-
PyBuffer_Release(&data);
411+
if (!PyArg_ParseTupleAndKeywords(
412+
args, kwargs, format, keywords, &data, &max_length)) {
413+
return NULL;
452414
}
453415

416+
PyObject *return_value = igzip_lib_IgzipDecompressor_decompress_impl(self, &data, max_length);
417+
PyBuffer_Release(&data);
454418
return return_value;
455419
}
420+
456421
PyDoc_STRVAR(igzip_lib_IgzipDecompressor___init____doc__,
457422
"IgzipDecompressor(flag=0, hist_bits=15, zdict=b\'\')\n"
458423
"--\n"

0 commit comments

Comments
 (0)