Skip to content

Commit f772e19

Browse files
committed
Custom compress flush parser
1 parent edd7d97 commit f772e19

File tree

1 file changed

+25
-12
lines changed

1 file changed

+25
-12
lines changed

src/isal/isal_zlib.c

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,7 @@ isal_zlib_Compress_flush_impl(compobject *self, int mode)
734734
} else {
735735
PyErr_Format(IsalError,
736736
"Unsupported flush mode: %d", mode);
737+
return NULL;
737738
}
738739

739740
self->zst.avail_in = 0;
@@ -1010,19 +1011,31 @@ PyDoc_STRVAR(isal_zlib_Compress_flush__doc__,
10101011
static PyObject *
10111012
isal_zlib_Compress_flush(compobject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
10121013
{
1013-
PyObject *return_value = NULL;
1014-
static const char * const _keywords[] = {"", NULL};
1015-
static _PyArg_Parser _parser = {"|i:flush", _keywords, 0};
1016-
int mode = Z_FINISH;
1017-
1018-
if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
1019-
&mode)) {
1020-
goto exit;
1014+
Py_ssize_t mode;
1015+
if (nargs == 0) {
1016+
mode = Z_FINISH;
10211017
}
1022-
return_value = isal_zlib_Compress_flush_impl(self, mode);
1023-
1024-
exit:
1025-
return return_value;
1018+
else if (nargs == 1) {
1019+
PyObject *mode_arg = args[0];
1020+
if (PyLong_Check(mode_arg)) {
1021+
mode = PyLong_AsSsize_t(mode_arg);
1022+
}
1023+
else {
1024+
mode = PyNumber_AsSsize_t(mode_arg, PyExc_OverflowError);
1025+
}
1026+
if (mode == -1 && PyErr_Occurred()) {
1027+
return NULL;
1028+
}
1029+
}
1030+
else {
1031+
PyErr_Format(
1032+
PyExc_TypeError,
1033+
"flush() only takes 0 or 1 positional arguments got %d",
1034+
nargs
1035+
);
1036+
return NULL;
1037+
}
1038+
return isal_zlib_Compress_flush_impl(self, mode);
10261039
}
10271040
PyDoc_STRVAR(isal_zlib_Decompress_flush__doc__,
10281041
"flush($self, length=zlib.DEF_BUF_SIZE, /)\n"

0 commit comments

Comments
 (0)