Commit Graph

9072 Commits

Author SHA1 Message Date
Miss Islington (bot) 8d50e0320b
[3.13] gh-125610: Fix `STORE_ATTR_INSTANCE_VALUE` specialization check (GH-125612) (GH-127698)
The `STORE_ATTR_INSTANCE_VALUE` opcode doesn't support objects with
non-NULL managed dictionaries, so don't specialize to that op in that case.
(cherry picked from commit a353455fca)

Co-authored-by: Sam Gross <colesbury@gmail.com>
2024-12-06 16:14:26 +00:00
Miss Islington (bot) dddea7c232
[3.13] gh-122907: Fix Builds Without HAVE_DYNAMIC_LOADING Set (gh-122952) (#122984)
gh-122907: Fix Builds Without HAVE_DYNAMIC_LOADING Set (gh-122952)

As of 529a160 (gh-118204), building with HAVE_DYNAMIC_LOADING stopped working.  This is a minimal fix just to get builds working again.  There are actually a number of long-standing deficiencies with HAVE_DYNAMIC_LOADING builds that need to be resolved separately.
(cherry picked from commit ee1b8ce26e)

Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
2024-12-03 16:46:30 +00:00
Eric Snow 219b8266db
[3.13] gh-126914: Store the Preallocated Thread State's Pointer in a PyInterpreterState Field (gh-127114)
This approach eliminates the originally reported race.  It also gets rid of the deadlock reported in gh-96071, so we can remove the workaround added then.

This is mostly a cherry-pick of 1c0a104 (AKA gh-126989).  The difference is we add PyInterpreterState.threads_preallocated at the end of PyInterpreterState, instead of adding PyInterpreterState.threads.preallocated.  That avoids ABI disruption.
2024-12-02 18:41:57 +00:00
Miss Islington (bot) 2813a61675
[3.13] gh-127165: Disallow embedded NULL characters in `_interpreters` (GH-127199) (#127463)
gh-127165: Disallow embedded NULL characters in `_interpreters` (GH-127199)
(cherry picked from commit 46bfd26fb2)

Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
2024-12-01 06:55:55 +00:00
Miss Islington (bot) 089d70614e
[3.13] gh-123967: Fix faulthandler for trampoline frames (GH-127329) (#127362)
gh-123967: Fix faulthandler for trampoline frames (GH-127329)

If the top-most frame is a trampoline frame, skip it.
(cherry picked from commit 58e334e143)

Co-authored-by: Victor Stinner <vstinner@python.org>
2024-11-30 09:14:29 +00:00
Miss Islington (bot) c4a359dc42
[3.13] gh-127208: Reject null character in _imp.create_dynamic() (GH-127400) (#127418)
gh-127208: Reject null character in _imp.create_dynamic() (GH-127400)

_imp.create_dynamic() now rejects embedded null characters in the
path and in the module name.
(cherry picked from commit b14fdadc6c)

Co-authored-by: Victor Stinner <vstinner@python.org>
2024-11-29 15:45:21 +00:00
Miss Islington (bot) 47b0f8f297
[3.13] gh-126881: fix finalization of dtoa state (GH-126904) (#127395)
gh-126881: fix finalization of dtoa state (GH-126904)
(cherry picked from commit 762c603a86)

Co-authored-by: Kumar Aditya <kumaraditya@python.org>
2024-11-29 10:52:21 +00:00
Serhiy Storchaka 75ef92da29
[3.13] gh-109746: Make _thread.start_new_thread delete state of new thread on its startup failure (GH-109761) (GH-127171)
If Python fails to start newly created thread
due to failure of underlying PyThread_start_new_thread() call,
its state should be removed from interpreter' thread states list
to avoid its double cleanup.

(cherry picked from commit ca3ea9ad05)

Co-authored-by: Radislav Chugunov <52372310+chgnrdv@users.noreply.github.com>
2024-11-22 19:55:44 +00:00
Eric Snow 8cdd636f87
[3.13] gh-126986: Stop Using _PyInterpreterState_FailIfNotRunning() (gh-127112)
This is a pseudo-backport of d6b3e78 (gh-126988).  In that change for 3.14+, we dropped _PyInterpreterState_FailIfNotRunning() and added _PyErr_SetInterpreterAlreadyRunning().  Here, we replace usage of _PyInterpreterState_FailIfNotRunning() with the inlined equivalent of _PyErr_SetInterpreterAlreadyRunning(), without adding that function.  That way we avoid changing the 3.13 ABI.
2024-11-21 10:33:15 -07:00
Miss Islington (bot) 48eb5c978e
gh-126780: Fix `ntpath.normpath()` for drive-relative paths (GH-126801)
(cherry picked from commit 60ec854bc2)

Co-authored-by: Nice Zombies <nineteendo19d0@gmail.com>
2024-11-21 15:10:12 +00:00
Peter Bierma ecda3ae2a5
[3.13] gh-126312: Don't traverse frozen objects on the free-threaded build (GH-126338) (#126866)
* Fix merge conflicts.

* [3.13] gh-126312: Don't traverse frozen objects on the free-threaded build (GH-126338)

Also, _PyGC_Freeze() no longer freezes unreachable objects.

(cherry picked from commit d4c72fed8c)

Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>

---------

Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
2024-11-15 14:46:00 +01:00
Miss Islington (bot) 13fe8f946e
[3.13] gh-126688: Reinit import lock after fork (GH-126692) (GH-126765)
The PyMutex implementation supports unlocking after fork because we
clear the list of waiters in parking_lot.c. This doesn't work as well
for _PyRecursiveMutex because on some systems, such as SerenityOS, the
thread id is not preserved across fork().
(cherry picked from commit 5610860840)

Co-authored-by: Sam Gross <colesbury@gmail.com>
2024-11-12 22:00:42 +00:00
Miss Islington (bot) 02cd3ce0f2
[3.13] gh-116510: Fix a Crash Due to Shared Immortal Interned Strings (gh-124865) (gh-125709) (GH-125204)
* gh-116510: Fix a Crash Due to Shared Immortal Interned Strings (gh-124865)

Fix a crash caused by immortal interned strings being shared between
sub-interpreters that use basic single-phase init. In that case, the string
can be used by an interpreter that outlives the interpreter that created and
interned it. For interpreters that share obmalloc state, also share the
interned dict with the main interpreter.

This is an un-revert of gh-124646 that then addresses the Py_TRACE_REFS
failures identified by gh-124785.
(cherry picked from commit f2cb399470)

Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>

* [3.13] gh-125286: Share the Main Refchain With Legacy Interpreters (gh-125709)

They used to be shared, before 3.12.  Returning to sharing them resolves a failure on Py_TRACE_REFS builds.

---------

Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
2024-11-12 13:45:12 +01:00
Miss Islington (bot) 23468acac4
[3.13] gh-126171: fix possible null dereference in _imp_find_frozen_impl (GH-126566) (#126567)
gh-126171: fix possible null dereference in _imp_find_frozen_impl (GH-126566)
(cherry picked from commit 9ecd8f7f40)

Co-authored-by: Valery Fedorenko <federicovalenso@gmail.com>
2024-11-08 16:25:38 +05:30
Valery Fedorenko 8059351051
[3.13] Fix possible null pointer dereference of freevars in _PyCompile_LookupArg (gh-126238) (#126475)
[3.13] gh-126238: Fix possible null pointer dereference of freevars in _PyCompile_LookupArg (GH-126239)

* Replace Py_DECREF by Py_XDECREF

(cherry picked from commit 8525c9375f)

Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
2024-11-06 08:10:04 +00:00
Donghee Na 36079f702a
[3.13] gh-125832: Clarify comment for inlined comprehensions as per PEP-709 (gh-126322) (gh-126344)
* gh-125832: Clarify comment for inlined comprehensions as per PEP-709 (#126322)

* Fix comprehensions comment to inlined by pep 709

* Update spacing

Co-authored-by: RUANG (James Roy) <longjinyii@outlook.com>

* Add reference to PEP 709

---------

Co-authored-by: Carol Willing <carolcode@willingconsulting.com>
Co-authored-by: RUANG (James Roy) <longjinyii@outlook.com>
(cherry picked from commit 868bfcc02e)

* Add space

---------

Co-authored-by: rimchoi <hyerimc858@gmail.com>
2024-11-03 04:10:15 +00:00
Miss Islington (bot) b9cbc58e13
[3.13] gh-126139: Improve error message location for future statement with unknown feature (GH-126140) (#126155)
gh-126139: Improve error message location for future statement with unknown feature (GH-126140)
(cherry picked from commit 224c370a36)

Co-authored-by: Brian Schubert <brianm.schubert@gmail.com>
2024-10-30 00:36:06 +00:00
Miss Islington (bot) 265bc19b84
[3.13] gh-126105: Fix crash in `ast` module, when `._fields` is deleted (GH-126115) (#126130)
gh-126105: Fix crash in `ast` module, when `._fields` is deleted (GH-126115)

Previously, if the `ast.AST._fields` attribute was deleted, attempts to create a new `as`t node would crash due to the assumption that `_fields` always had a non-NULL value. Now it has been fixed by adding an extra check to ensure that `_fields` does not have a NULL value (this can happen when you manually remove `_fields` attribute).
(cherry picked from commit b2eaa75b17)

Co-authored-by: sobolevn <mail@sobolevn.me>
2024-10-29 16:07:32 +00:00
Pablo Galindo Salgado 00b13ec050
[3.13] gh-125703: Correctly honour tracemalloc hooks on more PyDECREF specialized paths (GH-125712) (#125791)
(cherry picked from commit 3d1df3d84e)
2024-10-28 11:50:36 +00:00
Miss Islington (bot) e4157f0fd7
[3.13] gh-126018: Avoid aborting due to unnecessary assert in `sys.audit` (GH-126020) (#126042)
(cherry picked from commit 80eec52fc8)

Co-authored-by: devdanzin <74280297+devdanzin@users.noreply.github.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2024-10-27 15:07:33 +00:00
Shantanu 3d8b6f0977
[3.13] gh-123930: Better error for "from imports" when script shadows module (GH-123929) (#125937)
gh-123930: Better error for "from imports" when script shadows module (#123929)

(cherry picked from commit 500f5338a8)
2024-10-24 19:37:31 +00:00
Sam Gross 4b55d53316
[3.13] gh-125268: Use static string for "1e309" in AST (GH-125272) (GH-125280)
When formatting the AST as a string, infinite values are replaced by
1e309, which evaluates to infinity. The initialization of this string
replacement was not thread-safe in the free threading build.
(cherry picked from commit 427dcf24de)
2024-10-24 13:59:23 -04:00
Miss Islington (bot) 52b57eee64
[3.13] gh-125842: Fix `sys.exit(0xffff_ffff)` on Windows (GH-125896) (GH-125925)
On Windows, `long` is a signed 32-bit integer so it can't represent
`0xffff_ffff` without overflow. Windows exit codes are unsigned 32-bit
integers, so if a child process exits with `-1`, it will be represented
as `0xffff_ffff`.

Also fix a number of other possible cases where `_Py_HandleSystemExit`
could return with an exception set, leading to a `SystemError` (or
fatal error in debug builds) later on during shutdown.
(cherry picked from commit ad6110a93f)

Co-authored-by: Sam Gross <colesbury@gmail.com>
2024-10-24 16:27:30 +00:00
Miss Islington (bot) 5c2696bc26
[3.13] gh-125859: Fix crash when `gc.get_objects` is called during GC (GH-125882) (GH-125921)
This fixes a crash when `gc.get_objects()` or `gc.get_referrers()` is
called during a GC in the free threading build.

Switch to `_PyObjectStack` to avoid corrupting the `struct worklist`
linked list maintained by the GC. Also, don't return objects that are frozen
(`gc.freeze()`) or in the process of being collected to more closely match
the behavior of the default build.
(cherry picked from commit e545ead66c)

Co-authored-by: Sam Gross <colesbury@gmail.com>
2024-10-24 14:08:15 +00:00
Jelle Zijlstra bcc7227ef7
[3.13] gh-125038: Fix crash after genexpr.gi_frame.f_locals manipulations (GH-125178) (#125846)
(cherry picked from commit 079875e395)

Co-authored-by: Mikhail Efimov <efimov.mikhail@gmail.com>
2024-10-23 06:45:28 -07:00
Miss Islington (bot) 4d83f6ddc4
[3.13] gh-124375: Avoid calling `_PyMem_ProcessDelayed` on other thread states (GH-124459) (#125540)
This fixes a crash when running the PyO3 test suite on the free-threaded
build. The `qsbr` field is initialized after the `PyThreadState` is
added to the interpreter's linked list -- it might still be NULL.

Instead, we "steal" the queue of to-be-freed memory blocks. This is
always initialized (possibly empty) and protected by the stop the world
pause.
(cherry picked from commit 54c6fcbefd)

Co-authored-by: Sam Gross <colesbury@gmail.com>
2024-10-15 13:35:28 -04:00
Miss Islington (bot) 03ae82d0d3
[3.13] gh-124188: Fix PyErr_ProgramTextObject() (GH-124189) (GH-124423)
* Detect source file encoding.
* Use the "replace" error handler even for UTF-8 (default) encoding.
* Remove the BOM.
* Fix detection of too long lines if they contain NUL.
* Return the head rather than the tail for truncated long lines.
(cherry picked from commit e2f710792b)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2024-10-08 00:23:49 +03:00
Miss Islington (bot) 80ba17a3dd
[3.13] gh-112804: Clamping timeout value for _PySemaphore_PlatformWait (gh-124914) (gh-124991)
gh-112804: Clamping timeout value for _PySemaphore_PlatformWait (gh-124914)

* gh-112804: Clamping timeout value for _PySemaphore_PlatformWait

* Address code review

* nit
(cherry picked from commit a5fc50994a)

Co-authored-by: Donghee Na <donghee.na@python.org>
2024-10-07 16:53:32 +00:00
Miss Islington (bot) b87aea6b0d
[3.13] gh-124871: fix 'visited' tracking in compiler's reachability analysis (GH-124952) (#124977)
gh-124871: fix 'visited' tracking in compiler's reachability analysis (GH-124952)
(cherry picked from commit f474391b26)

Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
2024-10-04 15:34:20 -07:00
Jelle Zijlstra b99c6620b2
[3.13] gh-124442: make `__static_attributes__` deterministic by sorting (GH-124492) (#124738)
* [3.13] gh-124442: make `__static_attributes__` deterministic by sorting (GH-124492)
(cherry picked from commit 04c837d9d8)

Co-authored-by: Kira <kp2pml30@gmail.com>
Signed-off-by: kp2pml30 <kp2pml30@gmail.com>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
2024-09-30 18:53:17 -07:00
T. Wouters e0eb44ad49
[3.13] GH-124567: Revert the Incremental GC in 3.13 (#124770)
Revert the incremental GC in 3.13, since it's not clear that without further turning, the benefits outweigh the costs.

Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
2024-09-30 21:27:29 +00:00
Miss Islington (bot) 612e469624
[3.13] gh-123892: Add "_wmi" to sys.stdlib_module_names (GH-123893) (#123896)
gh-123892: Add "_wmi" to sys.stdlib_module_names (GH-123893)
(cherry picked from commit fb1b51a58d)

Co-authored-by: Victor Stinner <vstinner@python.org>
2024-09-29 18:24:55 -07:00
Irit Katriel cebc6f51ee
[3.13] gh-124746: remove assertion on exits having line numbers (#124762)
gh-124746: remove assertion in 3.13
2024-09-29 17:53:47 -07:00
Miss Islington (bot) 1cd2b97113
[3.13] gh-116510: Fix crash during sub-interpreter shutdown (gh-124645) (#124649)
gh-116510: Fix crash during sub-interpreter shutdown (gh-124645)

Fix a bug that can cause a crash when sub-interpreters use "basic"
single-phase extension modules.  Shared objects could refer to PyGC_Head
nodes that had been freed as part of interpreter shutdown.
(cherry picked from commit 6f9525dd3f)

Co-authored-by: Neil Schemenauer <nas-github@arctrix.com>
2024-09-27 11:11:02 -07:00
Miss Islington (bot) 9bae6815a3
[3.13] gh-124160: Pass main_tstate to update_global_state_for_extension() (GH-124164) (#124250)
gh-124160: Pass main_tstate to update_global_state_for_extension() (GH-124164)
(cherry picked from commit 7331d0f70b)

Co-authored-by: luk1337 <priv.luk@gmail.com>
2024-09-23 16:16:41 -07:00
Miss Islington (bot) de8dc92db7
[3.13] gh-123880: Allow recursive import of single-phase-init modules (GH-123950) (#124273)
gh-123880: Allow recursive import of single-phase-init modules (GH-123950)

(cherry picked from commit aee219f455)

Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
Co-authored-by: Brett Cannon <brett@python.org>
2024-09-23 12:56:00 -07:00
Savannah Ostrowski eac2fdacfb
[3.13] GH-123545: Remove duplicate Py_DECREF when handling _PyOptimizer_Optimize errors (GH-123759)
(cherry picked from commit 1fbc118c5d)

Co-authored-by: Savannah Ostrowski <savannahostrowski@gmail.com>
2024-09-06 09:02:32 -07:00
Miss Islington (bot) 92b9c4482f
[3.13] gh-123275: Support `-Xgil=1` and `PYTHON_GIL=1` on non-free-threaded builds (gh-123276) (gh-123753)
gh-123275: Support `-Xgil=1` and `PYTHON_GIL=1` on non-free-threaded builds (gh-123276)
(cherry picked from commit 84ad264ce6)

Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
2024-09-06 10:09:35 +09:00
Miss Islington (bot) 48941399e3
[3.13] gh-121804: always show error location for SyntaxError's in basic repl (GH-123202) (#123631)
gh-121804: always show error location for SyntaxError's in basic repl (GH-123202)
(cherry picked from commit 6822cb23c6)

Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
2024-09-03 13:06:31 +00:00
Petr Viktorin d655c65561
[3.13] gh-123091: Use more _Py_IsImmortalLoose() (GH-123602) (GH-123622)
Switch more _Py_IsImmortal(...) assertions to _Py_IsImmortalLoose(...)

The remaining calls to _Py_IsImmortal are in free-threaded-only code,
initialization of core objects, tests, and guards that fall back to
code that works with mortal objects.

(cherry picked from commit 57c471a688)
2024-09-03 12:36:42 +02:00
Miss Islington (bot) 80e0326b53
[3.13] gh-98442: fix locations of with statement's cleanup instructions (GH-120763) (#120786)
gh-98442: fix locations of with statement's cleanup instructions (GH-120763)
(cherry picked from commit 55596ae044)


gh-98442: fix location of with statement's cleanup instructions

Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
2024-09-02 15:46:41 +00:00
Miss Islington (bot) 494181e44d
[3.13] gh-93691: fix too broad source locations of with-statement instructions (GH-120125) (#123604)
gh-93691: fix too broad source locations of with-statement instructions (GH-120125)
(cherry picked from commit eca3f7762c)

Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
2024-09-02 14:53:39 +00:00
Victor Stinner 10735bff9e
[3.13] gh-123091: Use _Py_IsImmortalLoose() (#123511) (#123600)
gh-123091: Use _Py_IsImmortalLoose() (#123511)

Use _Py_IsImmortalLoose() in bytesobject.c, typeobject.c
and ceval.c.

(cherry picked from commit f1a0d96f41)
2024-09-02 15:23:29 +02:00
Miss Islington (bot) aca65112fe
[3.13] GH-117759: Document incremental GC (GH-123266) (#123395)
GH-117759: Document incremental GC (GH-123266)

* Update what's new

* Update gc module docs and fix inconsistency in gc.get_objects
(cherry picked from commit f49a91648a)

Co-authored-by: Mark Shannon <mark@hotpy.org>
2024-09-02 13:12:16 +02:00
Miss Islington (bot) b1372e2f1a
[3.13] GH-122298: Restore printing of GC stats (GH-123261) (#123268)
GH-122298: Restore printing of GC stats (GH-123261)
(cherry picked from commit 7cd3aa42f0)

Co-authored-by: Mark Shannon <mark@hotpy.org>
2024-09-02 13:10:27 +02:00
Alex Waygood 3455d8560a
[3.13] Fix typos in docs, error messages and comments (#122502) (#122606)
Fix typos in docs, error messages and comments (#122502)

(cherry-picked from commit 46f5a4f9e1)

Signed-off-by: jianghuyiyuan <shuangcui@live.com>
Co-authored-by: jianghuyiyuan <shuangcui@live.com>
2024-09-02 12:44:42 +02:00
Irit Katriel d379a92ddc
[3.13] gh-123142: fix too wide source location of GET_ITER/GET_AITER (GH-123420). (#123435)
(cherry picked from commit 61bef6245c)
2024-08-28 18:41:22 +01:00
Miss Islington (bot) 19a1f18740
[3.13] gh-123344: Add missing ast optimizations for PEP 696 (GH-123377) (#123427)
(cherry picked from commit be083cee34)

Co-authored-by: Bogdan Romanyuk <65823030+wrongnull@users.noreply.github.com>
Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2024-08-28 14:02:34 +00:00
Donghee Na 6cd67e413b
[3.13] gh-123083: Fix a potential use-after-free in ``STORE_ATTR_WITH… (#123235)
[3.13] gh-123083: Fix a potential use-after-free in ``STORE_ATTR_WITH_HINT`` (gh-123092)
(cherry picked from commit 297f2e093e)
2024-08-23 01:37:26 +09:00
Irit Katriel e4b91b7256
[3.13] gh-123142: Fix too wide source locations in tracebacks of exceptions from broken iterables in comprehensions (GH-123173). (#123209)
(cherry picked from commit ec89620e5e)
2024-08-22 10:22:39 +01:00
mpage 50a595b37f
[3.13] gh-122712: Guard against __code__ reassignment in CALL_ALLOC_AND_ENTER_INIT (GH-122713) (GH-123184) 2024-08-21 13:16:30 +01:00
Miss Islington (bot) 159db050f4
[3.13] gh-123048: Fix missing source location in pattern matching code (GH-123167) (#123169)
gh-123048: Fix missing source location in pattern matching code (GH-123167)
(cherry picked from commit bffed80230)

Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
2024-08-20 11:13:43 +00:00
Miss Islington (bot) 01ce10c690
[3.13] Add debug offsets for free threaded builds (GH-123041) (#123055)
* Add debug offsets for free threaded builds (GH-123041)
(cherry picked from commit d7a3df9150)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>

* Refresh ABI file

---------

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
2024-08-18 15:01:16 +00:00
Miss Islington (bot) 1f7071572e
[3.13] gh-122247: Move instruction instrumentation sanity check after tracing check (GH-122251) (GH-122812)
(cherry picked from commit 57d7c3e78f)

Co-authored-by: Tian Gao <gaogaotiantian@hotmail.com>
2024-08-16 12:01:40 +02:00
Serhiy Storchaka 1fd1c6c738
[3.13] gh-118814: Fix the TypeVar constructor when name is passed by keyword (GH-122664) (GH-122806)
Fix _PyArg_UnpackKeywordsWithVararg for the case when argument for
positional-or-keyword parameter is passed by keyword.
There was only one such case in the stdlib -- the TypeVar constructor.
(cherry picked from commit 540fcc62f5)
2024-08-08 09:49:21 +03:00
Miss Islington (bot) 5c161cb832
[3.13] gh-122728: Fix SystemError in PyEval_GetLocals() (GH-122735) (#122757)
gh-122728: Fix SystemError in PyEval_GetLocals() (GH-122735)

Fix PyEval_GetLocals() to avoid SystemError ("bad argument to
internal function"). Don't redefine the 'ret' variable in the if
block.

Add an unit test on PyEval_GetLocals().
(cherry picked from commit 4767a6e31c)

Co-authored-by: Victor Stinner <vstinner@python.org>
2024-08-06 23:37:10 +02:00
Irit Katriel 545a328eae
[3.13] gh-122445: populate only modified fields in __static_attributes__ (#122446) (#122621)
gh-122445: populate only modified fields in __static_attributes__ (#122446)

(cherry picked from commit 498376d7a7)
2024-08-02 19:26:57 +01:00
Miss Islington (bot) b20893b5c2
[3.13] gh-122334: Fix crash when importing ssl after re-initialization (GH-122481) (#122614)
gh-122334: Fix crash when importing ssl after re-initialization (GH-122481)

* Fix crash when importing ssl after re-initialization
(cherry picked from commit 9fc1c992d6)

Co-authored-by: neonene <53406459+neonene@users.noreply.github.com>
2024-08-02 14:07:16 +00:00
Miss Islington (bot) 8e96d85386
[3.13] gh-117657: Avoid race in `PAUSE_ADAPTIVE_COUNTER` in free-threaded build (GH-122190) (#122475)
The adaptive counter doesn't do anything currently in the free-threaded
build and TSan reports a data race due to concurrent modifications to
the counter.
(cherry picked from commit 2b163aa9e7)

Co-authored-by: Sam Gross <colesbury@gmail.com>
2024-07-30 18:18:25 +00:00
Brandt Bucher 55554fd215
[3.13] GH-116090: Fire RAISE events from _FOR_ITER_TIER_TWO (GH-122419)
(cherry picked from commit 15d4cd0967)
2024-07-29 14:51:19 -07:00
Miss Islington (bot) 9d5dde5006
[3.13] gh-122201: Lock mutex when setting handling_thread to NULL (GH-122204) (#122319)
In the free-threaded build, we need to lock pending->mutex when clearing
the handling_thread in order not to race with a concurrent
make_pending_calls in the same interpreter.
(cherry picked from commit c557ae97d6)

Co-authored-by: Sam Gross <colesbury@gmail.com>
2024-07-26 17:30:08 +00:00
Miss Islington (bot) 40cdec6a8a
[3.13] gh-122029: Log call events in sys.setprofile when it's a method with c function (GH-122072) (GH-122205)
gh-122029: Log call events in sys.setprofile when it's a method with c function (GH-122072)

Log call events in sys.setprofile when it is a method with a C function.
(cherry picked from commit e91ef13861)

Co-authored-by: Tian Gao <gaogaotiantian@hotmail.com>
2024-07-23 22:49:36 +00:00
Miss Islington (bot) 4b76404a51
[3.13] gh-121390: tracemalloc: Fix tracebacks memory leak (GH-121391) (#121392)
gh-121390: tracemalloc: Fix tracebacks memory leak (GH-121391)

The tracemalloc_tracebacks hash table has traceback keys and NULL
values, but its destructors do not reflect this -- key_destroy_func is
NULL while value_destroy_func is raw_free. Swap these to free the
traceback keys instead.
(cherry picked from commit db39bc42f9)

Co-authored-by: Josh Brobst <jbrobst@proton.me>
2024-07-21 13:12:13 +00:00
Miss Islington (bot) bf7f4f357b
[3.13] gh-120973: Fix thread-safety issues with `threading.local` (GH-121655) (#122042)
This is a small refactoring to the current design that allows us to
avoid manually iterating over threads.

This should also fix gh-118490.
(cherry picked from commit e059aa6b01)

Co-authored-by: mpage <mpage@meta.com>
2024-07-19 17:49:34 +00:00
Serhiy Storchaka a45d9051ed
[3.13] gh-121905: Consistently use "floating-point" instead of "floating point" (GH-121907) (GH-122012)
(cherry picked from commit 1a0c7b9ba4)
2024-07-19 09:13:08 +00:00
Miss Islington (bot) 233ed46e6d
[3.13] gh-118934: Make PyEval_GetLocals return borrowed reference (GH-119769) (#121869)
gh-118934: Make PyEval_GetLocals return borrowed reference (GH-119769)
(cherry picked from commit e65cb4c6f0)

Co-authored-by: Tian Gao <gaogaotiantian@hotmail.com>
Co-authored-by: Alyssa Coghlan <ncoghlan@gmail.com>
2024-07-19 01:38:28 +10:00
Miss Islington (bot) afa5321c6c
[3.13] gh-121621: Move asyncio_running_loop to private struct (GH-121939) (#121943)
gh-121621: Move asyncio_running_loop to private struct (GH-121939)

This avoids changing the ABI and keeps the field in the private struct.
(cherry picked from commit 81fd625b5c)

Co-authored-by: Sam Gross <colesbury@gmail.com>
2024-07-18 01:52:39 -07:00
Serhiy Storchaka 09ff4ec14f
[3.13] gh-121153: Fix some errors with use of _PyLong_CompactValue() (GH-121154) (GH-121900)
* The result has type Py_ssize_t, not intptr_t.
* Type cast between unsigned and signed integer types should be explicit.
* Downcasting should be explicit.
* Fix integer overflow check in sum().
(cherry picked from commit 1801545)
2024-07-17 08:04:45 +00:00
Miss Islington (bot) f888636182
[3.13] GH-121583: Remove dependency from pystats.h to internal header file (GH-121880)
(cherry picked from commit f036a463db)
Co-authored-by: Michael Droettboom <mdboom@gmail.com>
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
2024-07-16 23:03:07 +00:00
Miss Islington (bot) 06d76c4b94
[3.13] gh-121621: Move asyncio running loop to thread state (GH-121695) (GH-121864)
gh-121621: Move asyncio running loop to thread state (GH-121695)
(cherry picked from commit 69c68de43a)

Co-authored-by: Ken Jin <kenjin@python.org>
2024-07-17 01:57:37 +08:00
Miss Islington (bot) 54db42fe2c
[3.13] gh-121814: Only check f_trace_opcodes if Python frame exists (GH-121818) (#121861)
gh-121814: Only check f_trace_opcodes if Python frame exists (GH-121818)
(cherry picked from commit 2b1b68939b)

Co-authored-by: Tian Gao <gaogaotiantian@hotmail.com>
Co-authored-by: Matt Wozniski <godlygeek@gmail.com>
2024-07-16 10:13:28 -07:00
Miss Islington (bot) e45c61f736
[3.13] gh-120317: Lock around global state in the tokenize module (GH-120318) (#121841)
(cherry picked from commit 8549559f38)

Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
Co-authored-by: Pablo Galindo <pablogsal@gmail.com>
2024-07-16 10:03:47 +00:00
Miss Islington (bot) 0794220a69
[3.13] gh-121794: Don't set `ob_tid` to zero in fast-path dealloc (GH-121799) (#121821)
We should maintain the invariant that a zero `ob_tid` implies the
refcount fields are merged.

* Move the assignment in `_Py_MergeZeroLocalRefcount` to immediately
  before the refcount merge.
* Update `_PyTrash_thread_destroy_chain` to set `ob_ref_shared` to
  `_Py_REF_MERGED` when setting `ob_tid` to zero.

Also check this invariant with assertions in the GC in debug builds.
That uncovered a bug when running out of memory during GC.
(cherry picked from commit d23be3947c)

Co-authored-by: Sam Gross <colesbury@gmail.com>
2024-07-15 22:15:23 +00:00
Miss Islington (bot) 0a634e3702
[3.13] gh-121546: Disable contextvar caching on free-threading build (GH-121740) (#121808)
gh-121546: Disable contextvar caching on free-threading build (GH-121740)
(cherry picked from commit e904300882)

Co-authored-by: Ken Jin <kenjin@python.org>
2024-07-15 16:53:52 -04:00
Kirill Podoprigora c4daec4319
[3.13] gh-121657: Display correct error message for yield from outsid… (GH-121768)
(cherry picked from commit 178e44de8f)

Co-authored-by: Gregor <36135323+gege-hoho@users.noreply.github.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2024-07-15 21:25:54 +02:00
Miss Islington (bot) ff65d1e054
[3.13] gh-118297: Make Sure All Pending Calls Run in _Py_FinishPendingCalls() (gh-121806)
(cherry picked from commit 985dd8e17b, AKA gh-118298)

Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
2024-07-15 19:09:40 +00:00
Miss Islington (bot) f17057dab1
[3.13] gh-121698 Emscripten: Use updated WebAssembly type reflection proposal (GH-121699) (GH-121745)
(cherry picked from commit cae1526716)

Co-authored-by: Hood Chatham <roberthoodchatham@gmail.com>
2024-07-14 12:01:03 +02:00
Jelle Zijlstra 38c4028dd9
[3.13] gh-121332: Make AST node constructor check _attributes instead of hardcoding attributes (GH-121334) (#121625)
(cherry picked from commit 58e8cf2bb6)
2024-07-11 15:51:32 +00:00
Miss Islington (bot) c1891e225e
[3.13] gh-121110: Fix Extension Module Tests Under Py_TRACE_REFS Builds (gh-121517)
The change in gh-118157 (b2cd54a) should have also updated clear_singlephase_extension() but didn't.  We fix that here.  Note that clear_singlephase_extension() (AKA _PyImport_ClearExtension()) is only used in tests.

(cherry picked from commit 15d48aea02, AKA gh-121503)

Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
2024-07-08 21:34:58 +00:00
Miss Islington (bot) c128718f30
[3.13] gh-121368: Fix seq lock memory ordering in _PyType_Lookup (GH-121388) (#121505)
The `_PySeqLock_EndRead` function needs an acquire fence to ensure that
the load of the sequence happens after any loads within the read side
critical section. The missing fence can trigger bugs on macOS arm64.

Additionally, we need a release fence in `_PySeqLock_LockWrite` to
ensure that the sequence update is visible before any modifications to
the cache entry.
(cherry picked from commit 1d3cf79a50)

Co-authored-by: Sam Gross <colesbury@gmail.com>
2024-07-08 19:15:58 +00:00
Miss Islington (bot) 2f8919ee3c
[3.13] GH-121012: Set index to -1 when list iterators become exhausted in tier 2 (GH-121483) (GH-121494) 2024-07-08 18:09:54 +01:00
Miss Islington (bot) 0790418a04
[3.13] gh-121338: Remove GH-pragma optimize (GH-121340) (#121492)
gh-121338: Remove GH-pragma optimize (GH-121340)
(cherry picked from commit d69529d31c)

Co-authored-by: Michael Droettboom <mdboom@gmail.com>
2024-07-08 09:22:44 -04:00
Miss Islington (bot) d5441f6aac
[3.13] gh-120837: Update _Py_DumpExtensionModules to be async-signal-safe (gh-121051) (gh-121107)
gh-120837: Update _Py_DumpExtensionModules to be async-signal-safe (gh-121051)
(cherry picked from commit 1a2e7a7475)

Co-authored-by: Donghee Na <donghee.na@python.org>
2024-06-27 22:12:12 +00:00
Miss Islington (bot) c83997476f
[3.13] gh-113433: Automatically Clean Up Subinterpreters in Py_Finalize() (gh-121067)
This change makes things a little less painful for some users.  It also fixes a failing assert (gh-120765), by making sure all subinterpreters are destroyed before the main interpreter.  As part of that, we make sure Py_Finalize() always runs with the main interpreter active.

(cherry picked from commit 4be1f37b20, AKA gh-121060)

Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
2024-06-26 21:56:13 +00:00
Miss Islington (bot) c052b192aa
[3.13] gh-120838: Add _PyThreadState_WHENCE_FINI (gh-121013)
We also add _PyThreadState_NewBound() and drop _PyThreadState_SetWhence().

This change only affects internal API.

(cherry picked from commit a905721b9c, AKA gh-121010)

Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
2024-06-26 15:32:00 -06:00
Victor Stinner e26e0985d9
[3.13] gh-120642: Move private PyCode APIs to the internal C API (#120643) (#121043)
gh-120642: Move private PyCode APIs to the internal C API (#120643)

* Move _Py_CODEUNIT and related functions to pycore_code.h.
* Move _Py_BackoffCounter to pycore_backoff.h.
* Move Include/cpython/optimizer.h content to pycore_optimizer.h.
* Remove Include/cpython/optimizer.h.
* Remove PyUnstable_Replace_Executor().

Rename functions:

* PyUnstable_GetExecutor() => _Py_GetExecutor()
* PyUnstable_GetOptimizer() => _Py_GetOptimizer()
* PyUnstable_SetOptimizer() => _Py_SetTier2Optimizer()
* PyUnstable_Optimizer_NewCounter() => _PyOptimizer_NewCounter()
* PyUnstable_Optimizer_NewUOpOptimizer() => _PyOptimizer_NewUOpOptimizer()

(cherry picked from commit 9e4a81f00f)
2024-06-26 15:35:19 +02:00
Jelle Zijlstra 899dfbaf0e
[3.13] gh-120108: Fix deepcopying of AST trees with .parent attributes (GH-120114) (#121000)
(cherry picked from commit 42b2c9d78d)
2024-06-25 15:39:29 +00:00
Petr Viktorin 9769b7ae06
[3.13] gh-113993: Allow interned strings to be mortal, and fix related issues (GH-120520) (GH-120945)
* Add an InternalDocs file describing how interning should work and how to use it.

* Add internal functions to *explicitly* request what kind of interning is done:
  - `_PyUnicode_InternMortal`
  - `_PyUnicode_InternImmortal`
  - `_PyUnicode_InternStatic`

* Switch uses of `PyUnicode_InternInPlace` to those.

* Disallow using `_Py_SetImmortal` on strings directly.
  You should use `_PyUnicode_InternImmortal` instead:
  - Strings should be interned before immortalization, otherwise you're possibly
    interning a immortalizing copy.
  - `_Py_SetImmortal` doesn't handle the `SSTATE_INTERNED_MORTAL` to
    `SSTATE_INTERNED_IMMORTAL` update, and those flags can't be changed in
    backports, as they are now part of public API and version-specific ABI.

* Add private `_only_immortal` argument for `sys.getunicodeinternedsize`, used in refleak test machinery.

* Make sure the statically allocated string singletons are unique. This means these sets are now disjoint:
  - `_Py_ID`
  - `_Py_STR` (including the empty string)
  - one-character latin-1 singletons

  Now, when you intern a singleton, that exact singleton will be interned.

* Add a `_Py_LATIN1_CHR` macro, use it instead of `_Py_ID`/`_Py_STR` for one-character latin-1 singletons everywhere (including Clinic).

* Intern `_Py_STR` singletons at startup.

* For free-threaded builds, intern `_Py_LATIN1_CHR` singletons at startup.

* Beef up the tests. Cover internal details (marked with `@cpython_only`).

* Add lots of assertions

Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
2024-06-24 20:24:19 +02:00
Miss Islington (bot) a860b1d60b
[3.13] gh-120811: Fix reference leak upon `_PyContext_Exit` failure (GH-120812) (#120843)
gh-120811: Fix reference leak upon `_PyContext_Exit` failure (GH-120812)
(cherry picked from commit aed31beca9)

Co-authored-by: Peter <zintensitydev@gmail.com>
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
2024-06-22 16:44:46 +05:30
Sam Gross 4dc27bc0b7
[3.13] gh-119344: Make critical section API public (GH-119353) (#120856)
This makes the following macros public as part of the non-limited C-API for
locking a single object or two objects at once.

* `Py_BEGIN_CRITICAL_SECTION(op)` / `Py_END_CRITICAL_SECTION()`
* `Py_BEGIN_CRITICAL_SECTION2(a, b)` / `Py_END_CRITICAL_SECTION2()`

The supporting functions and structs used by the macros are also exposed for
cases where C macros are not available.
(cherry picked from commit 8f17d69b7b)
2024-06-21 20:20:41 +00:00
Sam Gross 3cb6c4cd60
[3.13] gh-117511: Make PyMutex public in the non-limited API (GH-117731) (#120800)
(cherry picked from commit 3af7263037)
2024-06-20 16:00:25 +00:00
Ken Jin 7c7aa5a99c
[3.13] gh-119258: Backport optimizer frame fixes in GH-119365 (GH-120699)
(cherry picked from commit 55402d3)
2024-06-20 23:55:20 +08:00
Miss Islington (bot) 5d194902cb
[3.13] Fix typos in comments (GH-120481) (#120774)
(cherry picked from commit 656a1c8108)

Co-authored-by: Xie Yanbo <xieyanbo@gmail.com>
2024-06-20 03:40:54 +00:00
Nadeshiko Manju ae04b6f636
[3.13] gh-120437: Fix `_CHECK_STACK_SPACE` optimization problems introduced in gh-118322 (GH-120712) (#120747)
[3.13] gh-120437: Fix `_CHECK_STACK_SPACE` optimization problems introduced in gh-118322 (GH-120712)

Signed-off-by: Manjusaka <me@manjusaka.me>
Co-authored-by: Ken Jin <kenjin4096@gmail.com>
2024-06-20 01:40:48 +08:00
Miss Islington (bot) 4ce1246a99
[3.13] gh-120722: Set position on RETURN_VALUE in lambda (GH-120724) (#120738)
(cherry picked from commit d8f27cb114)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2024-06-19 13:22:21 +00:00
Miss Islington (bot) 071b66b218
[3.13] gh-120726: Fix compiler warnings on is_core_module() (GH-120727) (#120729)
gh-120726: Fix compiler warnings on is_core_module() (GH-120727)

Fix compiler warnings on is_core_module() and
check_interpreter_whence(): only define them when
assertions are built.
(cherry picked from commit a816cd67f4)

Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
2024-06-19 10:23:28 +00:00
Miss Islington (bot) 50fa775e68
[3.13] gh-120367: fix bug where compiler detects redundant jump after pseudo op replacement (GH-120714) (#120716) 2024-06-18 22:34:07 +00:00
Miss Islington (bot) 396f8b0b98
[3.13] gh-117657: Fix `__slots__` thread safety in free-threaded build (GH-119368) (#120655)
Fix a race in `PyMember_GetOne` and `PyMember_SetOne` for `Py_T_OBJECT_EX`.
These functions implement `__slots__` accesses for Python objects.
(cherry picked from commit 362cd2680b)

Co-authored-by: Daniele Parmeggiani <8658291+dpdani@users.noreply.github.com>
2024-06-17 19:12:25 +00:00
Miss Islington (bot) 0dbb86c5be
[3.13] gh-117657: Fix TSan reported data race on ioctl_works (GH-120175) (#120654)
(cherry picked from commit 460cc9e14e)

Co-authored-by: Sam Gross <colesbury@gmail.com>
2024-06-17 17:52:49 +00:00
Miss Islington (bot) 9172bc35c6
[3.13] gh-115649: Copy the filename into main interpreter before intern in import.c (GH-120315) (#120652)
gh-115649: Copy the filename into main interpreter before intern in import.c (GH-120315)
(cherry picked from commit 28140d1f2d)

Co-authored-by: AN Long <aisk@users.noreply.github.com>
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
2024-06-17 22:30:26 +05:30