summaryrefslogtreecommitdiffstats
path: root/Python
Commit message (Collapse)AuthorAgeFilesLines
* [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>
* [3.13] gh-118851: Default ctx arguments to AST constructors to Load() ↵Miss Islington (bot)2024-05-091-0/+7
| | | | | | | | (GH-118854) (#118871) (cherry picked from commit 68fbc00dc870f6a8dcbecd2ec19298e21015867f) Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com> Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
* gh-118518: Rename `PYTHONPERFJITSUPPORT` and `-X perfjit` with underscores ↵Hugo van Kemenade2024-05-072-3/+3
| | | | (#118693)
* gh-118414: Fix assertion in YIELD_VALUE when tracing lines or instrs (#118683)Tian Gao2024-05-073-3/+9
|
* gh-117953: Always Run Extension Init Func in Main Interpreter First (gh-118157)Eric Snow2024-05-071-55/+197
| | | This change makes sure all extension/builtin modules have their init function run first by the main interpreter before proceeding with import in the original interpreter (main or otherwise). This means when the import of a single-phase init module fails in an isolated subinterpreter, it won't tie any global state/callbacks to the subinterpreter.
* gh-117953: Imply Single-phase Init if the Init Function Fails (gh-118684)Eric Snow2024-05-071-0/+7
| | | This ensures the kind is always either _Py_ext_module_kind_SINGLEPHASE or _Py_ext_module_kind_MULTIPHASE.
* gh-116322: Enable the GIL while loading C extension modules (#118560)Brett Simmers2024-05-074-26/+269
| | | | | | | | | | Add the ability to enable/disable the GIL at runtime, and use that in the C module loading code. We can't know before running a module init function if it supports free-threading, so the GIL is temporarily enabled before doing so. If the module declares support for running without the GIL, the GIL is later disabled. Otherwise, the GIL is permanently enabled, and will never be disabled again for the life of the current interpreter.
* gh-112075: use per-thread dict version pool (#118676)Dino Viehland2024-05-071-0/+1
| | | use thread state set of dict versions
* gh-118527: Intern code consts in free-threaded build (#118667)Sam Gross2024-05-073-0/+21
| | | | | | We already intern and immortalize most string constants. In the free-threaded build, other constants can be a source of reference count contention because they are shared by all threads running the same code objects.
* gh-118473: Fix set_asyncgen_hooks not to be partially set when arguments are ↵Jeong, YunWon2024-05-071-8/+20
| | | | invalid (#118474)
* gh-117486: Improve behavior for user-defined AST subclasses (#118212)Jelle Zijlstra2024-05-061-14/+17
| | | | | | | | Now, such classes will no longer require changes in Python 3.13 in the normal case. The test suite for robotframework passes with no DeprecationWarnings under this PR. I also added a new DeprecationWarning for the case where `_field_types` exists but is incomplete, since that seems likely to indicate a user mistake.
* GH-115709: Invalidate executors when a local variable is changed via ↵Mark Shannon2024-05-062-0/+6
| | | | | frame.f_locals (#118639) Also fix unrelated assert in debug Tier2/JIT builds.
* gh-118415: Fix issues with local tracing being enabled/disabled on a ↵Dino Viehland2024-05-061-46/+45
| | | | function (#118496)
* gh-118518: Ensure that the code padding it's applied (#118654)Pablo Galindo Salgado2024-05-061-1/+1
|
* gh-116322: Rename PyModule_ExperimentalSetGIL to PyUnstable_Module_SetGIL ↵Petr Viktorin2024-05-062-2/+2
| | | | (GH-118645)
* gh-118518: Correct type of perf_profiling in config (#118646)Pablo Galindo Salgado2024-05-061-1/+1
|
* gh-118465: Add __firstlineno__ attribute to class (GH-118475)Serhiy Storchaka2024-05-061-0/+5
| | | | It is set by compiler with the line number of the first line of the class definition.
* gh-118613: Fix error handling of `_PyEval_GetFrameLocals` in `ceval.c` (#118614)Nikita Sobolev2024-05-061-4/+8
|
* gh-111201: A new Python REPL (GH-111567)Pablo Galindo Salgado2024-05-054-3/+36
| | | | | | | Co-authored-by: Łukasz Langa <lukasz@langa.pl> Co-authored-by: Marta Gómez Macías <mgmacias@google.com> Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com> Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
* gh-118518: Use the raw syscall directly for gettid (#118592)Pablo Galindo Salgado2024-05-051-1/+2
|
* gh-110850: Remove _PyTime_TimeUnchecked() function (#118552)Victor Stinner2024-05-057-63/+51
| | | | | | | | | | | | | Use the new public Raw functions: * _PyTime_PerfCounterUnchecked() with PyTime_PerfCounterRaw() * _PyTime_TimeUnchecked() with PyTime_TimeRaw() * _PyTime_MonotonicUnchecked() with PyTime_MonotonicRaw() Remove internal functions: * _PyTime_PerfCounterUnchecked() * _PyTime_TimeUnchecked() * _PyTime_MonotonicUnchecked()
* gh-118518: Allow perf to work without frame pointers (#112254)Pablo Galindo Salgado2024-05-055-6/+694
|
* gh-117953: Track Extra Details in Global Extensions Cache (gh-118532)Eric Snow2024-05-042-137/+567
| | | | | | | | | | | | We have only been tracking each module's PyModuleDef. However, there are some problems with that. For example, in some cases we load single-phase init extension modules from def->m_base.m_init or def->m_base.m_copy, but if multiple modules share a def then we can end up with unexpected behavior. With this change, we track the following: * PyModuleDef (same as before) * for some modules, its init function or a copy of its __dict__, but specific to that module * whether it is a builtin/core module or a "dynamic" extension * the interpreter (ID) that owns the cached __dict__ (only if cached) This also makes it easier to remember the module's kind (e.g. single-phase init) and if loading it previously failed, which I'm doing separately.