Commit Graph

10330 Commits

Author SHA1 Message Date
Gregory P. Smith 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) <noreply@anthropic.com>
2026-04-11 21:54:23 +00:00
Kumar Aditya ba1e1c192b gh-131798: do not watch immutable types in JIT (#148383) 2026-04-11 15:43:53 +00:00
Sacul 83f33dccf2 gh-148374: Fix a bug in _Py_uop_sym_get_type (GH-148375) 2026-04-11 23:03:13 +08:00
Wulian233 a059e85866 gh-131798: Add _IS_NONE to the JIT optimizer (GH-148369) 2026-04-11 23:02:46 +08:00
Pieter Eendebak 1c89817f51 gh-148276: Optimize object creation and method calls in the JIT by resolving __init__ at trace optimization time (GH-148277)
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: Ken Jin <kenjin4096@gmail.com>
2026-04-11 22:22:42 +08:00
Donghee Na a71b043356 gh-148171: Convert CALL_BUILTIN_CLASS to leave arguments on the stack (gh-148381) 2026-04-11 23:01:25 +09:00
Neko Asakura 9831dea3bf gh-148211: decompose _POP_TWO/_POP_CALL(_ONE/_TWO) in JIT (GH-148377) 2026-04-11 20:46:56 +08:00
Neko Asakura 72006a71b2 gh-148211: decompose [_POP_TWO/_INSERT_2]_LOAD_CONST_INLINE_BORROW in JIT (GH-148357) 2026-04-11 18:27:51 +08:00
Sacul e872c19922 gh-148171: Convert variadic argument opcodes to leave their arguments on the stack (CALL_BUILTIN_FAST_WITH_KEYWORDS) (#148366) 2026-04-11 13:27:24 +08:00
Kumar Aditya 2b439da972 gh-148171: convert more variadic uops to leave input on stack in JIT (#148361) 2026-04-11 10:29:38 +05:30
Kumar Aditya 8f17140fc1 gh-131798: split _CALL_BUILTIN_CLASS to smaller uops (#148094) 2026-04-10 17:28:20 +00:00
Ken Jin 266247c9a6 gh-148171: Convert CALL_BUILTIN_FAST to leave inputs on the stack for refcount elimination in JIT (GH-148172) 2026-04-10 23:11:18 +08:00
Neko Asakura aea0b91d65 gh-148211: decompose [_POP_CALL_X/_SHUFFLE_2]_LOAD_CONST_INLINE_BORROW in JIT (GH-148313) 2026-04-10 21:57:01 +08:00
Kumar Aditya d3b7b93cbb gh-148037: remove critical section from PyCode_Addr2Line (#148103) 2026-04-10 17:58:17 +05:30
Neko Asakura 0f49232664 gh-148211: decompose _INSERT_1_LOAD_CONST_INLINE(_BORROW) in JIT (GH-148283) 2026-04-10 00:45:39 +08:00
Sacul 38d3aef375 gh-134584 : Optimize and eliminate redundant ref-counting for MAKE_FUNCTION in the JIT (GH-144963) 2026-04-09 22:22:53 +08:00
Kumar Aditya 458aca9237 gh-131798: fold super method lookups in JIT (#148231) 2026-04-09 13:25:01 +05:30
Neko Asakura b5ccf00bd6 gh-148211: refactor bool to explicit uops in JIT (GH-148258) 2026-04-09 13:20:31 +08:00
Kumar Aditya 6e081614eb gh-148210: fix incorrect _BINARY_OP_SUBSCR_DICT JIT optimization (GH-148213) 2026-04-08 23:23:20 +08:00
Sacul bb03c8bd02 gh-145866: Convert _CALL_METHOD_DESCRIPTOR_NOARGS to leave its inputs on the stack to be cleaned up by _POP_TOP (GH-148227) 2026-04-08 23:21:37 +08:00
Neko Asakura d2fa4b2b13 gh-148211: decompose _POP_TOP_LOAD_CONST_INLINE(_BORROW) in JIT (GH-148230) 2026-04-08 23:20:31 +08:00
Neko Asakura 756358524e gh-148235: remove duplicate uops _LOAD_CONST_UNDER_INLINE(_BORROW) in JIT (GH-148236) 2026-04-08 16:22:59 +08:00
Kumar Aditya e371ce10cd gh-95004: specialize access to enums and fix scaling on free-threading (#148184)
Co-authored-by: Ken Jin <kenjin4096@gmail.com>
2026-04-07 21:43:50 +05:30
Victor Stinner feee573f36 gh-148014: Accept a function name in -X presite option (#148015) 2026-04-07 14:05:39 +00:00
Brandt Bucher 6bb7b33e8f GH-146128: Remove the buggy AArch64 "33rx" relocation (#146263) 2026-04-07 07:52:59 +03:00
Pablo Galindo Salgado ca960b6f38 gh-148110: Resolve lazy import filter names for relative imports (#148111) 2026-04-06 22:29:02 +01:00
Junya Fukuda 3d724dd914 gh-148072: Cache pickle.dumps/loads per interpreter in XIData (GH-148125)
Store references to pickle.dumps and pickle.loads in _PyXI_state_t
so they are looked up only once per interpreter lifetime, avoiding
repeated PyImport_ImportModuleAttrString calls on every cross-interpreter
data transfer via pickle fallback.

Benchmarks show 1.7x-3.3x speedup for InterpreterPoolExecutor
when transferring mutable types (list, dict) through XIData.
2026-04-06 11:37:02 -04:00
Pieter Eendebak efda60e2ec gh-100239: Propagate type info through _BINARY_OP_EXTEND in tier 2 (GH-148146) 2026-04-06 20:52:42 +08:00
Stan Ulbrych d6e044512c Silence unused-variable warnings in optimizer_cases.c.h (#148127) 2026-04-05 19:22:10 +01:00
Pablo Galindo Salgado 21fb9dc71d gh-146527: Heap-allocate gc_stats to avoid bloating PyInterpreterState (#148057)
The gc_stats struct contains ring buffers of gc_generation_stats
entries (11 young + 3×2 old on default builds). Embedding it inline
in _gc_runtime_state, which is itself inline in PyInterpreterState,
pushed fields like _gil.locked and threads.head to offsets beyond
what out-of-process profilers and debuggers can reasonably read in
a single buffer (e.g. offset 9384 for _gil.locked vs an 8 KiB read
buffer).

Heap-allocate generation_stats via PyMem_RawCalloc in _PyGC_Init and
free it in _PyGC_Fini. This shrinks PyInterpreterState by ~1.6 KiB
and keeps the GIL, thread-list, and other frequently-inspected fields
at stable, low offsets.
2026-04-04 18:42:30 +01:00
Donghee Na 853dafe23a gh-148083: Prevent constant folding when lhs is container types (gh-148090) 2026-04-05 00:40:12 +09:00
Donghee Na 289f19adb0 gh-148083: Constant-fold _CONTAINS_OP_SET for frozenset (gh-148084) 2026-04-04 12:32:12 +00:00
Ken Jin 328da67b2c gh-146073: Revert "gh-146073: Add fitness/exit quality mechanism for JIT trace frontend (GH-147966)" (#148082)
This reverts commit 198b04b75f.
2026-04-04 11:56:40 +00:00
Ken Jin c50d6cd012 gh-148078: Fix uses of sym_is_not_null in JIT optimizer (GH-148079) 2026-04-04 18:16:23 +08:00
Kumar Aditya e7bf8eac0f gh-131798: split recursion check to _CHECK_RECURSION_LIMIT and combine checks (GH-148070) 2026-04-04 17:23:03 +08:00
Kumar Aditya 7bcc1c4920 gh-131798: relax GUARD_CALLABLE checks for self type checks (#148069) 2026-04-04 12:49:23 +05:30
Kumar Aditya 7e275d4965 gh-131798: JIT inline function addresses of builtin methods (#146906) 2026-04-04 09:12:13 +05:30
Hai Zhu 198b04b75f gh-146073: Add fitness/exit quality mechanism for JIT trace frontend (GH-147966) 2026-04-03 23:54:30 +08:00
Pieter Eendebak 48317feec8 gh-146640: Optimize int operations by mutating uniquely-referenced operands in place (JIT only) (GH-146641) 2026-04-03 23:23:04 +08:00
Petr Viktorin 9b08f8c56f GH-126910: Revert "Make _Py_get_machine_stack_pointer return the stack pointer (#147945)" (GH-147994)
Revert "GH-126910: Make `_Py_get_machine_stack_pointer` return the stack pointer (#147945)"

This reverts commit 255026d9ee,
which broke a tier-1 buildbot.
2026-04-02 16:53:09 +02:00
Petr Viktorin a86963b3e2 gh-146636: Py_mod_abi mandatory for modules created from slots array (GH-146855) 2026-04-02 13:54:21 +02:00
Yongtao Huang 4810beddbf gh-147960: Fix memory leak in crossinterp _tuple_shared() on alloc failure (#147961) 2026-04-01 18:34:55 +02:00
Mark Shannon 255026d9ee GH-126910: Make _Py_get_machine_stack_pointer return the stack pointer (#147945)
* Make _Py_get_machine_stack_pointer return the stack pointer (or close to it), not the frame pointer

* Make ``_Py_ReachedRecursionLimit`` inline again
* Remove ``_Py_MakeRecCheck`` relacing its use with ``_Py_ReachedRecursionLimit``
* Move stack swtiching check into ``_Py_CheckRecursiveCall``
2026-04-01 17:15:13 +01:00
Petr Viktorin 2452324001 gh-146636: PEP 803: add Py_TARGET_ABI3T and .abi3t.so extension (GH-146637)
- Add Py_TARGET_ABI3T macro.
- Add ".abi3t.so" to importlib EXTENSION_SUFFIXES.
- Remove ".abi3.so" from importlib EXTENSION_SUFFIXES on Free Threading.
- Adjust tests

This is part of the implementation for PEP-803.
Detailed documentation to come later.

Co-authored-by: Nathan Goldbaum <nathan.goldbaum@gmail.com>
2026-04-01 16:14:59 +02:00
Serhiy Storchaka 473d2a35ce gh-147944: Increase range of bytes_per_sep (GH-147946)
Accepted range for the bytes_per_sep argument of bytes.hex(),
bytearray.hex(), memoryview.hex(), and binascii.b2a_hex()
is now increased, so passing sys.maxsize and -sys.maxsize is now
valid.
2026-04-01 08:33:30 +00:00
sunmy2019 dcb260eff2 gh-146615: Fix format specifiers in Python/ directory (GH-146619) 2026-03-31 10:59:17 +03:00
Brandon ca95e979d6 gh-146442: Fix various bugs in compiler pipeline (#146443)
Fix null derefs, missing decrefs, and unchecked returns from bug report.
2026-03-30 22:04:04 +02:00
Kumar Aditya 8e9d21c64b gh-146558: JIT optimize dict access for objects with known hash (#146559) 2026-03-30 14:23:29 +00:00
Victor Stinner adf2c47911 gh-126835: Fix _PY_IS_SMALL_INT() macro (#146631) 2026-03-30 12:48:18 +00:00
Serhiy Storchaka 6932c3ee6a gh-145876: Do not mask KeyErrors raised during dictionary unpacking in call (GH-146472)
KeyErrors raised in keys() or __getitem__() during dictionary unpacking
in call (func(**mymapping)) are no longer masked by TypeError.
2026-03-29 11:58:52 +03:00