Commit Graph

9713 Commits

Author SHA1 Message Date
Sam Gross da53660f35
gh-131586: Avoid refcount contention in context managers (gh-131851)
This avoid reference count contention in the free threading build
when calling special methods like `__enter__` and `__exit__`.
2025-04-21 15:54:25 -04:00
Peter Bierma 8dfa840773
gh-127604: Add C stack dumps to `faulthandler` (#128159) 2025-04-21 20:48:02 +01:00
Brandt Bucher 4f7f72ce34
GH-130415: Improve the JIT's unneeded uop removal pass (GH-132333) 2025-04-21 09:58:55 -07:00
Bénédikt Tran 427e7fc099
gh-132399: ensure correct alignment of `PyInterpreterState` (#132428) 2025-04-19 11:03:06 +02:00
Bénédikt Tran 8a9c6c4d16
gh-128398: improve error messages when incorrectly using `with` and `async with` (#132218)
Improve the error message with a suggestion when an object supporting the synchronous
(resp. asynchronous) context manager protocol is entered using `async with` (resp. `with`)
instead of `with` (resp. `async with`).
2025-04-19 10:44:01 +02:00
Pablo Galindo Salgado c9a855a9e0
gh-131591: Execute the source and not the file to avoid locking it in Windows (#132712)
Signed-off-by: Pablo Galindo <pablogsal@gmail.com>
2025-04-19 00:38:12 +00:00
Kumar Aditya 7fd708b727
gh-132685: fix thread safety of `PyMember_GetOne` with `_Py_T_OBJECT` (#132690) 2025-04-18 21:03:42 +05:30
Brandt Bucher 40ae88988c
GH-131498: Replace single-element arrays with scalars in bytecodes.c (GH-132615) 2025-04-18 07:16:28 -07:00
Bénédikt Tran 379352620c
gh-132097: use a macro for semantically casting function pointers (#132406) 2025-04-18 12:24:34 +02:00
Kumar Aditya f3d877a27a
gh-132643: use atomic load for dict in specializer (#132653) 2025-04-18 15:06:27 +05:30
Adam Turner ea23c897cd
Remove duplicate includes: Python/importdl.c (#132623) 2025-04-18 02:49:19 +01:00
Alper 22830103e5
gh-131173: Improve exception handling during take_ownership processing (#132620)
Save and restore exceptions during take_ownership processing to preserve
exceptions currently being raised.

Co-authored-by: alperyoney <alperyoney@fb.com>
2025-04-17 13:38:34 -07:00
Bartosz Sławecki 954b2cf031
gh-130070: Fix `exec(<string>, closure=<non-None>)` unexpected path (#130071)
Fixed an assertion error (so, it could be reproduced only in builds with assertions enabled)
for `exec` when the `source` argument is a string and the `closure` argument is not `None`.

Co-authored-by: sobolevn <mail@sobolevn.me>
2025-04-17 10:14:55 +03:00
Adam Turner d7df7815f5
Remove duplicate includes: Python/ast_opt.c (#132621) 2025-04-17 10:10:01 +03:00
Nadeshiko Manju b9e88ff4cb
gh-131798: Use `sym_new_type` instead of `sym_new_not_null` for `_BUILD_LIST`, `_BUILD_SLICE`, and `_BUILD_MAP` (GH-132434)
---------

Signed-off-by: Manjusaka <me@manjusaka.me>
2025-04-17 01:17:48 +08:00
T. Wouters c66ffcf8e3
gh-129987: Selectively re-enable SLP autovectorization of _PyEval_EvalFrameDefault (#132530)
Only disable SLP autovectorization of `_PyEval_EvalFrameDefault` on newer
GCCs, as the optimization bug seems to exist only on GCC 12 and later, and
before GCC 9 disabling the optimization has a dramatic performance impact.
2025-04-15 09:39:32 +00:00
Serhiy Storchaka 102f825c51
gh-124476: Fix decoding from the locale encoding in the C.UTF-8 locale (GH-132477) 2025-04-14 21:32:41 +03:00
Mark Shannon 844596c09f
GH-131498: Cases generator: Allow input and 'peek' variables to be modified (GH-132506) 2025-04-14 12:19:53 +01:00
Furkan Onder c7f6535e4a
gh-131624: Fix posix_spawn tests failing on NetBSD with stack limit assertions (GH-131625)
Fix recursive limit assertions on NetBSD for posix_spawn.
2025-04-13 14:06:38 +03:00
Tomas R. 3d08c8ad20
gh-131927: Prevent emitting optimizer warnings twice in the REPL (#131993) 2025-04-12 11:34:36 +01:00
Serhiy Storchaka d4e2cdc15b
gh-125434: Fix building on OpenBSD (GH-132393)
pthread_get_name_np is defined in pthread_np.h.
2025-04-12 11:25:35 +03:00
Bénédikt Tran a81232c769
gh-132399: fix invalid function signatures on the free-threaded build (#132400) 2025-04-12 07:46:33 +00:00
Tomas R. e6ef47ac22
gh-132386: Fix a crash when passing a dict subclass to `exec` (GH-132412)
* Fix crash when passing a dict subclass to exec

* Add news entry
2025-04-12 05:05:03 +08:00
Mark Shannon d87e7f3529
GH-127682: Only call `__iter__` once in generator expressions. (GH-132351) 2025-04-11 09:37:22 +01:00
Jelle Zijlstra 07b8d3117f
gh-132261: Store annotations at hidden internal keys in the class dict (#132345) 2025-04-10 21:13:26 -07:00
Chris Eibl e5f68fd29b
GH-131296: Suppress "unused label" warning for clang-cl closer to actual occurrence (GH-131900) 2025-04-10 23:17:33 +01:00
Chu 3d83c1ec61
Fix a typo in Python/pylifecycle.c (#132350) 2025-04-10 17:27:37 +05:30
mpage 619edb802e
gh-132336: Mark a few "slow path" functions used by the interpreter loop as noinline (#132337)
Mark a few functions used by the interpreter loop as noinline

These are all the slow path and should not be inlined into the interpreter
loop. Unfortunately, they end up being inlined with LTO and the current PGO
task.
2025-04-10 10:41:15 +02:00
Neil Schemenauer d687900f98
gh-128384: Use a context variable for warnings.catch_warnings (gh-130010)
Make `warnings.catch_warnings()` use a context variable for holding
the warning filtering state if the `sys.flags.context_aware_warnings`
flag is set to true.  This makes using the context manager thread-safe in
multi-threaded programs.

Add the `sys.flags.thread_inherit_context` flag.  If true, starting a new
thread with `threading.Thread` will use a copy of the context
from the caller of `Thread.start()`.

Both these flags are set to true by default for the free-threaded build
and false for the default build.

Move the Python implementation of warnings.py into _py_warnings.py.

Make _contextvars a builtin module.

Co-authored-by: Kumar Aditya <kumaraditya@python.org>
2025-04-09 16:18:54 -07:00
Brandt Bucher 20926c73b5
GH-131798: Remove JIT guards for dict, frozenset, list, set, and tuple (GH-132289) 2025-04-09 14:32:21 -07:00
mpage 1f5682f3a2
gh-129987: Disable GCC SLP autovectorization for the interpreter loop on x86-64 (#132295)
The SLP autovectorizer can cause poor code generation for opcode dispatch, negating any benefit we get from vectorization elsewhere in the interpreter loop.
2025-04-09 10:34:12 -07:00
Serhiy Storchaka f5f1ac84b3
gh-112068: C API: Add support of nullable arguments in PyArg_Parse (GH-121303) 2025-04-08 22:08:00 +03:00
Nadeshiko Manju d753d8aed7
GH-131798: Narrow the result of _CONTAINS_OP_DICT to bool in the JIT (GH-132269)
Co-authored-by: Tomas R. <tomas.roun8@gmail.com>
2025-04-08 09:12:09 -07:00
Tomas R. 71009cb835
GH-131798: Narrow the result type of _BINARY_OP_SUBSCR_STR_INT to str in the JIT (GH-132153) 2025-04-08 08:22:54 -07:00
Serhiy Storchaka 0e4cf9ce7c
gh-50333: Deprecate support of non-tuple sequences in PyArg_ParseTuple() (GH-128374)
Non-tuple sequences are deprecated as argument for the "(items)" format unit
in PyArg_ParseTuple() and other argument parsing functions if items contains
format units which store borrowed buffer or reference (e.g. "s" and "O").

str and bytearray are no longer accepted as valid sequences.
2025-04-08 14:26:32 +03:00
Peter Bierma ac3c439cdf
gh-131998: Fix `NULL` dereference when using an unbound method descriptor in a specialized code path (#132000)
Co-authored-by: sobolevn <mail@sobolevn.me>
Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Mark Shannon <mark@hotpy.org>
2025-04-08 10:31:43 +00:00
Irit Katriel 8c9ef8f1f8
gh-100239: more stats for BINARY_OP/SUBSCR specialization (#132230) 2025-04-08 08:50:51 +00:00
sobolevn bc5233b6a5
gh-130775: Allow negative locations in `ast` (#130795)
Co-authored-by: Victor Stinner <vstinner@python.org>
2025-04-07 19:35:17 +03:00
Pablo Galindo Salgado 2067378e6d
gh-131591: Handle includes for iOS in remote_debugging.c (#132050) 2025-04-06 21:39:25 +01:00
sobolevn c0661df42a
gh-132011: Fix crash on invalid `CALL_LIST_APPEND` deoptimization (#132018)
Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
2025-04-06 19:10:39 +03:00
Tomas R. 85bc489b64
GH-131798: Narrow the result of _CONTAINS_OP_SET to bool in the JIT (GH-132057) 2025-04-05 15:56:01 -07:00
Adam Turner 231a50fa9a
gh-109599: Expose `CapsuleType` via the `_types` module (#131969) 2025-04-04 23:37:41 +01:00
Irit Katriel 68e72cf3a8
gh-100239: fix bug in comparison (#132093) 2025-04-04 18:09:49 +01:00
Bénédikt Tran 0a97427ee5
gh-99108: Implement HACL* HMAC (#130157)
A new extension module, `_hmac`, now exposes the HACL* HMAC (formally verified) implementation.

The HACL* implementation is used as a fallback implementation when the OpenSSL implementation of HMAC
is not available or disabled. For now, only named hash algorithms are recognized and SIMD support provided
by HACL* for the BLAKE2 hash functions is not yet used.
2025-04-04 19:04:00 +02:00
Mark Shannon 7099c75550
GH-131498: Cases generator: manage stacks automatically (GH-132074) 2025-04-04 17:59:36 +01:00
Irit Katriel df59226997
gh-100239: more refined specialisation stats for BINARY_OP/SUBSCR (#132068) 2025-04-04 15:33:31 +01:00
Vincent Fazio 72123063dd
gh-130115: fix thread identifiers for 32-bit musl (#130391)
CPython's pthread-based thread identifier relies on pthread_t being able
to be represented as an unsigned integer type.

This is true in most Linux libc implementations where it's defined as an
unsigned long, however musl typedefs it as a struct *.

If the pointer has the high bit set and is cast to PyThread_ident_t, the
resultant value can be sign-extended [0]. This can cause issues when
comparing against threading._MainThread's identifier. The main thread's
identifier value is retrieved via _get_main_thread_ident which is backed
by an unsigned long which truncates sign extended bits.

  >>> hex(threading.main_thread().ident)
  '0xb6f33f3c'
  >>> hex(threading.current_thread().ident)
  '0xffffffffb6f33f3c'

Work around this by conditionally compiling in some code for non-glibc
based Linux platforms that are at risk of sign-extension to return a
PyLong based on the main thread's unsigned long thread identifier if the
current thread is the main thread.

[0]: https://gcc.gnu.org/onlinedocs/gcc-14.2.0/gcc/Arrays-and-pointers-implementation.html

---------

Signed-off-by: Vincent Fazio <vfazio@gmail.com>
2025-04-04 16:31:37 +02:00
Tomasz Pytel 891c61c1fa
gh-128632: fix segfault on nested __classdict__ type param (#128744) 2025-04-04 06:23:35 -07:00
Victor Stinner 37d47d4965
gh-125434: Display thread name in faulthandler (#132016) 2025-04-04 12:24:41 +00:00
Filipe Laíns 🇵🇸 6ab4acecf9
GH-131770: increase assumed WASI stack size to 131072 (wasi-sdk default) (#131844)
e9524a0980/libc-top-half/musl/src/internal/pthread_impl.h (L220)

Signed-off-by: Filipe Laíns <lains@riseup.net>
2025-04-04 09:34:02 +01:00
Pablo Galindo Salgado 943cc1431e
gh-131591: Implement PEP 768 (#131937)
Co-authored-by: Ivona Stojanovic <stojanovic.i@hotmail.com>
Co-authored-by: Matt Wozniski <godlygeek@gmail.com>
2025-04-03 16:20:01 +01:00
Mark Shannon 275056a7fd
GH-131904: Fix Py_STACKREF_DEBUG build (GH-132022) 2025-04-03 09:40:37 +01:00
Adam Turner f20f02e6b5
gh-118761: Optimise import time for ast (#131953) 2025-04-02 17:22:15 +01:00
Mark Shannon ad053d8d6a
GH-131498: Cases generator: Parse down to C statement level. (GH-131948)
* Parse down to statement level in the cases generator

* Add handling for #if macros, treating them much like normal ifs.
2025-04-02 16:31:59 +01:00
sobolevn ab2a3dda1d
gh-132002: Fix crash of `ContextVar` on unhashable `str` subtype (#132003) 2025-04-02 14:48:47 +03:00
Brandt Bucher 3a8cefba0b
GH-131726: Split up _CHECK_VALIDITY_AND_SET_IP (GH-131810) 2025-04-01 16:55:05 -07:00
Brandt Bucher 1a9d4a1fb3
GH-131798: Allow the JIT to remove more int/float/str guards (GH-131800) 2025-04-01 15:10:15 -07:00
mpage 053c285f6b
gh-130704: Strength reduce `LOAD_FAST{_LOAD_FAST}` (#130708)
Optimize `LOAD_FAST` opcodes into faster versions that load borrowed references onto the operand stack when we can prove that the lifetime of the local outlives the lifetime of the temporary that is loaded onto the stack.
2025-04-01 10:18:42 -07:00
Bénédikt Tran edbf7fb129
gh-111178: remove redundant casts for functions with correct signatures (#131673) 2025-04-01 17:18:11 +02:00
Chris Eibl 2e96f5ae4d
GH-131296: Add missing UNREACHABLE mark in thread_nt.h (GH-131589) 2025-03-31 20:28:35 +01:00
sobolevn 1e3ec335e0
Fix PEP number in `ast_opt.c` for new `finally` check (#131928) 2025-03-31 16:29:23 +03:00
Mark Shannon c535a132e4
GH-131498: Another refactoring of the code generator (GH-131827)
* Rename 'defined' attribute to 'in_local' to more accurately reflect how it is used

* Make death of variables explicit even for array variables.

* Convert in_memory from boolean to stack offset

* Don't apply liveness analyis to optimizer generated code

* Add 'out' parameter to stack.pop
2025-03-31 13:52:48 +01:00
Amit Lavon 685fd74f81
GH-131798: Remove type checks for _TO_BOOL_STR (GH-131816) 2025-03-30 16:07:25 -07:00
Jelle Zijlstra 425f60b9eb
gh-130924: Do not create cells for usages of names in local annotations (#131843) 2025-03-29 21:15:48 +00:00
Martin DeMello 9c1e85fd64
gh-131740: minor readability fix in PyUnstable_GC_VisitObjects (gh-131786)
Minor readability fix in PyUnstable_GC_VisitObjects

Replaces `if (visit_generation())` with `if (visit_generation() < 0)`,
since we are checking for the failure case, and it's confusing to have
that be implicitly `true`.

Also fixes a misspelt variable name.
2025-03-29 08:58:17 +09:00
Dino Viehland 2984ff9e51
gh-130373: Avoid locking in _LOAD_ATTR_WITH_HINT (#130372)
Avoid locking in _LOAD_ATTR_WITH_HINT
2025-03-28 15:16:41 -07:00
Irit Katriel 2c8f329dc6
gh-131738: optimize builtin any/all/tuple calls with a generator expression arg (#131737) 2025-03-28 10:35:20 +00:00
Hang 8bd88e2827
gh-131818: Add imply `-P` in `-I`'s help message (#131819) 2025-03-28 08:49:13 +01:00
Brandt Bucher 972a295fe3
GH-130415: Remove redundant sym_matches_type calls in the JIT optimizer (GH-131778) 2025-03-27 09:12:30 -07:00
Michael Droettboom 8614f86b71
gh-131525: Cache the result of tuple_hash (#131529)
* gh-131525: Cache the result of tuple_hash

* Fix debug builds

* Add blurb

* Fix formatting

* Pre-compute empty tuple singleton

* Mostly set the cache within tuple_alloc

* Fixes for TSAN

* Pre-compute empty tuple singleton

* Fix for 32-bit platforms

* Assert that op != NULL in _PyTuple_RESET_HASH_CACHE

* Use FT_ATOMIC_STORE_SSIZE_RELAXED macro

* Update Include/internal/pycore_tuple.h

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>

* Fix alignment

* atomic load

* Update Objects/tupleobject.c

Co-authored-by: Chris Eibl <138194463+chris-eibl@users.noreply.github.com>

---------

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Chris Eibl <138194463+chris-eibl@users.noreply.github.com>
2025-03-27 09:57:06 -04:00
Mark Shannon d836d287a7
GH-131729: Consider in-memory state when merging storage and stack (GH-131773) 2025-03-27 08:32:45 +00:00
Sergey Muraviov 151d1bfd1b
gh-131763: Replace the redundant check with assert in remove_tools (#131765) 2025-03-26 18:36:04 -04:00
Sam Gross 67fbfb42bd
gh-131586: Avoid refcount contention in some "special" calls (#131588)
In the free threaded build, the `_PyObject_LookupSpecial()` call can lead to
reference count contention on the returned function object becuase it
doesn't use stackrefs. Refactor some of the callers to use
`_PyObject_MaybeCallSpecialNoArgs`, which uses stackrefs internally.

This fixes the scaling bottleneck in the "lookup_special" microbenchmark
in `ftscalingbench.py`. However, the are still some uses of
`_PyObject_LookupSpecial()` that need to be addressed in future PRs.
2025-03-26 14:38:47 -04:00
Sam Gross 3d4ac1a2c2
gh-123358: Use `_PyStackRef` in `LOAD_DEREF` (gh-130064)
Concurrent accesses from multiple threads to the same `cell` object did not
scale well in the free-threaded build. Use `_PyStackRef` and optimistically
avoid locking to improve scaling.

With the locks around cell reads gone, some of the free threading tests were
prone to starvation: the readers were able to run in a tight loop and the
writer threads weren't scheduled frequently enough to make timely progress.
Adjust the tests to avoid this.

Co-authored-by: Donghee Na <donghee.na@python.org>
2025-03-26 12:08:20 -04:00
Mark Shannon 1b8bb1ed0c
GH-131729: Code-gen better liveness analysis (GH-131732)
* Rename 'defined' attribute to 'in_local' to more accurately reflect how it is used

* Make death of variables explicit even for array variables.

* Convert in_memory from boolean to stack offset

* Don't apply liveness analysis to optimizer generated code

* Fix RETURN_VALUE in optimizer
2025-03-26 15:21:35 +00:00
Jelle Zijlstra 898e6b395e
gh-130881: Handle conditionally defined annotations (#130935) 2025-03-26 03:48:19 +00:00
Donghee Na 7bb41aef4b
gh-131740: Update PyUnstable_GC_VisitObjects to traverse perm gen (gh-131744) 2025-03-26 09:45:29 +09:00
sobolevn 929afd1d6e
gh-131670: Fix crash in `anext()` when `__anext__` is sync and raises (#131682)
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2025-03-24 19:00:48 +00:00
Sam Gross da6730caa5
gh-128421: Avoid TSAN warnings in `sys._current_frames()` (gh-131548)
This tells TSAN not to sanitize `PyUnstable_InterpreterFrame_GetLine()`.
There's a possible data race on the access to the frame's `instr_ptr`
if the frame is currently executing. We don't really care about the
race. In theory, we could use relaxed atomics for every access to
`instr_ptr`, but that would create more code churn and current compilers
are overly conservative with optimizations around relaxed atomic
accesses.

We also don't sanitize `_PyFrame_IsIncomplete()` because it accesses
`instr_ptr` and is called from assertions within PyFrame_GetCode().
2025-03-24 09:49:39 -04:00
Bénédikt Tran 511a844028
gh-111178: fix UBSan failures for `Python/legacy_tracing.c` (#131611) 2025-03-24 11:00:32 +01:00
Bénédikt Tran 43fde78bef
gh-111178: fix UBSan failures for `Python/instrumentation.c` (#131608) 2025-03-24 10:58:33 +01:00
Bénédikt Tran f65be097ed
gh-111178: fix UBSan failures for `_PyExecutorObject` (#131610) 2025-03-24 10:53:23 +01:00
Irit Katriel 64906bb223
gh-130080: do not fold match case constants in unoptimized AST (#131577) 2025-03-23 13:50:14 +00:00
Victor Stinner 9962469943
gh-131296: fix clang-cl warning in tracemalloc.c (#131514)
Always set MAX_NFRAME to UINT16_MAX.

Avoid the complicated code which emitted a compiler warning.
2025-03-22 10:38:47 +01:00
Victor Stinner 49fb75c676
gh-131238: Add missing pycore_function.h includes for JIT compiler (#131571) 2025-03-21 23:37:49 +00:00
Dino Viehland d9411ae3c2
gh-130312: SET_ADD should not lock (#130136)
SET_ADD should not lock
2025-03-21 15:58:32 -07:00
Victor Stinner 7101cba6bf
gh-131238: Move _Py_VISIT_STACKREF() to pycore_stackref.h (#131560)
* Move _Py_VISIT_STACKREF() from pycore_gc.h to pycore_stackref.h.
* Remove pycore_interpframe.h include from pycore_genobject.h.
* Remove now useless includes from C files.
* Add pycore_interpframe_structs.h to Makefile.pre.in and
  pythoncore.vcxproj.
2025-03-21 23:24:14 +01:00
Savannah Ostrowski b92ee14b80
GH-130415: Optimize constant comparison in JIT builds (GH-131489) 2025-03-21 11:23:12 -07:00
Sam Gross 0de5e0c544
gh-117657: Fix TSAN data race in _PyEval_SetTrace assertion (gh-131561)
The `sys_tracing_threads` variable should be read inside `LOCK_SETUP()`.
2025-03-21 14:22:37 -04:00
Victor Stinner 61317074d4
gh-131238: Add pycore_interpframe_structs.h header (#131553)
Add an explicit include to pycore_interpframe_structs.h in
pycore_runtime_structs.h to fix a dependency cycle.
2025-03-21 17:19:47 +00:00
Sam Gross 4f32516804
gh-128421: Add locking to most frame object functions (gh-131479)
This makes more operations on frame objects thread-safe in the free
threaded build, which fixes some data races that occurred when passing
exceptions between threads.

However, accessing local variables from another thread while its running
is still not thread-safe and may crash the interpreter.
2025-03-21 11:10:07 -04:00
Bénédikt Tran 883c2f682b
GH-131331: Rename "not" to "invert" (GH-131334) 2025-03-20 16:59:41 -07:00
Chris Eibl a2ea417578
GH-131296: fix clang-cl warnings in sysmodule.c (#131304) 2025-03-20 16:29:21 +00:00
Mark Shannon 7ebd71ee14
GH-131498: Remove conditional stack effects (GH-131499)
* Adds some missing #includes
2025-03-20 15:39:38 +00:00
Mark Shannon 83d54fa876
GH-130296: Remove `_PyOpcode_max_stack_effect` as it is no longer used (GH-131493) 2025-03-20 11:42:54 +00:00
Victor Stinner b69da006a4
gh-131238: Remove includes from pycore_interp.h (#131495)
Remove also now unused includes in C files.
2025-03-20 11:35:23 +00:00
Victor Stinner 34c1ea3109
gh-111178: Fix function signatures for multiple tests (#131496) 2025-03-20 12:27:03 +01:00
Victor Stinner 486d537065
Fix Windows build warnings (#131487)
Fix the following warnings:

* Modules\_io\fileio.c(1296,13): unused variable 'self'
* Modules\_io\winconsoleio.c(334,9): unused variable 'fd_is_own'
* Modules\faulthandler.c(409,11): unused variable 'flags'
* Modules\posixmodule.c(5699,9): unused variable 'pathError'
* PC\winreg.c(2077,5): suggest braces around initialization of
  subobject
* PC\winreg.c(34,13): unused variable 'errNotAHandle'
* Python\fileutils.c(132,12): result of comparison of constant
  1114111 with expression of type 'wchar_t' (aka 'unsigned short') is
  always false
* Python\fileutils.c(58,21): unused variable 'INCOMPLETE_CHARACTER'
* Python\sysmodule.c(2534,21): unused variable 'perf_map_state'
2025-03-20 12:03:20 +01:00
Kumar Aditya 39b37b0110
gh-128421: add critical section around `traceback.tb_next` (#131322) 2025-03-20 12:03:54 +05:30
Kumar Aditya b12af0a48f
gh-131401: fix data races in exception handling (#131447) 2025-03-20 12:02:05 +05:30
Victor Stinner 20c5f969dd
gh-131238: Remove more includes from pycore_interp.h (#131480) 2025-03-19 23:01:32 +01:00
Yan Yanchii 75103d975c
gh-126835: Move constant tuple folding from ast_opt to CFG (#130769) 2025-03-19 20:59:55 +00:00
Diego Russo 8a33034d82
GH-130956: Only emit AArch64 trampolines for long jumps (GH-131041) 2025-03-19 12:19:21 -07:00
Victor Stinner 22706843e0
gh-131238: Remove many includes from pycore_interp.h (#131472) 2025-03-19 17:46:24 +00:00
Victor Stinner 5c44d7d99c
gh-130931: Add pycore_interpframe.h internal header (#131249)
Move _PyInterpreterFrame and associated functions
to a new pycore_interpframe.h header.
2025-03-19 18:17:44 +01:00
Victor Stinner 4b54031323
gh-131238: Remove pycore_runtime.h from pycore_pystate.h (#131356)
* Remove includes from pycore_pystate.h:

  * pycore_runtime_structs.h
  * pycore_runtime.h
  * pycore_tstate.h
  * pycore_interp.h

* Reorganize internal headers. Move _gc_thread_state from
  pycore_interp_structs.h to pycore_tstate.h.
* Add 3 new header files to PCbuild/pythoncore.vcxproj.
2025-03-19 17:33:24 +01:00
Victor Stinner 0a54bd6dd7
gh-111178: Fix function signatures in legacy_tracing.c (#131464) 2025-03-19 16:54:41 +01:00
Victor Stinner bbe5baad6c
gh-111178: Fix function signatures for test_types (#131455) 2025-03-19 13:46:17 +00:00
Kumar Aditya 74b87515a7
gh-131401: fix data race in `_PyErr_Restore` (#131406) 2025-03-19 14:35:47 +05:30
Irit Katriel ffc2f1dd1c
gh-130080: implement PEP 765 (#130087) 2025-03-17 20:48:54 +00:00
Ken Jin b2ed7a6d6a
gh-131281: Add include for pystats builds (#131369)
Add include to for pystats builds
2025-03-18 00:36:06 +08:00
Mark Shannon a45f25361d
GH-131238: More refactoring of core header files (GH-131351)
Adds new pycore_stats.h header file to help break dependencies involving the pycore_code.h header.
2025-03-17 14:41:05 +00:00
Victor Stinner 978e37bb5f
gh-131238: Add explicit includes to pycore headers (#131257) 2025-03-17 12:32:43 +01:00
Victor Stinner 0453e494b6
gh-131238: Convert pycore_pystate.h static inline to functions (#131352)
Convert static inline functions to functions:

* _Py_IsMainThread()
* _PyInterpreterState_Main()
* _Py_IsMainInterpreterFinalizing()
* _Py_GetMainConfig()
2025-03-17 12:31:55 +01:00
Mark Shannon a1aeec61c4
GH-131238: Core header refactor (GH-131250)
* Moves most structs in pycore_ header files into pycore_structs.h and pycore_runtime_structs.h

* Removes many cross-header dependencies
2025-03-17 09:19:04 +00:00
Chris Eibl f104c19a94
GH-131296: fix clang-cl warning on Windows in pytime.c (GH-131297)
fix warning : integer literal is too large

to be represented in a signed integer type,
interpreting as unsigned [-Wimplicitly-unsigned-literal]
2025-03-15 11:41:34 -07:00
Xuanteng Huang 1821f8f10c
gh-131281: fix compile error due to `BINARY_SUBSCR` (GH-131283)
* fix compile error due to `BINARY_SUBSCR`

* replace stat_inc with `BINARY_OP`
2025-03-15 23:38:46 +08:00
Yan Yanchii 55815a6474
gh-130480: Move duplicate `LOAD_SMALL_INT` optimization from codegen to CFG (#130481) 2025-03-14 21:23:27 +00:00
Victor Stinner a5776639c8
gh-111178: Fix function signatures to fix undefined behavior (#131191) 2025-03-14 09:52:15 +00:00
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