Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[3.14] gh-132983: Make _zstd C code PEP 7 compliant (GH-134605)#134609

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
gpshead merged 1 commit intopython:3.14frommiss-islington:backport-973b8f6-3.14
May 24, 2025
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 61 additions & 57 deletionsModules/_zstd/_zstdmodule.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -28,41 +28,42 @@ set_zstd_error(const _zstd_state* const state,
char*msg;
assert(ZSTD_isError(zstd_ret));

switch (type)
{
caseERR_DECOMPRESS:
msg="Unable to decompress Zstandard data: %s";
break;
caseERR_COMPRESS:
msg="Unable to compress Zstandard data: %s";
break;

caseERR_LOAD_D_DICT:
msg="Unable to load Zstandard dictionary or prefix for decompression: %s";
break;
caseERR_LOAD_C_DICT:
msg="Unable to load Zstandard dictionary or prefix for compression: %s";
break;

caseERR_GET_C_BOUNDS:
msg="Unable to get zstd compression parameter bounds: %s";
break;
caseERR_GET_D_BOUNDS:
msg="Unable to get zstd decompression parameter bounds: %s";
break;
caseERR_SET_C_LEVEL:
msg="Unable to set zstd compression level: %s";
break;

caseERR_TRAIN_DICT:
msg="Unable to train the Zstandard dictionary: %s";
break;
caseERR_FINALIZE_DICT:
msg="Unable to finalize the Zstandard dictionary: %s";
break;

default:
Py_UNREACHABLE();
switch (type) {
caseERR_DECOMPRESS:
msg="Unable to decompress Zstandard data: %s";
break;
caseERR_COMPRESS:
msg="Unable to compress Zstandard data: %s";
break;

caseERR_LOAD_D_DICT:
msg="Unable to load Zstandard dictionary or prefix for "
"decompression: %s";
break;
caseERR_LOAD_C_DICT:
msg="Unable to load Zstandard dictionary or prefix for "
"compression: %s";
break;

caseERR_GET_C_BOUNDS:
msg="Unable to get zstd compression parameter bounds: %s";
break;
caseERR_GET_D_BOUNDS:
msg="Unable to get zstd decompression parameter bounds: %s";
break;
caseERR_SET_C_LEVEL:
msg="Unable to set zstd compression level: %s";
break;

caseERR_TRAIN_DICT:
msg="Unable to train the Zstandard dictionary: %s";
break;
caseERR_FINALIZE_DICT:
msg="Unable to finalize the Zstandard dictionary: %s";
break;

default:
Py_UNREACHABLE();
}
PyErr_Format(state->ZstdError,msg,ZSTD_getErrorName(zstd_ret));
}
Expand DownExpand Up@@ -183,7 +184,7 @@ calculate_samples_stats(PyBytesObject *samples_bytes, PyObject *samples_sizes,
chunks_number=Py_SIZE(samples_sizes);
if ((size_t)chunks_number>UINT32_MAX) {
PyErr_Format(PyExc_ValueError,
"The number of samples should be <= %u.",UINT32_MAX);
"The number of samples should be <= %u.",UINT32_MAX);
return-1;
}

Expand All@@ -200,16 +201,17 @@ calculate_samples_stats(PyBytesObject *samples_bytes, PyObject *samples_sizes,
(*chunk_sizes)[i]=PyLong_AsSize_t(size);
if ((*chunk_sizes)[i]== (size_t)-1&&PyErr_Occurred()) {
PyErr_Format(PyExc_ValueError,
"Items in samples_sizes should be an int "
"object, with a value between 0 and %u.",SIZE_MAX);
"Items in samples_sizes should be an int "
"object, with a value between 0 and %u.",SIZE_MAX);
return-1;
}
sizes_sum+= (*chunk_sizes)[i];
}

