20 Commits

Author SHA1 Message Date
Karolina Surma 1887a95f51 gh-128341: Use _Py_ABI_SLOT in stdlib modules (#145770)
Rename from _Py_INTERNAL_ABI_SLOT to _Py_ABI_SLOT
and define the macro using _PyABIInfo_DEFAULT.

Use the ABI slot in stdlib extension modules to enable running
a check of ABI version compatibility.

_tkinter, _tracemalloc and readline don't use the slots, hence they need
explicit handling.

Co-authored-by: Victor Stinner <vstinner@python.org>
2026-03-24 17:47:55 +00:00
Adam Turner 918e3ba6c0 GH-137623: Use an AC decorator for docstring line length enforcement (#137690) 2025-08-18 18:29:00 +01:00
Adam Turner b6d3242244 GH-136975: Emend a spelling error (algorthm -> algorithm) (#136999) 2025-07-22 13:48:58 +00:00
Emma Smith 4b44b3409a gh-134938: Add set_pledged_input_size() to ZstdCompressor (GH-135010) 2025-06-05 14:31:49 +03:00
Serhiy Storchaka b595237166 gh-132983: Minor fixes and clean up for the _zstd module (GH-134930) 2025-06-01 11:22:15 +03:00
Jelle Zijlstra 45c6c48afc gh-134885: zstd: Use Py_XSETREF (GH-134886) 2025-05-30 11:30:05 +02:00
Adam Turner 11f7a939de gh-132983: Split `_zstd_set_c_parameters` (#133921) 2025-05-28 14:45:08 +00:00
Emma Smith 973b8f69d3 gh-132983: Make _zstd C code PEP 7 compliant (GH-134605)
Make _zstd C code PEP 7 compliant
2025-05-23 19:03:21 -07:00
Emma Smith fb68776591 gh-132983: Fix refleak in zstd dictionary functions (gh-134459) 2025-05-21 19:09:34 +00:00
Emma Smith c64a21454b gh-132983: Refactor shared code in train_dict and finalize_dict (GH-134432)
Refactor shared code in train_dict and finalize_dict
2025-05-21 08:53:13 -07:00
Adam Turner d29ddbd90c gh-132983: Convert zstd `__new__` methods to Argument Clinic (#133860) 2025-05-12 08:51:53 +00:00
Adam Turner 1a87b6e9ae gh-132983: Make zstd types immutable (#133784) 2025-05-10 22:37:17 +00:00
Adam Turner 1a548c0a50 gh-132983: Reduce the size of `_zstdmodule.h` (#133793) 2025-05-10 22:25:22 +01:00
Adam Turner 1978904a2f GH-132983: PEP 7 and Argument Clinic changes for zstd (#133791) 2025-05-10 00:33:45 +00:00
Adam Turner 98e2c3af47 GH-132983: remove empty_bytes from _zstd module state (#133785) 2025-05-09 20:17:12 +00:00
Adam Turner bbe9c31edc gh-132983: Simplify `_zstd_exec()` (#133775) 2025-05-09 20:15:19 +01:00
Adam Turner c2a5d4b383 gh-132983: Clean-ups for `_zstd` (#133670) 2025-05-09 15:08:51 +01:00
Adam Turner 6f6f48d289 gh-103092: Support subinterpreters in `_zstd` (#133674) 2025-05-08 19:11:34 +01:00
Emma Smith c273f59fb3 gh-132983: Add the compression.zstd pacakge and tests (#133365)
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
Co-authored-by: Tomas R. <tomas.roun8@gmail.com>
Co-authored-by: Rogdham <contact@rogdham.net>
2025-05-06 01:38:08 +01:00
Emma Smith 3b4333583f gh-132983: Introduce _zstd bindings module (GH-133027)
* Add _zstd module for https://peps.python.org/pep-0784/

This commit introduces the `_zstd` module, with bindings to libzstd from
the pyzstd project. It also includes the unix build system configuration.
Windows build system support will be integrated independently as it
depends on integration with cpython-source-deps.

* Add _zstd to modules

* Fix path for compression.zstd module

* Ignore _zstd module like _io

* Expand module state macros to improve code quality

Also removes module state references from the classes in the _zstd
module and instead uses PyType_GetModuleState()

* Remove backticks suggested in review

Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>

* Use critical sections to lock object state

This should avoid races and deadlocks.

* Remove compress/decompress and mark module as not reliant on the GIL

The `compress`/`decompress` functions will be moved to Python code for simplicity.
C implementations can always be re-added in the future.

Also, mark _zstd as not requiring the GIL.

* Lift critical section to avoid clang warning

* Respond to comments by picnixz

* Call out pyzstd explicitly in license description

Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>

* Use a much more robust implementation...

... for `get_zstd_state_from_type`

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>

* Use PyList_GetItemRef for thread safety purposes

* Use a macro for the minimum supported version

* remove const from primivite types

* Use PyMem_New in another spot

* Simplify error handling in _get_frame_size

* Another simplification of error handling in get_frame_info

* Rename _module_state to mod_state

* Rewrite comment explaining the context of the code

* Add link to pyzstd

* Add TODO about refactoring dict training code

* Use PyModule_AddObjectRef over PyModule_AddObject

PyModule_AddObject is soft-deprecated, so we should use PyModule_AddObjectRef

* Check result of OutputBufferGrow

* Simplify return logic in `add_constant_to_type`

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>

* Ignore return value of _zstd_clear()

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>

* Remove redundant comments

* Remove __reduce__ from ZstdDict

We should instead document that to pickle a dictionary a user should use
the `.dict_content` attribute.

* Use PyUnicode_FromFormat instead of a buffer

* Don't use C constants/types in error messages

* Make error messages easier to understand for Python users

* Lower minimum required version 1.4.0

* Use casts and make slot function signatures correct

* Be consistent with CPython on const usage

* Make else clauses in line with PEP 7

* Fix over-indented blocks in argument clinic

* Add critical section around ZSTD_DCtx_setParameter

* Add a TODO about refactoring critical sections

* Use Py_UNREACHABLE

* Move bytes operations out of Py_BEGIN_ALLOW_THREADS

* Add TODO about ensuring a lock is held

* Remove asserts that may not be correct

* Add TODO to make ZstdDict and others GC objects

* Make objects GC tracked

* Remove unused include

* Fix some memory issues

* Fix refleaks on module and in ZstdDict

* Update configure to check for ZDICT_finalizeDictionary

* Properly check version in configure

* exit(1) if check fails

* Use AC_RUN_IFELSE

* Use a define() to re-use version check

* Actually properly set _zstd module status based on version

---------

Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2025-05-04 01:29:55 +00:00