Skip to content

gh-132983: Clean-ups for _zstd #133670

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 16 commits into from
May 9, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Calculate zstd_version_info in Python
  • Loading branch information
AA-Turner committed May 9, 2025
commit 3d3dbf7e0cfafa10973ace36d570d7e4eccf31f8
9 changes: 7 additions & 2 deletions Lib/compression/zstd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,15 @@

import _zstd
import enum
from _zstd import (get_frame_size, zstd_version, zstd_version_info,
ZstdCompressor, ZstdDecompressor, ZstdDict, ZstdError)
from _zstd import (ZstdCompressor, ZstdDecompressor, ZstdDict, ZstdError,
get_frame_size, zstd_version)
from compression.zstd._zstdfile import ZstdFile, open, _nbytes

# zstd_version_number is (MAJOR * 100 * 100 + MINOR * 100 + RELEASE)
zstd_version_info = (*divmod(_zstd.zstd_version_number // 100, 100),
_zstd.zstd_version_number % 100)
"""Version number of the runtime zstd library as a tuple of integers."""

COMPRESSION_LEVEL_DEFAULT = _zstd.ZSTD_CLEVEL_DEFAULT
"""The default compression level for Zstandard, currently '3'."""

Expand Down
16 changes: 6 additions & 10 deletions Modules/_zstd/_zstdmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -563,19 +563,15 @@ add_vars_to_module(PyObject *m)
return -1; \
}

/* zstd_version, str */
if (PyModule_AddStringConstant(m, "zstd_version",
ZSTD_versionString()) < 0) {
/* zstd_version_number, int */
if (PyModule_AddIntConstant(m, "zstd_version_number",
ZSTD_versionNumber()) < 0) {
return -1;
}

/* zstd_version_info, tuple of (int, int, int) */
const unsigned version = ZSTD_versionNumber();
const uint8_t v_major = version / 100 / 100;
const uint8_t v_minor = (version / 100) % 100;
const uint8_t v_release = version % 100;
if (PyModule_Add(m, "zstd_version_info",
Py_BuildValue("BBB", v_major, v_minor, v_release)) < 0) {
/* zstd_version, str */
if (PyModule_AddStringConstant(m, "zstd_version",
ZSTD_versionString()) < 0) {
return -1;
}

Expand Down
Loading
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