@@ -166,11 +166,6 @@ isal_zlib_adler32(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
166
166
if (PyObject_GetBuffer (args [0 ], & data , PyBUF_SIMPLE ) != 0 ) {
167
167
return NULL ;
168
168
}
169
- if (!PyBuffer_IsContiguous (& data , 'C' )) {
170
- PyErr_SetString (PyExc_ValueError , "data is not a contiguous buffer" );
171
- PyBuffer_Release (& data );
172
- return NULL ;
173
- }
174
169
if (nargs > 1 ) {
175
170
value = (uint32_t )PyLong_AsUnsignedLongMask (args [1 ]);
176
171
if (value == (uint32_t )-1 && PyErr_Occurred ()) {
@@ -205,32 +200,26 @@ isal_zlib_crc32(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
205
200
Py_buffer data = {NULL , NULL };
206
201
uint32_t value = 0 ;
207
202
208
- if (!_PyArg_CheckPositional ("crc32" , nargs , 1 , 2 )) {
209
- goto exit ;
203
+ if (nargs < 1 || nargs > 2 ) {
204
+ PyErr_Format (
205
+ PyExc_TypeError ,
206
+ "crc32 takes exactly 1 or 2 arguments, got %d" ,
207
+ nargs );
208
+ return NULL ;
210
209
}
211
210
if (PyObject_GetBuffer (args [0 ], & data , PyBUF_SIMPLE ) != 0 ) {
212
- goto exit ;
213
- }
214
- if (!PyBuffer_IsContiguous (& data , 'C' )) {
215
- _PyArg_BadArgument ("crc32" , "argument 1" , "contiguous buffer" , args [0 ]);
216
- goto exit ;
217
- }
218
- if (nargs < 2 ) {
219
- goto skip_optional ;
211
+ return NULL ;
220
212
}
221
- value = (uint32_t )PyLong_AsUnsignedLongMask (args [1 ]);
222
- if (value == (uint32_t )-1 && PyErr_Occurred ()) {
223
- goto exit ;
213
+ if (nargs > 1 ) {
214
+ value = (uint32_t )PyLong_AsUnsignedLongMask (args [1 ]);
215
+ if (value == (uint32_t )-1 && PyErr_Occurred ()) {
216
+ PyBuffer_Release (& data );
217
+ return NULL ;
218
+ }
224
219
}
225
- skip_optional :
226
220
value = crc32_gzip_refl (value , data .buf , (uint64_t )data .len );
227
221
return_value = PyLong_FromUnsignedLong (value & 0xffffffffU );
228
-
229
- exit :
230
- /* Cleanup for data */
231
- if (data .obj ) {
232
- PyBuffer_Release (& data );
233
- }
222
+ PyBuffer_Release (& data );
234
223
return return_value ;
235
224
}
236
225
PyDoc_STRVAR (zlib_compress__doc__ ,
0 commit comments