From dfde59f0e18648f874ab9d41774b6be03d66f6a7 Mon Sep 17 00:00:00 2001 From: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com> Date: Wed, 18 Mar 2026 12:43:55 +0000 Subject: [PATCH 01/11] Fix entry in `fuzz_pycompile.dict` (GH-146069) --- Modules/_xxtestfuzz/dictionaries/fuzz_pycompile.dict | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/_xxtestfuzz/dictionaries/fuzz_pycompile.dict b/Modules/_xxtestfuzz/dictionaries/fuzz_pycompile.dict index d36f55a40905d2..322d8180f7baa5 100644 --- a/Modules/_xxtestfuzz/dictionaries/fuzz_pycompile.dict +++ b/Modules/_xxtestfuzz/dictionaries/fuzz_pycompile.dict @@ -54,7 +54,7 @@ " " "\\t" ":\\n " -"\\\n" +"\\\\n" # type signatures and functions "-> " From 64862112b7beb005523e7bca15c59c78c5319e58 Mon Sep 17 00:00:00 2001 From: bkap123 <97006829+bkap123@users.noreply.github.com> Date: Wed, 18 Mar 2026 08:46:01 -0400 Subject: [PATCH 02/11] gh-146075: Prevent crash in `functools.partial()` from malformed `str` subclass (GH-146078) In `partial_vectorcall`, an error returned by `PyDict_Contains` was considered to be a truthy value. Now, the error is handled appropriately. --- Lib/test/test_functools.py | 12 ++++++++++++ .../2026-03-17-19-30-45.gh-issue-146075.85sCSh.rst | 1 + Modules/_functoolsmodule.c | 6 +++++- 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Library/2026-03-17-19-30-45.gh-issue-146075.85sCSh.rst diff --git a/Lib/test/test_functools.py b/Lib/test/test_functools.py index dda42cb33072c3..efa85b564f7cdf 100644 --- a/Lib/test/test_functools.py +++ b/Lib/test/test_functools.py @@ -565,7 +565,19 @@ def __repr__(self): g_partial = functools.partial(func, trigger, None, None, None, None, arg=None) self.assertEqual(repr(g_partial),"functools.partial(Function(old_function), EvilObject, None, None, None, None, arg=None)") + def test_str_subclass_error(self): + class BadStr(str): + def __eq__(self, other): + raise RuntimeError + def __hash__(self): + return str.__hash__(self) + + def f(**kwargs): + return kwargs + p = functools.partial(f, poison="") + with self.assertRaises(RuntimeError): + result = p(**{BadStr("poison"): "new_value"}) @unittest.skipUnless(c_functools, 'requires the C _functools module') class TestPartialC(TestPartial, unittest.TestCase): diff --git a/Misc/NEWS.d/next/Library/2026-03-17-19-30-45.gh-issue-146075.85sCSh.rst b/Misc/NEWS.d/next/Library/2026-03-17-19-30-45.gh-issue-146075.85sCSh.rst new file mode 100644 index 00000000000000..792ea3ad668690 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-03-17-19-30-45.gh-issue-146075.85sCSh.rst @@ -0,0 +1 @@ +Errors when calling :func:`functools.partial` with a malformed keyword will no longer crash the interpreter. diff --git a/Modules/_functoolsmodule.c b/Modules/_functoolsmodule.c index 723080ede1d9ae..576494e846ca0c 100644 --- a/Modules/_functoolsmodule.c +++ b/Modules/_functoolsmodule.c @@ -457,7 +457,11 @@ partial_vectorcall(PyObject *self, PyObject *const *args, for (Py_ssize_t i = 0; i < nkwds; ++i) { key = PyTuple_GET_ITEM(kwnames, i); val = args[nargs + i]; - if (PyDict_Contains(pto->kw, key)) { + int contains = PyDict_Contains(pto->kw, key); + if (contains < 0) { + goto error; + } + else if (contains == 1) { if (pto_kw_merged == NULL) { pto_kw_merged = PyDict_Copy(pto->kw); if (pto_kw_merged == NULL) { From d42a04c0450283acf452d8fa6bbc188c27a6c639 Mon Sep 17 00:00:00 2001 From: "Michiel W. Beijen" Date: Wed, 18 Mar 2026 13:46:26 +0100 Subject: [PATCH 03/11] GH-60729: Add IEEE format wave audio support (GH-145931) (this re-applies reverted commit 61f2a1a5993967ed4b97ba93a4477c37fe68cf59, with a test fix) Co-authored-by: Lionel Koenig --- Doc/library/wave.rst | 69 ++++++- Doc/whatsnew/3.15.rst | 15 ++ Lib/test/audiodata/pluck-float32.wav | Bin 0 -> 26514 bytes Lib/test/audiotests.py | 16 +- Lib/test/test_wave.py | 190 +++++++++++++++++- Lib/wave.py | 88 ++++++-- ...3-03-10-13-10-06.gh-issue-60729.KCCHTe.rst | 1 + 7 files changed, 354 insertions(+), 25 deletions(-) create mode 100644 Lib/test/audiodata/pluck-float32.wav create mode 100644 Misc/NEWS.d/next/Library/2023-03-10-13-10-06.gh-issue-60729.KCCHTe.rst diff --git a/Doc/library/wave.rst b/Doc/library/wave.rst index ff020b52da3f23..9d30a14f112937 100644 --- a/Doc/library/wave.rst +++ b/Doc/library/wave.rst @@ -9,14 +9,19 @@ -------------- The :mod:`!wave` module provides a convenient interface to the Waveform Audio -"WAVE" (or "WAV") file format. Only uncompressed PCM encoded wave files are -supported. +"WAVE" (or "WAV") file format. + +The module supports uncompressed PCM and IEEE floating-point WAV formats. .. versionchanged:: 3.12 Support for ``WAVE_FORMAT_EXTENSIBLE`` headers was added, provided that the extended format is ``KSDATAFORMAT_SUBTYPE_PCM``. +.. versionchanged:: next + + Support for reading and writing ``WAVE_FORMAT_IEEE_FLOAT`` files was added. + The :mod:`!wave` module defines the following function and exception: @@ -60,6 +65,21 @@ The :mod:`!wave` module defines the following function and exception: specification or hits an implementation deficiency. +.. data:: WAVE_FORMAT_PCM + + Format code for uncompressed PCM audio. + + +.. data:: WAVE_FORMAT_IEEE_FLOAT + + Format code for IEEE floating-point audio. + + +.. data:: WAVE_FORMAT_EXTENSIBLE + + Format code for WAVE extensible headers. + + .. _wave-read-objects: Wave_read Objects @@ -98,6 +118,14 @@ Wave_read Objects Returns number of audio frames. + .. method:: getformat() + + Returns the frame format code. + + This is one of :data:`WAVE_FORMAT_PCM`, + :data:`WAVE_FORMAT_IEEE_FLOAT`, or :data:`WAVE_FORMAT_EXTENSIBLE`. + + .. method:: getcomptype() Returns compression type (``'NONE'`` is the only supported type). @@ -112,8 +140,8 @@ Wave_read Objects .. method:: getparams() Returns a :func:`~collections.namedtuple` ``(nchannels, sampwidth, - framerate, nframes, comptype, compname)``, equivalent to output of the - ``get*()`` methods. + framerate, nframes, comptype, compname)``, equivalent to output + of the ``get*()`` methods. .. method:: readframes(n) @@ -190,6 +218,9 @@ Wave_write Objects Set the sample width to *n* bytes. + For :data:`WAVE_FORMAT_IEEE_FLOAT`, only 4-byte (32-bit) and + 8-byte (64-bit) sample widths are supported. + .. method:: getsampwidth() @@ -238,11 +269,32 @@ Wave_write Objects Return the human-readable compression type name. + .. method:: setformat(format) + + Set the frame format code. + + Supported values are :data:`WAVE_FORMAT_PCM` and + :data:`WAVE_FORMAT_IEEE_FLOAT`. + + When setting :data:`WAVE_FORMAT_IEEE_FLOAT`, the sample width must be + 4 or 8 bytes. + + + .. method:: getformat() + + Return the current frame format code. + + .. method:: setparams(tuple) - The *tuple* should be ``(nchannels, sampwidth, framerate, nframes, comptype, - compname)``, with values valid for the ``set*()`` methods. Sets all - parameters. + The *tuple* should be + ``(nchannels, sampwidth, framerate, nframes, comptype, compname, format)``, + with values valid for the ``set*()`` methods. Sets all parameters. + + For backwards compatibility, a 6-item tuple without *format* is also + accepted and defaults to :data:`WAVE_FORMAT_PCM`. + + For ``format=WAVE_FORMAT_IEEE_FLOAT``, *sampwidth* must be 4 or 8. .. method:: getparams() @@ -279,3 +331,6 @@ Wave_write Objects Note that it is invalid to set any parameters after calling :meth:`writeframes` or :meth:`writeframesraw`, and any attempt to do so will raise :exc:`wave.Error`. + + For :data:`WAVE_FORMAT_IEEE_FLOAT` output, a ``fact`` chunk is written as + required by the WAVE specification for non-PCM formats. diff --git a/Doc/whatsnew/3.15.rst b/Doc/whatsnew/3.15.rst index d4c4483bc5eb78..7d5c6e224789be 100644 --- a/Doc/whatsnew/3.15.rst +++ b/Doc/whatsnew/3.15.rst @@ -1511,6 +1511,21 @@ typing wave ---- +* Added support for IEEE floating-point WAVE audio + (``WAVE_FORMAT_IEEE_FLOAT``) in :mod:`wave`. + +* Added :meth:`wave.Wave_read.getformat`, :meth:`wave.Wave_write.getformat`, + and :meth:`wave.Wave_write.setformat` for explicit frame format handling. + +* :meth:`wave.Wave_write.setparams` accepts both 7-item tuples including + ``format`` and 6-item tuples for backwards compatibility (defaulting to + ``WAVE_FORMAT_PCM``). + +* ``WAVE_FORMAT_IEEE_FLOAT`` output now includes a ``fact`` chunk, + as required for non-PCM WAVE formats. + +(Contributed by Lionel Koenig and Michiel W. Beijen in :gh:`60729`.) + * Removed the ``getmark()``, ``setmark()`` and ``getmarkers()`` methods of the :class:`~wave.Wave_read` and :class:`~wave.Wave_write` classes, which were deprecated since Python 3.13. diff --git a/Lib/test/audiodata/pluck-float32.wav b/Lib/test/audiodata/pluck-float32.wav new file mode 100644 index 0000000000000000000000000000000000000000..2030fb16d6e3bd797523605091ff1d732b432b88 GIT binary patch literal 26514 zcmW(+dss~C_unOiFsKZ|NC;sNMzhyyAGZ_2phF153AxW9P6%6)K{N=1Fz$me2x<1a zW)R|pLDF#@bO>?A<&gVte}8|?^UU)!&8)rNwLZ6ZNZ&qvR!-u$;lB*)J#l)XsxHTI zl{jy%PFs#M#(HtSoJxLY;<(=vedO0yejFD+E^%C}{1^HWt9Z`8d0x|;z(_IXi?-IF zd=xJb?!@k?G@xdYZMJhcux1V)5tv14PxKmK7Qd8) zC-s@n&l>1S>du~Q`HJFxe|APu)#2`OOFDUYK%{upVsCitJlO_%!>x!akxuI-5bJ&> zcVaor{v|lFC?Eh!e5#Spz6j*rEpSLJIwQx4k>6Se|L@hI+3$~CHT5DxwXYy~MvF-9 z$~{P!;!Vcy|G_%HOBDL}D=0^eq>^3NVDO4Qkp=trLRm&Scz*7Lpl3(WZLz^4Q*fkm zU@3H)l;8*}sfM9}bshQ>Z=gd<-$-N5UYPM{wvNs)-^lo$ zD=4&Y8_cdbmc+qxq>_lnWO+B2`L;d85-!bfsE!9Rb5ISkd^{;xW+7MxS*4N{jmWaw zEV(1LFw3WlQsBl`k=)v4Qk%aTIJlB^cIRx26ru<5h6J_zJ%52OH*FX?$_7H+?o^TC zg^3bi^4CVlRVu)&*7*PRQ%%5pUX}6)Uc@AkF9)_6R9U_g-mw>N01@(`U!9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2L>V+R{r1uBAp)rj3(%qWM z`e!qG)-+MJSc10qI_iTdC?oYy?EIc^zJ9u1+J$OQGmv8`K6gm!%b#~x8Uj0+-7(@{ z0xQtYWY>>@&XW&V-ob=d{eYFr2kxLBXzeRGqAKO&t27i@he>20Pl`xuDK zFTgmhAw0hbH~!S%?U|Q+&m+LfJoAaANc&=vPTEa+p(YsQ&snc>a%;~L2plfSb>Btc zPIw9KGs>CUxg6vEOo~V9Z+ca(+%GsV{;s9Cgr^# zJ^l6XD6S_Xi@6#yqW95zJ~t)%4YlP%+2AS7cFo0v*V$-sdLOSU6l zyBf$=<*5dK2eL%ivGNfodSBR)-5&v)Rm&8al$$p`nBvcGLI2nVgj)#QM)Sx!jfpq> z+rVA12CZN^>A*f{@A?tgwnS6+R=`@<1M5jTM9O5Rnejv5wk*u8ZRsFAH182lakWGgNOP#52=ef7*j``ijqbcoSK+;f}XL8S>i8qKJ8d+AmS|TvxTDTiIXMLo%ark#th zWBDV~Sda)T+yeC3qF|&@ZFo`K6kXQ?%S=XnXfOG5RFf(H+2L67C=U{MC<^js8gaVY zU|%4eKDZcnJ$pdrZ9u)zouI$1gVrRfvBmP6#&hyr_Ff_HIfeL@ha2hBKn%;yMZsyb zr$s<49}l7*J=^cSsER7EdAnQHKw09jP969V5yIrcIvr)W>P|oH 4: + if self._format == WAVE_FORMAT_IEEE_FLOAT: + if sampwidth not in (4, 8): + raise Error('unsupported sample width for IEEE float format') + elif sampwidth < 1 or sampwidth > 4: raise Error('bad sample width') self._sampwidth = sampwidth @@ -519,6 +547,18 @@ def setcomptype(self, comptype, compname): self._comptype = comptype self._compname = compname + def setformat(self, format): + if self._datawritten: + raise Error('cannot change parameters after starting to write') + if format not in (WAVE_FORMAT_IEEE_FLOAT, WAVE_FORMAT_PCM): + raise Error('unsupported wave format') + if format == WAVE_FORMAT_IEEE_FLOAT and self._sampwidth and self._sampwidth not in (4, 8): + raise Error('unsupported sample width for IEEE float format') + self._format = format + + def getformat(self): + return self._format + def getcomptype(self): return self._comptype @@ -526,10 +566,15 @@ def getcompname(self): return self._compname def setparams(self, params): - nchannels, sampwidth, framerate, nframes, comptype, compname = params if self._datawritten: raise Error('cannot change parameters after starting to write') + if len(params) == 6: + nchannels, sampwidth, framerate, nframes, comptype, compname = params + format = WAVE_FORMAT_PCM + else: + nchannels, sampwidth, framerate, nframes, comptype, compname, format = params self.setnchannels(nchannels) + self.setformat(format) self.setsampwidth(sampwidth) self.setframerate(framerate) self.setnframes(nframes) @@ -590,6 +635,9 @@ def _ensure_header_written(self, datasize): raise Error('sampling rate not specified') self._write_header(datasize) + def _needs_fact_chunk(self): + return self._format == WAVE_FORMAT_IEEE_FLOAT + def _write_header(self, initlength): assert not self._headerwritten self._file.write(b'RIFF') @@ -600,12 +648,23 @@ def _write_header(self, initlength): self._form_length_pos = self._file.tell() except (AttributeError, OSError): self._form_length_pos = None - self._file.write(struct.pack(' Date: Wed, 18 Mar 2026 12:58:08 +0000 Subject: [PATCH 04/11] gh-146076: Fix crash when a `ZoneInfo` subclass is missing a `_weak_cache` (#146082) --- Lib/test/test_zoneinfo/test_zoneinfo.py | 12 ++++++++++++ .../2026-03-17-20-41-27.gh-issue-146076.yoBNnB.rst | 2 ++ Modules/_zoneinfo.c | 6 ++++++ 3 files changed, 20 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2026-03-17-20-41-27.gh-issue-146076.yoBNnB.rst diff --git a/Lib/test/test_zoneinfo/test_zoneinfo.py b/Lib/test/test_zoneinfo/test_zoneinfo.py index a5dea802a9898d..aaab4709464fd0 100644 --- a/Lib/test/test_zoneinfo/test_zoneinfo.py +++ b/Lib/test/test_zoneinfo/test_zoneinfo.py @@ -1595,6 +1595,18 @@ class ZI(self.klass): "Unexpected instance of int in ZI weak cache for key 'America/Los_Angeles'" ) + def test_deleted_weak_cache(self): + class ZI(self.klass): + pass + delattr(ZI, '_weak_cache') + + # These should not segfault + with self.assertRaises(AttributeError): + ZI("UTC") + + with self.assertRaises(AttributeError): + ZI.clear_cache() + def test_inconsistent_weak_cache_setdefault(self): class Cache: def get(self, key, default=None): diff --git a/Misc/NEWS.d/next/Library/2026-03-17-20-41-27.gh-issue-146076.yoBNnB.rst b/Misc/NEWS.d/next/Library/2026-03-17-20-41-27.gh-issue-146076.yoBNnB.rst new file mode 100644 index 00000000000000..746f5b278829bd --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-03-17-20-41-27.gh-issue-146076.yoBNnB.rst @@ -0,0 +1,2 @@ +:mod:`zoneinfo`: fix crashes when deleting ``_weak_cache`` from a +:class:`zoneinfo.ZoneInfo` subclass. diff --git a/Modules/_zoneinfo.c b/Modules/_zoneinfo.c index 39671d1ab51dfa..e2ab04cc2073c5 100644 --- a/Modules/_zoneinfo.c +++ b/Modules/_zoneinfo.c @@ -321,6 +321,9 @@ zoneinfo_ZoneInfo_impl(PyTypeObject *type, PyObject *key) } PyObject *weak_cache = get_weak_cache(state, type); + if (weak_cache == NULL) { + return NULL; + } instance = PyObject_CallMethod(weak_cache, "get", "O", key, Py_None); if (instance == NULL) { Py_DECREF(weak_cache); @@ -505,6 +508,9 @@ zoneinfo_ZoneInfo_clear_cache_impl(PyTypeObject *type, PyTypeObject *cls, { zoneinfo_state *state = zoneinfo_get_state_by_cls(cls); PyObject *weak_cache = get_weak_cache(state, type); + if (weak_cache == NULL) { + return NULL; + } if (only_keys == NULL || only_keys == Py_None) { PyObject *rv = PyObject_CallMethod(weak_cache, "clear", NULL); From 847f83ef1c1693d75cc024b31c3dcb9bcaca826f Mon Sep 17 00:00:00 2001 From: Lysandros Nikolaou Date: Wed, 18 Mar 2026 14:18:28 +0100 Subject: [PATCH 05/11] gh-142518: Add thread safety notes for the buffer protocol (#145911) --- Doc/c-api/typeobj.rst | 28 ++++++++++++++++++ Doc/library/stdtypes.rst | 3 ++ Doc/library/threadsafety.rst | 56 ++++++++++++++++++++++++++++++++++++ Doc/reference/datamodel.rst | 13 +++++++++ 4 files changed, 100 insertions(+) diff --git a/Doc/c-api/typeobj.rst b/Doc/c-api/typeobj.rst index 87b488912653b9..cd13c0f4d61a42 100644 --- a/Doc/c-api/typeobj.rst +++ b/Doc/c-api/typeobj.rst @@ -3057,6 +3057,24 @@ Buffer Object Structures (5) Return ``0``. + **Thread safety:** + + In the :term:`free-threaded build`, implementations must ensure: + + * The export counter increment in step (3) is atomic. + + * The underlying buffer data remains valid and at a stable memory + location for the lifetime of all exports. + + * For objects that support resizing or reallocation (such as + :class:`bytearray`), the export counter is checked atomically before + such operations, and :exc:`BufferError` is raised if exports exist. + + * The function is safe to call concurrently from multiple threads. + + See also :ref:`thread-safety-memoryview` for the Python-level + thread safety guarantees of :class:`memoryview` objects. + If *exporter* is part of a chain or tree of buffer providers, two main schemes can be used: @@ -3102,6 +3120,16 @@ Buffer Object Structures (2) If the counter is ``0``, free all memory associated with *view*. + **Thread safety:** + + In the :term:`free-threaded build`: + + * The export counter decrement in step (1) must be atomic. + + * Resource cleanup when the counter reaches zero must be done atomically, + as the final release may race with concurrent releases from other + threads and dellocation must only happen once. + The exporter MUST use the :c:member:`~Py_buffer.internal` field to keep track of buffer-specific resources. This field is guaranteed to remain constant, while a consumer MAY pass a copy of the original buffer as the diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index 24f53a3a272d73..48291622d7be89 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -5045,6 +5045,9 @@ copying. .. versionadded:: 3.3 +For information on the thread safety of :class:`memoryview` objects in +the :term:`free-threaded build`, see :ref:`thread-safety-memoryview`. + .. _types-set: diff --git a/Doc/library/threadsafety.rst b/Doc/library/threadsafety.rst index 8063c2ea5011e7..a529f7803affbc 100644 --- a/Doc/library/threadsafety.rst +++ b/Doc/library/threadsafety.rst @@ -548,3 +548,59 @@ Thread safety for bytearray objects Consider external synchronization when sharing :class:`bytearray` instances across threads. See :ref:`freethreading-python-howto` for more information. + + +.. _thread-safety-memoryview: + +Thread safety for memoryview objects +==================================== + +:class:`memoryview` objects provide access to the internal data of an +underlying object without copying. Thread safety depends on both the +memoryview itself and the underlying buffer exporter. + +The memoryview implementation uses atomic operations to track its own +exports in the :term:`free-threaded build`. Creating and +releasing a memoryview are thread-safe. Attribute access (e.g., +:attr:`~memoryview.shape`, :attr:`~memoryview.format`) reads fields that +are immutable for the lifetime of the memoryview, so concurrent reads +are safe as long as the memoryview has not been released. + +However, the actual data accessed through the memoryview is owned by the +underlying object. Concurrent access to this data is only safe if the +underlying object supports it: + +* For immutable objects like :class:`bytes`, concurrent reads through + multiple memoryviews are safe. + +* For mutable objects like :class:`bytearray`, reading and writing the + same memory region from multiple threads without external + synchronization is not safe and may result in data corruption. + Note that even read-only memoryviews of mutable objects do not + prevent data races if the underlying object is modified from + another thread. + +.. code-block:: + :class: bad + + # NOT safe: concurrent writes to the same buffer + data = bytearray(1000) + view = memoryview(data) + # Thread 1: view[0:500] = b'x' * 500 + # Thread 2: view[0:500] = b'y' * 500 + +.. code-block:: + :class: good + + # Safe: use a lock for concurrent access + import threading + lock = threading.Lock() + data = bytearray(1000) + view = memoryview(data) + + with lock: + view[0:500] = b'x' * 500 + +Resizing or reallocating the underlying object (such as calling +:meth:`bytearray.resize`) while a memoryview is exported raises +:exc:`BufferError`. This is enforced regardless of threading. diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst index 90b8821daaf3fb..1e53c0e0e6f971 100644 --- a/Doc/reference/datamodel.rst +++ b/Doc/reference/datamodel.rst @@ -3637,12 +3637,25 @@ implement the protocol in Python. provides a convenient way to interpret the flags. The method must return a :class:`memoryview` object. + **Thread safety:** In :term:`free-threaded ` Python, + implementations must manage any internal export counter using atomic + operations. The method must be safe to call concurrently from multiple + threads, and the returned buffer's underlying data must remain valid + until the corresponding :meth:`~object.__release_buffer__` call + completes. See :ref:`thread-safety-memoryview` for details. + .. method:: object.__release_buffer__(self, buffer) Called when a buffer is no longer needed. The *buffer* argument is a :class:`memoryview` object that was previously returned by :meth:`~object.__buffer__`. The method must release any resources associated with the buffer. This method should return ``None``. + + **Thread safety:** In :term:`free-threaded ` Python, + any export counter decrement must use atomic operations. Resource + cleanup must be thread-safe, as the final release may race with + concurrent releases from other threads. + Buffer objects that do not need to perform any cleanup are not required to implement this method. From 70c7e040d4f50219bd2832391e1a98701281fc58 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Wed, 18 Mar 2026 17:04:11 +0200 Subject: [PATCH 06/11] gh-66419: Make optional arguments with nargs=REMAINDER consume all arguments (GH-124509) It no longer stops at the first '--'. --- Lib/argparse.py | 2 +- Lib/test/test_argparse.py | 14 ++++++++++++++ .../2024-09-25-12-47-50.gh-issue-66419.DVSukU.rst | 2 ++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Library/2024-09-25-12-47-50.gh-issue-66419.DVSukU.rst diff --git a/Lib/argparse.py b/Lib/argparse.py index 296a210ad832da..d91707d9eec546 100644 --- a/Lib/argparse.py +++ b/Lib/argparse.py @@ -2623,7 +2623,7 @@ def _get_nargs_pattern(self, action): # allow any number of options or arguments elif nargs == REMAINDER: - nargs_pattern = '([AO]*)' if option else '(.*)' + nargs_pattern = '(.*)' # allow one argument followed by any number of options or arguments elif nargs == PARSER: diff --git a/Lib/test/test_argparse.py b/Lib/test/test_argparse.py index 4526efe4b80ef4..e0c32976fd6f0d 100644 --- a/Lib/test/test_argparse.py +++ b/Lib/test/test_argparse.py @@ -6605,6 +6605,20 @@ def test_remainder(self): args = parser.parse_args(['--foo', 'a', '--', 'b', '--', 'c']) self.assertEqual(NS(foo='a', bar=['--', 'b', '--', 'c']), args) + def test_optional_remainder(self): + parser = argparse.ArgumentParser(exit_on_error=False) + parser.add_argument('--foo', nargs='...') + parser.add_argument('bar', nargs='*') + + args = parser.parse_args(['--', '--foo', 'a', 'b']) + self.assertEqual(NS(foo=None, bar=['--foo', 'a', 'b']), args) + args = parser.parse_args(['--foo', '--', 'a', 'b']) + self.assertEqual(NS(foo=['--', 'a', 'b'], bar=[]), args) + args = parser.parse_args(['--foo', 'a', '--', 'b']) + self.assertEqual(NS(foo=['a', '--', 'b'], bar=[]), args) + args = parser.parse_args(['--foo', 'a', 'b', '--']) + self.assertEqual(NS(foo=['a', 'b', '--'], bar=[]), args) + def test_subparser(self): parser = argparse.ArgumentParser(exit_on_error=False) parser.add_argument('foo') diff --git a/Misc/NEWS.d/next/Library/2024-09-25-12-47-50.gh-issue-66419.DVSukU.rst b/Misc/NEWS.d/next/Library/2024-09-25-12-47-50.gh-issue-66419.DVSukU.rst new file mode 100644 index 00000000000000..ceac0616599466 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2024-09-25-12-47-50.gh-issue-66419.DVSukU.rst @@ -0,0 +1,2 @@ +Optional argument with :ref:`nargs` equals to ``argparse.REMAINDER`` now +consumes all remaining arguments including ``'--'``. From 1e4ed932109c4f8ee4f43bc3e6fdb7710a3606bd Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 18 Mar 2026 17:23:05 +0100 Subject: [PATCH 07/11] gh-146092: Fix error handling in _BINARY_OP_ADD_UNICODE opcode (#146117) Fix also error handling in _BINARY_OP_ADD_FLOAT, _BINARY_OP_SUBTRACT_FLOAT and _BINARY_OP_MULTIPLY_FLOAT opcodes. PyStackRef_FromPyObjectSteal() must not be called with a NULL pointer. --- Modules/_testinternalcapi/test_cases.c.h | 19 ++++---- Python/bytecodes.c | 19 ++++---- Python/executor_cases.c.h | 57 ++++++++++++++---------- Python/generated_cases.c.h | 19 ++++---- 4 files changed, 66 insertions(+), 48 deletions(-) diff --git a/Modules/_testinternalcapi/test_cases.c.h b/Modules/_testinternalcapi/test_cases.c.h index 948a413d98ddcd..12480e2cb1962f 100644 --- a/Modules/_testinternalcapi/test_cases.c.h +++ b/Modules/_testinternalcapi/test_cases.c.h @@ -141,10 +141,11 @@ double dres = ((PyFloatObject *)left_o)->ob_fval + ((PyFloatObject *)right_o)->ob_fval; - res = PyStackRef_FromPyObjectSteal(PyFloat_FromDouble(dres)); - if (PyStackRef_IsNull(res)) { + PyObject *d = PyFloat_FromDouble(dres); + if (d == NULL) { JUMP_TO_LABEL(error); } + res = PyStackRef_FromPyObjectSteal(d); l = left; r = right; } @@ -289,10 +290,10 @@ assert(PyUnicode_CheckExact(right_o)); STAT_INC(BINARY_OP, hit); PyObject *res_o = PyUnicode_Concat(left_o, right_o); - res = PyStackRef_FromPyObjectSteal(res_o); - if (PyStackRef_IsNull(res)) { + if (res_o == NULL) { JUMP_TO_LABEL(error); } + res = PyStackRef_FromPyObjectSteal(res_o); l = left; r = right; } @@ -521,10 +522,11 @@ double dres = ((PyFloatObject *)left_o)->ob_fval * ((PyFloatObject *)right_o)->ob_fval; - res = PyStackRef_FromPyObjectSteal(PyFloat_FromDouble(dres)); - if (PyStackRef_IsNull(res)) { + PyObject *d = PyFloat_FromDouble(dres); + if (d == NULL) { JUMP_TO_LABEL(error); } + res = PyStackRef_FromPyObjectSteal(d); l = left; r = right; } @@ -1270,10 +1272,11 @@ double dres = ((PyFloatObject *)left_o)->ob_fval - ((PyFloatObject *)right_o)->ob_fval; - res = PyStackRef_FromPyObjectSteal(PyFloat_FromDouble(dres)); - if (PyStackRef_IsNull(res)) { + PyObject *d = PyFloat_FromDouble(dres); + if (d == NULL) { JUMP_TO_LABEL(error); } + res = PyStackRef_FromPyObjectSteal(d); l = left; r = right; } diff --git a/Python/bytecodes.c b/Python/bytecodes.c index 2fb2c33428255a..e170fd65a20f64 100644 --- a/Python/bytecodes.c +++ b/Python/bytecodes.c @@ -710,10 +710,11 @@ dummy_func( double dres = ((PyFloatObject *)left_o)->ob_fval * ((PyFloatObject *)right_o)->ob_fval; - res = PyStackRef_FromPyObjectSteal(PyFloat_FromDouble(dres)); - if (PyStackRef_IsNull(res)) { + PyObject *d = PyFloat_FromDouble(dres); + if (d == NULL) { ERROR_NO_POP(); } + res = PyStackRef_FromPyObjectSteal(d); l = left; r = right; INPUTS_DEAD(); @@ -729,10 +730,11 @@ dummy_func( double dres = ((PyFloatObject *)left_o)->ob_fval + ((PyFloatObject *)right_o)->ob_fval; - res = PyStackRef_FromPyObjectSteal(PyFloat_FromDouble(dres)); - if (PyStackRef_IsNull(res)) { + PyObject *d = PyFloat_FromDouble(dres); + if (d == NULL) { ERROR_NO_POP(); } + res = PyStackRef_FromPyObjectSteal(d); l = left; r = right; INPUTS_DEAD(); @@ -748,10 +750,11 @@ dummy_func( double dres = ((PyFloatObject *)left_o)->ob_fval - ((PyFloatObject *)right_o)->ob_fval; - res = PyStackRef_FromPyObjectSteal(PyFloat_FromDouble(dres)); - if (PyStackRef_IsNull(res)) { + PyObject *d = PyFloat_FromDouble(dres); + if (d == NULL) { ERROR_NO_POP(); } + res = PyStackRef_FromPyObjectSteal(d); l = left; r = right; INPUTS_DEAD(); @@ -772,10 +775,10 @@ dummy_func( STAT_INC(BINARY_OP, hit); PyObject *res_o = PyUnicode_Concat(left_o, right_o); - res = PyStackRef_FromPyObjectSteal(res_o); - if (PyStackRef_IsNull(res)) { + if (res_o == NULL) { ERROR_NO_POP(); } + res = PyStackRef_FromPyObjectSteal(res_o); l = left; r = right; INPUTS_DEAD(); diff --git a/Python/executor_cases.c.h b/Python/executor_cases.c.h index d89d512fd5630a..d33c67dd745bbf 100644 --- a/Python/executor_cases.c.h +++ b/Python/executor_cases.c.h @@ -4620,11 +4620,12 @@ double dres = ((PyFloatObject *)left_o)->ob_fval * ((PyFloatObject *)right_o)->ob_fval; - res = PyStackRef_FromPyObjectSteal(PyFloat_FromDouble(dres)); - if (PyStackRef_IsNull(res)) { + PyObject *d = PyFloat_FromDouble(dres); + if (d == NULL) { SET_CURRENT_CACHED_VALUES(0); JUMP_TO_ERROR(); } + res = PyStackRef_FromPyObjectSteal(d); l = left; r = right; _tos_cache2 = r; @@ -4656,14 +4657,15 @@ double dres = ((PyFloatObject *)left_o)->ob_fval * ((PyFloatObject *)right_o)->ob_fval; - res = PyStackRef_FromPyObjectSteal(PyFloat_FromDouble(dres)); - if (PyStackRef_IsNull(res)) { + PyObject *d = PyFloat_FromDouble(dres); + if (d == NULL) { stack_pointer[0] = right; stack_pointer += 1; ASSERT_WITHIN_STACK_BOUNDS(__FILE__, __LINE__); SET_CURRENT_CACHED_VALUES(0); JUMP_TO_ERROR(); } + res = PyStackRef_FromPyObjectSteal(d); l = left; r = right; _tos_cache2 = r; @@ -4696,8 +4698,8 @@ double dres = ((PyFloatObject *)left_o)->ob_fval * ((PyFloatObject *)right_o)->ob_fval; - res = PyStackRef_FromPyObjectSteal(PyFloat_FromDouble(dres)); - if (PyStackRef_IsNull(res)) { + PyObject *d = PyFloat_FromDouble(dres); + if (d == NULL) { stack_pointer[0] = left; stack_pointer[1] = right; stack_pointer += 2; @@ -4705,6 +4707,7 @@ SET_CURRENT_CACHED_VALUES(0); JUMP_TO_ERROR(); } + res = PyStackRef_FromPyObjectSteal(d); l = left; r = right; _tos_cache2 = r; @@ -4733,11 +4736,12 @@ double dres = ((PyFloatObject *)left_o)->ob_fval + ((PyFloatObject *)right_o)->ob_fval; - res = PyStackRef_FromPyObjectSteal(PyFloat_FromDouble(dres)); - if (PyStackRef_IsNull(res)) { + PyObject *d = PyFloat_FromDouble(dres); + if (d == NULL) { SET_CURRENT_CACHED_VALUES(0); JUMP_TO_ERROR(); } + res = PyStackRef_FromPyObjectSteal(d); l = left; r = right; _tos_cache2 = r; @@ -4769,14 +4773,15 @@ double dres = ((PyFloatObject *)left_o)->ob_fval + ((PyFloatObject *)right_o)->ob_fval; - res = PyStackRef_FromPyObjectSteal(PyFloat_FromDouble(dres)); - if (PyStackRef_IsNull(res)) { + PyObject *d = PyFloat_FromDouble(dres); + if (d == NULL) { stack_pointer[0] = right; stack_pointer += 1; ASSERT_WITHIN_STACK_BOUNDS(__FILE__, __LINE__); SET_CURRENT_CACHED_VALUES(0); JUMP_TO_ERROR(); } + res = PyStackRef_FromPyObjectSteal(d); l = left; r = right; _tos_cache2 = r; @@ -4809,8 +4814,8 @@ double dres = ((PyFloatObject *)left_o)->ob_fval + ((PyFloatObject *)right_o)->ob_fval; - res = PyStackRef_FromPyObjectSteal(PyFloat_FromDouble(dres)); - if (PyStackRef_IsNull(res)) { + PyObject *d = PyFloat_FromDouble(dres); + if (d == NULL) { stack_pointer[0] = left; stack_pointer[1] = right; stack_pointer += 2; @@ -4818,6 +4823,7 @@ SET_CURRENT_CACHED_VALUES(0); JUMP_TO_ERROR(); } + res = PyStackRef_FromPyObjectSteal(d); l = left; r = right; _tos_cache2 = r; @@ -4846,11 +4852,12 @@ double dres = ((PyFloatObject *)left_o)->ob_fval - ((PyFloatObject *)right_o)->ob_fval; - res = PyStackRef_FromPyObjectSteal(PyFloat_FromDouble(dres)); - if (PyStackRef_IsNull(res)) { + PyObject *d = PyFloat_FromDouble(dres); + if (d == NULL) { SET_CURRENT_CACHED_VALUES(0); JUMP_TO_ERROR(); } + res = PyStackRef_FromPyObjectSteal(d); l = left; r = right; _tos_cache2 = r; @@ -4882,14 +4889,15 @@ double dres = ((PyFloatObject *)left_o)->ob_fval - ((PyFloatObject *)right_o)->ob_fval; - res = PyStackRef_FromPyObjectSteal(PyFloat_FromDouble(dres)); - if (PyStackRef_IsNull(res)) { + PyObject *d = PyFloat_FromDouble(dres); + if (d == NULL) { stack_pointer[0] = right; stack_pointer += 1; ASSERT_WITHIN_STACK_BOUNDS(__FILE__, __LINE__); SET_CURRENT_CACHED_VALUES(0); JUMP_TO_ERROR(); } + res = PyStackRef_FromPyObjectSteal(d); l = left; r = right; _tos_cache2 = r; @@ -4922,8 +4930,8 @@ double dres = ((PyFloatObject *)left_o)->ob_fval - ((PyFloatObject *)right_o)->ob_fval; - res = PyStackRef_FromPyObjectSteal(PyFloat_FromDouble(dres)); - if (PyStackRef_IsNull(res)) { + PyObject *d = PyFloat_FromDouble(dres); + if (d == NULL) { stack_pointer[0] = left; stack_pointer[1] = right; stack_pointer += 2; @@ -4931,6 +4939,7 @@ SET_CURRENT_CACHED_VALUES(0); JUMP_TO_ERROR(); } + res = PyStackRef_FromPyObjectSteal(d); l = left; r = right; _tos_cache2 = r; @@ -4957,11 +4966,11 @@ assert(PyUnicode_CheckExact(right_o)); STAT_INC(BINARY_OP, hit); PyObject *res_o = PyUnicode_Concat(left_o, right_o); - res = PyStackRef_FromPyObjectSteal(res_o); - if (PyStackRef_IsNull(res)) { + if (res_o == NULL) { SET_CURRENT_CACHED_VALUES(0); JUMP_TO_ERROR(); } + res = PyStackRef_FromPyObjectSteal(res_o); l = left; r = right; _tos_cache2 = r; @@ -4991,14 +5000,14 @@ assert(PyUnicode_CheckExact(right_o)); STAT_INC(BINARY_OP, hit); PyObject *res_o = PyUnicode_Concat(left_o, right_o); - res = PyStackRef_FromPyObjectSteal(res_o); - if (PyStackRef_IsNull(res)) { + if (res_o == NULL) { stack_pointer[0] = right; stack_pointer += 1; ASSERT_WITHIN_STACK_BOUNDS(__FILE__, __LINE__); SET_CURRENT_CACHED_VALUES(0); JUMP_TO_ERROR(); } + res = PyStackRef_FromPyObjectSteal(res_o); l = left; r = right; _tos_cache2 = r; @@ -5029,8 +5038,7 @@ assert(PyUnicode_CheckExact(right_o)); STAT_INC(BINARY_OP, hit); PyObject *res_o = PyUnicode_Concat(left_o, right_o); - res = PyStackRef_FromPyObjectSteal(res_o); - if (PyStackRef_IsNull(res)) { + if (res_o == NULL) { stack_pointer[0] = left; stack_pointer[1] = right; stack_pointer += 2; @@ -5038,6 +5046,7 @@ SET_CURRENT_CACHED_VALUES(0); JUMP_TO_ERROR(); } + res = PyStackRef_FromPyObjectSteal(res_o); l = left; r = right; _tos_cache2 = r; diff --git a/Python/generated_cases.c.h b/Python/generated_cases.c.h index a66d6ccff2d82d..628f0cc4d37310 100644 --- a/Python/generated_cases.c.h +++ b/Python/generated_cases.c.h @@ -141,10 +141,11 @@ double dres = ((PyFloatObject *)left_o)->ob_fval + ((PyFloatObject *)right_o)->ob_fval; - res = PyStackRef_FromPyObjectSteal(PyFloat_FromDouble(dres)); - if (PyStackRef_IsNull(res)) { + PyObject *d = PyFloat_FromDouble(dres); + if (d == NULL) { JUMP_TO_LABEL(error); } + res = PyStackRef_FromPyObjectSteal(d); l = left; r = right; } @@ -289,10 +290,10 @@ assert(PyUnicode_CheckExact(right_o)); STAT_INC(BINARY_OP, hit); PyObject *res_o = PyUnicode_Concat(left_o, right_o); - res = PyStackRef_FromPyObjectSteal(res_o); - if (PyStackRef_IsNull(res)) { + if (res_o == NULL) { JUMP_TO_LABEL(error); } + res = PyStackRef_FromPyObjectSteal(res_o); l = left; r = right; } @@ -521,10 +522,11 @@ double dres = ((PyFloatObject *)left_o)->ob_fval * ((PyFloatObject *)right_o)->ob_fval; - res = PyStackRef_FromPyObjectSteal(PyFloat_FromDouble(dres)); - if (PyStackRef_IsNull(res)) { + PyObject *d = PyFloat_FromDouble(dres); + if (d == NULL) { JUMP_TO_LABEL(error); } + res = PyStackRef_FromPyObjectSteal(d); l = left; r = right; } @@ -1270,10 +1272,11 @@ double dres = ((PyFloatObject *)left_o)->ob_fval - ((PyFloatObject *)right_o)->ob_fval; - res = PyStackRef_FromPyObjectSteal(PyFloat_FromDouble(dres)); - if (PyStackRef_IsNull(res)) { + PyObject *d = PyFloat_FromDouble(dres); + if (d == NULL) { JUMP_TO_LABEL(error); } + res = PyStackRef_FromPyObjectSteal(d); l = left; r = right; } From 5b25eaec373430b628a1e591f7312f9bdafe55b2 Mon Sep 17 00:00:00 2001 From: Lysandros Nikolaou Date: Wed, 18 Mar 2026 17:42:20 +0100 Subject: [PATCH 08/11] gh-142518: Annotate PyList_* C APIs for thread safety (#146109) --- Doc/c-api/list.rst | 44 ++++++++++++++++++++++++++++++ Doc/data/threadsafety.dat | 56 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+) diff --git a/Doc/c-api/list.rst b/Doc/c-api/list.rst index 758415a76e5cb4..8f560699d355e4 100644 --- a/Doc/c-api/list.rst +++ b/Doc/c-api/list.rst @@ -74,11 +74,25 @@ List Objects Like :c:func:`PyList_GetItemRef`, but returns a :term:`borrowed reference` instead of a :term:`strong reference`. + .. note:: + + In the :term:`free-threaded build`, the returned + :term:`borrowed reference` may become invalid if another thread modifies + the list concurrently. Prefer :c:func:`PyList_GetItemRef`, which returns + a :term:`strong reference`. + .. c:function:: PyObject* PyList_GET_ITEM(PyObject *list, Py_ssize_t i) Similar to :c:func:`PyList_GetItem`, but without error checking. + .. note:: + + In the :term:`free-threaded build`, the returned + :term:`borrowed reference` may become invalid if another thread modifies + the list concurrently. Prefer :c:func:`PyList_GetItemRef`, which returns + a :term:`strong reference`. + .. c:function:: int PyList_SetItem(PyObject *list, Py_ssize_t index, PyObject *item) @@ -108,6 +122,14 @@ List Objects is being replaced; any reference in *list* at position *i* will be leaked. + .. note:: + + In the :term:`free-threaded build`, this macro has no internal + synchronization. It is normally only used to fill in new lists where no + other thread has a reference to the list. If the list may be shared, + use :c:func:`PyList_SetItem` instead, which uses a :term:`per-object + lock`. + .. c:function:: int PyList_Insert(PyObject *list, Py_ssize_t index, PyObject *item) @@ -138,6 +160,12 @@ List Objects Return ``0`` on success, ``-1`` on failure. Indexing from the end of the list is not supported. + .. note:: + + In the :term:`free-threaded build`, when *itemlist* is a :class:`list`, + both *list* and *itemlist* are locked for the duration of the operation. + For other iterables (or ``NULL``), only *list* is locked. + .. c:function:: int PyList_Extend(PyObject *list, PyObject *iterable) @@ -150,6 +178,14 @@ List Objects .. versionadded:: 3.13 + .. note:: + + In the :term:`free-threaded build`, when *iterable* is a :class:`list`, + :class:`set`, :class:`dict`, or dict view, both *list* and *iterable* + (or its underlying dict) are locked for the duration of the operation. + For other iterables, only *list* is locked; *iterable* may be + concurrently modified by another thread. + .. c:function:: int PyList_Clear(PyObject *list) @@ -168,6 +204,14 @@ List Objects Sort the items of *list* in place. Return ``0`` on success, ``-1`` on failure. This is equivalent to ``list.sort()``. + .. note:: + + In the :term:`free-threaded build`, element comparison via + :meth:`~object.__lt__` can execute arbitrary Python code, during which + the :term:`per-object lock` may be temporarily released. For built-in + types (:class:`str`, :class:`int`, :class:`float`), the lock is not + released during comparison. + .. c:function:: int PyList_Reverse(PyObject *list) diff --git a/Doc/data/threadsafety.dat b/Doc/data/threadsafety.dat index f063ca1360d5fb..103e8ef3e97ed1 100644 --- a/Doc/data/threadsafety.dat +++ b/Doc/data/threadsafety.dat @@ -17,3 +17,59 @@ PyMutex_Lock:shared: PyMutex_Unlock:shared: PyMutex_IsLocked:atomic: + +# List objects (Doc/c-api/list.rst) + +# Type checks - read ob_type pointer, always safe +PyList_Check:atomic: +PyList_CheckExact:atomic: + +# Creation - pure allocation, no shared state +PyList_New:atomic: + +# Size - uses atomic load on free-threaded builds +PyList_Size:atomic: +PyList_GET_SIZE:atomic: + +# Strong-reference lookup - lock-free with atomic ops +PyList_GetItemRef:atomic: + +# Borrowed-reference lookups - no locking; returned borrowed +# reference is unsafe in free-threaded builds without +# external synchronization +PyList_GetItem:compatible: +PyList_GET_ITEM:compatible: + +# Single-item mutations - hold per-object lock for duration; +# appear atomic to lock-free readers +PyList_SetItem:atomic: +PyList_Append:atomic: + +# Insert - protected by per-object critical section; shifts +# elements so lock-free readers may observe intermediate states +PyList_Insert:shared: + +# Initialization macro - no synchronization; normally only used +# to fill in new lists where there is no previous content +PyList_SET_ITEM:compatible: + +# Bulk operations - hold per-object lock for duration +PyList_GetSlice:atomic: +PyList_AsTuple:atomic: +PyList_Clear:atomic: + +# Reverse - protected by per-object critical section; swaps +# elements so lock-free readers may observe intermediate states +PyList_Reverse:shared: + +# Slice assignment - lock target list; also lock source when it +# is a list +PyList_SetSlice:shared: + +# Sort - per-object lock held; comparison callbacks may execute +# arbitrary Python code +PyList_Sort:shared: + +# Extend - lock target list; also lock source when it is a +# list, set, or dict +PyList_Extend:shared: From 2c6afb935ad588f32cb969345d0345e45d3a766e Mon Sep 17 00:00:00 2001 From: Bartosz Grabowski <58475557+bartosz-grabowski@users.noreply.github.com> Date: Wed, 18 Mar 2026 17:49:15 +0100 Subject: [PATCH 09/11] docs: fix f-string in ExceptionGroup example (#146108) --- Doc/tutorial/errors.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/tutorial/errors.rst b/Doc/tutorial/errors.rst index ae21dfdbf0ac44..3c6edf2c4793ab 100644 --- a/Doc/tutorial/errors.rst +++ b/Doc/tutorial/errors.rst @@ -549,9 +549,9 @@ caught like any other exception. :: >>> try: ... f() ... except Exception as e: - ... print(f'caught {type(e)}: e') + ... print(f'caught {type(e)}: {e}') ... - caught : e + caught : there were problems (2 sub-exceptions) >>> By using ``except*`` instead of ``except``, we can selectively From 6fe91a9e803e1cae6d7341a02f1f45244ec45b20 Mon Sep 17 00:00:00 2001 From: Hai Zhu Date: Thu, 19 Mar 2026 00:58:14 +0800 Subject: [PATCH 10/11] gh-144888: JIT executor bloom filter wide-type optimization and function Inlining (GH-146114) --- Include/internal/pycore_optimizer.h | 81 ++++++++++++++++++++++++++- Include/internal/pycore_uop.h | 15 ++++- Python/optimizer.c | 85 ----------------------------- 3 files changed, 92 insertions(+), 89 deletions(-) diff --git a/Include/internal/pycore_optimizer.h b/Include/internal/pycore_optimizer.h index 8b52d77538abf2..6b3c39d64c9c32 100644 --- a/Include/internal/pycore_optimizer.h +++ b/Include/internal/pycore_optimizer.h @@ -159,10 +159,87 @@ PyAPI_FUNC(_PyExecutorObject*) _Py_GetExecutor(PyCodeObject *code, int offset); int _Py_ExecutorInit(_PyExecutorObject *, const _PyBloomFilter *); void _Py_ExecutorDetach(_PyExecutorObject *); -void _Py_BloomFilter_Init(_PyBloomFilter *); -void _Py_BloomFilter_Add(_PyBloomFilter *bloom, void *obj); PyAPI_FUNC(void) _Py_Executor_DependsOn(_PyExecutorObject *executor, void *obj); +/* We use a bloomfilter with k = 6, m = 256 + * The choice of k and the following constants + * could do with a more rigorous analysis, + * but here is a simple analysis: + * + * We want to keep the false positive rate low. + * For n = 5 (a trace depends on 5 objects), + * we expect 30 bits set, giving a false positive + * rate of (30/256)**6 == 2.5e-6 which is plenty + * good enough. + * + * However with n = 10 we expect 60 bits set (worst case), + * giving a false positive of (60/256)**6 == 0.0001 + * + * We choose k = 6, rather than a higher number as + * it means the false positive rate grows slower for high n. + * + * n = 5, k = 6 => fp = 2.6e-6 + * n = 5, k = 8 => fp = 3.5e-7 + * n = 10, k = 6 => fp = 1.6e-4 + * n = 10, k = 8 => fp = 0.9e-4 + * n = 15, k = 6 => fp = 0.18% + * n = 15, k = 8 => fp = 0.23% + * n = 20, k = 6 => fp = 1.1% + * n = 20, k = 8 => fp = 2.3% + * + * The above analysis assumes perfect hash functions, + * but those don't exist, so the real false positive + * rates may be worse. + */ + +#define _Py_BLOOM_FILTER_K 6 +#define _Py_BLOOM_FILTER_SEED 20221211 + +static inline uint64_t +address_to_hash(void *ptr) { + assert(ptr != NULL); + uint64_t uhash = _Py_BLOOM_FILTER_SEED; + uintptr_t addr = (uintptr_t)ptr; + for (int i = 0; i < SIZEOF_VOID_P; i++) { + uhash ^= addr & 255; + uhash *= (uint64_t)PyHASH_MULTIPLIER; + addr >>= 8; + } + return uhash; +} + +static inline void +_Py_BloomFilter_Init(_PyBloomFilter *bloom) +{ + for (int i = 0; i < _Py_BLOOM_FILTER_WORDS; i++) { + bloom->bits[i] = 0; + } +} + +static inline void +_Py_BloomFilter_Add(_PyBloomFilter *bloom, void *ptr) +{ + uint64_t hash = address_to_hash(ptr); + assert(_Py_BLOOM_FILTER_K <= 8); + for (int i = 0; i < _Py_BLOOM_FILTER_K; i++) { + uint8_t bits = hash & 255; + bloom->bits[bits >> _Py_BLOOM_FILTER_WORD_SHIFT] |= + (_Py_bloom_filter_word_t)1 << (bits & (_Py_BLOOM_FILTER_BITS_PER_WORD - 1)); + hash >>= 8; + } +} + +static inline bool +bloom_filter_may_contain(const _PyBloomFilter *bloom, const _PyBloomFilter *hashes) +{ + for (int i = 0; i < _Py_BLOOM_FILTER_WORDS; i++) { + if ((bloom->bits[i] & hashes->bits[i]) != hashes->bits[i]) { + return false; + } + } + return true; +} + #define _Py_MAX_ALLOWED_BUILTINS_MODIFICATIONS 3 #define _Py_MAX_ALLOWED_GLOBALS_MODIFICATIONS 6 diff --git a/Include/internal/pycore_uop.h b/Include/internal/pycore_uop.h index e7ac7d59ff7e27..7bc8947cfa9a9d 100644 --- a/Include/internal/pycore_uop.h +++ b/Include/internal/pycore_uop.h @@ -45,10 +45,21 @@ typedef struct _PyUOpInstruction{ /* Bloom filter with m = 256 * https://en.wikipedia.org/wiki/Bloom_filter */ -#define _Py_BLOOM_FILTER_WORDS 8 +#ifdef HAVE_GCC_UINT128_T +#define _Py_BLOOM_FILTER_WORDS 2 +typedef __uint128_t _Py_bloom_filter_word_t; +#else +#define _Py_BLOOM_FILTER_WORDS 4 +typedef uint64_t _Py_bloom_filter_word_t; +#endif + +#define _Py_BLOOM_FILTER_BITS_PER_WORD \ + ((int)(sizeof(_Py_bloom_filter_word_t) * 8)) +#define _Py_BLOOM_FILTER_WORD_SHIFT \ + ((sizeof(_Py_bloom_filter_word_t) == 16) ? 7 : 6) typedef struct { - uint32_t bits[_Py_BLOOM_FILTER_WORDS]; + _Py_bloom_filter_word_t bits[_Py_BLOOM_FILTER_WORDS]; } _PyBloomFilter; #ifdef __cplusplus diff --git a/Python/optimizer.c b/Python/optimizer.c index 83a11f613a2db7..f09bf778587b12 100644 --- a/Python/optimizer.c +++ b/Python/optimizer.c @@ -1601,91 +1601,6 @@ uop_optimize( * Executor management ****************************************/ -/* We use a bloomfilter with k = 6, m = 256 - * The choice of k and the following constants - * could do with a more rigorous analysis, - * but here is a simple analysis: - * - * We want to keep the false positive rate low. - * For n = 5 (a trace depends on 5 objects), - * we expect 30 bits set, giving a false positive - * rate of (30/256)**6 == 2.5e-6 which is plenty - * good enough. - * - * However with n = 10 we expect 60 bits set (worst case), - * giving a false positive of (60/256)**6 == 0.0001 - * - * We choose k = 6, rather than a higher number as - * it means the false positive rate grows slower for high n. - * - * n = 5, k = 6 => fp = 2.6e-6 - * n = 5, k = 8 => fp = 3.5e-7 - * n = 10, k = 6 => fp = 1.6e-4 - * n = 10, k = 8 => fp = 0.9e-4 - * n = 15, k = 6 => fp = 0.18% - * n = 15, k = 8 => fp = 0.23% - * n = 20, k = 6 => fp = 1.1% - * n = 20, k = 8 => fp = 2.3% - * - * The above analysis assumes perfect hash functions, - * but those don't exist, so the real false positive - * rates may be worse. - */ - -#define K 6 - -#define SEED 20221211 - -/* TO DO -- Use more modern hash functions with better distribution of bits */ -static uint64_t -address_to_hash(void *ptr) { - assert(ptr != NULL); - uint64_t uhash = SEED; - uintptr_t addr = (uintptr_t)ptr; - for (int i = 0; i < SIZEOF_VOID_P; i++) { - uhash ^= addr & 255; - uhash *= (uint64_t)PyHASH_MULTIPLIER; - addr >>= 8; - } - return uhash; -} - -void -_Py_BloomFilter_Init(_PyBloomFilter *bloom) -{ - for (int i = 0; i < _Py_BLOOM_FILTER_WORDS; i++) { - bloom->bits[i] = 0; - } -} - -/* We want K hash functions that each set 1 bit. - * A hash function that sets 1 bit in M bits can be trivially - * derived from a log2(M) bit hash function. - * So we extract 8 (log2(256)) bits at a time from - * the 64bit hash. */ -void -_Py_BloomFilter_Add(_PyBloomFilter *bloom, void *ptr) -{ - uint64_t hash = address_to_hash(ptr); - assert(K <= 8); - for (int i = 0; i < K; i++) { - uint8_t bits = hash & 255; - bloom->bits[bits >> 5] |= (1 << (bits&31)); - hash >>= 8; - } -} - -static bool -bloom_filter_may_contain(_PyBloomFilter *bloom, _PyBloomFilter *hashes) -{ - for (int i = 0; i < _Py_BLOOM_FILTER_WORDS; i++) { - if ((bloom->bits[i] & hashes->bits[i]) != hashes->bits[i]) { - return false; - } - } - return true; -} - static int link_executor(_PyExecutorObject *executor, const _PyBloomFilter *bloom) { From 724c7c8146f44a7c737ec4588a1ee4b9db994f6f Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 18 Mar 2026 18:20:35 +0100 Subject: [PATCH 11/11] gh-146093: Fix csv _set_str(): check if PyUnicode_DecodeASCII() failed (#146113) The function can fail on a memory allocation failure. Bug reported by devdanzin. --- Modules/_csv.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Modules/_csv.c b/Modules/_csv.c index c48f44c0f07867..a3f840acbe8c0b 100644 --- a/Modules/_csv.c +++ b/Modules/_csv.c @@ -315,8 +315,12 @@ _set_char(const char *name, Py_UCS4 *target, PyObject *src, Py_UCS4 dflt) static int _set_str(const char *name, PyObject **target, PyObject *src, const char *dflt) { - if (src == NULL) + if (src == NULL) { *target = PyUnicode_DecodeASCII(dflt, strlen(dflt), NULL); + if (*target == NULL) { + return -1; + } + } else { if (!PyUnicode_Check(src)) { PyErr_Format(PyExc_TypeError,