@@ -156,32 +156,31 @@ isal_zlib_adler32(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
156
156
Py_buffer data = {NULL , NULL };
157
157
uint32_t value = 1 ;
158
158
159
- if (!_PyArg_CheckPositional ("adler32" , nargs , 1 , 2 )) {
160
- goto exit ;
159
+ if (nargs < 1 || nargs > 2 ) {
160
+ PyErr_Format (
161
+ PyExc_TypeError ,
162
+ "adler32 takes exactly 1 or 2 arguments, got %d" ,
163
+ nargs );
164
+ return NULL ;
161
165
}
162
166
if (PyObject_GetBuffer (args [0 ], & data , PyBUF_SIMPLE ) != 0 ) {
163
- goto exit ;
167
+ return NULL ;
164
168
}
165
169
if (!PyBuffer_IsContiguous (& data , 'C' )) {
166
- _PyArg_BadArgument ("adler32" , "argument 1" , "contiguous buffer" , args [0 ]);
167
- goto exit ;
168
- }
169
- if (nargs < 2 ) {
170
- goto skip_optional ;
170
+ PyErr_SetString (PyExc_ValueError , "data is not a contiguous buffer" );
171
+ PyBuffer_Release (& data );
172
+ return NULL ;
171
173
}
172
- value = (uint32_t )PyLong_AsUnsignedLongMask (args [1 ]);
173
- if (value == (uint32_t )-1 && PyErr_Occurred ()) {
174
- goto exit ;
174
+ if (nargs > 1 ) {
175
+ value = (uint32_t )PyLong_AsUnsignedLongMask (args [1 ]);
176
+ if (value == (uint32_t )-1 && PyErr_Occurred ()) {
177
+ PyBuffer_Release (& data );
178
+ return NULL ;
179
+ }
175
180
}
176
- skip_optional :
177
181
value = isal_adler32 (value , data .buf , (uint64_t )data .len );
178
182
return_value = PyLong_FromUnsignedLong (value & 0xffffffffU );
179
-
180
- exit :
181
- /* Cleanup for data */
182
- if (data .obj ) {
183
- PyBuffer_Release (& data );
184
- }
183
+ PyBuffer_Release (& data );
185
184
return return_value ;
186
185
}
187
186
0 commit comments