if (sizes_sum!=Py_SIZE(samples_bytes)) {
PyErr_SetString(PyExc_ValueError,
"The samples size tuple doesn't match the concatenation's size.");
"The samples size tuple doesn't match the "
"concatenation's size.");
return-1;
}
returnchunks_number;
Expand DownExpand Up@@ -242,15 +244,15 @@ _zstd_train_dict_impl(PyObject *module, PyBytesObject *samples_bytes,

/* Check arguments */
if (dict_size <=0) {
PyErr_SetString(PyExc_ValueError,"dict_size argument should be positive number.");
PyErr_SetString(PyExc_ValueError,
"dict_size argument should be positive number.");
returnNULL;
}

/* Check that the samples are valid and get their sizes */
chunks_number=calculate_samples_stats(samples_bytes,samples_sizes,
&chunk_sizes);
if (chunks_number<0)
{
if (chunks_number<0) {
gotoerror;
}

Expand All@@ -271,7 +273,7 @@ _zstd_train_dict_impl(PyObject *module, PyBytesObject *samples_bytes,

/* Check Zstandard dict error */
if (ZDICT_isError(zstd_ret)) {
_zstd_state*constmod_state=get_zstd_state(module);
_zstd_state*mod_state=get_zstd_state(module);
set_zstd_error(mod_state,ERR_TRAIN_DICT,zstd_ret);
gotoerror;
}
Expand DownExpand Up@@ -324,15 +326,15 @@ _zstd_finalize_dict_impl(PyObject *module, PyBytesObject *custom_dict_bytes,

/* Check arguments */
if (dict_size <=0) {
PyErr_SetString(PyExc_ValueError,"dict_size argument should be positive number.");
PyErr_SetString(PyExc_ValueError,
"dict_size argument should be positive number.");
returnNULL;
}

/* Check that the samples are valid and get their sizes */
chunks_number=calculate_samples_stats(samples_bytes,samples_sizes,
&chunk_sizes);
if (chunks_number<0)
{
if (chunks_number<0) {
gotoerror;
}

Expand All@@ -355,14 +357,15 @@ _zstd_finalize_dict_impl(PyObject *module, PyBytesObject *custom_dict_bytes,
Py_BEGIN_ALLOW_THREADS
zstd_ret=ZDICT_finalizeDictionary(
PyBytes_AS_STRING(dst_dict_bytes),dict_size,
PyBytes_AS_STRING(custom_dict_bytes),Py_SIZE(custom_dict_bytes),
PyBytes_AS_STRING(custom_dict_bytes),
Py_SIZE(custom_dict_bytes),
PyBytes_AS_STRING(samples_bytes),chunk_sizes,
(uint32_t)chunks_number,params);
Py_END_ALLOW_THREADS

/* Check Zstandard dict error */
if (ZDICT_isError(zstd_ret)) {
_zstd_state*constmod_state=get_zstd_state(module);
_zstd_state*mod_state=get_zstd_state(module);
set_zstd_error(mod_state,ERR_FINALIZE_DICT,zstd_ret);
gotoerror;
}
Expand DownExpand Up@@ -402,15 +405,15 @@ _zstd_get_param_bounds_impl(PyObject *module, int parameter, int is_compress)
if (is_compress) {
bound=ZSTD_cParam_getBounds(parameter);
if (ZSTD_isError(bound.error)) {
_zstd_state*constmod_state=get_zstd_state(module);
_zstd_state*mod_state=get_zstd_state(module);
set_zstd_error(mod_state,ERR_GET_C_BOUNDS,bound.error);
returnNULL;
}
}
else {
bound=ZSTD_dParam_getBounds(parameter);
if (ZSTD_isError(bound.error)) {
_zstd_state*constmod_state=get_zstd_state(module);
_zstd_state*mod_state=get_zstd_state(module);
set_zstd_error(mod_state,ERR_GET_D_BOUNDS,bound.error);
returnNULL;
}
Expand All@@ -435,9 +438,10 @@ _zstd_get_frame_size_impl(PyObject *module, Py_buffer *frame_buffer)
{
size_tframe_size;

frame_size=ZSTD_findFrameCompressedSize(frame_buffer->buf,frame_buffer->len);
frame_size=ZSTD_findFrameCompressedSize(frame_buffer->buf,
frame_buffer->len);
if (ZSTD_isError(frame_size)) {
_zstd_state*constmod_state=get_zstd_state(module);
_zstd_state*mod_state=get_zstd_state(module);
PyErr_Format(mod_state->ZstdError,
"Error when finding the compressed size of a Zstandard frame. "
"Ensure the frame_buffer argument starts from the "
Expand DownExpand Up@@ -473,7 +477,7 @@ _zstd_get_frame_info_impl(PyObject *module, Py_buffer *frame_buffer)
/* #define ZSTD_CONTENTSIZE_UNKNOWN (0ULL - 1)
#define ZSTD_CONTENTSIZE_ERROR (0ULL - 2) */
if (decompressed_size==ZSTD_CONTENTSIZE_ERROR) {
_zstd_state*constmod_state=get_zstd_state(module);
_zstd_state*mod_state=get_zstd_state(module);
PyErr_SetString(mod_state->ZstdError,
"Error when getting information from the header of "
"a Zstandard frame. Ensure the frame_buffer argument "
Expand DownExpand Up@@ -508,7 +512,7 @@ _zstd_set_parameter_types_impl(PyObject *module, PyObject *c_parameter_type,
PyObject*d_parameter_type)
/*[clinic end generated code: output=f3313b1294f19502 input=75d7a953580fae5f]*/
{
_zstd_state*constmod_state=get_zstd_state(module);
_zstd_state*mod_state=get_zstd_state(module);

if (!PyType_Check(c_parameter_type)|| !PyType_Check(d_parameter_type)) {
PyErr_SetString(PyExc_ValueError,
Expand DownExpand Up@@ -568,7 +572,7 @@ do { \
Py_DECREF(v); \
} while (0)

_zstd_state*constmod_state=get_zstd_state(m);
_zstd_state*mod_state=get_zstd_state(m);

/* Reusable objects & variables */
mod_state->CParameter_type=NULL;
Expand DownExpand Up@@ -674,7 +678,7 @@ do { \
staticint
_zstd_traverse(PyObject*module,visitprocvisit,void*arg)
{
_zstd_state*constmod_state=get_zstd_state(module);
_zstd_state*mod_state=get_zstd_state(module);

Py_VISIT(mod_state->ZstdDict_type);
Py_VISIT(mod_state->ZstdCompressor_type);
Expand All@@ -691,7 +695,7 @@ _zstd_traverse(PyObject *module, visitproc visit, void *arg)
staticint
_zstd_clear(PyObject*module)
{
_zstd_state*constmod_state=get_zstd_state(module);
_zstd_state*mod_state=get_zstd_state(module);

Py_CLEAR(mod_state->ZstdDict_type);
Py_CLEAR(mod_state->ZstdCompressor_type);
Expand Down
9 changes: 5 additions & 4 deletionsModules/_zstd/buffer.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -19,7 +19,8 @@ _OutputBuffer_InitAndGrow(_BlocksOutputBuffer *buffer, ZSTD_outBuffer *ob,
/* Ensure .list was set to NULL */
assert(buffer->list == NULL);

Py_ssize_t res = _BlocksOutputBuffer_InitAndGrow(buffer, max_length, &ob->dst);
Py_ssize_t res = _BlocksOutputBuffer_InitAndGrow(buffer, max_length,
&ob->dst);
if (res < 0) {
return -1;
}
Expand All@@ -34,8 +35,7 @@ _OutputBuffer_InitAndGrow(_BlocksOutputBuffer *buffer, ZSTD_outBuffer *ob,
Return -1 on failure */
static inline int
_OutputBuffer_InitWithSize(_BlocksOutputBuffer *buffer, ZSTD_outBuffer *ob,
Py_ssize_t max_length,
Py_ssize_t init_size)
Py_ssize_t max_length, Py_ssize_t init_size)
{
Py_ssize_t block_size;

Expand All@@ -50,7 +50,8 @@ _OutputBuffer_InitWithSize(_BlocksOutputBuffer *buffer, ZSTD_outBuffer *ob,
block_size = init_size;
}

Py_ssize_t res = _BlocksOutputBuffer_InitWithSize(buffer, block_size, &ob->dst);
Py_ssize_t res = _BlocksOutputBuffer_InitWithSize(buffer, block_size,
&ob->dst);
if (res < 0) {
return -1;
}
Expand Down
14 changes: 10 additions & 4 deletionsModules/_zstd/clinic/zstddict.c.h
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

Loading
Loading

[8]ページ先頭

©2009-2025 Movatter.jp