gh-136421: Load `_datetime` static types during interpreter initialization (GH-136583)
`_datetime` is a special module, because it's the only non-builtin C extension that contains static types. As such, it would initialize static types in the module's execution function, which can run concurrently. Since static type initialization is not thread-safe, this caused crashes. This fixes it by moving the initialization of `_datetime`'s static types to interpreter startup (where all other static types are initialized), which is already properly protected through other locks.
(cherry picked from commit a10960699a)
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
gh-116738: Make grp module thread-safe (GH-135434)
Make grp module methods getgrgid() and getgrnam() thread-safe when the GIL is disabled and getgrgid_r()/getgrnam_r() C APIs are not available.
---------
(cherry picked from commit 9363703bd3)
Co-authored-by: Alper <alperyoney@fb.com>
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
gh-136476: Show the full stack in get_async_stack_trace in _remote_debugging (GH-136483)
(cherry picked from commit ea45a2f97c)
Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
gh-91048: Revert the memory cache removal for remote debugging (GH-136440)
(cherry picked from commit 77d25e5b16)
gh-91048: Reintroduce the memory cache for remote debugging
Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
gh-136288: Fix error message in `_testcapi/vectorcall.c` (GH-136258)
Use the %N format specifier instead of %s and `PyType_GetName`.
(cherry picked from commit d1d5dce14f)
Co-authored-by: William S Fulton <wsf@fultondesigns.co.uk>
gh-135773: have pyvenv.cfg without home key anchor a venv and deduce home (GH-135831)
This is still formally undefined behaviour, but we may as well
keep the *same* undefined behaviour as previous versions.
PEP 796 proposes a cleaner and more consistent replacement for 3.15+
(cherry picked from commit 93263d4314)
Co-authored-by: Richard Levasseur <rlevasseur@google.com>
There is no need to temporary switch locale for items ALT_DIGITS and ERA
if the nl_langinfo() result is empty (most locales).
(cherry picked from commit 5c984ae35e)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
gh-130396: Move PYOS_LOG2_STACK_MARGIN to internal headers (GH-135928)
Move PYOS_LOG2_STACK_MARGIN, PYOS_STACK_MARGIN,
PYOS_STACK_MARGIN_BYTES and PYOS_STACK_MARGIN_SHIFT macros to
pycore_pythonrun.h internal header. Add underscore (_) prefix to the
names to make them private. Rename _PYOS to _PyOS.
(cherry picked from commit 28940e8e48)
Co-authored-by: Victor Stinner <vstinner@python.org>
gh-135607: remove null checking of weakref list in dealloc of extension modules and objects (#135614)
(cherry picked from commit b1056c2a44)
Co-authored-by: Xuanteng Huang <44627253+xuantengh@users.noreply.github.com>
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
Rename undocumented `HACL_CAN_COMPILE_SIMD{128,256}` macros
to `_Py_HACL_CAN_COMPILE_VEC{128,256}`. These macros are private.
(cherry picked from commit 1e975aee28)
gh-108765: fix comment about macro definitions in `_stat.c` post GH-108854 (GH-136027)
(cherry picked from commit 0141e7f9e6)
Co-authored-by: Lee Dogeon <dev.moreal@gmail.com>
Names/macros defined in public headers should have `Py`/`_Py` prefixes.
(cherry picked from commit a1da208eec)
Co-authored-by: Petr Viktorin <encukou@gmail.com>
gh-135557: use atomic stores in `heapq` operations in free-threading (GH-135601)
(cherry picked from commit 13cac83347)
Co-authored-by: Xuanteng Huang <44627253+xuantengh@users.noreply.github.com>
We weren't handling non-positive maxsize values (including the default) properly
in Queue.full(). This change fixes that and adjusts an associated assert.
(cherry picked from commit c5ea8e8e8, AKA gh-135724)
Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
gh-135561: ensure that the GIL is held when handling an HACL* error in `_hmac` (GH-135562)
(cherry picked from commit c765683398)
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
As noted in the new tests, there are a few situations we must carefully accommodate
for functions that get pickled during interp.call(). We do so by running the script
from the main interpreter's __main__ module in a hidden module in the other
interpreter. That hidden module is used as the function __globals__.
(cherry picked from commit 269e19e0a7, AKA gh-135595)
Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
Use critical sections to make heapq methods that update the heap thread-safe when the GIL is disabled.
(cherry picked from commit a58026a5e3)
Co-authored-by: Alper <alperyoney@fb.com>
Co-authored-by: mpage <mpage@meta.com>
In this refactor we:
* move some code around
* make a couple of typedefs opaque
* decouple errors from session state
* improve tracebacks for propagated exceptions
This change helps simplify several upcoming changes.
(cherry picked from commit c7f4a80079, AKA gh-135369)
Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
Revert "gh-135410: use a critical section around `StringIO.__next__` (GH-135412)" (GH-135439)
This reverts commit e6c3039cb3.
(cherry picked from commit 73431356d3)
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
PEP-734 has been accepted (for 3.14).
(FTR, I'm opposed to putting this under the concurrent package, but
doing so is the SC condition under which the module can land in 3.14.)
(cherry picked from commit 62143736b, AKA gh-133958)
gh-135410: use a critical section around `StringIO.__next__` (GH-135412)
(cherry picked from commit e6c3039cb3)
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
* gh-91048: Reorder result tuple of parse_code_object (GH-134898)
Reorder result tuple of parse_code_object
The standard followed by APIs like pstat.Stats is to take a file, line,
function triplet. The parse_code_object function (and callers exposing
this in Python like RemoteUnwinder.get_stack_trace) return function,
file, line triplets which requires the caller to reorder these when
using it in classes like pstat.Stats.
(cherry picked from commit 8e8786f898)
Co-authored-by: László Kiss Kollár <kiss.kollar.laszlo@gmail.com>
* Reorder asyncio
---------
Co-authored-by: László Kiss Kollár <kiss.kollar.laszlo@gmail.com>
Co-authored-by: Pablo Galindo <pablogsal@gmail.com>
gh-133968: Add PyUnicodeWriter_WriteASCII() function (#133973)
Replace most PyUnicodeWriter_WriteUTF8() calls with
PyUnicodeWriter_WriteASCII().
(cherry picked from commit f49a07b531)
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
gh-134160: Use PyModuleDef.m_free in the example module xxlimited (GH-135174)
(cherry picked from commit 1adca08d65)
Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: neonene <53406459+neonene@users.noreply.github.com>
The `getlogin` function is not thread-safe: replace with `getlogin_r` where
available.
(cherry picked from commit 1ffe913c20)
Co-authored-by: Duane Griffin <duaneg@dghda.com>