Victor Stinner [Sat, 18 Jan 2025 15:13:54 +0000 (16:13 +0100)]
gh-128679: Skip test_tracemalloc_track_race() on debug build (#128988)
There is a race condition between PyMem_SetAllocator() and
PyMem_RawMalloc()/PyMem_RawFree(). While PyMem_SetAllocator() write
is protected by a lock, PyMem_RawMalloc()/PyMem_RawFree() reads are
not protected by a lock. PyMem_RawMalloc()/PyMem_RawFree() can be
called with an old context and the new function pointer.
On a release build, it's not an issue since the context is not used.
On a debug build, the debug hooks use the context and so can crash.
Michał Górny [Sat, 18 Jan 2025 00:49:16 +0000 (01:49 +0100)]
gh-128916: Do not set `SO_REUSEPORT` on non-`AF_INET*` sockets (GH-128933)
* gh-128916: Do not set `SO_REUSEPORT` on non-`AF_INET*` sockets
Do not attempt to set ``SO_REUSEPORT`` on sockets of address familifies other
than ``AF_INET`` and ``AF_INET6``, as it is meaningless with these address
families, and the call with fail with Linux kernel 6.12.9 and newer.
Sam Gross [Fri, 17 Jan 2025 15:42:27 +0000 (10:42 -0500)]
gh-128923: Use zero to indicate unassigned unique id (#128925)
In the free threading build, the per thread reference counting uses a
unique id for some objects to index into the local reference count
table. Use 0 instead of -1 to indicate that the id is not assigned. This
avoids bugs where zero-initialized heap type objects look like they have
a unique id assigned.
Victor Stinner [Fri, 17 Jan 2025 13:55:43 +0000 (14:55 +0100)]
gh-59705: Implement _thread.set_name() on Windows (#128675)
Implement set_name() with SetThreadDescription() and _get_name() with
GetThreadDescription(). If SetThreadDescription() or
GetThreadDescription() is not available in kernelbase.dll, delete the
method when the _thread module is imported.
tracemalloc_alloc(), tracemalloc_realloc(), tracemalloc_free(),
_PyTraceMalloc_TraceRef() and _PyTraceMalloc_GetMemory() now check
'tracemalloc_config.tracing' after calling TABLES_LOCK().
Victor Stinner [Wed, 15 Jan 2025 20:22:44 +0000 (21:22 +0100)]
gh-128679: Redesign tracemalloc locking (#128888)
* Use TABLES_LOCK() to protect 'tracemalloc_config.tracing'.
* Hold TABLES_LOCK() longer while accessing tables.
* tracemalloc_realloc() and tracemalloc_free() no longer
remove the trace on reentrant call.
* _PyTraceMalloc_Stop() unregisters _PyTraceMalloc_TraceRef().
* _PyTraceMalloc_GetTraces() sets the reentrant flag.
* tracemalloc_clear_traces_unlocked() sets the reentrant flag.
Thomas Grainger [Wed, 15 Jan 2025 13:05:59 +0000 (13:05 +0000)]
gh-128816: Fix warnings in test_doctest (GH-128817)
* Fix a deprecation warning for using importlib.resources.abc.ResourceReader.
* Fix an import warning when importing readline (if it has not yet been imported).
Yan Yanchii [Wed, 15 Jan 2025 09:38:43 +0000 (10:38 +0100)]
gh-128438: Use `EnvironmentVarGuard` for `test_{builtin,io,locale}.py` (#128476)
Modifying locale-related environment variables in `Lib/test/test_builtin.py`,
`Lib/test/test_io.py` and `Lib/test/test_locale.py` is now achieved by using
an `EnvironmentVarGuard` context instead of an explicit `try-finally` block.
Bénédikt Tran [Tue, 14 Jan 2025 13:25:33 +0000 (14:25 +0100)]
gh-118761: substitute `re` import in `base64.b16decode` for a more efficient alternative (#128736)
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com> Co-authored-by: Chris Markiewicz <effigies@gmail.com> Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
Serhiy Storchaka [Tue, 14 Jan 2025 08:02:38 +0000 (10:02 +0200)]
gh-71339: Add additional assertion methods for unittest (GH-128707)
Add the following methods:
* assertHasAttr() and assertNotHasAttr()
* assertIsSubclass() and assertNotIsSubclass()
* assertStartsWith() and assertNotStartsWith()
* assertEndsWith() and assertNotEndsWith()
Also improve error messages for assertIsInstance() and
assertNotIsInstance().
Bénédikt Tran [Mon, 13 Jan 2025 16:58:11 +0000 (17:58 +0100)]
gh-125997: Increase test coverage for `time.sleep()` (#128751)
- Add tests for durations of invalid types.
- Add tests for `int` and `float` durations, including signed zeroes durations.
- Add tests for nonzero very small durations and durations close to the clock resolution.
---------
Co-authored-by: Victor Stinner <vstinner@python.org>
Bénédikt Tran [Mon, 13 Jan 2025 11:46:13 +0000 (12:46 +0100)]
gh-128150: Improve performances of `uuid.uuid*` constructor functions. (#128151)
We introduce a private constructor `UUID._from_int()` for RFC 4122/9562 UUIDs,
which takes the integral UUID value as input. The latter must have correctly set
its variant and version bits. We also make `UUID.__init__()` slightly more efficient.
Hood Chatham [Sun, 12 Jan 2025 23:09:39 +0000 (00:09 +0100)]
gh-128627: Emscripten: Use wasm-gc based call adaptor if available (#128628)
Replaces the trampoline mechanism in Emscripten with an implementation that uses a
recently added feature of wasm-gc instead of JS type reflection, when that feature is
available.
Yan Yanchii [Sun, 12 Jan 2025 08:27:28 +0000 (09:27 +0100)]
gh-128377: Skip `test_cmd_line.test_non_interactive_output_buffering` when `PYTHONUNBUFFERED=1` (#128378)
The `test_cmd_line.test_non_interactive_output_buffering` test assumes a buffered `stdio`
without checking the `PYTHONUNBUFFERED` value. Instead of changing the environment
variable for the duration of the test, it is better to simply skip it.
Barney Gale [Sat, 11 Jan 2025 19:27:47 +0000 (19:27 +0000)]
GH-128520: Divide pathlib ABCs into three classes (#128523)
In the private pathlib ABCs, rename `PurePathBase` to `JoinablePath`, and
split `PathBase` into `ReadablePath` and `WritablePath`. This improves the
API fit for read-only virtual filesystems.
The split of `PathBase` entails a similar split of `CopyWorker` (implements
copying) and the test cases in `test_pathlib_abc`.
In a later patch, we'll make `WritablePath` inherit directly from
`JoinablePath` rather than `ReadablePath`. For a couple of reasons,
this isn't quite possible yet.