605 Commits
Author SHA1 Message Date
Stan UlbrychandGitHub 33bb297b43 [3.15] Fix ignored error returns in sys initialization, _ctypes and _interpchannels (GH-160614) (#160711)
(cherry picked from commit c5d09789ea)
2026-10-26 19:49:41 +00:00
de106cc321 [3.15] gh-154822: Fix racy assertion during finalization (GH-154824) (GH-154828)
(cherry picked from commit cb0f028537)

Co-authored-by: Peter Bierma <[email protected]>
2026-07-28 16:39:33 +00:00
ff6e973c3b [3.15] gh-151218: Replace sys.flags in PyConfig_Set() (GH-151402) (#151552)
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 <[email protected]>
Co-authored-by: Bénédikt Tran <[email protected]>
2026-06-16 16:48:56 +00:00
e8d914fd49 [3.15] gh-151278: Fix test_faulthandler on UBSan (GH-151279) (#151281)
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 <[email protected]>
2026-06-10 20:07:07 +00:00
Pablo Galindo SalgadoandGitHub 83e26a43a7 [3.15] gh-149321: Remove lazy_imports=none startup mode (GH-149389) (#150129) 2026-06-08 22:55:57 +00:00
042428f443 [3.15] gh-150644: Tag Apple system log messages as public. (GH-150645) (#150738)
macOS 26 changed the default visibility of "dynamic" system messages. This
changes the logging strategy to tag all messages as "public" so they are
visible in the system log without special configuration.
(cherry picked from commit 71fc4c66d3)

Co-authored-by: Russell Keith-Magee <[email protected]>
2026-06-01 22:53:51 +00:00
2b7c28a440 gh-149101: Implement PEP 788 (GH-149116)
Co-authored-by: Petr Viktorin <[email protected]>
Co-authored-by: Sam Gross <[email protected]>
2026-05-06 17:39:30 -04:00
646853df13 gh-145559: Add PyUnstable_DumpTraceback() and PyUnstable_DumpTracebackThreads() (#148145)
Co-authored-by: Petr Viktorin <[email protected]>
Co-authored-by: Victor Stinner <[email protected]>
2026-05-06 15:01:12 +00:00
Neko AsakuraandGitHub 7c9ad27dd1 gh-148871: extend and improve LOAD_COMMON_CONSTANT (GH-148971) 2026-05-02 19:59:51 +01:00
Eric FroemlingandGitHub 7686abe063 gh-149085: Add max_threads keyword to faulthandler.dump_traceback() (GH-149106)
Add a keyword-only `max_threads` argument to `dump_traceback()` and
`dump_traceback_later()`, defaulting to 100 to preserve existing
behavior. Allows server processes with many worker threads to dump
beyond the historical 100-thread cap (previously a hardcoded
`MAX_NTHREADS = 100` in `Python/traceback.c`).

The cap matters in practice: tstates are prepended to the
PyInterpreterState linked list, so the dump walks newest-first. With
more than 100 threads alive, the main thread (oldest, at the tail) is
silently elided from watchdog dumps -- exactly the thread that's
usually wanted.

The hardcoded value is moved to a new internal macro
`_Py_TRACEBACK_MAX_NTHREADS` in `pycore_traceback.h` so the in-tree
fatal-signal callers all reference one source of truth.
2026-04-30 09:27:57 -04:00
Diego RussoandGitHub 9633c5239d GH-126910: Build/link the JIT shim in the Python interpreter (#148872) 2026-04-23 12:23:18 +01:00
AraHaanandGitHub 789120e826 gh-148790: Eliminate redundant call to _PyRuntime_Initialize in Py_InitializeEx (GH-121628) 2026-04-20 10:01:06 -04:00
64afa947f4 gh-146302: make Py_IsInitialized() thread-safe and reflect true init completion (GH-146303)
## Summary

- Move the `runtime->initialized = 1` store from before `site.py` import to the end of `init_interp_main()`, so `Py_IsInitialized()` only returns true after initialization has fully completed
- Access `initialized` and `core_initialized` through new inline accessors using acquire/release atomics, to also protect from data race undefined behavior
- `PySys_AddAuditHook()` now uses the accessor, so with the flag move it correctly skips audit hook invocation during all init phases (matching the documented "after runtime initialization" behavior) ... We could argue that running these earlier would be good even if the intent was never explicitly expressed, but that'd be its own issue.

## Motivation

`Py_IsInitialized()` returned 1 while `Py_InitializeEx()` was still running — specifically, before `site.py` had been imported. See https://github.com/PyO3/pyo3/issues/5900 where a second thread could acquire the GIL and start executing Python with an incomplete `sys.path` because `site.py` hadn't finished.

The flag was also a plain `int` with no atomic operations, making concurrent reads a C-standard data race, though unlikely to manifest.

## Regression test:

The added test properly fails on `main` with `ERROR: Py_IsInitialized() was true during site import`.

---

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
2026-04-11 21:54:23 +00:00
Victor StinnerandGitHub feee573f36 gh-148014: Accept a function name in -X presite option (#148015) 2026-04-07 14:05:39 +00:00
Chris EiblandGitHub 306c556fdb gh-144319: obtain SeLockMemoryPrivilege on Windows (#144928) 2026-03-23 23:00:26 +00:00
Hai ZhuandGitHub 81ef1b7317 gh-144888: Replace bloom filter linked lists with continuous arrays to optimize executor invalidating performance (GH-145873) 2026-03-16 15:58:18 +00:00
Sergey MiryanovandGitHub d19de375a2 GH-145247: Use _PyTuple_FromPair in Parser and Python (#145842)
Use _PyTuple_FromPair in Parser and Python
2026-03-11 21:08:18 +00:00
dae85c4d93 gh-145633: Remove support for ancient ARM platforms with mixed-endian doubles (#145634)
* Drop DOUBLE_IS_ARM_MIXED_ENDIAN_IEEE754 macro.
* Use DOUBLE_IS_BIG/LITTLE_ENDIAN_IEEE754 to detect endianness of
  float/doubles.
* Drop "unknown_format" code path in PyFloat_Pack/Unpack*().

Co-authored-by: Victor Stinner <[email protected]>
2026-03-11 12:39:24 +01:00
31343cf2bc gh-142417: Restore private _Py_InitializeMain() function (#145472)
This reverts commit 07c3518ffb.

Co-authored-by: Petr Viktorin <[email protected]>
2026-03-04 11:00:08 +01:00
46d5106cfa gh-142349: Implement PEP 810 - Explicit lazy imports (#142351)
Co-authored-by: T. Wouters <[email protected] >
Co-authored-by: Brittany Reynoso <[email protected]>
Co-authored-by: Dino Viehland <[email protected]>
2026-02-12 00:15:33 +00:00
Victor StinnerandGitHub 2aea861fe0 gh-140824: Fix _Py_DumpExtensionModules() to ignore sub-modules (#144339)
Ignore "math.integer" extension if "math" is in
sys.stdlib_module_names.
2026-02-04 16:06:35 +01:00
Yongtao HuangGitHubblurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
219b7ac9d5 gh-144307: Fix a reference leak during module teardown (GH-144308)
Signed-off-by: Yongtao Huang <[email protected]>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
2026-01-29 13:50:54 -05:00
Sam GrossandGitHub f11f5ebfe6 gh-129824: Fix data race on runtime->gilstate.check_enabled (gh-143530) 2026-01-07 17:56:14 -05:00
Kumar AdityaandGitHub 74bb3ca1f8 gh-142863: optimize list and set calls with generator expressions (#142864) 2026-01-06 23:23:28 +05:30
Pablo Galindo SalgadoandGitHub 3ccc76f036 gh-143228: Fix UAF in perf trampoline during finalization (#143233) 2025-12-28 13:50:23 +00:00
Diego RussoandGitHub 450e836aef JIT: don't leak shim memory when shutting down the interpreter (#142984) 2025-12-23 17:50:00 +00:00
Pablo Galindo SalgadoandGitHub d6d850df89 gh-138122: Don't sample partial frame chains (#141912) 2025-12-07 15:53:48 +00:00
fa245df4a0 GH-141509: Fix warning about remaining subinterpreters (GH-141528)
Co-authored-by: Peter Bierma <[email protected]>
2025-11-14 14:55:04 +00:00
Neil SchemenauerandGitHub c98c5b3449 gh-131253: free-threaded build support for pystats (gh-137189)
Allow the --enable-pystats build option to be used with free-threading.  The
stats are now stored on a per-interpreter basis, rather than process global.
For free-threaded builds, the stats structure is allocated per-thread and
then periodically merged into the per-interpreter stats structure (on thread
exit or when the reporting function is called). Most of the pystats related
code has be moved into the file Python/pystats.c.
2025-11-03 11:36:37 -08:00
Victor StinnerandGitHub 313145eab5 gh-125434: Display thread name in faulthandler on Windows (#140675) 2025-10-27 18:41:18 +01:00
e6e376a760 gh-132042: Remove resolve_slotdups() to speedup class creation (#132156)
Co-authored-by: Victor Stinner <[email protected]>
Co-authored-by: sobolevn <[email protected]>
Co-authored-by: Kumar Aditya <[email protected]>
2025-10-03 11:58:00 +02:00
Victor StinnerandGitHub e8382e55c5 gh-74857, PEP 538: Coerce POSIX locale to UTF-8 based locale (#139238) 2025-09-23 19:20:59 +02:00
Peter BiermaandGitHub d06113c7a7 gh-112729: Correctly fail when the process is out of memory during interpreter creation (GH-139164) 2025-09-19 10:41:09 -04:00
Peter BiermaandGitHub 3eec897752 gh-136003: Skip non-daemon threads when exceptions occur during finalization (GH-139129)
During finalization, we need to mark all non-daemon threads as daemon to quickly shut down threads when sending CTRL^C to the process. This was a minor regression from GH-136004.
2025-09-18 16:04:01 -04:00
Peter BiermaandGitHub 2191497933 gh-136003: Execute pre-finalization callbacks in a loop (GH-136004) 2025-09-18 08:29:12 -04:00
Donghee NaandGitHub d873fb42f3 gh-137838: Move _PyUOpInstruction buffer to PyInterpreterState (gh-138918) 2025-09-17 18:50:16 +01:00
Peter BiermaandGitHub a64881363b gh-128639: Don't assume one thread in subinterpreter finalization with fixed daemon thread support (GH-134606)
This reapplies GH-128640.
2025-09-17 11:14:19 -04:00
mqudahandGitHub 2f5ace780b fix comment reference from man 7 signal to man 7 signal-safety (#138554)
docs: fix comment reference from man 7 signal to man 7 signal-safety
2025-09-06 18:40:15 +00:00
7dfa048bbb gh-135228: Create __dict__ and __weakref__ descriptors for object (GH-136966)
This partially reverts #137047, keeping the tests for GC collectability of the
original class that dataclass adds `__slots__` to.
The reference leaks solved there are instead solved by having the `__dict__` &
`__weakref__` descriptors not tied to (and referencing) their class.

Instead, they're shared between all classes that need them (within
an interpreter).
The `__objclass__` ol the descriptors is set to `object`, since these
descriptors work with *any* object. (The appropriate checks were already
made in the get/set code, so the `__objclass__` check was redundant.)

The repr of these descriptors (and any others whose `__objclass__` is `object`)
now doesn't mention the objclass.

This change required adjustment of introspection code that checks
`__objclass__` to determine an object's “own” (i.e. not inherited) `__dict__`.
Third-party code that does similar introspection of the internals will also
need adjusting.


Co-authored-by: Jelle Zijlstra <[email protected]>
2025-08-18 14:25:51 +02:00
Peter BiermaandGitHub a10960699a 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.
2025-07-21 13:47:26 -04:00
Kumar AdityaandGitHub 0c3e3da195 gh-109700: fix interpreter finalization while handling memory error (#136342) 2025-07-07 12:45:22 +05:30
Serhiy StorchakaandGitHub bac3fcba5b gh-108512: Add and use new replacements for PySys_GetObject() (GH-111035)
Add functions PySys_GetAttr(), PySys_GetAttrString(),
PySys_GetOptionalAttr() and PySys_GetOptionalAttrString().
2025-05-28 20:11:09 +03:00
Peter BiermaandGitHub 27bd08273c Revert "gh-128639: Don't assume one thread in subinterpreter finalization (gh-128640)" (gh-134256)
This reverts commit 9859791f9e.

The original change broke the iOS and android buildbots, where the tests are run single-process.
2025-05-19 12:22:05 -06:00
Peter BiermaandGitHub 9859791f9e gh-128639: Don't assume one thread in subinterpreter finalization (gh-128640)
Incidentally, this also fixed the warning not showing up if a subinterpreter wasn't
cleaned up via _interpreters.destroy. I had to update some of the tests as a result.
2025-05-19 10:24:08 -06:00
Xuehai PanandGitHub f0f93ba5fa gh-131942: Use the Python-specific Py_DEBUG macro rather than _DEBUG in Windows-related C code (GH-131944) 2025-05-08 15:01:25 +00:00
Mark ShannonandGitHub 44e4c479fb GH-124715: Move trashcan mechanism into Py_Dealloc (GH-132280) 2025-04-30 11:37:53 +01:00
+1 60202609a2 gh-132661: Implement PEP 750 (#132662)
Co-authored-by: Lysandros Nikolaou <[email protected]>
Co-authored-by: Bénédikt Tran <[email protected]>
Co-authored-by: Adam Turner <[email protected]>
Co-authored-by: Hugo van Kemenade <[email protected]>
Co-authored-by: Wingy <[email protected]>
Co-authored-by: Koudai Aono <[email protected]>
Co-authored-by: Dave Peck <[email protected]>
Co-authored-by: Terry Jan Reedy <[email protected]>
Co-authored-by: Paul Everitt <[email protected]>
Co-authored-by: sobolevn <[email protected]>
2025-04-30 11:46:41 +02:00
Jelle ZijlstraandGitHub 58567cc18c gh-132952: Speed up startup by importing _io instead of io (#132957) 2025-04-28 08:38:56 -07:00
Eric SnowandGitHub 2a28b21a51 gh-132776: Revert Moving memoryview XIData Code to memoryobject.c (gh-132960)
This is a partial revert of gh-132821.  It resolves the refleak introduced by that PR.
2025-04-25 16:43:50 +00:00
Eric SnowandGitHub e54e828852 gh-132776: Cleanup for XIBufferViewType (gh-132821)
* add notes
* rename XIBufferViewObject to xibufferview
* move memoryview XIData code to memoryobject.c
2025-04-24 18:25:29 -06:00