Skip to content

Commit 6275ad0

Browse files
committed
Make _zstd C code PEP 7 compliant
1 parent f478331 commit 6275ad0

File tree

6 files changed

+131
-106
lines changed

6 files changed

+131
-106
lines changed

Modules/_zstd/_zstdmodule.c

Lines changed: 59 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -28,41 +28,40 @@ set_zstd_error(const _zstd_state* const state,
2828
char *msg;
2929
assert(ZSTD_isError(zstd_ret));
3030

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 decompression: %s";
41+
break;
42+
case ERR_LOAD_C_DICT:
43+
msg = "Unable to load Zstandard dictionary or prefix for compression: %s";
44+
break;
45+
46+
case ERR_GET_C_BOUNDS:
47+
msg = "Unable to get zstd compression parameter bounds: %s";
48+
break;
49+
case ERR_GET_D_BOUNDS:
50+
msg = "Unable to get zstd decompression parameter bounds: %s";
51+
break;
52+
case ERR_SET_C_LEVEL:
53+
msg = "Unable to set zstd compression level: %s";
54+
break;
55+
56+
case ERR_TRAIN_DICT:
57+
msg = "Unable to train the Zstandard dictionary: %s";
58+
break;
59+
case ERR_FINALIZE_DICT:
60+
msg = "Unable to finalize the Zstandard dictionary: %s";
61+
break;
62+
63+
default:
64+
Py_UNREACHABLE();
6665
}
6766
PyErr_Format(state->ZstdError, msg, ZSTD_getErrorName(zstd_ret));
6867
}
@@ -183,7 +182,7 @@ calculate_samples_stats(PyBytesObject *samples_bytes, PyObject *samples_sizes,
183182
chunks_number = Py_SIZE(samples_sizes);
184183
if ((size_t) chunks_number > UINT32_MAX) {
185184
PyErr_Format(PyExc_ValueError,
186-
"The number of samples should be <= %u.", UINT32_MAX);
185+
"The number of samples should be <= %u.", UINT32_MAX);
187186
return -1;
188187
}
189188

@@ -200,16 +199,17 @@ calculate_samples_stats(PyBytesObject *samples_bytes, PyObject *samples_sizes,
200199
(*chunk_sizes)[i] = PyLong_AsSize_t(size);
201200
if ((*chunk_sizes)[i] == (size_t)-1 && PyErr_Occurred()) {
202201
PyErr_Format(PyExc_ValueError,
203-
"Items in samples_sizes should be an int "
204-
"object, with a value between 0 and %u.", SIZE_MAX);
202+
"Items in samples_sizes should be an int "
203+
"object, with a value between 0 and %u.", SIZE_MAX);
205204
return -1;
206205
}
207206
sizes_sum += (*chunk_sizes)[i];
208207
}
209208

