8000 gh-132983: Minor fixes and clean up for the _zstd module by serhiy-storchaka · Pull Request #134930 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-132983: Minor fixes and clean up for the _zstd module #134930

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 9 commits into from
Jun 1, 2025
Prev Previous commit
Next Next commit
Remove defensive double checks after releasing the GIL.
  • Loading branch information
serhiy-storchaka committed May 31, 2025
commit 0251f9ed11b62a24c68a2d678a7db62494582e57
12 changes: 6 additions & 6 deletions Modules/_zstd/compressor.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,16 +200,16 @@ _get_CDict(ZstdDict *self, int compressionLevel)
goto error;
}

/* Add PyCapsule object to self->c_dicts if it is not already present. */
PyObject *result;
ret = PyDict_SetDefaultRef(self->c_dicts, level, capsule, &result);
/* Add PyCapsule object to self->c_dicts */
ret = PyDict_SetItem(self->c_dicts, level, capsule);
if (ret < 0) {
goto error;
}
Py_DECREF(capsule);
capsule = result;
}
cdict = PyCapsule_GetPointer(capsule, NULL);
else {
/* ZSTD_CDict instance already exists */
cdict = PyCapsule_GetPointer(capsule, NULL);
}
goto success;

error:
Expand Down
20 changes: 8 additions & 12 deletions Modules/_zstd/decompressor.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,14 @@ _get_DDict(ZstdDict *self)
Py_BEGIN_ALLOW_THREADS
ret = ZSTD_createDDict(self->dict_buffer, self->dict_len);
Py_END_ALLOW_THREADS
if (self->d_dict != NULL) {
ZSTD_freeDDict(ret);
}
else {
self->d_dict = ret;
if (self->d_dict == NULL) {
_zstd_state* mod_state = PyType_GetModuleState(Py_TYPE(self));
if (mod_state != NULL) {
PyErr_SetString(mod_state->ZstdError,
"Failed to create a ZSTD_DDict instance from "
"Zstandard dictionary content.");
}
self->d_dict = ret;

if (self->d_dict == NULL) {
_zstd_state* mod_state = PyType_GetModuleState(Py_TYPE(self));
if (mod_state != NULL) {
PyErr_SetString(mod_state->ZstdError,
"Failed to create a ZSTD_DDict instance from "
"Zstandard dictionary content.");
}
}
}
Expand Down
0