Commit graph

9677 commits

Author SHA1 Message Date
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
Mark Shannon
3831752689
PyStats: Make sure that the failure_kinds array is big enough. (#133245) 2025-05-01 10:02:51 +00:00
Eric Snow
cb35c11d82
gh-132775: Add _PyPickle_GetXIData() (gh-133107)
There's some extra complexity due to making sure we we get things right when handling functions and classes defined in the __main__ module.  This is also reflected in the tests, including the addition of extra functions in test.support.import_helper.
2025-04-30 17:34:05 -06:00
Russell Keith-Magee
6c522debc2
GH-125515: Remove two unused error branches. (#133181)
Remove two unused error branches in the generated bytecode handling.
2025-05-01 06:21:57 +08:00
Mark Shannon
44e4c479fb
GH-124715: Move trashcan mechanism into Py_Dealloc (GH-132280) 2025-04-30 11:37:53 +01:00
Lysandros Nikolaou
60202609a2
gh-132661: Implement PEP 750 (#132662)
Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
Co-authored-by: Wingy <git@wingysam.xyz>
Co-authored-by: Koudai Aono <koxudaxi@gmail.com>
Co-authored-by: Dave Peck <davepeck@gmail.com>
Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
Co-authored-by: Paul Everitt <pauleveritt@me.com>
Co-authored-by: sobolevn <mail@sobolevn.me>
2025-04-30 11:46:41 +02:00
Inada Naoki
4e294f6feb
gh-133036: Deprecate codecs.open (#133038)
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
2025-04-30 10:11:09 +09:00
Brandt Bucher
732d1b0241
Get rid of ERROR_IF's "label" parameter (GH-132654) 2025-04-29 17:21:53 -07:00
Brandt Bucher
b329096cfb
GH-125515: Mark code after "return" as unreachable in the cases generator (#133178)
Mark code after "return" as unreachable
2025-04-30 00:21:14 +00:00
Mark Shannon
ccf1b0b1c1
GH-132508: Use tagged integers on the evaluation stack for the last instruction offset (GH-132545) 2025-04-29 18:00:35 +01:00
Petr Viktorin
0c26dbd16e
gh-133079: Remove Py_C_RECURSION_LIMIT & PyThreadState.c_recursion_remaining (GH-133080)
Both were added in 3.13, are undocumented, and don't make sense in 3.14 due to
changes in the stack overflow detection machinery (gh-112282).

PEP 387 exception for skipping a deprecation period: https://github.com/python/steering-council/issues/288
2025-04-29 12:56:20 +02:00
Mark Shannon
622300bdfa
GH-132554: Add stats for GET_ITER (GH-132592)
* Add stats for GET_ITER

* Look for common iterable types, not iterator types

* Add stats for self iter and fix naming in summary
2025-04-29 09:00:14 +01:00
Neil Schemenauer
eecafc3380
Revert gh-127266: avoid data races when updating type slots (gh-131174) (gh-133129)
This is triggering deadlocks in test_opcache.  See GH-133130 for stack trace.
2025-04-28 23:38:29 -07:00
Eric Snow
219d8d24b5
gh-87859: Track Code Object Local Kinds For Arguments (gh-132980)
Doing this was always the intention. I was finally motivated to find the time to do it.

See #87859 (comment).
2025-04-29 02:21:47 +00:00
Eric Snow
96a7fb93a8
gh-132775: Add _PyCode_ReturnsOnlyNone() (gh-132981)
The function indicates whether or not the function has a return statement.

This is used by a later change related treating some functions like scripts.
2025-04-28 20:12:52 -06:00
Eric Snow
bdd23c0bb9
gh-132775: Add _PyMarshal_GetXIData() (gh-133108)
Note that the bulk of this change is tests.
2025-04-28 17:23:46 -06:00
Neil Schemenauer
e414a2d81c
gh-127266: avoid data races when updating type slots (gh-131174)
In the free-threaded build, avoid data races caused by updating type slots
or type flags after the type was initially created.  For those (typically
rare) cases, use the stop-the-world mechanism.  Remove the use of atomics
when reading or writing type flags.  The use of atomics is not sufficient to
avoid races (since flags are sometimes read without a lock and without
atomics) and are no longer required.
2025-04-28 20:28:44 +00:00
Eric Snow
606003ffa9
gh-132775: Add _PyBytes_GetXIData() (gh-133101)
This is the base for several other XIData wrappers, like pickle and marshal. It is essentially a refactor of the existing bytes XIData code.
2025-04-28 12:52:36 -06:00
Eric Snow
fe462f5a91
gh-132775: Drop PyUnstable_InterpreterState_GetMainModule() (gh-132978)
We replace it with _Py_GetMainModule(), and add _Py_CheckMainModule(), but both in the internal-only C-API.  We also add _PyImport_GetModulesRef(), which is the equivalent of _PyImport_GetModules(), but which increfs before the lock is released.

This is used by a later change related to pickle and handling __main__.
2025-04-28 12:46:22 -06:00
Eric Snow
6f04325992
gh-132775: Cleanup Related to crossinterp.c Before Further Changes (gh-132974)
This change consists of adding tests and moving code around, with some renaming thrown in.
2025-04-28 11:55:15 -06:00
Jelle Zijlstra
58567cc18c
gh-132952: Speed up startup by importing _io instead of io (#132957) 2025-04-28 08:38:56 -07:00
Jelle Zijlstra
922049b613
gh-130907: Treat all module-level annotations as conditional (#131550) 2025-04-28 06:10:28 -07:00
Bénédikt Tran
af3f6fcb7e
gh-127604: ensure -ldl is passed only once to the linker (#133071) 2025-04-28 11:55:02 +02:00
Emma Smith
20be6ba61a
gh-132983: Introduce compression package and move _compression module (GH-133018)
* Introduces `compression` package for https://peps.python.org/pep-0784/

This commit introduces the `compression` package, specified in PEP 784
to re-export the `lzma`, `bz2`, `gzip`, and `zlib` modules. Introduction
of `compression.zstd` will be completed in a future commit once the
`_zstd` module is merged.

This commit also moves the `_compression` private module to
`compression._common._streams`.

* Re-exports existing module docstrings.
2025-04-27 14:41:30 -07:00
Nadeshiko Manju
614d79231d
gh-131798: JIT - Use sym_new_type instead of sym_new_not_null for _BUILD_STRING, _BUILD_SET (GH-132564)
Signed-off-by: Manjusaka <me@manjusaka.me>
2025-04-27 20:30:28 +08:00
Tomas R.
5e96e4fca8
gh-131798: JIT: Propagate the result in _BINARY_OP_SUBSCR_TUPLE_INT (GH-133003) 2025-04-27 02:47:55 +08:00
Serhiy Storchaka
632524a5cb
gh-132987: Support __index__() for "k" and "K" formats in PyArg_Parse (GH-132988) 2025-04-26 17:14:18 +03:00
Bénédikt Tran
ca12a744ab
gh-132781: fix refleaks in crossinterp_exceptions.h post gh-132782 (#132989) 2025-04-26 12:14:14 +02:00
Eric Snow
8a4d4f37ab
gh-132781: Make NotShareableError a TypeError Subclass (gh-132973)
It was a subclass of ValueError. However, shareability is a feature of types, not values.
2025-04-25 21:10:43 +00:00
Eric Snow
cd9536a087
gh-132781: Cleanup Code Related to NotShareableError (gh-132782)
The following are added to the internal C-API:

* _PyErr_FormatV()
* _PyErr_SetModuleNotFoundError()
* _PyXIData_GetNotShareableErrorType()
* _PyXIData_FormatNotShareableError()

We also drop _PyXIData_lookup_context_t and _PyXIData_GetLookupContext().
2025-04-25 14:43:38 -06:00
Diego Russo
4c20f46fa0
gh-131798: JIT: Narrow the return type of _CALL_LEN to int (#132940)
Reduce unnecessary guards whenever `len()` is called and used
after.

Co-authored-by: Max Bernstein <tekknolagi@gmail.com>
2025-04-26 02:57:42 +08:00
Eric Snow
2a28b21a51
gh-132776: Revert Moving memoryview XIData Code to memoryobject.c (gh-132960)
This is a partial revert of gh-132821.  It resolves the refleak introduced by that PR.
2025-04-25 16:43:50 +00:00
Pablo Galindo Salgado
622176513e
gh-132950: Check for Py_SUPPORTS_REMOTE_DEBUG in sys.is_remote_debug_enabled (#132959) 2025-04-25 16:38:48 +00:00
Victor Stinner
ac5424d6a9
gh-107954: Add audit event to PyConfig_Set() (#132958) 2025-04-25 18:30:39 +02:00
Victor Stinner
070d866567
gh-107954: Allow setting cpu_count in PyConfig_Set() (#132954)
* gh-107954: Allow setting cpu_count in PyConfig_Set()

* Update the doc
2025-04-25 18:29:55 +02:00
Victor Stinner
17718b0503
gh-91048: Fix _testexternalinspection.c on FreeBSD (#132945) 2025-04-25 14:57:01 +00:00
Pablo Galindo Salgado
e8cf3a1a64
gh-91048: Refactor _testexternalinspection and add Windows support (#132852) 2025-04-25 14:12:16 +01:00