Commit Graph

9713 Commits

Author SHA1 Message Date
Diego Russo 42d03f3933
GH-131798: Split CALL_LIST_APPEND into several uops (GH-134240) 2025-05-19 15:48:55 -04:00
Peter Bierma 27bd08273c
Revert "gh-128639: Don't assume one thread in subinterpreter finalization (gh-128640)" (gh-134256)
This reverts commit 9859791f9e.

The original change broke the iOS and android buildbots, where the tests are run single-process.
2025-05-19 12:22:05 -06:00
Victor Stinner e79f640eb6
Simplify interp_look_up_id() (#134257)
Don't use PyInterpreterState_GetID() but get directly the interpreter
'id' member which cannot fail.
2025-05-19 18:09:10 +00:00
Tomas R. 8d490b3687
GH-131798: Narrow the return type of isinstance for some known arguments in the JIT (GH-133172) 2025-05-19 13:19:24 -04:00
Peter Bierma 9859791f9e
gh-128639: Don't assume one thread in subinterpreter finalization (gh-128640)
Incidentally, this also fixed the warning not showing up if a subinterpreter wasn't
cleaned up via _interpreters.destroy. I had to update some of the tests as a result.
2025-05-19 10:24:08 -06:00
b-pass f2de1e6861
gh-134144: Fix use-after-free in zapthreads() (#134145) 2025-05-18 20:32:29 +05:30
Nico-Posada 4e9005d32f
gh-134100: Fix use-after-free in `PyImport_ImportModuleLevelObject` (#134117) 2025-05-18 12:41:38 +05:30
Victor Stinner 009e7b3698
gh-134064: Fix sys.remote_exec() error checking (#134067) 2025-05-18 00:24:40 +02:00
Max Bachmann 20095fb29a
Fix GetNamedPipeHandleStateW on non-desktop Windows API partitions (GH-134049) 2025-05-15 21:12:10 +01:00
Max Bachmann 5d118d0a92
gh-133580: Add missing exception to _sys_getwindowsversion_from_kernel32 (GH-133574) 2025-05-14 14:10:35 +01:00
Serhiy Storchaka c09cec5d69
gh-133886: Fix sys.remote_exec() for non-UTF-8 paths (GH-133887)
It now supports non-ASCII paths in non-UTF-8 locales and
non-UTF-8 paths in UTF-8 locales.
2025-05-13 11:55:24 +03:00
Eric Snow 8cf4947b0f
gh-132775: Add _PyFunction_GetXIData() (gh-133481) 2025-05-12 22:10:56 +00:00
Lauta c838e21fda
gh-133590: ensure that `TableEntry.linenumber_borrow` is initialized (#133681) 2025-05-11 10:16:28 +02:00
Bénédikt Tran dc191d2484
gh-133336: Remove comment about reserved -J in ``initconfig.c`` (#133821) 2025-05-10 22:31:45 +01:00
Jelle Zijlstra 7dddb4e667
gh-133783: Fix __replace__ on AST nodes for optional attributes (#133797) 2025-05-10 09:17:38 -07:00
Stan Ulbrych dbca27cfca
gh-133379: Fix misuse of the term "arguments" in error messages (GH-133382)
The right term is "parameters".
2025-05-10 15:00:43 +03:00
Bénédikt Tran 5044e85265
gh-133644: Remove deprecated Python initialization getter functions (#133661)
Remove functions:

* Py_GetExecPrefix()
* Py_GetPath()
* Py_GetPrefix()
* Py_GetProgramFullPath()
* Py_GetProgramName()
* Py_GetPythonHome()
2025-05-09 11:39:23 +00:00
Jelle Zijlstra 308ceffc68
gh-133581: Fix refleak in t-string AST unparsing (#133724) 2025-05-09 09:10:52 +02:00
Tomas R. c492ac7252
GH-131798: Split up and optimize CALL_ISINSTANCE (GH-133339) 2025-05-08 14:26:30 -07:00
Tomas R. 3f2f59a91d
gh-133273: Keep instruction definitions in `bytecodes.c` and `optimizer_bytecodes.c` in sync (GH-133320) 2025-05-09 01:54:49 +08:00
Eric Snow c81fa2b9cd
gh-132775: Add _PyCode_GetScriptXIData() (gh-133480)
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.
2025-05-08 15:07:46 +00:00
Xuehai Pan f0f93ba5fa
gh-131942: Use the Python-specific `Py_DEBUG` macro rather than `_DEBUG` in Windows-related C code (GH-131944) 2025-05-08 15:01:25 +00:00
Jelle Zijlstra bfac7d2edc
gh-133581: Improve AST unparsing of t-strings (#133635) 2025-05-08 06:13:57 -07:00
Bénédikt Tran a2c4467d06
gh-133644: remove deprecated `PyImport_ImportModuleNoBlock` (#133655) 2025-05-08 13:08:43 +00:00
Sergey Miryanov 0ec8fc83a8
gh-133597: Fix memory leak if error occurred in _sys_getwindowsversion_from_kernel32 (GH-133598) 2025-05-08 12:09:20 +01:00
Neil Schemenauer 751db4e649
gh-132917: Use /proc/self/status for mem usage info. (#133544)
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.
2025-05-08 04:32:23 +00:00
T. Wouters 53e6d76aa3
gh-132917: Fix data race detected by tsan (#133508)
Fix data race detected by tsan
(https://github.com/python/cpython/actions/runs/14857021107/job/41712717208?pr=133502):
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
Sergey Miryanov bd2ed7c7ce
gh-91048: Chain some exceptions in _testexternalinspection.c (#132970) 2025-05-03 01:35:30 +02:00
Ken Jin ddac7ac59a
gh-132744: Check recursion limit in CALL_PY_GENERAL (GH-132746) 2025-05-02 17:36:29 +01:00
Nybblista 20f8ed595d
gh-133279: Assert with HAS_TARGET in the codegen_addop_j function (#133280) 2025-05-02 13:52:48 +01:00
Irit Katriel a4be3bc34f
gh-133258: Fix crash in test_index (GH-133262) 2025-05-01 19:15:53 +02:00
Adam Turner f21e42d906
Remove duplicate includes: Python/{bytecodes,ceval,optimizer_analysis}.c (#132622) 2025-05-01 12:07:53 +01:00
Irit Katriel 5529213d4e
gh-100239: specialize BINARY_OP/SUBSCR for list-slice (#132626) 2025-05-01 10:28:52 +00:00