Skip to content

Commit cbdbaab

Browse files
committed
Simplify decompressobj parser
1 parent e45600c commit cbdbaab

File tree

1 file changed

+9
-27
lines changed

1 file changed

+9
-27
lines changed

src/isal/isal_zlib.c

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -906,41 +906,23 @@ PyDoc_STRVAR(isal_zlib_decompressobj__doc__,
906906
" dictionary as used by the compressor that produced the input data.");
907907

908908
#define ISAL_ZLIB_DECOMPRESSOBJ_METHODDEF \
909-
{"decompressobj", (PyCFunction)(void(*)(void))isal_zlib_decompressobj, METH_FASTCALL|METH_KEYWORDS, isal_zlib_decompressobj__doc__}
909+
{"decompressobj", (PyCFunction)(void(*)(void))isal_zlib_decompressobj, METH_VARARGS|METH_KEYWORDS, isal_zlib_decompressobj__doc__}
910910

911911
static PyObject *
912-
isal_zlib_decompressobj(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
912+
isal_zlib_decompressobj(PyObject *module, PyObject *args, PyObject *kwargs)
913913
{
914914
PyObject *return_value = NULL;
915-
static const char * const _keywords[] = {"wbits", "zdict", NULL};
916-
static _PyArg_Parser _parser = {NULL, _keywords, "decompressobj", 0};
917-
PyObject *argsbuf[2];
918-
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
915+
char *keywords[] = {"wbits", "zdict", NULL};
916+
char *format = "|iO:decompressobj";
919917
int wbits = ISAL_DEF_MAX_HIST_BITS;
920918
PyObject *zdict = NULL;
921919

922-
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 2, 0, argsbuf);
923-
if (!args) {
924-
goto exit;
925-
}
926-
if (!noptargs) {
927-
goto skip_optional_pos;
928-
}
929-
if (args[0]) {
930-
wbits = _PyLong_AsInt(args[0]);
931-
if (wbits == -1 && PyErr_Occurred()) {
932-
goto exit;
933-
}
934-
if (!--noptargs) {
935-
goto skip_optional_pos;
936-
}
920+
if (!PyArg_ParseTupleAndKeywords(
921+
args, kwargs, format, keywords,
922+
&wbits, &zdict)) {
923+
return NULL;
937924
}
938-
zdict = args[1];
939-
skip_optional_pos:
940-
return_value = isal_zlib_decompressobj_impl(module, wbits, zdict);
941-
942-
exit:
943-
return return_value;
925+
return isal_zlib_decompressobj_impl(module, wbits, zdict);
944926
}
945927

946928
PyDoc_STRVAR(isal_zlib_Compress_compress__doc__,

0 commit comments

Comments
 (0)