Commit Graph

9544 Commits

Author SHA1 Message Date
Victor Stinner 0ddfb5717f
gh-111178: Fix _PyLegacyEventHandler_Type deallocator (#131193)
Don't use PyObject_Free() as tp_dealloc to avoid an undefined
behavior. Instead, use the default deallocator which just calls
tp_free which is PyObject_Free().
2025-03-14 10:23:54 +01:00
Hood Chatham f3e275f1a9
GH-130396: Work around for broken `pthread_get_stackaddr_np` on Emscripten (#131088)
Tests / Ubuntu SSL tests with OpenSSL (3.1.7, ubuntu-24.04) (push) Blocked by required conditions Details
Tests / Ubuntu SSL tests with OpenSSL (3.2.3, ubuntu-24.04) (push) Blocked by required conditions Details
Tests / Ubuntu SSL tests with OpenSSL (3.3.2, ubuntu-24.04) (push) Blocked by required conditions Details
Tests / Ubuntu SSL tests with OpenSSL (3.4.0, ubuntu-24.04) (push) Blocked by required conditions Details
Tests / Hypothesis tests on Ubuntu (push) Blocked by required conditions Details
Tests / Address sanitizer (ubuntu-24.04) (push) Blocked by required conditions Details
Tests / All required checks pass (push) Blocked by required conditions Details
mypy / Run mypy on ${{ matrix.target }} (Lib/_pyrepl) (push) Successful in 14s Details
mypy / Run mypy on ${{ matrix.target }} (Lib/test/libregrtest) (push) Successful in 13s Details
mypy / Run mypy on ${{ matrix.target }} (Tools/build) (push) Successful in 11s Details
mypy / Run mypy on ${{ matrix.target }} (Tools/cases_generator) (push) Successful in 12s Details
mypy / Run mypy on ${{ matrix.target }} (Tools/clinic) (push) Successful in 11s Details
mypy / Run mypy on ${{ matrix.target }} (Tools/jit) (push) Successful in 11s Details
mypy / Run mypy on ${{ matrix.target }} (Tools/peg_generator) (push) Successful in 12s Details
Lint / lint (push) Failing after 1m32s Details
mypy / Run mypy on ${{ matrix.target }} (Tools/wasm) (push) Successful in 11s Details
Tests / Change detection (push) Successful in 26m17s Details
Tests / Docs (push) Has been skipped Details
Tests / Windows ${{ fromJSON(matrix.free-threading) && '(free-threading)' || '' }} (Win32, false, windows-latest) (push) Has been skipped Details
Tests / Windows ${{ fromJSON(matrix.free-threading) && '(free-threading)' || '' }} (arm64, true, windows-latest) (push) Has been skipped Details
Tests / Windows ${{ fromJSON(matrix.free-threading) && '(free-threading)' || '' }} (arm64, false, windows-latest) (push) Has been skipped Details
Tests / Windows ${{ fromJSON(matrix.free-threading) && '(free-threading)' || '' }} (x64, false, windows-latest) (push) Has been skipped Details
Tests / Windows ${{ fromJSON(matrix.free-threading) && '(free-threading)' || '' }} (x64, true, windows-latest) (push) Has been skipped Details
Tests / Windows MSI${{ '' }} (arm64) (push) Has been skipped Details
Tests / Windows MSI${{ '' }} (x64) (push) Has been skipped Details
Tests / Windows MSI${{ '' }} (x86) (push) Has been skipped Details
Tests / macOS ${{ fromJSON(matrix.free-threading) && '(free-threading)' || '' }} (true, ${{ github.repository_owner != 'python' }}, ghcr.io/cirruslabs/macos-runner:sonoma) (push) Failing after 24m9s Details
Tests / macOS ${{ fromJSON(matrix.free-threading) && '(free-threading)' || '' }} (false, ${{ github.repository_owner != 'python' }}, macos-13) (push) Failing after 33m1s Details
Tests / macOS ${{ fromJSON(matrix.free-threading) && '(free-threading)' || '' }} (true, ${{ github.repository_owner != 'python' }}, macos-14) (push) Failing after 33m1s Details
Tests / macOS ${{ fromJSON(matrix.free-threading) && '(free-threading)' || '' }} (false, ${{ github.repository_owner != 'python' }}, macos-14) (push) Failing after 33m3s Details
Tests / macOS ${{ fromJSON(matrix.free-threading) && '(free-threading)' || '' }} (false, ${{ github.repository_owner != 'python' }}, ghcr.io/cirruslabs/macos-runner:sonoma) (push) Failing after 33m5s Details
Tests / Ubuntu ${{ fromJSON(matrix.free-threading) && '(free-threading)' || '' }} ${{ fromJSON(matrix.bolt) && '(bolt)' || '' }} (false, false, ubuntu-24.04-arm) (push) Failing after 26m22s Details
Tests / Ubuntu ${{ fromJSON(matrix.free-threading) && '(free-threading)' || '' }} ${{ fromJSON(matrix.bolt) && '(bolt)' || '' }} (false, false, ubuntu-24.04) (push) Failing after 38m7s Details
Tests / WASI (push) Failing after 29m5s Details
Tests / Ubuntu ${{ fromJSON(matrix.free-threading) && '(free-threading)' || '' }} ${{ fromJSON(matrix.bolt) && '(bolt)' || '' }} (true, false, ubuntu-24.04) (push) Failing after 30m29s Details
Tests / CIFuzz (address) (push) Has been skipped Details
Tests / CIFuzz (memory) (push) Has been skipped Details
Tests / CIFuzz (undefined) (push) Has been skipped Details
Tests / Ubuntu ${{ fromJSON(matrix.free-threading) && '(free-threading)' || '' }} ${{ fromJSON(matrix.bolt) && '(bolt)' || '' }} (false, true, ubuntu-24.04) (push) Failing after 36m25s Details
Tests / Cross build Linux (push) Successful in 7m48s Details
Tests / Ubuntu ${{ fromJSON(matrix.free-threading) && '(free-threading)' || '' }} ${{ fromJSON(matrix.bolt) && '(bolt)' || '' }} (false, true, ubuntu-24.04-arm) (push) Failing after 39m37s Details
Tests / Thread sanitizer ${{ fromJSON(matrix.free-threading) && '(free-threading)' || '' }} (false) (push) Failing after 30m37s Details
Tests / Thread sanitizer ${{ fromJSON(matrix.free-threading) && '(free-threading)' || '' }} (true) (push) Successful in 49m39s Details
Mark stale pull requests / stale (push) Has been skipped Details
Tail calling interpreter / ${{ matrix.target }} (aarch64, 19, macos-14, aarch64-apple-darwin/clang) (push) Has been cancelled Details
Tail calling interpreter / ${{ matrix.target }} (aarch64, 19, ubuntu-24.04-arm, aarch64-unknown-linux-gnu/gcc) (push) Has been cancelled Details
Tail calling interpreter / ${{ matrix.target }} (x64, 19, windows-latest, x86_64-pc-windows-msvc/msvc) (push) Has been cancelled Details
Tail calling interpreter / ${{ matrix.target }} (x86_64, 19, macos-13, x86_64-apple-darwin/clang) (push) Has been cancelled Details
Tail calling interpreter / ${{ matrix.target }} (x86_64, 19, ubuntu-24.04, free-threading) (push) Has been cancelled Details
Tail calling interpreter / ${{ matrix.target }} (x86_64, 19, ubuntu-24.04, x86_64-unknown-linux-gnu/gcc) (push) Has been cancelled Details
Implements a workaround implementation of `pthread_get_stackaddr_np` for Emscripten.
This will be replaced by an implementation that will be included in Emscripten 4.0.6.
2025-03-14 07:04:40 +08:00
Tomasz Pytel c5abded099
gh-130382: add missing `_PyReftracerTrack` to ceval `Py_DECREF` (#130689) 2025-03-13 12:31:49 -04:00
Irit Katriel 4242c2b8d0
gh-130080: move _Py_EnsureArrayLargeEnough to a separate header so it can be used outside of the compiler (#130930) 2025-03-13 16:02:58 +00:00
Victor Stinner 9a63138e09
gh-111178: Fix function signatures in misc files (#131180) 2025-03-13 16:55:08 +01:00
Russell Keith-Magee dd6d24e9d2
gh-130940: Modify default behavior of `PyConfig.use_system_logger` to enable on iOS (#131172)
Modify default behavior of use_system_log to enable on iOS.
2025-03-13 14:28:49 +08:00
Yan Yanchii 3618240624
gh-126835: Avoid creating unnecessary tuple when looking for constant sequence during constant folding (#131054) 2025-03-12 21:45:54 +00:00
Kumar Aditya ea57ffa02e
gh-131141: fix data race in instrumentation while registering callback (#131142) 2025-03-13 00:11:52 +05:30
T. Wouters de2f7da77d
gh-115999: Add free-threaded specialization for FOR_ITER (#128798)
Add free-threaded versions of existing specialization for FOR_ITER (list, tuples, fast range iterators and generators), without significantly affecting their thread-safety. (Iterating over shared lists/tuples/ranges should be fine like before. Reusing iterators between threads is not fine, like before. Sharing generators between threads is a recipe for significant crashes, like before.)
2025-03-12 16:21:46 +01:00
Stan Ulbrych 155c44b901
gh-81267: Correct time.sleep() error message (#131055) 2025-03-12 08:12:57 +00:00
Tian Gao 8b1edae93a
gh-122029: Do not unpack method for legacy tracing anymore (#130898) 2025-03-11 14:04:22 -04:00
Victor Stinner 9d759b63d8
gh-111178: Change Argument Clinic signature for METH_O (#130682)
Use "PyObject*" for METH_O functions to fix an undefined behavior.
2025-03-11 16:33:36 +01:00
Sam Gross 4162bc133b
gh-130396: Fix thread sanitizer crashes on stack overflow tests (gh-130966)
Thread sanitizer will often crash if a test uses more than half the
stack.
2025-03-11 10:33:23 -04:00
Max Bachmann de8818ae23
gh-131082: Add missing guards for WIN32_LEAN_AND_MEAN (#131044)
* Add missing guards for WIN32_LEAN_AND_MEAN

* add missing whitespaces
2025-03-11 12:33:01 +01:00
Pablo Galindo Salgado a931a8b324
gh-117174: Add a new route in linecache to fetch interactive source code (#117500) 2025-03-10 21:54:05 +00:00
Mark Shannon be046ee6e0
GH-123044: Give the `POP_TOP` after a case test a location in the body, not the pattern. (GH-130627) 2025-03-10 17:31:16 +00:00
Mark Shannon 2bef8ea8ea
GH-127705: Use `_PyStackRef`s in the default build. (GH-127875) 2025-03-10 14:06:56 +00:00
Mark Shannon 89df62c120
GH-128534: Fix behavior of branch monitoring for `async for` (GH-130847)
* Both branches in a pair now have a common source and are included in co_branches
2025-03-07 14:30:31 +00:00
Sam Gross a025f27d94
gh-130920: Fix data race in STORE_SUBSCR_LIST_INT (#130923)
The write of the item to the list needs to use an atomic operation in
the free threading build.

Co-authored-by: Tomasz Pytel <tompytel@gmail.com>
2025-03-06 15:59:48 -05:00
Sam Gross 052cb717f5
gh-124878: Fix race conditions during interpreter finalization (#130649)
The PyThreadState field gains a reference count field to avoid
issues with PyThreadState being a dangling pointer to freed memory.
The refcount starts with a value of two: one reference is owned by the
interpreter's linked list of thread states and one reference is owned by
the OS thread. The reference count is decremented when the thread state
is removed from the interpreter's linked list and before the OS thread
calls `PyThread_hang_thread()`. The thread that decrements it to zero
frees the `PyThreadState` memory.

The `holds_gil` field is moved out of the `_status` bit field, to avoid
a data race where on thread calls `PyThreadState_Clear()`, modifying the
`_status` bit field while the OS thread reads `holds_gil` when
attempting to acquire the GIL.

The `PyThreadState.state` field now has `_Py_THREAD_SHUTTING_DOWN` as a
possible value. This corresponds to the `_PyThreadState_MustExit()`
check. This avoids race conditions in the free threading build when
checking `_PyThreadState_MustExit()`.
2025-03-06 10:38:34 -05:00
Sergey B Kirpichev 2352bd418a
gh-130860: Fix width calculation, when separators in fractional part (GH-130865)
This amends f39a07be47
2025-03-06 14:26:29 +02:00
Jamie Phan 10cdd7f91f
GH-130903: typo in optimizer DSL for _GUARD_BOTH_UNICODE (#130904)
Typo introduced in gh-118910.
2025-03-06 12:11:08 +01:00
Tomasz Pytel aeb2327386
gh-130574: renumber RESUME opcode from 149 to 128 (GH-130685) 2025-03-06 08:59:36 +00:00
mpage d7bb7c7817
gh-118331: Fix a couple of issues when list allocation fails (#130811)
* Fix use after free in list objects

Set the items pointer in the list object to NULL after the items array
is freed during list deallocation. Otherwise, we can end up with a list
object added to the free list that contains a pointer to an already-freed
items array.

* Mark `_PyList_FromStackRefStealOnSuccess` as escaping

I think technically it's not escaping, because the only object that
can be decrefed if allocation fails is an exact list, which cannot
execute arbitrary code when it is destroyed. However, this seems less
intrusive than trying to special cases objects in the assert in `_Py_Dealloc`
that checks for non-null stackpointers and shouldn't matter for performance.
2025-03-05 10:42:09 -08:00
Mark Shannon 78d50e91ff
GH-127705: better double free message. (GH-130785)
* Add location information when accessing already closed stackref

* Add #def option to track closed stackrefs to provide precise information for use after free and double frees.
2025-03-05 14:00:42 +00:00
Sam Gross 2f6e0e9f70
gh-130794: Process interpreter QSBR queue in _PyMem_AbandonDelayed. (gh-130808)
This avoids a case where the interpreter's queue of memory to be freed
could grow rapidly if there are many short lived threads.
2025-03-04 18:04:04 -05:00
Amit Lavon 691354ccb0
GH-130415: Narrow str to "" based on boolean tests (GH-130476) 2025-03-04 13:20:17 -08:00
Klaus117 c989e74446
GH-130415: Narrow int to 0 based on boolean tests (GH-130772) 2025-03-04 12:44:09 -08:00
Sergey Miryanov 3a7f17c7e2
gh-130790: Remove references about unicode's readiness from comments (#130801) 2025-03-03 19:18:09 +00:00
Bénédikt Tran 3146a25e97
gh-129173: refactor `PyCodec_BackslashReplaceErrors` into separate functions (#129895)
The logic of `PyCodec_BackslashReplaceErrors` is now split into separate functions,
each of which handling a specific exception type.
2025-03-03 13:58:15 +01:00
Bénédikt Tran f693f84227
gh-129173: simplify `PyCodec_XMLCharRefReplaceErrors` logic (#129894)
Writing the decimal representation of a Unicode codepoint only requires to know the number of digits.

---------

Co-authored-by: Petr Viktorin <encukou@gmail.com>
2025-03-03 11:43:22 +00:00
Ned Batchelder efbc5929ca
docs: internal notes have moved, correct references (#130762) 2025-03-03 06:38:49 -05:00
Brandt Bucher 7afa476874
GH-130415: Use boolean guards to narrow types to values in the JIT (GH-130659) 2025-03-02 13:21:34 -08:00
Hugo Beauzée-Luyssen 214562ed4d
gh-130740: Move some `stdbool.h` includes after `Python.h` (#130738)
Move some `#include <stdbool.h>` after `#include "Python.h"` when `pyconfig.h` is not
included first and when we are in a platform-agnostic context. This is to avoid having
features defined by `stdbool.h` before those decided by `Python.h`.
2025-03-02 09:56:49 +00:00
Mark Shannon 54965f3fb2
GH-130296: Avoid stack transients in four instructions. (GH-130310)
* Combine _GUARD_GLOBALS_VERSION_PUSH_KEYS and _LOAD_GLOBAL_MODULE_FROM_KEYS into _LOAD_GLOBAL_MODULE

* Combine _GUARD_BUILTINS_VERSION_PUSH_KEYS and _LOAD_GLOBAL_BUILTINS_FROM_KEYS into _LOAD_GLOBAL_BUILTINS

* Combine _CHECK_ATTR_MODULE_PUSH_KEYS and _LOAD_ATTR_MODULE_FROM_KEYS into _LOAD_ATTR_MODULE

* Remove stack transient in LOAD_ATTR_WITH_HINT
2025-02-28 18:00:38 +00:00
Sam Gross 038e4d606b
gh-130605: Use relaxed atomics to set the GIL switch interval (gh-130654)
The interval may be concurrently read by a thread attempting to acquire
the GIL.
2025-02-28 09:27:18 -05:00
Hugo Beauzée-Luyssen 830f04b505
Postpone <stdbool.h> inclusion after Python.h (#130641)
Remove inclusions prior to Python.h.

<stdbool.h> will cause <features.h> to be included before Python.h can
define some macros to enable some additional features, causing multiple
types not to be defined down the line.
2025-02-28 10:09:27 +01:00
Petr Viktorin fecf8bc8f2
gh-130595: Fix leak in WITH_EXCEPT_START error case (GH-130626)
Co-authored-by: Ken Jin <kenjin@python.org>
2025-02-28 08:58:50 +00:00
Sam Gross 7aeaa5af2c
gh-130091: Reorder `_PyThreadState_Attach` to avoid data race (gh-130092)
This moves `tstate_activate()` down to avoid a data race in the free
threading build on the `_PyRuntime`'s thread-local `autoTSSkey`. This
key is deleted during runtime finalization, which may happen
concurrently with a call to `_PyThreadState_Attach`.

The earlier `tstate_try/wait_attach` ensures that the thread is blocked
before it attempts to access the deleted `autoTSSkey`.

This fixes a TSAN reported data race in
`test_threading.test_import_from_another_thread`.
2025-02-27 13:57:19 -05:00
Sam Gross d027787c8d
gh-130421: Fix data race on timebase initialization (gh-130592)
Windows and macOS require precomputing a "timebase" in order to convert
OS timestamps into nanoseconds. Retrieve and compute this value during
runtime initialization to avoid data races when accessing the time.
2025-02-27 13:27:54 +00:00
Mark Shannon 2a18e80695
GH-128534: Instrument branches for `async for` loops. (GH-130569) 2025-02-27 09:36:41 +00:00
Victor Stinner 05aba4e799
gh-111178: Fix function signatures in instruction_sequence.c (#130591) 2025-02-26 21:36:26 +01:00
Victor Stinner 1b635d86cd
gh-111178: Fix function signatures in symtable.c (#130589) 2025-02-26 21:35:24 +01:00
Dino Viehland 5c8e8704c3
gh-130595: Keep traceback alive for WITH_EXCEPT_START (#130562)
Keep traceback alive for WITH_EXCEPT_START
2025-02-26 10:41:26 -08:00
Serhiy Storchaka 0ef4ffeefd
gh-130163: Fix crashes related to PySys_GetObject() (GH-130503)
The use of PySys_GetObject() and _PySys_GetAttr(), which return a borrowed
reference, has been replaced by using one of the following functions, which
return a strong reference and distinguish a missing attribute from an error:
_PySys_GetOptionalAttr(), _PySys_GetOptionalAttrString(),
_PySys_GetRequiredAttr(), and _PySys_GetRequiredAttrString().
2025-02-25 23:04:27 +02:00
Tian Gao c5f925c8c9
gh-122029: Move monitoring after method expand for CALL_KW (GH-130488) 2025-02-25 15:43:49 +00:00
Sergey B Kirpichev f39a07be47
gh-87790: support thousands separators for formatting fractional part of floats (#125304)
```pycon
>>> f"{123_456.123_456:_._f}"  # Whole and fractional
'123_456.123_456'
>>> f"{123_456.123_456:_f}"    # Integer component only
'123_456.123456'
>>> f"{123_456.123_456:._f}"   # Fractional component only
'123456.123_456'
>>> f"{123_456.123_456:.4_f}"  # with precision
'123456.1_235'
```
2025-02-25 16:27:07 +01:00
Bénédikt Tran fa6a8140dd
gh-129173: refactor `PyCodec_ReplaceErrors` into separate functions (#129893)
The logic of `PyCodec_ReplaceErrors` is now split into separate functions,
each of which handling a specific exception type.
2025-02-25 14:24:46 +01:00
Mark Shannon 014223649c
GH-130396: Use computed stack limits on linux (GH-130398)
* Implement C recursion protection with limit pointers for Linux, MacOS and Windows

* Remove calls to PyOS_CheckStack

* Add stack protection to parser

* Make tests more robust to low stacks

* Improve error messages for stack overflow
2025-02-25 09:24:48 +00:00
Petr Viktorin ef29104f7d
GH-91079: Revert "GH-91079: Implement C stack limits using addresses, not counters. (GH-130007)" for now (GH130413)
Revert "GH-91079: Implement C stack limits using addresses, not counters. (GH-130007)" for now

Unfortunatlely, the change broke some buildbots.

This reverts commit 2498c22fa0.
2025-02-24 11:16:08 +01:00
Łukasz Langa 72ea3c030a
gh-128627: Skip wasm-gc on iOS Safari where it's broken (#130418)
As of iOS 18.3.1, enabling wasm-gc breaks the interpreter. This disables the wasm-gc
trampoline on iOS.

Co-authored-by: Hood Chatham <roberthoodchatham@gmail.com>
2025-02-24 07:26:04 +08:00
Yan Yanchii 38642bff13
gh-126835: Move constant unaryop & binop folding to CFG (#129550) 2025-02-21 17:54:22 +00:00
Sam Gross ca22147547
gh-111924: Fix data races when swapping allocators (gh-130287)
CPython current temporarily changes `PYMEM_DOMAIN_RAW` to the default
allocator during initialization and shutdown. The motivation is to
ensure that core runtime structures are allocated and freed using the
same allocator. However, modifying the current allocator changes global
state and is not thread-safe even with the GIL. Other threads may be
allocating or freeing objects use PYMEM_DOMAIN_RAW; they are not
required to hold the GIL to call PyMem_RawMalloc/PyMem_RawFree.

This adds new internal-only functions like `_PyMem_DefaultRawMalloc`
that aren't affected by calls to `PyMem_SetAllocator()`, so they're
appropriate for Python runtime initialization and finalization. Use
these calls in places where we previously swapped to the default raw
allocator.
2025-02-20 11:31:15 -05:00
Bénédikt Tran e24a1ac17c
gh-129173: Use `_PyUnicodeError_GetParams` in `PyCodec_SurrogateEscapeErrors` (GH-129175) 2025-02-20 13:18:47 +00:00
Mark Shannon 2498c22fa0
GH-91079: Implement C stack limits using addresses, not counters. (GH-130007)
* Implement C recursion protection with limit pointers

* Remove calls to PyOS_CheckStack

* Add stack protection to parser

* Make tests more robust to low stacks

* Improve error messages for stack overflow
2025-02-19 11:44:57 +00:00
Pablo Galindo Salgado 51d4bf1e0e
bpo-45325: Add a new 'p' parameter to Py_BuildValue to convert an integer into a Python bool (#28634) 2025-02-18 17:14:11 +00:00
Ken Jin 46ac85e4d9
gh-129989: Change Py_TAIL_CALL_INTERP ifndef to ! (#130269)
Change Py_TAIL_CALL_INTERP ifndef to !
2025-02-18 15:48:49 +00:00
Irit Katriel c9b1bf302c
gh-130139: always check ast node type in ast.parse() with ast input (#130140) 2025-02-16 13:32:39 +00:00
Ken Jin 359c7dde3b
gh-129989: Properly disable tailcall interp in configure (GH-129991)
Co-authored-by: Zanie Blue <contact@zanie.dev>
2025-02-16 03:01:24 +08:00
Bénédikt Tran 1775091dc1
gh-129173: Use `_PyUnicodeError_GetParams` in `PyCodec_SurrogatePassErrors` (GH-129134) 2025-02-14 18:34:32 +01:00
Yan Yanchii 334589f619
gh-126835: Set location for noped out instructions after constant folding in CFG. (#130109) 2025-02-14 14:15:08 +00:00
Sam Gross 451f291baa
gh-128130: Fix unhandled keyboard interrupt data race (gh-129975)
Use an atomic operation when setting
`_PyRuntime.signals.unhandled_keyboard_interrupt`. We now only clear the
variable at the start of `_PyRun_Main`, which is the same function where
we check it.

This avoids race conditions where previously another thread might call
`run_eval_code_obj()` and erroneously clear the unhandled keyboard
interrupt.
2025-02-13 12:29:03 -05:00
Sam Gross 0559339ccd
gh-130019: Fix data race in _PyType_AllocNoTrack (gh-130058)
The reference count fields, such as `ob_tid` and `ob_ref_shared`, may be
accessed concurrently in the free threading build by a `_Py_TryXGetRef`
or similar operation. The PyObject header fields will be initialized by
`_PyObject_Init`, so only call `memset()` to zero-initialize the remainder
of the allocation.
2025-02-13 11:50:45 -05:00
Yan Yanchii 140e69c4a8
gh-126835: Move const folding of lists & sets from ast_opt.c to flowgraph.c (#130032) 2025-02-13 12:11:07 +00:00
Sam Gross e09442089e
gh-130030: Fix crash on 32-bit Linux with free threading (gh-130043)
The `gc_get_refs` assertion needs to be after we check the alive and
unreachable bits. Otherwise, `ob_tid` may store the actual thread id
instead of the computed `gc_refs`, which may trigger the assertion if
the `ob_tid` looks like a negative value.

Also fix a few type warnings on 32-bit systems.
2025-02-12 18:09:15 -05:00
Ken Jin 1b27f36eb0
gh-129819: Allow tier2/JIT and tailcall (GH-129820) 2025-02-13 02:18:36 +08:00
Brandt Bucher 11bb08e4ec
GH-129715: Don't project traces that return to an unknown caller (GH-130024) 2025-02-12 10:16:43 -08:00
Mark Shannon 72f56654d0
GH-128682: Account for escapes in `DECREF_INPUTS` (GH-129953)
* Handle escapes in DECREF_INPUTS

* Mark a few more functions as escaping

* Replace DECREF_INPUTS with PyStackRef_CLOSE where possible
2025-02-12 17:44:59 +00:00
Andrew Svetlov 469d2e416c
gh-129889: Support context manager protocol by contextvars.Token (#129888) 2025-02-12 12:32:58 +01:00
Stefano Rivera e1b38ea82e
Update manpage environment variables and command line arguments (#129623)
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
2025-02-12 13:00:35 +02:00
Michael Droettboom 00ec781877
gh-129244: Only remove the workaround when MSVC has the bugfix (#130011) 2025-02-11 14:49:42 -05:00
Ken Jin 5cdd6e5e75
gh-130004: Disable PGO for ceval.c on MSVC for default build (GH-130009)
Disable PGO for ceval.c on MSVC on default build
2025-02-12 01:13:05 +08:00
Ken Jin 247b50dec8
gh-130004: Revert commit 9e52e55 (GH-130005)
Revert commit 9e52e55
2025-02-11 23:23:58 +08:00
Yan Yanchii 91d9544112
gh-126835: Make CFG optimizer skip over NOP's when looking for const sequence construction (#129703)
Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
2025-02-09 18:00:41 +00:00
Bénédikt Tran a56ead089c
gh-129173: Use `_PyUnicodeError_GetParams` in `PyCodec_NameReplaceErrors` (GH-129135) 2025-02-08 16:01:57 +01:00
Irit Katriel a1417b211f
gh-100239: replace BINARY_SUBSCR & family by BINARY_OP with oparg NB_SUBSCR (#129700) 2025-02-07 22:39:54 +00:00
Brandt Bucher 5fa7e1b7fd
GH-129715: Remove _DYNAMIC_EXIT (GH-129716) 2025-02-07 11:41:17 -08:00
Brandt Bucher 70e387c990
GH-129709: Clean up tier two (GH-129710) 2025-02-07 09:52:49 -08:00
Brandt Bucher fbaa6c8ff0
GH-129763: Remove the LLTRACE macro (GH-129764) 2025-02-07 08:49:51 -08:00
Ken Jin 175844713a
gh-128563: Move assignment of opcode into ifdef (GH-129803) 2025-02-07 21:11:57 +08:00
sobolevn ae132edc29
gh-129766: Fix crash on calling `warnings._release_lock` with no lock (#129771) 2025-02-07 12:59:52 +03:00
Donghee Na b184abf074
gh-129533: Update PyGC_Enable/Disable/IsEnabled to use atomic operation (gh-129563) 2025-02-07 07:41:13 +09:00
Kumar Aditya 0d68b14a0d
gh-128002: use per threads tasks linked list in asyncio (#128869)
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
2025-02-06 19:51:07 +01:00
Peter Hawkins b4ff8b22b3
gh-129732: Fix race on `shared->array` in qsbr code under free-threading (gh-129738)
The read of `shared->array` should happen under the lock to avoid a race.
2025-02-06 18:49:29 +00:00
Ken Jin cb640b659e
gh-128563: A new tail-calling interpreter (GH-128718)
Co-authored-by: Garrett Gu <garrettgu777@gmail.com>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
2025-02-06 23:21:57 +08:00
Neil Schemenauer cdcacec79f
gh-129201: Use prefetch in GC mark alive phase. (gh-129203)
For the free-threaded version of the cyclic GC, restructure the "mark alive" phase to use software prefetch instructions.  This gives a speedup in most cases when the number of objects is large enough.  The prefetching is enabled conditionally based on the number of long-lived objects the GC finds.
2025-02-05 11:38:30 -08:00
Victor Stinner a25042e6d2
gh-129354: Use PyErr_FormatUnraisable() function (#129523)
Replace PyErr_WriteUnraisable() with PyErr_FormatUnraisable().

Update tests:

* test_coroutines
* test_exceptions
* test_generators
* test_struct
2025-02-05 10:31:59 +00:00
Victor Stinner dc804ffb2f
gh-128911: Use PyImport_ImportModuleAttr() function (#129657)
* Replace PyImport_ImportModule() + PyObject_GetAttr() with
  PyImport_ImportModuleAttr().
* Replace PyImport_ImportModule() + PyObject_GetAttrString() with
  PyImport_ImportModuleAttrString().
2025-02-05 11:03:58 +01:00
Mark Shannon 96ff4c2486
GH-128682: Mark two more macros as escaping. (GH-129645)
Expand out SETLOCAL so that code generator can see the decref. Mark Py_CLEAR as escaping
2025-02-04 14:00:51 +00:00
Mark Shannon 2effea4dab
GH-128682: Spill the stack pointer in labels, as well as instructions (GH-129618) 2025-02-04 12:18:31 +00:00
Yan Yanchii d3c54f3788
gh-126835: Fix reference leak in `Python/flowgrapc.::optimize_if_const_subscr` (#129634) 2025-02-04 10:38:06 +00:00
Yan Yanchii 0664c1af9b
gh-126835: Move constant subscript folding to CFG (#129568)
Move folding of constant subscription from AST optimizer to CFG.

Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
2025-02-04 10:10:55 +02:00
Mark Shannon 75b628adeb
GH-128563: Generate `opcode = ...` in instructions that need `opcode` (GH-129608)
* Remove support for GO_TO_INSTRUCTION
2025-02-03 15:09:21 +00:00
Mark Shannon 808071b994
GH-128682: Make `PyStackRef_CLOSE` escaping. (GH-129404) 2025-02-03 12:41:32 +00:00
Diego Russo a29a9c0f38
GH-129231: Group executable JIT code in memory (GH-129232) 2025-02-02 15:19:55 -08:00
Diego Russo 567394517a
GH-128842: Collect JIT memory stats (GH-128941) 2025-02-02 15:17:53 -08:00
Yan Yanchii e6c76b947b
GH-128872: Remove unused argument from _PyCode_Quicken (GH-128873)
Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
2025-02-02 15:09:30 -08:00
Kirill Podoprigora 7d0521d5fc
gh-126835: Move optimization of constant sequence creation from codegen to CFG (#129426)
Codegen phase has an optimization that transforms
```
LOAD_CONST x
LOAD_CONST y
LOAD_CONXT z
BUILD_LIST/BUILD_SET (3)
```
->
```
BUILD_LIST/BUILD_SET (0)
LOAD_CONST (x, y, z)
LIST_EXTEND/SET_UPDATE 1
```
This optimization has now been moved to CFG phase to make #128802 work.


Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
Co-authored-by: Yan Yanchii <yyanchiy@gmail.com>
2025-02-01 11:39:44 +00:00
Mark Shannon 54f74b80ae
GH-128563: Move some labels, to simplify implementing tailcalling interpreter. (GH-129525) 2025-01-31 17:13:20 +00:00
Peter Bierma 9ba281d871
gh-128509: Add `sys._is_immortal` for identifying immortal objects (#128510)
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
2025-01-31 15:27:08 +00:00