gh-151546: Fix stack limits on musl (#151548)
If the thread stack size is set by linker flags, pass the stack size
to Python/ceval.c via the new _Py_LINKER_THREAD_STACK_SIZE variable
to set Py_C_STACK_SIZE macro.
(cherry picked from commit 9a61d1c0c8)
gh-151218: Replace sys.flags in PyConfig_Set() (GH-151402)
PyConfig_Set() and sys.set_int_max_str_digits() now replace
sys.flags (create a new object), instead of modifying sys.flags in-place.
Modifying sys.flags in-place can lead to data races when multiple
threads are reading or writing sys.flags in parallel.
Use _Py_atomic functions to get and set max_str_digits members.
(cherry picked from commit b16d23fc9f)
Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
gh-151519: Check effective gid in `_test_all_chown_common` group-0 guard (GH-151521)
The guard that skips the "chown to gid 0 should fail" assertion used
only `os.getgroups()` (supplementary groups). The kernel also accepts
the effective/filesystem gid for chown, so when a process runs with
egid 0 and a non-zero uid (common in containers and user namespaces),
chown(-1, 0) succeeds and the assertion spuriously fails.
Add an `os.getegid() != 0` check alongside the existing
`0 not in os.getgroups()` guard.
(cherry picked from commit 2ce260033b)
Co-authored-by: Itamar Oren <itamarost@gmail.com>
gh-151522: Guard against None transport in slow-socket SSL test (GH-151523)
(cherry picked from commit 11f032f904)
Co-authored-by: Itamar Oren <itamarost@gmail.com>
_ctypes_test doesn't use libffi directly, and linking it into the module
causes emscripten tests to fail.
(cherry picked from commit 8646385076)
Co-authored-by: Hood Chatham <roberthoodchatham@gmail.com>
gh-151223: fix tsan data races in load global specializations (GH-151393)
(cherry picked from commit e9d5280f6c)
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
gh-148853: Catch PermissionError in test in_systemd_nspawn_sync_suppressed() (GH-148854)
/run/ on my FreeBSD install is not readable causing failing test.
(cherry picked from commit 35ce2e5f98)
Co-authored-by: Nick Begg <nick@stunttruck.net>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
gh-149671: Restore compatibility with setuptools -nspkg.pth files in site module (GH-151319)
Inject the "sitedir" variable in the frame which executes ".pth" code.
(cherry picked from commit 18f3ffec43)
Co-authored-by: Victor Stinner <vstinner@python.org>
Skip test_highly_nested_objects_decoding during the PGO profile task. (GH-151460)
Since the recursion guard tracks real C-stack bounds (gh-91079), this test
asserts that 500k nesting levels overflow the stack margin. On a 64 MiB stack
(some Nix build envs use one that large), the optimized interpreter uses ~160
bytes/level (raises at ~420k levels) so the assertion holds with only ~16%
margin; the PGO *instrumented* stage inlines less, its per-level scanner frames
are smaller, and the 500k-deep decode completes -- "RecursionError not raised"
fails the profile run and aborts `make profile-opt`. Upstream's
skip_if_unlimited_stack_size (gh-143460) only covers RLIM_INFINITY, not
large-finite stacks like ours.
We could also keep playing whack a mole and raise the 500k to a much larger
number... but there's little value in PGO training on this test anyways.
(cherry picked from commit e91f68ab40)
Co-authored-by: Gregory P. Smith <68491+gpshead@users.noreply.github.com>
gh-151424: Fix impossible stack traces in `RemoteUnwinder(..., cache_frames=True)` by copying chunks on cache miss (GH-151426)
(cherry picked from commit 6ce088e20a)
Co-authored-by: Maurycy Pawłowski-Wieroński <maurycy@maurycy.com>
gh-101267: ProcessPoolExecutor no longer shares 1 BrokenProcessPool exception among all failed futures (GH-101268)
(cherry picked from commit 3c00ebc2bb)
Co-authored-by: Daniel Shields <daniel.shields@twosigma.com>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
(cherry picked from commit f4f102027a)
Co-authored-by: Rafael Fontenelle <rffontenelle@users.noreply.github.com>
Co-authored-by: Stan Ulbrych <stan@python.org>
gh-151284: Fix test_capi on UBSan (GH-151286)
Comment two checks relying on undefined behavior in
test_fromwidechar() of test_capi.
Enable test_capi in GitHub Action "Reusable Sanitizer".
(cherry picked from commit d87d772873)
Co-authored-by: Victor Stinner <vstinner@python.org>
The standard says that a call to `memcpy` must pass a valid source and
destination pointer even if the size is 0, so we must avoid calling
`memcpy` when our source pointer is NULL. If we don't, an optimizing
compiler can decide that the pointer must be non-NULL based on the
presence of UB, and optimize out checks for null pointers.
Specifically, note that the standard says:
Where an argument declared as size_t n specifies the length of the
array for a function, n can have the value zero on a call to that
function. Unless explicitly stated otherwise in the description of
a particular function in this subclause, pointer arguments on such
a call shall still have valid values, as described in 7.1.4.
And section 7.1.4 says:
If an argument to a function has an invalid value (such as a value
outside the domain of the function, or a pointer outside the address
space of the program, or a null pointer, or a pointer to
non-modifiable storage when the corresponding parameter is not
const-qualified) or a type (after default argument promotion) not
expected by a function with a variable number of arguments, the
behavior is undefined.
The specification for `memcpy` doesn't state that it's allowed to be
called with null pointers, and Linux's `/usr/include/string.h` declares
`memcpy` as `__nonnull ((1, 2))`.
(cherry picked from commit c37599200f)
Co-authored-by: Matt Wozniski <mwozniski@bloomberg.net>
gh-138991: Update dataclass documentation for new eq behavior in Python 3.13 (GH-139007)
And add tests.
(cherry picked from commit 402668b2b1)
Co-authored-by: Aniket <148300120+Aniketsy@users.noreply.github.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
gh-123619: Fix PyUnstable_Object_EnableDeferredRefcount() (GH-151260)
Return 0 if the object is not tracked by the GC.
(cherry picked from commit 72e7eddce6)
Co-authored-by: Victor Stinner <vstinner@python.org>
gh-151278: Fix test_faulthandler on UBSan (GH-151279)
* Py_FatalError() no longer calls _PyFaulthandler_Fini() if it
doesn't hold the GIL.
* Skip test_faulthandler tests raising signals if run with UBSan.
* Enable test_faulthandler in GitHub Action "Reusable Sanitizer".
(cherry picked from commit e60c42dc3f)
Co-authored-by: Victor Stinner <vstinner@python.org>
gh-151253: Dump the Python path configuration on _PyCodec_InitRegistry() failure (#151250)
If "import encodings" fails at Python startup, dump the Python path
configuration to help users debugging their configuration. The
encodings module is the first module imported during Python startup.
(cherry picked from commit 7b6e98911e)
GHA: Display output when a sanitizer test fails (GH-151268)
Modify GitHub Action "Reusable Sanitizer" to display output when a
test fails: pass -W option.
(cherry picked from commit 3a8bebd86f)
Co-authored-by: Victor Stinner <vstinner@python.org>