When formatting the AST as a string, infinite values are replaced by
1e309, which evaluates to infinity. The initialization of this string
replacement was not thread-safe in the free threading build.
(cherry picked from commit 427dcf24de)
On Windows, `long` is a signed 32-bit integer so it can't represent
`0xffff_ffff` without overflow. Windows exit codes are unsigned 32-bit
integers, so if a child process exits with `-1`, it will be represented
as `0xffff_ffff`.
Also fix a number of other possible cases where `_Py_HandleSystemExit`
could return with an exception set, leading to a `SystemError` (or
fatal error in debug builds) later on during shutdown.
(cherry picked from commit ad6110a93f)
Co-authored-by: Sam Gross <colesbury@gmail.com>
This fixes a crash when `gc.get_objects()` or `gc.get_referrers()` is
called during a GC in the free threading build.
Switch to `_PyObjectStack` to avoid corrupting the `struct worklist`
linked list maintained by the GC. Also, don't return objects that are frozen
(`gc.freeze()`) or in the process of being collected to more closely match
the behavior of the default build.
(cherry picked from commit e545ead66c)
Co-authored-by: Sam Gross <colesbury@gmail.com>
This fixes a crash when running the PyO3 test suite on the free-threaded
build. The `qsbr` field is initialized after the `PyThreadState` is
added to the interpreter's linked list -- it might still be NULL.
Instead, we "steal" the queue of to-be-freed memory blocks. This is
always initialized (possibly empty) and protected by the stop the world
pause.
(cherry picked from commit 54c6fcbefd)
Co-authored-by: Sam Gross <colesbury@gmail.com>
* Detect source file encoding.
* Use the "replace" error handler even for UTF-8 (default) encoding.
* Remove the BOM.
* Fix detection of too long lines if they contain NUL.
* Return the head rather than the tail for truncated long lines.
(cherry picked from commit e2f710792b)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
gh-112804: Clamping timeout value for _PySemaphore_PlatformWait (gh-124914)
* gh-112804: Clamping timeout value for _PySemaphore_PlatformWait
* Address code review
* nit
(cherry picked from commit a5fc50994a)
Co-authored-by: Donghee Na <donghee.na@python.org>
Revert the incremental GC in 3.13, since it's not clear that without further turning, the benefits outweigh the costs.
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
gh-123892: Add "_wmi" to sys.stdlib_module_names (GH-123893)
(cherry picked from commit fb1b51a58d)
Co-authored-by: Victor Stinner <vstinner@python.org>
gh-116510: Fix crash during sub-interpreter shutdown (gh-124645)
Fix a bug that can cause a crash when sub-interpreters use "basic"
single-phase extension modules. Shared objects could refer to PyGC_Head
nodes that had been freed as part of interpreter shutdown.
(cherry picked from commit 6f9525dd3f)
Co-authored-by: Neil Schemenauer <nas-github@arctrix.com>
gh-123275: Support `-Xgil=1` and `PYTHON_GIL=1` on non-free-threaded builds (gh-123276)
(cherry picked from commit 84ad264ce6)
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
gh-121804: always show error location for SyntaxError's in basic repl (GH-123202)
(cherry picked from commit 6822cb23c6)
Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
Switch more _Py_IsImmortal(...) assertions to _Py_IsImmortalLoose(...)
The remaining calls to _Py_IsImmortal are in free-threaded-only code,
initialization of core objects, tests, and guards that fall back to
code that works with mortal objects.
(cherry picked from commit 57c471a688)
gh-123091: Use _Py_IsImmortalLoose() (#123511)
Use _Py_IsImmortalLoose() in bytesobject.c, typeobject.c
and ceval.c.
(cherry picked from commit f1a0d96f41)
Fix _PyArg_UnpackKeywordsWithVararg for the case when argument for
positional-or-keyword parameter is passed by keyword.
There was only one such case in the stdlib -- the TypeVar constructor.
(cherry picked from commit 540fcc62f5)
gh-122728: Fix SystemError in PyEval_GetLocals() (GH-122735)
Fix PyEval_GetLocals() to avoid SystemError ("bad argument to
internal function"). Don't redefine the 'ret' variable in the if
block.
Add an unit test on PyEval_GetLocals().
(cherry picked from commit 4767a6e31c)
Co-authored-by: Victor Stinner <vstinner@python.org>
gh-122334: Fix crash when importing ssl after re-initialization (GH-122481)
* Fix crash when importing ssl after re-initialization
(cherry picked from commit 9fc1c992d6)
Co-authored-by: neonene <53406459+neonene@users.noreply.github.com>
The adaptive counter doesn't do anything currently in the free-threaded
build and TSan reports a data race due to concurrent modifications to
the counter.
(cherry picked from commit 2b163aa9e7)
Co-authored-by: Sam Gross <colesbury@gmail.com>
In the free-threaded build, we need to lock pending->mutex when clearing
the handling_thread in order not to race with a concurrent
make_pending_calls in the same interpreter.
(cherry picked from commit c557ae97d6)
Co-authored-by: Sam Gross <colesbury@gmail.com>
gh-122029: Log call events in sys.setprofile when it's a method with c function (GH-122072)
Log call events in sys.setprofile when it is a method with a C function.
(cherry picked from commit e91ef13861)
Co-authored-by: Tian Gao <gaogaotiantian@hotmail.com>
gh-121390: tracemalloc: Fix tracebacks memory leak (GH-121391)
The tracemalloc_tracebacks hash table has traceback keys and NULL
values, but its destructors do not reflect this -- key_destroy_func is
NULL while value_destroy_func is raw_free. Swap these to free the
traceback keys instead.
(cherry picked from commit db39bc42f9)
Co-authored-by: Josh Brobst <jbrobst@proton.me>
This is a small refactoring to the current design that allows us to
avoid manually iterating over threads.
This should also fix gh-118490.
(cherry picked from commit e059aa6b01)
Co-authored-by: mpage <mpage@meta.com>
gh-121621: Move asyncio_running_loop to private struct (GH-121939)
This avoids changing the ABI and keeps the field in the private struct.
(cherry picked from commit 81fd625b5c)
Co-authored-by: Sam Gross <colesbury@gmail.com>
* The result has type Py_ssize_t, not intptr_t.
* Type cast between unsigned and signed integer types should be explicit.
* Downcasting should be explicit.
* Fix integer overflow check in sum().
(cherry picked from commit 1801545)