210209
if (sizes_sum != Py_SIZE(samples_bytes)) {
211210
PyErr_SetString(PyExc_ValueError,
212-
"The samples size tuple doesn't match the concatenation's size.");
211+
"The samples size tuple doesn't match the "
212+
"concatenation's size.");
213213
return -1;
214214
}
215215
return chunks_number;
@@ -242,15 +242,15 @@ _zstd_train_dict_impl(PyObject *module, PyBytesObject *samples_bytes,
242242

243243
/* Check arguments */
244244
if (dict_size <= 0) {
245-
PyErr_SetString(PyExc_ValueError, "dict_size argument should be positive number.");
245+
PyErr_SetString(PyExc_ValueError,
246+
"dict_size argument should be positive number.");
246247
return NULL;
247248
}
248249

249250
/* Check that the samples are valid and get their sizes */
250251
chunks_number = calculate_samples_stats(samples_bytes, samples_sizes,
251252
&chunk_sizes);
252-
if (chunks_number < 0)
253-
{
253+
if (chunks_number < 0) {
254254
goto error;
255255
}
256256

@@ -271,7 +271,7 @@ _zstd_train_dict_impl(PyObject *module, PyBytesObject *samples_bytes,
271271

272272
/* Check Zstandard dict error */
273273
if (ZDICT_isError(zstd_ret)) {
274-
_zstd_state* const mod_state = get_zstd_state(module);
274+
_zstd_state* mod_state = get_zstd_state(module);
275275
set_zstd_error(mod_state, ERR_TRAIN_DICT, zstd_ret);
276276
goto error;
277277
}
@@ -324,15 +324,15 @@ _zstd_finalize_dict_impl(PyObject *module, PyBytesObject *custom_dict_bytes,
324324

325325
/* Check arguments */
326326
if (dict_size <= 0) {
327-
PyErr_SetString(PyExc_ValueError, "dict_size argument should be positive number.");
327+
PyErr_SetString(PyExc_ValueError,
328+
"dict_size argument should be positive number.");
328329
return NULL;
329330
}
330331

331332
/* Check that the samples are valid and get their sizes */
332333
chunks_number = calculate_samples_stats(samples_bytes, samples_sizes,
333334
&chunk_sizes);
334-
if (chunks_number < 0)
335-
{
335+
if (chunks_number < 0) {
336336
goto error;
337337
}
338338

@@ -355,14 +355,15 @@ _zstd_finalize_dict_impl(PyObject *module, PyBytesObject *custom_dict_bytes,
355355
Py_BEGIN_ALLOW_THREADS
356356
zstd_ret = ZDICT_finalizeDictionary(
357357
PyBytes_AS_STRING(dst_dict_bytes), dict_size,
358-
PyBytes_AS_STRING(custom_dict_bytes), Py_SIZE(custom_dict_bytes),
358+
PyBytes_AS_STRING(custom_dict_bytes),
359+
Py_SIZE(custom_dict_bytes),
359360
PyBytes_AS_STRING(samples_bytes), chunk_sizes,
360361
(uint32_t)chunks_number, params);
361362
Py_END_ALLOW_THREADS
362363

363364
/* Check Zstandard dict error */
364365
if (ZDICT_isError(zstd_ret)) {
365-
_zstd_state* const mod_state = get_zstd_state(module);
366+
_zstd_state* mod_state = get_zstd_state(module);
366367
set_zstd_error(mod_state, ERR_FINALIZE_DICT, zstd_ret);
367368
goto error;
368369
}
@@ -402,15 +403,15 @@ _zstd_get_param_bounds_impl(PyObject *module, int parameter, int is_compress)
402403
if (is_compress) {
403404
bound = ZSTD_cParam_getBounds(parameter);
404405
if (ZSTD_isError(bound.error)) {
405-
_zstd_state* const mod_state = get_zstd_state(module);
406+
_zstd_state* mod_state = get_zstd_state(module);
406407
set_zstd_error(mod_state, ERR_GET_C_BOUNDS, bound.error);
407408
return NULL;
408409
}
409410
}
410411
else {
411412
bound = ZSTD_dParam_getBounds(parameter);
412413
if (ZSTD_isError(bound.error)) {
413-
_zstd_state* const mod_state = get_zstd_state(module);
414+
_zstd_state* mod_state = get_zstd_state(module);
414415
set_zstd_error(mod_state, ERR_GET_D_BOUNDS, bound.error);
415416
return NULL;
416417
}
@@ -435,9 +436,10 @@ _zstd_get_frame_size_impl(PyObject *module, Py_buffer *frame_buffer)
435436
{
436437
size_t frame_size;
437438

438-
frame_size = ZSTD_findFrameCompressedSize(frame_buffer->buf, frame_buffer->len);
439+
frame_size = ZSTD_findFrameCompressedSize(frame_buffer->buf,
440+
frame_buffer->len);
439441
if (ZSTD_isError(frame_size)) {
440-
_zstd_state* const mod_state = get_zstd_state(module);
442+
_zstd_state* mod_state = get_zstd_state(module);
441443
PyErr_Format(mod_state->ZstdError,
442444
"Error when finding the compressed size of a Zstandard frame. "
443445
"Ensure the frame_buffer argument starts from the "
@@ -473,7 +475,7 @@ _zstd_get_frame_info_impl(PyObject *module, Py_buffer *frame_buffer)
473475
/* #define ZSTD_CONTENTSIZE_UNKNOWN (0ULL - 1)
474476
#define ZSTD_CONTENTSIZE_ERROR (0ULL - 2) */
475477
if (decompressed_size == ZSTD_CONTENTSIZE_ERROR) {
476-
_zstd_state* const mod_state = get_zstd_state(module);
478+
_zstd_state* mod_state = get_zstd_state(module);
477479
PyErr_SetString(mod_state->ZstdError,
478480
"Error when getting information from the header of "
479481
"a Zstandard frame. Ensure the frame_buffer argument "
@@ -508,7 +510,7 @@ _zstd_set_parameter_types_impl(PyObject *module, PyObject *c_parameter_type,
508510
PyObject *d_parameter_type)
509511
/*[clinic end generated code: output=f3313b1294f19502 input=75d7a953580fae5f]*/
510512
{
511-
_zstd_state* const mod_state = get_zstd_state(module);
513+
_zstd_state* mod_state = get_zstd_state(module);
512514

513515
if (!PyType_Check(c_parameter_type) || !PyType_Check(d_parameter_type)) {
514516
PyErr_SetString(PyExc_ValueError,
@@ -568,7 +570,7 @@ do { \
568570
Py_DECREF(v); \
569571
} while (0)
570572

571-
_zstd_state* const mod_state = get_zstd_state(m);
573+
_zstd_state* mod_state = get_zstd_state(m);
572574

573575
/* Reusable objects & variables */
574576
mod_state->CParameter_type = NULL;
@@ -674,7 +676,7 @@ do { \
674676
static int
675677
_zstd_traverse(PyObject *module, visitproc visit, void *arg)
676678
{
677-
_zstd_state* const mod_state = get_zstd_state(module);
679+
_zstd_state* mod_state = get_zstd_state(module);
678680

679681
Py_VISIT(mod_state->ZstdDict_type);
680682
Py_VISIT(mod_state->ZstdCompressor_type);
@@ -691,7 +693,7 @@ _zstd_traverse(PyObject *module, visitproc visit, void *arg)
691693
static int
692694
_zstd_clear(PyObject *module)
693695
{
694-
_zstd_state* const mod_state = get_zstd_state(module);
696+
_zstd_state* mod_state = get_zstd_state(module);
695697

696698
Py_CLEAR(mod_state->ZstdDict_type);
697699
Py_CLEAR(mod_state->ZstdCompressor_type);

Modules/_zstd/buffer.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ _OutputBuffer_InitAndGrow(_BlocksOutputBuffer *buffer, ZSTD_outBuffer *ob,
1919
/* Ensure .list was set to NULL */
2020
assert(buffer->list == NULL);
2121

22-
Py_ssize_t res = _BlocksOutputBuffer_InitAndGrow(buffer, max_length, &ob->dst);
22+
Py_ssize_t res = _BlocksOutputBuffer_InitAndGrow(buffer, max_length,
23+
&ob->dst);
2324
if (res < 0) {
2425
return -1;
2526
}
@@ -34,8 +35,7 @@ _OutputBuffer_InitAndGrow(_BlocksOutputBuffer *buffer, ZSTD_outBuffer *ob,
3435
Return -1 on failure */
3536
static inline int
3637
_OutputBuffer_InitWithSize(_BlocksOutputBuffer *buffer, ZSTD_outBuffer *ob,
37-
Py_ssize_t max_length,
38-
Py_ssize_t init_size)
38+
Py_ssize_t max_length, Py_ssize_t init_size)
3939
{
4040
Py_ssize_t block_size;
4141

@@ -50,7 +50,8 @@ _OutputBuffer_InitWithSize(_BlocksOutputBuffer *buffer, ZSTD_outBuffer *ob,
5050
block_size = init_size;
5151
}
5252

53-
Py_ssize_t res = _BlocksOutputBuffer_InitWithSize(buffer, block_size, &ob->dst);
53+
Py_ssize_t res = _BlocksOutputBuffer_InitWithSize(buffer, block_size,
54+
&ob->dst);
5455
if (res < 0) {
5556
return -1;
5657
}

Modules/_zstd/clinic/zstddict.c.h

Lines changed: 10 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)