summaryrefslogtreecommitdiffstats
path: root/Python
Commit message (Collapse)AuthorAgeFilesLines
* [3.13] gh-120811: Fix reference leak upon `_PyContext_Exit` failure ↵Miss Islington (bot)2024-06-221-0/+1
| | | | | | | | | (GH-120812) (#120843) gh-120811: Fix reference leak upon `_PyContext_Exit` failure (GH-120812) (cherry picked from commit aed31beca9a54b85a1392631a48da80602210f18) Co-authored-by: Peter <zintensitydev@gmail.com> Co-authored-by: Kumar Aditya <kumaraditya@python.org>
* [3.13] gh-119344: Make critical section API public (GH-119353) (#120856)Sam Gross2024-06-211-29/+77
| | | | | | | | | | | 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 8f17d69b7bc906e8407095317842cc0fd52cd84a)
* [3.13] gh-117511: Make PyMutex public in the non-limited API (GH-117731) ↵Sam Gross2024-06-202-26/+28
| | | | | (#120800) (cherry picked from commit 3af7263037de1d0ef63b070fc7bfc2cf042eaebe)
* [3.13] gh-119258: Backport optimizer frame fixes in GH-119365 (GH-120699)Ken Jin2024-06-204-32/+18
| | | (cherry picked from commit 55402d3)
* [3.13] Fix typos in comments (GH-120481) (#120774)Miss Islington (bot)2024-06-202-3/+3
| | | | | (cherry picked from commit 656a1c81083b76b9d998c983f4329348a65985d3) Co-authored-by: Xie Yanbo <xieyanbo@gmail.com>
* [3.13] gh-120437: Fix `_CHECK_STACK_SPACE` optimization problems introduced ↵Nadeshiko Manju2024-06-192-2/+0
| | | | | | | | 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>
* [3.13] gh-120722: Set position on RETURN_VALUE in lambda (GH-120724) (#120738)Miss Islington (bot)2024-06-191-1/+1
| | | | | (cherry picked from commit d8f27cb1141fd3575de816438ed80a916c0560ed) Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
* [3.13] gh-120726: Fix compiler warnings on is_core_module() (GH-120727) ↵Miss Islington (bot)2024-06-192-4/+5
| | | | | | | | | | | | (#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 a816cd67f43d9adb27ccdb6331e08c835247d1df) Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
* [3.13] gh-120367: fix bug where compiler detects redundant jump after pseudo ↵Miss Islington (bot)2024-06-181-1/+1
| | | | op replacement (GH-120714) (#120716)
* [3.13] gh-117657: Fix `__slots__` thread safety in free-threaded build ↵Miss Islington (bot)2024-06-171-9/+33
| | | | | | | | | (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 362cd2680b45a36c3467b9721ff7fc0ceb338452) Co-authored-by: Daniele Parmeggiani <8658291+dpdani@users.noreply.github.com>
* [3.13] gh-117657: Fix TSan reported data race on ioctl_works (GH-120175) ↵Miss Islington (bot)2024-06-171-3/+5
| | | | | | | (#120654) (cherry picked from commit 460cc9e14e221c53c0038a847bfd411fe184ebf3) Co-authored-by: Sam Gross <colesbury@gmail.com>
* [3.13] gh-115649: Copy the filename into main interpreter before intern in ↵Miss Islington (bot)2024-06-171-1/+11
| | | | | | | | | import.c (GH-120315) (#120652) gh-115649: Copy the filename into main interpreter before intern in import.c (GH-120315) (cherry picked from commit 28140d1f2da1766bfbb83f58779f15255c73c871) Co-authored-by: AN Long <aisk@users.noreply.github.com> Co-authored-by: Kumar Aditya <kumaraditya@python.org>
* [3.13] gh-120367: fix removal of redundant NOPs and jumps after reordering ↵Miss Islington (bot)2024-06-171-12/+18
| | | | | | | | hot-cold blocks (GH-120425) (#120621) gh-120367: fix removal of redundant NOPs and jumps after reordering hot-cold blocks (GH-120425) (cherry picked from commit 21866c8ed296524f0ca175c0f55b43744c2b30df) Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
* [3.13] gh-119933: Improve ``SyntaxError`` message for invalid type ↵Jelle Zijlstra2024-06-171-26/+54
| | | | | | | parameters expressions (GH-119976) (#120641) (cherry picked from commit 4bf17c381fb7b465f0f26aecb94a6c54cf9be2d3) Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
* [3.13] gh-120526: Correct signature of map() builtin (GH-120528) (GH-120539)Miss Islington (bot)2024-06-151-1/+1
| | | | | | | | map() requires at least one iterable arg. (cherry picked from commit d4039d3f6f8cb7738c5cd272dde04171446dfd2b) Signed-off-by: Adam Williamson <awilliam@redhat.com> Co-authored-by: Adam Williamson <adam@blueradius.ca>
* [3.13] gh-120161: Fix a Crash in the _datetime Module (gh-120518)Miss Islington (bot)2024-06-141-0/+1
| | | | | | | | | | | In gh-120009 I used an atexit hook to finalize the _datetime module's static types at interpreter shutdown. However, atexit hooks are executed very early in finalization, which is a problem in the few cases where a subclass of one of those static types is still alive until the final GC collection. The static builtin types don't have this probably because they are finalized toward the end, after the final GC collection. To avoid the problem for _datetime, I have applied a similar approach here. Also, credit goes to @mgorny and @neonene for the new tests. FYI, I would have liked to take a slightly cleaner approach with managed static types, but wanted to get a smaller fix in first for the sake of backporting. I'll circle back to the cleaner approach with a future change on the main branch. (cherry picked from commit b2e71ff4f8fa5b7d8117dd8125137aee3d01f015, AKA gh-120182) Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
* [3.13] gh-120400 :Support Linux perf profile to see Python calls on RISC-V ↵Miss Islington (bot)2024-06-141-0/+8
| | | | | | | | | architecture (GH-120089) (#120413) gh-120400 :Support Linux perf profile to see Python calls on RISC-V architecture (GH-120089) (cherry picked from commit 4b1e85bafc5bcb8cb70bb17164e07aebf7ad7e8e) Co-authored-by: ixgbe00 <yangwang@iscas.ac.cn> Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
* [3.13] gh-117657: Fix some simple races in instrumentation.c (GH-120118) ↵Miss Islington (bot)2024-06-131-2/+2
| | | | | | | | | | (#120444) gh-117657: Fix some simple races in instrumentation.c (GH-120118) * stop the world when setting local events (cherry picked from commit b1b61dc4cee43920ef2b08d5ac94ddf08119c507) Co-authored-by: Ken Jin <kenjin@python.org>
* [3.13] gh-120343: Fix column offsets of multiline tokens in tokenize ↵Miss Islington (bot)2024-06-121-4/+10
| | | | | | | (GH-120391) (#120427) (cherry picked from commit 4b5d3e0e721a952f4ac9d17bee331e6dfe543dcd) Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
* [3.13] gh-93691: fix too broad source locations of for statement iterators ↵Miss Islington (bot)2024-06-121-0/+7
| | | | | | | | (GH-120330) (#120399) gh-93691: fix too broad source locations of for statement iterators (GH-120330) (cherry picked from commit 97b69db167be28a33688db436551a6c3c3ea4662) Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
* [3.13] gh-120343: Do not reset byte_col_offset_diff after multiline tokens ↵Miss Islington (bot)2024-06-111-1/+6
| | | | | | | | (GH-120352) (#120355) (cherry picked from commit 1b62bcee941e54244b3ce6476aef8913604987c9) Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com> Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
* [3.13] gh-119666: fix multiple class-scope comprehensions referencing ↵Miss Islington (bot)2024-06-101-13/+10
| | | | __class__ (GH-120295) (#120299)
* [3.13] gh-120225: fix crash in compiler on empty block at end of exception ↵Miss Islington (bot)2024-06-071-6/+2
| | | | | | | | handler (GH-120235) (#120249) gh-120225: fix crash in compiler on empty block at end of exception handler (GH-120235) (cherry picked from commit 4fc82b6d3b99f873179937215833e7a573ca7876) Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
* [3.13] gh-117657: Fix TSAN race involving import lock (GH-118523) (#120169)Miss Islington (bot)2024-06-062-76/+49
| | | | | | | | This adds a `_PyRecursiveMutex` type based on `PyMutex` and uses that for the import lock. This fixes some data races in the free-threaded build and generally simplifies the import lock code. (cherry picked from commit e21057b99967eb5323320e6d1121955e0cd2985e) Co-authored-by: Sam Gross <colesbury@gmail.com>
* [3.13] gh-117657: Fix race involving GC and heap initialization (GH-119923) ↵Miss Islington (bot)2024-06-042-0/+6
| | | | | | | | | | | | | | | | | (#120038) The `_PyThreadState_Bind()` function is called before the first `PyEval_AcquireThread()` so it's not synchronized with the stop the world GC. We had a race where `gc_visit_heaps()` might visit a thread's heap while it's being initialized. Use a simple atomic int to avoid visiting heaps for threads that are not yet fully initialized (i.e., before `tstate_mimalloc_bind()` is called). The race was reproducible by running: `python Lib/test/test_importlib/partial/pool_in_threads.py`. (cherry picked from commit e69d068ad0bd6a25434ea476a647b635da4d82bb) Co-authored-by: Sam Gross <colesbury@gmail.com>
* [3.13] gh-111499: Fix PYTHONMALLOCSTATS at Python exit (GH-120021) (#120022)Miss Islington (bot)2024-06-041-6/+6
| | | | | | | | | gh-111499: Fix PYTHONMALLOCSTATS at Python exit (GH-120021) Call _PyObject_DebugMallocStats() earlier in Py_FinalizeEx(), before the interpreter is deleted. (cherry picked from commit 5a1205b641df133932ed4c65b9a4ff5724e89963) Co-authored-by: Victor Stinner <vstinner@python.org>
* [3.13] gh-111389: Add PyHASH_MULTIPLIER constant (GH-119214) (#119334)Miss Islington (bot)2024-06-043-4/+4
| | | | | | gh-111389: Add PyHASH_MULTIPLIER constant (GH-119214) (cherry picked from commit f6da790122fdae1a28f444edfbb55202d6829cd1) Co-authored-by: Victor Stinner <vstinner@python.org>
* [3.13] gh-117398: Use Per-Interpreter State for the _datetime Static Types ↵Miss Islington (bot)2024-06-031-2/+2
| | | | | | | | | | | (gh-120009) We make use of the same mechanism that we use for the static builtin types. This required a few tweaks. This change is the final piece needed to make _datetime support multiple interpreters. I've updated the module slot accordingly. (cherry picked from commit 105f22ea46ac16866e6df18ebae2a8ba422b7f45, AKA gh-119929) Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
* [3.13] gh-117657: Fix race involving immortalizing objects (GH-119927) (#120005)Sam Gross2024-06-033-13/+11
| | | | | | | | | | | The free-threaded build currently immortalizes objects that use deferred reference counting (see gh-117783). This typically happens once the first non-main thread is created, but the behavior can be suppressed for tests, in subinterpreters, or during a compile() call. This fixes a race condition involving the tracking of whether the behavior is suppressed. (cherry picked from commit 47fb4327b5c405da6df066dcaa01b7c1aefab313)
* [3.13] gh-117657: Avoid `sem_clockwait` in TSAN (GH-119915) (#119992)Miss Islington (bot)2024-06-031-1/+1
| | | | | | | The `sem_clockwait` function is not currently instrumented, which leads to false positives. (cherry picked from commit 41c1cefbae71d687d1a935233b086473df65e15c) Co-authored-by: Sam Gross <colesbury@gmail.com>
* [3.13] gh-117657: Fix TSAN race in QSBR assertion (GH-119887) (#119904)Miss Islington (bot)2024-06-011-1/+2
| | | | | | | Due to a limitation in TSAN, all reads from `PyThreadState.state` must be atomic to avoid reported races. (cherry picked from commit 90ec19fd33e2452902b9788d4821f1fbf6542304) Co-authored-by: Sam Gross <colesbury@gmail.com>
* [3.13] gh-117657: Fix TSAN race in free-threaded GC (GH-119883) (#119903)Miss Islington (bot)2024-06-011-3/+2
| | | | | | | | Only call `gc_restore_tid()` from stop-the-world contexts. `worklist_pop()` can be called while other threads are running, so use a relaxed atomic to modify `ob_tid`. (cherry picked from commit 60593b2052ca275559c11028d50e19f8e5dfee13) Co-authored-by: Sam Gross <colesbury@gmail.com>
* [3.13] gh-119821: Support non-dict globals in LOAD_FROM_DICT_OR_GLOBALS ↵Jelle Zijlstra2024-06-014-54/+54
| | | | | | | | | | | | | (#119822) (#119889) dSupport non-dict globals in LOAD_FROM_DICT_OR_GLOBALS The implementation basically copies LOAD_GLOBAL. Possibly it could be deduplicated, but that seems like it may get hairy since the two operations have different operands. This is important to fix in 3.14 for PEP 649, but it's a bug in earlier versions too, and we should backport to 3.13 and 3.12 if possible. (cherry picked from commit 80a4e3899420faaa012c82b4e82cdb6675a6a944)
* [3.13] gh-74929: PEP 667 C API documentation (gh-119892)Miss Islington (bot)2024-06-014-4/+3
| | | | | | | | | | | * Add docs for new APIs * Add soft-deprecation notices * Add What's New porting entries * Update comments referencing `PyFrame_LocalsToFast()` to mention the proxy instead * Other related cleanups found when looking for refs to the deprecated APIs (cherry picked from commit 3859e09e3d92d004978dd838f0511364e7edfb94) Co-authored-by: Alyssa Coghlan <ncoghlan@gmail.com>
* [3.13] gh-119369: Fix deadlock during thread exit in free-threaded build ↵Miss Islington (bot)2024-05-312-9/+17
| | | | | | | | | | | | (GH-119528) (#119868) Release the GIL before calling `_Py_qsbr_unregister`. The deadlock could occur when the GIL was enabled at runtime. The `_Py_qsbr_unregister` call might block while holding the GIL because the thread state was not active, but the GIL was still held. (cherry picked from commit 078b8c8cf2bf68f7484cc4d2e3dd74b6fab55664) Co-authored-by: Sam Gross <colesbury@gmail.com>
* [3.13] gh-119585: Fix crash involving `PyGILState_Release()` and ↵Miss Islington (bot)2024-05-311-0/+6
| | | | | | | | | | | | | `PyThreadState_Clear()` (GH-119753) (#119859) Make sure that `gilstate_counter` is not zero in when calling `PyThreadState_Clear()`. A destructor called from `PyThreadState_Clear()` may call back into `PyGILState_Ensure()` and `PyGILState_Release()`. If `gilstate_counter` is zero, it will try to create a new thread state before the current active thread state is destroyed, leading to an assertion failure or crash. (cherry picked from commit bcc1be39cb1d04ad9fc0bd1b9193d3972835a57c) Co-authored-by: Sam Gross <colesbury@gmail.com>
* [3.13] gh-119704: Fix reference leak in the ``Python/Python-tokenize.c`` ↵Miss Islington (bot)2024-05-291-0/+1
| | | | (GH-119705) (#119707)
* [3.13] gh-119118: Fix performance regression in tokenize module (GH-119615) ↵Miss Islington (bot)2024-05-281-4/+40
| | | | | | | | | | | | | (#119682) - Cache line object to avoid creating a Unicode object for all of the tokens in the same line. - Speed up byte offset to column offset conversion by using the smallest buffer possible to measure the difference. (cherry picked from commit d87b0151062e36e67f9e42e1595fba5bf23a485c) Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com> Co-authored-by: Pablo Galindo <pablogsal@gmail.com>
* [3.13] gh-119311: Fix name mangling with PEP 695 generic classes (#119464) ↵Jelle Zijlstra2024-05-282-13/+48
| | | | | | | | (#119643) Fixes #119311. Fixes #119395. (cherry picked from commit a9a74da4a0ca0645f049e67b6434a95e30592c32)
* [3.13] gh-119584: Fix test_import Failed Assertion (gh-119623) (gh-119633)Miss Islington (bot)2024-05-271-2/+2
| | | | | | | The fix in gh-119561 introduced an assertion that doesn't hold true if any of the three new test extension modules are loaded more than once. This is fine normally but breaks if the new test_check_state_first() is run more than once, which happens for refleak checking and with the regrtest --forever flag. We fix that here by clearing each of the three modules after loading them. We also tweak a check in _modules_by_index_check(). (cherry picked from commit ae7b17673f29efe17b416cbcfbf43b5b3ff5977c) Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
* [3.13] gh-119560: Drop an Invalid Assert in PyState_FindModule() (gh-119561) ↵Miss Islington (bot)2024-05-271-2/+1
| | | | | | | | | (gh-119632) The assertion was added in gh-118532 but was based on the invalid assumption that PyState_FindModule() would only be called with an already-initialized module def. I've added a test to make sure we don't make that assumption again. (cherry picked from commit 0c5ebe13e9937c446e9947c44f2570737ecca135) Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
* [3.13] gh-111997: Fix argument count for LINE event and clarify type of ↵Miss Islington (bot)2024-05-261-10/+12
| | | | | | | | argument counts. (GH-119179) (GH-119575) gh-111997: Fix argument count for LINE event and clarify type of argument counts. (GH-119179) (cherry picked from commit 70b07aa4153c1a914a3d69307d5b258cf7ed16ab) Co-authored-by: scoder <stefan_ml@behnel.de>
* [3.13] gh-118692: Avoid creating unnecessary StopIteration instances for ↵Miss Islington (bot)2024-05-244-18/+21
| | | | | | | | | | monitoring (GH-119216) (#119497) * gh-118692: Avoid creating unnecessary StopIteration instances for monitoring (GH-119216) (cherry picked from commit 6e9863d7a3516cc76d6ce13923b15620499f3855) --------- Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
* [3.13] gh-118727: Don't drop the GIL in `drop_gil()` unless the current ↵Miss Islington (bot)2024-05-232-46/+61
| | | | | | | | | | | | | | | | | | | | thread holds it (GH-118745) (#119474) `drop_gil()` assumes that its caller is attached, which means that the current thread holds the GIL if and only if the GIL is enabled, and the enabled-state of the GIL won't change. This isn't true, though, because `detach_thread()` calls `_PyEval_ReleaseLock()` after detaching and `_PyThreadState_DeleteCurrent()` calls it after removing the current thread from consideration for stop-the-world requests (effectively detaching it). Fix this by remembering whether or not a thread acquired the GIL when it last attached, in `PyThreadState._status.holds_gil`, and check this in `drop_gil()` instead of `gil->enabled`. This fixes a crash in `test_multiprocessing_pool_circular_import()`, so I've reenabled it. (cherry picked from commit be1dfccdf2c5c7671b8a549e969b8cf7d60d9936) Co-authored-by: Brett Simmers <swtaarrs@users.noreply.github.com>
* [3.13] gh-119213: Be More Careful About _PyArg_Parser.kwtuple Across ↵Miss Islington (bot)2024-05-221-2/+19
| | | | | | | | | | | | | Interpreters (gh-119331) (gh-119410) _PyArg_Parser holds static global data generated for modules by Argument Clinic. The _PyArg_Parser.kwtuple field is a tuple object, even though it's stored within a static global. In some cases the tuple is statically allocated and thus it's okay that it gets shared by multiple interpreters. However, in other cases the tuple is set lazily, allocated from the heap using the active interprepreter at the point the tuple is needed. This is a problem once that interpreter is destroyed since _PyArg_Parser.kwtuple becomes at dangling pointer, leading to crashes. It isn't a problem if the tuple is allocated under the main interpreter, since its lifetime is bound to the lifetime of the runtime. The solution here is to temporarily switch to the main interpreter. The alternative would be to always statically allocate the tuple. This change also fixes a bug where only the most recent parser was added to the global linked list. (cherry picked from commit 81865002aee8eaaeb3c7e402f86183afa6de77bf) Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
* [3.13] gh-119132: Update sys.version to identify free-threaded or not. ↵Miss Islington (bot)2024-05-181-2/+7
| | | | | | | | (gh-119134) (#119153) gh-119132: Update sys.version to identify free-threaded or not. (gh-119134) (cherry picked from commit c141d4393750c827cbcb3867f0f42997a3bb3528) Co-authored-by: Donghee Na <donghee.na@python.org>
* [3.13] gh-119049: Fix incorrect display of warning which is constructed by C ↵Miss Islington (bot)2024-05-171-3/+2
| | | | | | | | | API (GH-119063) (GH-119106) The source line was not displayed if the warnings module had not yet been imported. (cherry picked from commit 100c7ab00ab66a8c0d54582f35e38d8eb691743c) Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
* [3.13] GH-118844: Fix build failures when combining --disable-gil with ↵Miss Islington (bot)2024-05-132-2/+3
| | | | | | | --enable-experimental-jit (GH-118959) (cherry picked from commit 5b941e57c71d7d0ab983d81a169f892662cfe446) Co-authored-by: Savannah Ostrowski <savannahostrowski@gmail.com>
* [3.13] gh-117657: Fix QSBR race condition (GH-118843) (#118905)Miss Islington (bot)2024-05-102-6/+7
| | | | | | | | | `_Py_qsbr_unregister` is called when the PyThreadState is already detached, so the access to `tstate->qsbr` isn't safe without locking the shared mutex. Grab the `struct _qsbr_shared` from the interpreter instead. (cherry picked from commit 33d20199af65c741bdc908a968edd8dc179b6974) Co-authored-by: Alex Turner <alexturner@meta.com>
* [3.13] gh-117657: Fix data races reported by TSAN on `interp->threads.main` ↵Miss Islington (bot)2024-05-101-11/+20
| | | | | | | | (GH-118865) (#118904) Use relaxed loads/stores when reading/writing to this field. (cherry picked from commit 22d5185308f85efa22ec1e8251c409fe1cbd9e6b) Co-authored-by: mpage <mpage@meta.com>