Skip to content

Commit 9023b6f

Browse files
[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 98e2c3a) Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
1 parent 5796e3b commit 9023b6f

File tree

3 files changed

+2
-29
lines changed

3 files changed

+2
-29
lines changed

Modules/_zstd/_zstdmodule.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -587,11 +587,6 @@ do { \
587587
_zstd_state* const mod_state = get_zstd_state(m);
588588

589589
/* Reusable objects & variables */
590-
mod_state->empty_bytes = PyBytes_FromStringAndSize(NULL, 0);
591-
if (mod_state->empty_bytes == NULL) {
592-
return -1;
593-
}
594-
595590
mod_state->CParameter_type = NULL;
596591
mod_state->DParameter_type = NULL;
597592

@@ -694,8 +689,6 @@ _zstd_traverse(PyObject *module, visitproc visit, void *arg)
694689
{
695690
_zstd_state* const mod_state = get_zstd_state(module);
696691

697-
Py_VISIT(mod_state->empty_bytes);
698-
699692
Py_VISIT(mod_state->ZstdDict_type);
700693
Py_VISIT(mod_state->ZstdCompressor_type);
701694

@@ -713,8 +706,6 @@ _zstd_clear(PyObject *module)
713706
{
714707
_zstd_state* const mod_state = get_zstd_state(module);
715708

716-
Py_CLEAR(mod_state->empty_bytes);
717-
718709
Py_CLEAR(mod_state->ZstdDict_type);
719710
Py_CLEAR(mod_state->ZstdCompressor_type);
720711

Modules/_zstd/_zstdmodule.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ extern PyType_Spec zstd_compressor_type_spec;
3535
extern PyType_Spec zstd_decompressor_type_spec;
3636

3737
struct _zstd_state {
38-
PyObject *empty_bytes;
39-
4038
PyTypeObject *ZstdDict_type;
4139
PyTypeObject *ZstdCompressor_type;
4240
PyTypeObject *ZstdDecompressor_type;

Modules/_zstd/decompressor.c

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -290,13 +290,7 @@ decompress_impl(ZstdDecompressor *self, ZSTD_inBuffer *in,
290290
/* The first AFE check for setting .at_frame_edge flag */
291291
if (type == TYPE_ENDLESS_DECOMPRESSOR) {
292292
if (self->at_frame_edge && in->pos == in->size) {
293-
_zstd_state* const mod_state = PyType_GetModuleState(Py_TYPE(self));
294-
if (mod_state == NULL) {
295-
return NULL;
296-
}
297-
ret = mod_state->empty_bytes;
298-
Py_INCREF(ret);
299-
return ret;
293+
return Py_GetConstant(Py_CONSTANT_EMPTY_BYTES);
300294
}
301295
}
302296

@@ -747,16 +741,8 @@ _zstd_ZstdDecompressor_unused_data_get_impl(ZstdDecompressor *self)
747741
{
748742
PyObject *ret;
749743

750-
/* Thread-safe code */
751-
Py_BEGIN_CRITICAL_SECTION(self);
752-
753744
if (!self->eof) {
754-
_zstd_state* const mod_state = PyType_GetModuleState(Py_TYPE(self));
755-
if (mod_state == NULL) {
756-
return NULL;
757-
}
758-
ret = mod_state->empty_bytes;
759-
Py_INCREF(ret);
745+
return Py_GetConstant(Py_CONSTANT_EMPTY_BYTES);
760746
}
761747
else {
762748
if (self->unused_data == NULL) {
@@ -772,8 +758,6 @@ _zstd_ZstdDecompressor_unused_data_get_impl(ZstdDecompressor *self)
772758
}
773759
}
774760

775-
Py_END_CRITICAL_SECTION();
776-
777761
return ret;
778762
}
779763

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy