Skip to content

gh-132983: Make zstd types immutable #133784

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 10, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions Modules/_zstd/_zstdmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,9 @@ do { \
ADD_INT_CONST_TO_TYPE(mod_state->ZstdCompressor_type,
"FLUSH_FRAME", ZSTD_e_end);

/* Make ZstdCompressor immutable (set Py_TPFLAGS_IMMUTABLETYPE) */
PyType_Freeze(mod_state->ZstdCompressor_type);

#undef ADD_TYPE
#undef ADD_INT_MACRO
#undef ADD_ZSTD_COMPRESSOR_INT_CONST
Expand Down
3 changes: 3 additions & 0 deletions Modules/_zstd/compressor.c
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,9 @@ static PyType_Slot zstdcompressor_slots[] = {
PyType_Spec zstd_compressor_type_spec = {
.name = "compression.zstd.ZstdCompressor",
.basicsize = sizeof(ZstdCompressor),
// Py_TPFLAGS_IMMUTABLETYPE is not used here as several
// associated constants need to be added to the type.
// PyType_Freeze is called later to set the flag.
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
.slots = zstdcompressor_slots,
};
3 changes: 2 additions & 1 deletion Modules/_zstd/decompressor.c
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,7 @@ static PyType_Slot ZstdDecompressor_slots[] = {
PyType_Spec zstd_decompressor_type_spec = {
.name = "compression.zstd.ZstdDecompressor",
.basicsize = sizeof(ZstdDecompressor),
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE
| Py_TPFLAGS_HAVE_GC,
.slots = ZstdDecompressor_slots,
};
3 changes: 2 additions & 1 deletion Modules/_zstd/zstddict.c
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ static PyType_Slot zstddict_slots[] = {
PyType_Spec zstd_dict_type_spec = {
.name = "compression.zstd.ZstdDict",
.basicsize = sizeof(ZstdDict),
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE
| Py_TPFLAGS_HAVE_GC,
.slots = zstddict_slots,
};
Loading