From 381020d41fb1f8b33421f01c609ba0d0edb99764 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Thu, 29 May 2025 21:11:20 -0700 Subject: [PATCH 1/5] ast docs: Fix description of ast.Constant (#134741) Contrary to the current docs, ast.Constant will never hold containers such as frozenset or tuple; the Python parser only emits it for simple literals. For precision, add the exact list of types that may be contained in an ast.Constant. --- Doc/library/ast.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/library/ast.rst b/Doc/library/ast.rst index ca9a6b0712c9a2..cf22250cac6091 100644 --- a/Doc/library/ast.rst +++ b/Doc/library/ast.rst @@ -268,9 +268,9 @@ Literals .. class:: Constant(value) A constant value. The ``value`` attribute of the ``Constant`` literal contains the - Python object it represents. The values represented can be simple types - such as a number, string or ``None``, but also immutable container types - (tuples and frozensets) if all of their elements are constant. + Python object it represents. The values represented can be instances of :class:`str`, + :class:`bytes`, :class:`int`, :class:`float`, :class:`complex`, and :class:`bool`, + and the constants :data:`None` and :data:`Ellipsis`. .. doctest:: From 5f60d0fcccbf6676f5bc924f05452bd5321446f0 Mon Sep 17 00:00:00 2001 From: Emma Smith Date: Thu, 29 May 2025 21:37:43 -0700 Subject: [PATCH 2/5] gh-134906: Document CompressionParameter.content_size_flag (#134907) * Document CompressionParameter.content_size_flag --- Doc/library/compression.zstd.rst | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Doc/library/compression.zstd.rst b/Doc/library/compression.zstd.rst index 1e1802155a19ec..35bcbc2bfd8eac 100644 --- a/Doc/library/compression.zstd.rst +++ b/Doc/library/compression.zstd.rst @@ -615,6 +615,24 @@ Advanced parameter control A value of zero causes the value to be selected automatically. + .. attribute:: content_size_flag + + Write the size of the data to be compressed into the Zstandard frame + header when known prior to compressing. + + This flag only takes effect under the following two scenarios: + + * Calling :func:`compress` for one-shot compression + * Providing all of the data to be compressed in the frame in a single + :meth:`ZstdCompressor.compress` call, with the + :attr:`ZstdCompressor.FLUSH_FRAME` mode. + + All other compression calls may not write the size information into the + frame header. + + ``True`` or ``1`` enable the content size flag while ``False`` or ``0`` + disable it. + .. attribute:: checksum_flag A four-byte checksum using XXHash64 of the uncompressed content is From 2f2bee21118adce653ee5bc4eb31d30327465966 Mon Sep 17 00:00:00 2001 From: Sam James Date: Fri, 30 May 2025 05:42:19 +0100 Subject: [PATCH 3/5] gh-134768: Fix definition of `mt_continue_should_break()` (#134769) In 121ed71f4e395948d313249b2ad33e1e21581f8a, mt_continue_should_break was changed to be guarded by `Py_DEBUG`, but it's used in `compress_mt_continue_lock_held` with just `assert`, so it needs to be available when `NDEBUG` is undefined too. `Py_DEBUG` implies `NDEBUG` is undefined, so we can check just that. Fixes: 121ed71f4e395948d313249b2ad33e1e21581f8a --- Modules/_zstd/compressor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/_zstd/compressor.c b/Modules/_zstd/compressor.c index 0fc3d7d36c68fe..8ff2a3aadc1cd6 100644 --- a/Modules/_zstd/compressor.c +++ b/Modules/_zstd/compressor.c @@ -512,7 +512,7 @@ compress_lock_held(ZstdCompressor *self, Py_buffer *data, return NULL; } -#ifdef Py_DEBUG +#ifndef NDEBUG static inline int mt_continue_should_break(ZSTD_inBuffer *in, ZSTD_outBuffer *out) { From b367e27af9b52528e395f95b277ec7b69e98e287 Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Fri, 30 May 2025 17:59:23 +0900 Subject: [PATCH 4/5] Doc: remove unnecessary section header (GH-134917) --- Doc/c-api/unicode.rst | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Doc/c-api/unicode.rst b/Doc/c-api/unicode.rst index ef180464ef1688..45f50ba5f97d26 100644 --- a/Doc/c-api/unicode.rst +++ b/Doc/c-api/unicode.rst @@ -1461,10 +1461,6 @@ the user settings on the machine running the codec. .. versionadded:: 3.3 -Methods & Slots -""""""""""""""" - - .. _unicodemethodsandslots: Methods and Slot Functions From 45c6c48afc13f9897010e32171a3e02d0624258c Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Fri, 30 May 2025 02:30:05 -0700 Subject: [PATCH 5/5] gh-134885: zstd: Use Py_XSETREF (GH-134886) --- .../2025-05-29-06-53-40.gh-issue-134885.-_L22o.rst | 2 ++ Modules/_zstd/_zstdmodule.c | 11 ++++------- 2 files changed, 6 insertions(+), 7 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2025-05-29-06-53-40.gh-issue-134885.-_L22o.rst diff --git a/Misc/NEWS.d/next/Library/2025-05-29-06-53-40.gh-issue-134885.-_L22o.rst b/Misc/NEWS.d/next/Library/2025-05-29-06-53-40.gh-issue-134885.-_L22o.rst new file mode 100644 index 00000000000000..4b05d42c109d06 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-05-29-06-53-40.gh-issue-134885.-_L22o.rst @@ -0,0 +1,2 @@ +Fix possible crash in the :mod:`compression.zstd` module related to setting +parameter types. Patch by Jelle Zijlstra. diff --git a/Modules/_zstd/_zstdmodule.c b/Modules/_zstd/_zstdmodule.c index 5ad697d2b83dd6..986b3579479f0f 100644 --- a/Modules/_zstd/_zstdmodule.c +++ b/Modules/_zstd/_zstdmodule.c @@ -514,13 +514,10 @@ _zstd_set_parameter_types_impl(PyObject *module, PyObject *c_parameter_type, return NULL; } - Py_XDECREF(mod_state->CParameter_type); - Py_INCREF(c_parameter_type); - mod_state->CParameter_type = (PyTypeObject*)c_parameter_type; - - Py_XDECREF(mod_state->DParameter_type); - Py_INCREF(d_parameter_type); - mod_state->DParameter_type = (PyTypeObject*)d_parameter_type; + Py_XSETREF( + mod_state->CParameter_type, (PyTypeObject*)Py_NewRef(c_parameter_type)); + Py_XSETREF( + mod_state->DParameter_type, (PyTypeObject*)Py_NewRef(d_parameter_type)); Py_RETURN_NONE; }