@@ -734,6 +734,7 @@ isal_zlib_Compress_flush_impl(compobject *self, int mode)
734
734
} else {
735
735
PyErr_Format (IsalError ,
736
736
"Unsupported flush mode: %d" , mode );
737
+ return NULL ;
737
738
}
738
739
739
740
self -> zst .avail_in = 0 ;
@@ -1010,19 +1011,31 @@ PyDoc_STRVAR(isal_zlib_Compress_flush__doc__,
1010
1011
static PyObject *
1011
1012
isal_zlib_Compress_flush (compobject * self , PyObject * const * args , Py_ssize_t nargs , PyObject * kwnames )
1012
1013
{
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 ;
1021
1017
}
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 );
1026
1039
}
1027
1040
PyDoc_STRVAR (isal_zlib_Decompress_flush__doc__ ,
1028
1041
"flush($self, length=zlib.DEF_BUF_SIZE, /)\n"
0 commit comments