Commit graph

9719 commits

Author SHA1 Message Date
Miss Islington (bot)
ef539654e6
[3.14] gh-134876: Add fallback for when process_vm_readv fails with ENOSYS (GH-134878) (#135240)
gh-134876: Add fallback for when process_vm_readv fails with ENOSYS (GH-134878)
(cherry picked from commit ac9c3431cc)

Co-authored-by: Daniel Golding <goldingd89@gmail.com>
2025-06-07 18:56:38 +00:00
Petr Viktorin
b477e21d5c
[3.14] gh-128605: Revert "Add branch protections for x86_64 in asm_tr…ampoline.S (#128606) (#135077)" (GH-135175)
This reverts commit 899cca6dbf,
which broke buildbots.
2025-06-06 13:55:26 +02:00
mpage
be2f32e60f
[3.14] gh-134889: Fix handling of a few opcodes when optimizing LOAD_FAST (#134958) (#135187)
We were incorrectly handling a few opcodes that leave their operands on the stack. Treat all of these conservatively; assume that they always leave operands on the stack.

(cherry picked from commit 6b77af257c)
2025-06-05 13:06:51 -07:00
Miss Islington (bot)
b2b9aaa93d
[3.14] gh-135099: Only wait on _PyOS_SigintEvent() in main thread (GH-135100) (GH-135116)
On Windows, the `_PyOS_SigintEvent()` event handle is used to interrupt
the main thread when Ctrl-C is pressed. Previously, we also waited on
the event from other threads, but ignored the result. However, this can
race with interpreter shutdown because the main thread closes the handle
in `_PySignal_Fini` and threads may still be running and using mutexes
during interpreter shtudown.

Only use `_PyOS_SigintEvent()` in the main thread in parking_lot.c, like
we do in other places in the CPython codebase.
(cherry picked from commit cc581f32bf)

Co-authored-by: Sam Gross <colesbury@gmail.com>
2025-06-04 08:44:35 -04:00
stratakis
899cca6dbf
[3.14] gh-128605: Add branch protections for x86_64 in asm_trampoline.S (#128606) (#135077)
Apply Intel Control-flow Technology for x86-64 on asm_trampoline.S.

Required for mitigation against return-oriented programming (ROP)
and Call or Jump Oriented Programming (COP/JOP) attacks.

Manual application is required for the assembly files.

See also: https://sourceware.org/annobin/annobin.html/Test-cf-protection.html
2025-06-03 15:31:06 +02:00
Miss Islington (bot)
d45d053267
[3.14] gh-132775: Expand the Capability of Interpreter.call() (gh-134933)
It now supports most callables, full args, and return values.

(cherry picked from commit 52deabe, AKA gh-133484)

Co-authored-by: Eric Snow ericsnowcurrently@gmail.com
2025-05-30 18:28:35 +00:00
Miss Islington (bot)
cc81b63a75
[3.14] gh-132917: fix data race on last_mem in free-threading gc (GH-134692) (#134802)
gh-132917: fix data race on `last_mem` in free-threading gc  (GH-134692)
(cherry picked from commit ac539e7e0d)

Co-authored-by: Kumar Aditya <kumaraditya@python.org>
2025-05-27 18:00:19 +00:00
Miss Islington (bot)
6493395f4b
[3.14] gh-132775: Always Set __builtins__ In _PyFunction_FromXIData() (gh-134794)
This is a small follow-up to gh-133481.  There's a corner case
in the behavior of PyImport_ImportModuleAttrString(), where
it expects __builtins__ to be set if __globals__ is set.

(cherry picked from commit 9b5e80000, AKA gh-134758)

Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
2025-05-27 16:07:44 +00:00
Mark Shannon
00122c8b2a
[3.14] GH-128161: Remove redundant GET_ITER from list comprehension code (GH-134778) 2025-05-27 12:29:48 +01:00
Miss Islington (bot)
c6cc28299e
[3.14] gh-134557: Suppress immortalization in _PyCode_GetScriptXIData under free-threading (gh134738)
Disable immortalization around Py_CompileString*().

The same approach as 332356b that fixed the refleaks in compile() and eval().

E: 09e72cf can pass test_capi, test_sys and test__interpchannels with this patch for me.

(cherry picked from commit c60f39ada6, AKA gh-134686)

Co-authored-by: neonene <53406459+neonene@users.noreply.github.com>
2025-05-26 13:14:58 -06:00
Miss Islington (bot)
aded785b8c
[3.14] gh-91048: Add better error messages for remote debugging for CI builds (GH-134682) (#134719) 2025-05-26 15:04:36 +00:00
Miss Islington (bot)
6c917cb11c
[3.14] gh-91048: Correct Apple platform includes for iOS. (GH-134712) (#134714)
Correct Apple platform includes for iOS.
(cherry picked from commit 965662ee4a)

Co-authored-by: Russell Keith-Magee <russell@keith-magee.com>
2025-05-26 13:10:37 +00:00
Pablo Galindo Salgado
1822f33b1a
[3.14] gh-91048: Refactor and optimize remote debugging module (#134652) (#134673)
gh-91048: Refactor and optimize remote debugging module (#134652)

Completely refactor Modules/_remote_debugging_module.c with improved
code organization, replacing scattered reference counting and error
handling with centralized goto error paths. This cleanup improves
maintainability and reduces code duplication throughout the module while
preserving the same external API.

Implement memory page caching optimization in Python/remote_debug.h to
avoid repeated reads of the same memory regions during debugging
operations. The cache stores previously read memory pages and reuses
them for subsequent reads, significantly reducing system calls and
improving performance.

Add code object caching mechanism with a new code_object_generation
field in the interpreter state that tracks when code object caches need
invalidation. This allows efficient reuse of parsed code object metadata
and eliminates redundant processing of the same code objects across
debugging sessions.

Optimize memory operations by replacing multiple individual structure
copies with single bulk reads for the same data structures. This reduces
the number of memory operations and system calls required to gather
debugging information from the target process.

Update Makefile.pre.in to include Python/remote_debug.h in the headers
list, ensuring that changes to the remote debugging header force proper
recompilation of dependent modules and maintain build consistency across
the codebase.

Also, make the module compatible with the free threading build as an extra :)

Co-authored-by: Łukasz Langa <lukasz@langa.pl>

(cherry picked from commit 42b25ad4d3)
2025-05-25 22:10:20 +00:00
Miss Islington (bot)
15e26eebf7
[3.14] GH-130397: remove special-casing of C stack depth for WASI (GH-134469) (GH-134547)
GH-130397: remove special-casing of C stack depth for WASI (GH-134469)

Removed special-casing for WASI when setting C stack depth limits. Since WASI has its own C stack checking this isn't a security risk.

Also disabled some tests that stopped passing. They all happened to have already been disabled under Emscripten.
(cherry picked from commit ad42dc1909)

Co-authored-by: Brett Cannon <brett@python.org>
2025-05-22 14:42:23 -07:00
Miss Islington (bot)
7480e50217
[3.14] gh-132775: Fix Recently Introduced Warnings (gh-134532)
(cherry picked from commit ac06b534ee, AKA gh-134530)

Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
2025-05-22 17:49:05 +00:00
Miss Islington (bot)
04e2dd6513
[3.14] gh-132775: Make _PyXI_session Opaque (gh-134522)
This is mostly a refactor to clean things up a bit, most notably the "XI namespace" code.

Making the session opaque requires adding the following internal-only functions:

* _PyXI_NewSession()
* _PyXI_FreeSession()
* _PyXI_GetMainNamespace()

(cherry picked from commit 4a4ac3ab4d, gh-134452)

Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
2025-05-22 17:12:52 +00:00
Miss Islington (bot)
85c8c0a003
[3.14] gh-132775: Use _PyObject_GetXIData (With Fallback) (gh-134507)
This change includes some semi-related refactoring of queues and channels.

(cherry picked from commit d0eedfa10e, gh-134440)

Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
2025-05-22 07:21:05 -06:00
Miss Islington (bot)
2ffc10bd39
[3.14] gh-132775: Support Fallbacks in _PyObject_GetXIData() (gh-134418)
It now supports a "full" fallback to _PyFunction_GetXIData() and then `_PyPickle_GetXIData()`.
There's also room for other fallback modes if that later makes sense.

(cherry picked from commit 88f8102a8f, AKA gh-133482)

Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
2025-05-21 14:47:56 +00:00
Miss Islington (bot)
2d90cc8b35
[3.14] gh-106213: Shorten Emscripten wasm-gc trampoline by a little (GH-133984) (#134376)
Using the if instruction results in slightly shorter trampoline code.
(cherry picked from commit 3b7888bf3d)

Co-authored-by: Hood Chatham <roberthoodchatham@gmail.com>
2025-05-20 18:49:29 +00:00
Miss Islington (bot)
bb5f92adcf
[3.14] gh-134144: Fix use-after-free in zapthreads() (GH-134145) (#134182)
gh-134144: Fix use-after-free in zapthreads() (GH-134145)
(cherry picked from commit f2de1e6861)

Co-authored-by: b-pass <b-pass@users.noreply.github.com>
2025-05-18 15:29:19 +00:00
Miss Islington (bot)
8d51ed6b05
[3.14] gh-134100: Fix use-after-free in PyImport_ImportModuleLevelObject (GH-134117) (#134171)
gh-134100: Fix use-after-free in `PyImport_ImportModuleLevelObject` (GH-134117)
(cherry picked from commit 4e9005d32f)

Co-authored-by: Nico-Posada <102486290+Nico-Posada@users.noreply.github.com>
2025-05-18 20:38:40 +05:30
Miss Islington (bot)
eaee2ae033
[3.14] gh-134064: Fix sys.remote_exec() error checking (GH-134067) (#134162)
gh-134064: Fix sys.remote_exec() error checking (GH-134067)
(cherry picked from commit 009e7b3698)

Co-authored-by: Victor Stinner <vstinner@python.org>
2025-05-17 22:50:00 +00:00
Miss Islington (bot)
f0a7a6c2cc
[3.14] gh-133886: Fix sys.remote_exec() for non-UTF-8 paths (GH-133887) (GH-133963)
It now supports non-ASCII paths in non-UTF-8 locales and
non-UTF-8 paths in UTF-8 locales.
(cherry picked from commit c09cec5d69)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2025-05-13 09:23:39 +00:00
Miss Islington (bot)
3467656b18
[3.14] gh-132775: Add _PyFunction_GetXIData() (gh-133955)
(cherry picked from commit 8cf4947b0f, AKA gh-133481)

Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
2025-05-12 22:37:55 +00:00
Miss Islington (bot)
98ef4837ec
[3.14] gh-133590: ensure that TableEntry.linenumber_borrow is initialized (GH-133681) (#133872)
gh-133590: ensure that `TableEntry.linenumber_borrow` is initialized (GH-133681)
(cherry picked from commit c838e21fda)

Co-authored-by: Lauta <ljfp@ljfp.xyz>
2025-05-11 08:44:22 +00:00
Miss Islington (bot)
da1e5c434b
[3.14] gh-133336: Remove comment about reserved -J in `initconfig.c` (GH-133821) (#133855) 2025-05-10 22:25:42 +00:00
Miss Islington (bot)
856e5903ba
[3.14] gh-133783: Fix __replace__ on AST nodes for optional attributes (GH-133797) (#133842)
gh-133783: Fix __replace__ on AST nodes for optional attributes (GH-133797)
(cherry picked from commit 7dddb4e667)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2025-05-10 16:44:07 +00:00
Miss Islington (bot)
92d56777a1
[3.14] gh-133581: Fix refleak in t-string AST unparsing (GH-133724) (#133731)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2025-05-09 07:38:12 +00:00
Miss Islington (bot)
8e86f9c3cc
[3.14] gh-132917: Use /proc/self/status for mem usage info. (GH-133544) (gh-133718)
On Linux, use /proc/self/status for mem usage info.  Using smaps_rollup is quite a lot slower and
we can get the similar info from /proc/self/status.
(cherry picked from commit 751db4e649)

Co-authored-by: Neil Schemenauer <nas-github@arctrix.com>
2025-05-08 16:37:59 -07:00
Miss Islington (bot)
1059548686
[3.14] gh-132775: Add _PyCode_GetScriptXIData() (gh-133676)
This converts functions, code, str, bytes, bytearray, and memoryview objects to PyCodeObject,
and ensure that the object looks like a script.  That means no args, no return, and no closure.
_PyCode_GetPureScriptXIData() takes it a step further and ensures there are no globals.

We also add _PyObject_SupportedAsScript() to the internal C-API.

(cherry picked from commit c81fa2b9cd, AKA gh-133480)

Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
2025-05-08 10:05:34 -06:00
Miss Islington (bot)
153496921a
[3.14] gh-133581: Improve AST unparsing of t-strings (GH-133635) (#133666)
gh-133581: Improve AST unparsing of t-strings (GH-133635)
(cherry picked from commit bfac7d2edc)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2025-05-08 13:40:44 +00:00
Miss Islington (bot)
caeb422cbc
gh-133597: Fix memory leak if error occurred in _sys_getwindowsversion_from_kernel32 (GH-133598)
(cherry picked from commit 0ec8fc83a8)

Co-authored-by: Sergey Miryanov <sergey.miryanov@gmail.com>
2025-05-08 11:36:38 +00:00
T. Wouters
53e6d76aa3
gh-132917: Fix data race detected by tsan (#133508)
Fix data race detected by tsan
(4171271720):
young.count can be modified by other threads even while the gcstate is
locked.

This is the simplest fix to (potentially) unblock beta 1, although this
particular code path seems like it could just be an atomic swap followed by
an atomic add, without having the lock at all.
2025-05-06 11:23:10 +00:00
Irit Katriel
296cd128bf
Revert "gh-133395: add option for extension modules to specialize BINARY_OP/SUBSCR, apply to arrays (#133396)" (#133498) 2025-05-06 13:12:26 +03:00
Noah Kim
c4bcc6a778
gh-102567: Add -X importtime=2 for logging an importtime message for already-loaded modules (#118655)
Co-authored-by: Adam Turner <9087854+aa-turner@users.noreply.github.com>
2025-05-06 01:03:55 +01:00
Eric Snow
ea598730ef
gh-132775: Add _PyCode_GetXIData() (gh-133475) 2025-05-05 23:46:03 +00:00
Eric Snow
e9616110aa
gh-132775: Do Not Set __name__ to __main__ With _PyPickle_GetXIData() (gh-133472)
This is a follow-up to gh-133107.  I realized that we could end up with an
infinite recursion if we try to run a function from __main__ in a subinterpreter.
2025-05-05 17:25:26 -06:00
Brandt Bucher
b1aa515bd6
GH-133231: Add JIT utilities in sys._jit (GH-133233) 2025-05-05 15:25:22 -07:00
Diego Russo
9cc77aaf9d
GH-131798: Split CALL_LEN into several uops (GH-133180) 2025-05-05 14:31:48 -07:00
Neil Schemenauer
893034cf93
gh-132917: Use RSS + swap for estimate of process memory usage (gh-133464) 2025-05-05 14:15:05 -07:00
Neil Schemenauer
5c245ffce7
gh-132917: Check resident set size (RSS) before GC trigger. (gh-133399)
For the free-threaded build, check the process resident set size (RSS)
increase before triggering a full automatic garbage collection.  If the RSS
has not increased 10% since the last collection then it is deferred.
2025-05-05 17:17:05 +00:00
Irit Katriel
082dbf7788
gh-133395: add option for extension modules to specialize BINARY_OP/SUBSCR, apply to arrays (#133396) 2025-05-05 17:46:56 +01:00
Adam Turner
4c56563f7a
GH-133336: Remove reserved `-J` flag for Jython (#133444) 2025-05-05 15:09:19 +00:00
Mark Shannon
f554237b8e
GH-133261: Make sure that the GC doesn't untrack objects in trashcan (GH-133431) 2025-05-05 13:44:50 +01:00
mpage
78adb63ee1
gh-133371: Don't optimize LOAD_FAST instructions whose local is killed by DELETE_FAST (#133383)
In certain cases it's possible for locals loaded by `LOAD_FAST` instructions
to be on the stack when the local is killed by `DEL_FAST`. These `LOAD_FAST`
instructions should not be optimized into `LOAD_FAST_BORROW` as the strong
reference in the frame is killed while there is still a reference on the stack.
2025-05-04 21:00:11 -07:00
Adam Turner
3f80165a26
GH-91048: Minor fixes for `_remotedebugging & rename to _remote_debugging` (#133398) 2025-05-05 02:30:14 +02:00
Samuel
30840706b0
gh-131421: fix ASDL grammar for Dict to have an expr?* keys field (#131419)
In the `ast` documentation for Python:

* https://docs.python.org/3/library/ast.html#ast.Dict
it is made clear that:

> When doing dictionary unpacking using dictionary literals the expression to be expanded goes in the values list, with a `None` at the corresponding position in `keys`.

Hence, `keys` is really a `expr?*` and *not* a `expr*`.

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2025-05-04 16:03:38 -07:00
Yan Yanchii
0a1fedb70b
gh-126835: Rename ast_opt.c to ast_preprocess.c and related stuff after moving const folding to the peephole optimizier (#131830) 2025-05-04 21:07:35 +03:00
Mark Shannon
ac7d5ba96e
GH-133231: Changes to executor management to support proposed sys._jit module (GH-133287)
* Track the current executor, not the previous one, on the thread-state. 

* Batch executors for deallocation to avoid having to constantly incref executors; this is an ad-hoc form of deferred reference counting.
2025-05-04 10:05:35 +01:00
Emma Smith
3b4333583f
gh-132983: Introduce _zstd bindings module (GH-133027)
* Add _zstd module for https://peps.python.org/pep-0784/

This commit introduces the `_zstd` module, with bindings to libzstd from
the pyzstd project. It also includes the unix build system configuration.
Windows build system support will be integrated independently as it
depends on integration with cpython-source-deps.

* Add _zstd to modules

* Fix path for compression.zstd module

* Ignore _zstd module like _io

* Expand module state macros to improve code quality

Also removes module state references from the classes in the _zstd
module and instead uses PyType_GetModuleState()

* Remove backticks suggested in review

Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>

* Use critical sections to lock object state

This should avoid races and deadlocks.

* Remove compress/decompress and mark module as not reliant on the GIL

The `compress`/`decompress` functions will be moved to Python code for simplicity.
C implementations can always be re-added in the future.

Also, mark _zstd as not requiring the GIL.

* Lift critical section to avoid clang warning

* Respond to comments by picnixz

* Call out pyzstd explicitly in license description

Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>

* Use a much more robust implementation...

... for `get_zstd_state_from_type`

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

* Use PyList_GetItemRef for thread safety purposes

* Use a macro for the minimum supported version

* remove const from primivite types

* Use PyMem_New in another spot

* Simplify error handling in _get_frame_size

* Another simplification of error handling in get_frame_info

* Rename _module_state to mod_state

* Rewrite comment explaining the context of the code

* Add link to pyzstd

* Add TODO about refactoring dict training code

* Use PyModule_AddObjectRef over PyModule_AddObject

PyModule_AddObject is soft-deprecated, so we should use PyModule_AddObjectRef

* Check result of OutputBufferGrow

* Simplify return logic in `add_constant_to_type`

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

* Ignore return value of _zstd_clear()

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

* Remove redundant comments

* Remove __reduce__ from ZstdDict

We should instead document that to pickle a dictionary a user should use
the `.dict_content` attribute.

* Use PyUnicode_FromFormat instead of a buffer

* Don't use C constants/types in error messages

* Make error messages easier to understand for Python users

* Lower minimum required version 1.4.0

* Use casts and make slot function signatures correct

* Be consistent with CPython on const usage

* Make else clauses in line with PEP 7

* Fix over-indented blocks in argument clinic

* Add critical section around ZSTD_DCtx_setParameter

* Add a TODO about refactoring critical sections

* Use Py_UNREACHABLE

* Move bytes operations out of Py_BEGIN_ALLOW_THREADS

* Add TODO about ensuring a lock is held

* Remove asserts that may not be correct

* Add TODO to make ZstdDict and others GC objects

* Make objects GC tracked

* Remove unused include

* Fix some memory issues

* Fix refleaks on module and in ZstdDict

* Update configure to check for ZDICT_finalizeDictionary

* Properly check version in configure

* exit(1) if check fails

* Use AC_RUN_IFELSE

* Use a define() to re-use version check

* Actually properly set _zstd module status based on version

---------

Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2025-05-04 01:29:55 +00:00