* EOFError no longer overrides other errors such as MemoryError or OSError at
the start of the object.
* Raise more relevant error when the NULL object occurs as a code object
component.
* Minimize an overhead of calling PyErr_Occurred().
(cherry picked from commit 8bf6904b22)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
[3.12] gh-106033: Get rid of new occurrences of PyDict_GetItem and PyObject_HasAttr (GH-106034)
These functions are broken by design because they discard any exceptions raised
inside, including MemoryError and KeyboardInterrupt. They should not be
used in new code.
(cherry picked from commit 1d33d53780)
GH-105840: Fix assertion failures when specializing calls with too many __defaults__ (GH-105847)
(cherry picked from commit 2beab5bdef)
Co-authored-by: Brandt Bucher <brandtbucher@microsoft.com>
This fixes a race during import. The existing _PyRuntimeState.imports.pkgcontext is shared between interpreters, and occasionally this would cause a crash when multiple interpreters were importing extensions modules at the same time. To solve this we add a thread-local variable for the value. We also leave the existing state (and infrequent race) in place for platforms that do not support thread-local variables.
(cherry picked from commit b87d288275)
Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
For a while now, pending calls only run in the main thread (in the main interpreter). This PR changes things to allow any thread run a pending call, unless the pending call was explicitly added for the main thread to run.
(cherry picked from commit 757b402)
We are changing it to be more flexible that a strict bool can be for possible future expanded used cases.
(cherry picked from commit b97e14a806)
Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
In sys_add_xoption(), 'value' may be uninitialized for some error paths.
(cherry picked from commit a8d69fe92c)
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
In _PySys_AddXOptionWithError() and sys_add_xoption(),
bail on first error to prevent exceptions from possibly being
overwritten.
(cherry picked from commit 41cddc2e93)
Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
Bail on first error to prevent exceptions from possibly being
overwritten.
(cherry picked from commit 567d6ae8e7)
Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
The risk of a race with this state is relatively low, but we play it safe anyway. We do avoid using the lock in performance-sensitive cases where the risk of a race is very, very low.
(cherry picked from commit 68dfa49627)
Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
The risk of a race with this state is relatively low, but we play it safe anyway.
(cherry picked from commit 7799c8e678)
Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
gh-105184: document that marshal functions can fail and need to be checked with PyErr_Occurred (GH-105185)
(cherry picked from commit ee26ca13a1)
Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
This avoids the problematic race in drop_gil() by skipping the FORCE_SWITCHING code there for finalizing threads.
(The idea for this approach came out of discussions with @markshannon.)
(cherry picked from commit 3698fda)
Co-authored-by: Eric Snow ericsnowcurrently@gmail.com
gh-105069: Add a readline-like callable to the tokenizer to consume input iteratively (GH-105070)
(cherry picked from commit 9216e69a87)
Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
gh-105017: Include CRLF lines in strings and column numbers (GH-105030)
(cherry picked from commit 96fff35325)
Co-authored-by: Marta Gómez Macías <mgmacias@google.com>
Co-authored-by: Pablo Galindo <pablogsal@gmail.com>
gh-104972: Ensure that line attributes in tokens in the tokenize module are correct (GH-104975)
(cherry picked from commit 3fdb55c482)
Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
This commit replaces the Python implementation of the tokenize module with an implementation
that reuses the real C tokenizer via a private extension module. The tokenize module now implements
a compatibility layer that transforms tokens from the C tokenizer into Python tokenize tokens for backward
compatibility.
As the C tokenizer does not emit some tokens that the Python tokenizer provides (such as comments and non-semantic newlines), a new special mode has been added to the C tokenizer mode that currently is only used via
the extension module that exposes it to the Python layer. This new mode forces the C tokenizer to emit these new extra tokens and add the appropriate metadata that is needed to match the old Python implementation.
Co-authored-by: Pablo Galindo <pablogsal@gmail.com>