@@ -28,41 +28,42 @@ set_zstd_error(const _zstd_state* const state,
28
28
char * msg ;
29
29
assert (ZSTD_isError (zstd_ret ));
30
30
31
- switch (type )
32
- {
33
- case ERR_DECOMPRESS :
34
- msg = "Unable to decompress Zstandard data: %s" ;
35
- break ;
36
- case ERR_COMPRESS :
37
- msg = "Unable to compress Zstandard data: %s" ;
38
- break ;
39
-
40
- case ERR_LOAD_D_DICT :
41
- msg = "Unable to load Zstandard dictionary or prefix for decompression: %s" ;
42
- break ;
43
- case ERR_LOAD_C_DICT :
44
- msg = "Unable to load Zstandard dictionary or prefix for compression: %s" ;
45
- break ;
46
-
47
- case ERR_GET_C_BOUNDS :
48
- msg = "Unable to get zstd compression parameter bounds: %s" ;
49
- break ;
50
- case ERR_GET_D_BOUNDS :
51
- msg = "Unable to get zstd decompression parameter bounds: %s" ;
52
- break ;
53
- case ERR_SET_C_LEVEL :
54
- msg = "Unable to set zstd compression level: %s" ;
55
- break ;
56
-
57
- case ERR_TRAIN_DICT :
58
- msg = "Unable to train the Zstandard dictionary: %s" ;
59
- break ;
60
- case ERR_FINALIZE_DICT :
61
- msg = "Unable to finalize the Zstandard dictionary: %s" ;
62
- break ;
63
-
64
- default :
65
- Py_UNREACHABLE ();
31
+ switch (type ) {
32
+ case ERR_DECOMPRESS :
33
+ msg = "Unable to decompress Zstandard data: %s" ;
34
+ break ;
35
+ case ERR_COMPRESS :
36
+ msg = "Unable to compress Zstandard data: %s" ;
37
+ break ;
38
+
39
+ case ERR_LOAD_D_DICT :
40
+ msg = "Unable to load Zstandard dictionary or prefix for "
41
+ "decompression: %s" ;
42
+ break ;
43
+ case ERR_LOAD_C_DICT :
44
+ msg = "Unable to load Zstandard dictionary or prefix for "
45
+ "compression: %s" ;
46
+ break ;
47
+
48
+ case ERR_GET_C_BOUNDS :
49
+ msg = "Unable to get zstd compression parameter bounds: %s" ;
50
+ break ;
51
+ case ERR_GET_D_BOUNDS :
52
+ msg = "Unable to get zstd decompression parameter bounds: %s" ;
53
+ break ;
54
+ case ERR_SET_C_LEVEL :
55
+ msg = "Unable to set zstd compression level: %s" ;
56
+ break ;
57
+
58
+ case ERR_TRAIN_DICT :
59
+ msg = "Unable to train the Zstandard dictionary: %s" ;
60
+ break ;
61
+ case ERR_FINALIZE_DICT :
62
+ msg = "Unable to finalize the Zstandard dictionary: %s" ;
63
+ break ;
64
+
65
+ default :
66
+ Py_UNREACHABLE ();
66
67
}
67
68
PyErr_Format (state -> ZstdError , msg , ZSTD_getErrorName (zstd_ret ));
68
69
}
@@ -183,7 +184,7 @@ calculate_samples_stats(PyBytesObject *samples_bytes, PyObject *samples_sizes,
183
184
chunks_number = Py_SIZE (samples_sizes );
184
185
if ((size_t ) chunks_number > UINT32_MAX ) {
185
186
PyErr_Format (PyExc_ValueError ,
186
- "The number of samples should be <= %u." , UINT32_MAX );
187
+ "The number of samples should be <= %u." , UINT32_MAX );
187
188
return -1 ;
188
189
}
189
190
@@ -200,16 +201,17 @@ calculate_samples_stats(PyBytesObject *samples_bytes, PyObject *samples_sizes,
200
201
(* chunk_sizes )[i ] = PyLong_AsSize_t (size );
201
202
if ((* chunk_sizes )[i ] == (size_t )-1 && PyErr_Occurred ()) {
202
203
PyErr_Format (PyExc_ValueError ,
203
- "Items in samples_sizes should be an int "
204
- "object, with a value between 0 and %u." , SIZE_MAX );
204
+ "Items in samples_sizes should be an int "
205
+ "object, with a value between 0 and %u." , SIZE_MAX );
205
206
return -1 ;
206
207
}
207
208
sizes_sum += (* chunk_sizes )[i ];
208
209
}
209
210
210
211
if (sizes_sum != Py_SIZE (samples_bytes )) {
211
212
PyErr_SetString (PyExc_ValueError ,
212
- "The samples size tuple doesn't match the concatenation's size." );
213
+ "The samples size tuple doesn't match the "
214
+ "concatenation's size." );
213
215
return -1 ;
214
216
}
215
217
return chunks_number ;
@@ -242,15 +244,15 @@ _zstd_train_dict_impl(PyObject *module, PyBytesObject *samples_bytes,
242
244
243
245
/* Check arguments */
244
246
if (dict_size <= 0 ) {
245
- PyErr_SetString (PyExc_ValueError , "dict_size argument should be positive number." );
247
+ PyErr_SetString (PyExc_ValueError ,
248
+ "dict_size argument should be positive number." );
246
249
return NULL ;
247
250
}
248
251
249
252
/* Check that the samples are valid and get their sizes */
250
253
chunks_number = calculate_samples_stats (samples_bytes , samples_sizes ,
251
254
& chunk_sizes );
252
- if (chunks_number < 0 )
253
- {
255
+ if (chunks_number < 0 ) {
254
256
goto error ;
255
257
}
256
258
@@ -271,7 +273,7 @@ _zstd_train_dict_impl(PyObject *module, PyBytesObject *samples_bytes,
271
273
272
274
/* Check Zstandard dict error */
273
275
if (ZDICT_isError (zstd_ret )) {
274
- _zstd_state * const mod_state = get_zstd_state (module );
276
+ _zstd_state * mod_state = get_zstd_state (module );
275
277
set_zstd_error (mod_state , ERR_TRAIN_DICT , zstd_ret );
276
278
goto error ;
277
279
}
@@ -324,15 +326,15 @@ _zstd_finalize_dict_impl(PyObject *module, PyBytesObject *custom_dict_bytes,
324
326
325
327
/* Check arguments */
326
328
if (dict_size <= 0 ) {
327
- PyErr_SetString (PyExc_ValueError , "dict_size argument should be positive number." );
329
+ PyErr_SetString (PyExc_ValueError ,
330
+ "dict_size argument should be positive number." );
328
331
return NULL ;
329
332
}
330
333
331
334
/* Check that the samples are valid and get their sizes */
332
335
chunks_number = calculate_samples_stats (samples_bytes , samples_sizes ,
333
336
& chunk_sizes );
334
- if (chunks_number < 0 )
335
- {
337
+ if (chunks_number < 0 ) {
336
338
goto error ;
337
339
}
338
340
@@ -355,14 +357,15 @@ _zstd_finalize_dict_impl(PyObject *module, PyBytesObject *custom_dict_bytes,
355
357
Py_BEGIN_ALLOW_THREADS
356
358
zstd_ret = ZDICT_finalizeDictionary (
357
359
PyBytes_AS_STRING (dst_dict_bytes ), dict_size ,
358
- PyBytes_AS_STRING (custom_dict_bytes ), Py_SIZE (custom_dict_bytes ),
360
+ PyBytes_AS_STRING (custom_dict_bytes ),
361
+ Py_SIZE (custom_dict_bytes ),
359
362
PyBytes_AS_STRING (samples_bytes ), chunk_sizes ,
360
363
(uint32_t )chunks_number , params );
361
364
Py_END_ALLOW_THREADS
362
365
363
366
/* Check Zstandard dict error */
364
367
if (ZDICT_isError (zstd_ret )) {
365
- _zstd_state * const mod_state = get_zstd_state (module );
368
+ _zstd_state * mod_state = get_zstd_state (module );
366
369
set_zstd_error (mod_state , ERR_FINALIZE_DICT , zstd_ret );
367
370
goto error ;
368
371
}
@@ -402,15 +405,15 @@ _zstd_get_param_bounds_impl(PyObject *module, int parameter, int is_compress)
402
405
if (is_compress ) {
403
406
bound = ZSTD_cParam_getBounds (parameter );
404
407
if (ZSTD_isError (bound .error )) {
405
- _zstd_state * const mod_state = get_zstd_state (module );
408
+ _zstd_state * mod_state = get_zstd_state (module );
406
409
set_zstd_error (mod_state , ERR_GET_C_BOUNDS , bound .error );
407
410
return NULL ;
408
411
}
409
412
}
410
413
else {
411
414
bound = ZSTD_dParam_getBounds (parameter );
412
415
if (ZSTD_isError (bound .error )) {
413
- _zstd_state * const mod_state = get_zstd_state (module );
416
+ _zstd_state * mod_state = get_zstd_state (module );
414
417
set_zstd_error (mod_state , ERR_GET_D_BOUNDS , bound .error );
415
418
return NULL ;
416
419
}
@@ -435,9 +438,10 @@ _zstd_get_frame_size_impl(PyObject *module, Py_buffer *frame_buffer)
435
438
{
436
439
size_t frame_size ;
437
440
438
- frame_size = ZSTD_findFrameCompressedSize (frame_buffer -> buf , frame_buffer -> len );
441
+ frame_size = ZSTD_findFrameCompressedSize (frame_buffer -> buf ,
442
+ frame_buffer -> len );
439
443
if (ZSTD_isError (frame_size )) {
440
- _zstd_state * const mod_state = get_zstd_state (module );
444
+ _zstd_state * mod_state = get_zstd_state (module );
441
445
PyErr_Format (mod_state -> ZstdError ,
442
446
"Error when finding the compressed size of a Zstandard frame. "
443
447
"Ensure the frame_buffer argument starts from the "
@@ -473,7 +477,7 @@ _zstd_get_frame_info_impl(PyObject *module, Py_buffer *frame_buffer)
473
477
/* #define ZSTD_CONTENTSIZE_UNKNOWN (0ULL - 1)
474
478
#define ZSTD_CONTENTSIZE_ERROR (0ULL - 2) */
475
479
if (decompressed_size == ZSTD_CONTENTSIZE_ERROR ) {
476
- _zstd_state * const mod_state = get_zstd_state (module );
480
+ _zstd_state * mod_state = get_zstd_state (module );
477
481
PyErr_SetString (mod_state -> ZstdError ,
478
482
"Error when getting information from the header of "
479
483
"a Zstandard frame. Ensure the frame_buffer argument "
@@ -508,7 +512,7 @@ _zstd_set_parameter_types_impl(PyObject *module, PyObject *c_parameter_type,
508
512
PyObject * d_parameter_type )
509
513
/*[clinic end generated code: output=f3313b1294f19502 input=75d7a953580fae5f]*/
510
514
{
511
- _zstd_state * const mod_state = get_zstd_state (module );
515
+ _zstd_state * mod_state = get_zstd_state (module );
512
516
513
517
if (!PyType_Check (c_parameter_type ) || !PyType_Check (d_parameter_type )) {
514
518
PyErr_SetString (PyExc_ValueError ,
@@ -568,7 +572,7 @@ do { \
568
572
Py_DECREF(v); \
569
573
} while (0)
570
574
571
- _zstd_state * const mod_state = get_zstd_state (m );
575
+ _zstd_state * mod_state = get_zstd_state (m );
572
576
573
577
/* Reusable objects & variables */
574
578
mod_state -> CParameter_type = NULL ;
@@ -674,7 +678,7 @@ do { \
674
678
static int
675
679
_zstd_traverse (PyObject * module , visitproc visit , void * arg )
676
680
{
677
- _zstd_state * const mod_state = get_zstd_state (module );
681
+ _zstd_state * mod_state = get_zstd_state (module );
678
682
679
683
Py_VISIT (mod_state -> ZstdDict_type );
680
684
Py_VISIT (mod_state -> ZstdCompressor_type );
@@ -691,7 +695,7 @@ _zstd_traverse(PyObject *module, visitproc visit, void *arg)
691
695
static int
692
696
_zstd_clear (PyObject * module )
693
697
{
694
- _zstd_state * const mod_state = get_zstd_state (module );
698
+ _zstd_state * mod_state = get_zstd_state (module );
695
699
696
700
Py_CLEAR (mod_state -> ZstdDict_type );
697
701
Py_CLEAR (mod_state -> ZstdCompressor_type );
0 commit comments