Skip to content

Commit edd7d97

Browse files
committed
Custom parser for decompress.flush
1 parent 60b1d76 commit edd7d97

File tree

1 file changed

+26
-14
lines changed

1 file changed

+26
-14
lines changed

src/isal/isal_zlib.c

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,24 +1035,36 @@ PyDoc_STRVAR(isal_zlib_Decompress_flush__doc__,
10351035

10361036

10371037
#define ISAL_ZLIB_DECOMPRESS_FLUSH_METHODDEF \
1038-
{"flush", (PyCFunction)(void(*)(void))isal_zlib_Decompress_flush, METH_FASTCALL|METH_KEYWORDS, isal_zlib_Decompress_flush__doc__}
1038+
{"flush", (PyCFunction)(void(*)(void))isal_zlib_Decompress_flush, METH_FASTCALL, isal_zlib_Decompress_flush__doc__}
10391039

10401040
static PyObject *
1041-
isal_zlib_Decompress_flush(decompobject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1041+
isal_zlib_Decompress_flush(decompobject *self, PyObject *const *args, Py_ssize_t nargs)
10421042
{
1043-
PyObject *return_value = NULL;
1044-
static const char * const _keywords[] = {"", NULL};
1045-
static _PyArg_Parser _parser = {"|n:flush", _keywords, 0};
1046-
Py_ssize_t length = DEF_BUF_SIZE;
1047-
1048-
if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
1049-
&length)) {
1050-
goto exit;
1043+
Py_ssize_t length;
1044+
if (nargs == 0) {
1045+
length = DEF_BUF_SIZE;
10511046
}
1052-
return_value = isal_zlib_Decompress_flush_impl(self, length);
1053-
1054-
exit:
1055-
return return_value;
1047+
else if (nargs == 1) {
1048+
PyObject *length_arg = args[0];
1049+
if (PyLong_Check(length_arg)) {
1050+
length = PyLong_AsSsize_t(length_arg);
1051+
}
1052+
else {
1053+
length = PyNumber_AsSsize_t(length_arg, PyExc_OverflowError);
1054+
}
1055+
if (length == -1 && PyErr_Occurred()) {
1056+
return NULL;
1057+
}
1058+
}
1059+
else {
1060+
PyErr_Format(
1061+
PyExc_TypeError,
1062+
"flush() only takes 0 or 1 positional arguments got %d",
1063+
nargs
1064+
);
1065+
return NULL;
1066+
}
1067+
return isal_zlib_Decompress_flush_impl(self, length);
10561068
}
10571069

10581070

0 commit comments

Comments
 (0)