mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
[3.14] GH-132983: remove empty_bytes from _zstd module state (GH-133785) (#133788)
GH-132983: remove empty_bytes from _zstd module state (GH-133785)
(cherry picked from commit 98e2c3af47
)
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
This commit is contained in:
parent
5796e3b588
commit
9023b6ffae
3 changed files with 2 additions and 29 deletions
|
@ -587,11 +587,6 @@ do { \
|
||||||
_zstd_state* const mod_state = get_zstd_state(m);
|
_zstd_state* const mod_state = get_zstd_state(m);
|
||||||
|
|
||||||
/* Reusable objects & variables */
|
/* Reusable objects & variables */
|
||||||
mod_state->empty_bytes = PyBytes_FromStringAndSize(NULL, 0);
|
|
||||||
if (mod_state->empty_bytes == NULL) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
mod_state->CParameter_type = NULL;
|
mod_state->CParameter_type = NULL;
|
||||||
mod_state->DParameter_type = NULL;
|
mod_state->DParameter_type = NULL;
|
||||||
|
|
||||||
|
@ -694,8 +689,6 @@ _zstd_traverse(PyObject *module, visitproc visit, void *arg)
|
||||||
{
|
{
|
||||||
_zstd_state* const mod_state = get_zstd_state(module);
|
_zstd_state* const mod_state = get_zstd_state(module);
|
||||||
|
|
||||||
Py_VISIT(mod_state->empty_bytes);
|
|
||||||
|
|
||||||
Py_VISIT(mod_state->ZstdDict_type);
|
Py_VISIT(mod_state->ZstdDict_type);
|
||||||
Py_VISIT(mod_state->ZstdCompressor_type);
|
Py_VISIT(mod_state->ZstdCompressor_type);
|
||||||
|
|
||||||
|
@ -713,8 +706,6 @@ _zstd_clear(PyObject *module)
|
||||||
{
|
{
|
||||||
_zstd_state* const mod_state = get_zstd_state(module);
|
_zstd_state* const mod_state = get_zstd_state(module);
|
||||||
|
|
||||||
Py_CLEAR(mod_state->empty_bytes);
|
|
||||||
|
|
||||||
Py_CLEAR(mod_state->ZstdDict_type);
|
Py_CLEAR(mod_state->ZstdDict_type);
|
||||||
Py_CLEAR(mod_state->ZstdCompressor_type);
|
Py_CLEAR(mod_state->ZstdCompressor_type);
|
||||||
|
|
||||||
|
|
|
@ -35,8 +35,6 @@ extern PyType_Spec zstd_compressor_type_spec;
|
||||||
extern PyType_Spec zstd_decompressor_type_spec;
|
extern PyType_Spec zstd_decompressor_type_spec;
|
||||||
|
|
||||||
struct _zstd_state {
|
struct _zstd_state {
|
||||||
PyObject *empty_bytes;
|
|
||||||
|
|
||||||
PyTypeObject *ZstdDict_type;
|
PyTypeObject *ZstdDict_type;
|
||||||
PyTypeObject *ZstdCompressor_type;
|
PyTypeObject *ZstdCompressor_type;
|
||||||
PyTypeObject *ZstdDecompressor_type;
|
PyTypeObject *ZstdDecompressor_type;
|
||||||
|
|
|
@ -290,13 +290,7 @@ decompress_impl(ZstdDecompressor *self, ZSTD_inBuffer *in,
|
||||||
/* The first AFE check for setting .at_frame_edge flag */
|
/* The first AFE check for setting .at_frame_edge flag */
|
||||||
if (type == TYPE_ENDLESS_DECOMPRESSOR) {
|
if (type == TYPE_ENDLESS_DECOMPRESSOR) {
|
||||||
if (self->at_frame_edge && in->pos == in->size) {
|
if (self->at_frame_edge && in->pos == in->size) {
|
||||||
_zstd_state* const mod_state = PyType_GetModuleState(Py_TYPE(self));
|
return Py_GetConstant(Py_CONSTANT_EMPTY_BYTES);
|
||||||
if (mod_state == NULL) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
ret = mod_state->empty_bytes;
|
|
||||||
Py_INCREF(ret);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -747,16 +741,8 @@ _zstd_ZstdDecompressor_unused_data_get_impl(ZstdDecompressor *self)
|
||||||
{
|
{
|
||||||
PyObject *ret;
|
PyObject *ret;
|
||||||
|
|
||||||
/* Thread-safe code */
|
|
||||||
Py_BEGIN_CRITICAL_SECTION(self);
|
|
||||||
|
|
||||||
if (!self->eof) {
|
if (!self->eof) {
|
||||||
_zstd_state* const mod_state = PyType_GetModuleState(Py_TYPE(self));
|
return Py_GetConstant(Py_CONSTANT_EMPTY_BYTES);
|
||||||
if (mod_state == NULL) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
ret = mod_state->empty_bytes;
|
|
||||||
Py_INCREF(ret);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (self->unused_data == NULL) {
|
if (self->unused_data == NULL) {
|
||||||
|
@ -772,8 +758,6 @@ _zstd_ZstdDecompressor_unused_data_get_impl(ZstdDecompressor *self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Py_END_CRITICAL_SECTION();
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue