PyImport_GetImporter() now sets RuntimeError if it fails to get sys.path_hooks
or sys.path_importer_cache or they are not list and dict correspondingly.
Previously it could return NULL without setting error in obscure cases,
crash or raise SystemError if these attributes have wrong type.
(cherry picked from commit 62c7015e89)
gh-110052: Fix faulthandler for freed tstate (#110069)
faulthandler now detected freed interp and freed tstate, and no
longer dereference them.
Backport to 3.11: add pycore_pymem.h include to traceback.c.
(cherry picked from commit 2e37a38bcb)
gh-108987: Fix _thread.start_new_thread() race condition (#109135)
Fix _thread.start_new_thread() race condition. If a thread is created
during Python finalization, the newly spawned thread now exits
immediately instead of trying to access freed memory and lead to a
crash.
thread_run() calls PyEval_AcquireThread() which checks if the thread
must exit. The problem was that tstate was dereferenced earlier in
_PyThreadState_Bind() which leads to a crash most of the time.
Move _PyThreadState_CheckConsistency() from thread_run() to
_PyThreadState_Bind().
(cherry picked from commit 517cd82ea7)
gh-104690: thread_run() checks for tstate dangling pointer (#109056)
thread_run() of _threadmodule.c now calls
_PyThreadState_CheckConsistency() to check if tstate is a dangling
pointer when Python is built in debug mode.
Rename ceval_gil.c is_tstate_valid() to
_PyThreadState_CheckConsistency() to reuse it in _threadmodule.c.
(cherry picked from commit f63d37877a)
Functions like PyErr_SetFromErrno() and SetFromWindowsErr() should be
called immediately after using the C API which sets errno or the Windows
error code.
(cherry picked from commit 2b15536fa9)
Such C API functions as PyErr_SetString(), PyErr_Format(),
PyErr_SetFromErrnoWithFilename() and many others no longer crash or
ignore errors if it failed to format the error message or decode the
filename. Instead, they keep a corresponding error.
(cherry picked from commit 633ea217a8)
* 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.11] 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)
* PyUnicode_CompareWithASCIIString() only works if the second argument
is ASCII string.
* Refleak in get_suggestions_for_name_error.
* Add some missing error checks.
(cherry picked from commit c8c162ef52)
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>
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>
(cherry picked from commit 41cddc2e93)
In _PySys_AddXOptionWithError() and sys_add_xoption(),
bail on first error to prevent exceptions from possibly being
overwritten.
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>
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>
gh-104018: remove unused format "z" handling in string formatfloat() (GH-104107)
This is a cleanup overlooked in PR GH-104033.
(cherry picked from commit 69621d1b09)
Co-authored-by: John Belmonte <john@neggie.net>
The error-handling code in new_interpreter() has been broken for a while. We hadn't noticed because those code mostly doesn't fail. (I noticed while working on gh-101660.) The problem is that we try to clear/delete the newly-created thread/interpreter using itself, which just failed. The solution is to switch back to the calling thread state first.
(cherry picked from commit d1b883b52a)
Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
https: //github.com/python/cpython/issues/98608
Add thrashcan macros to the deallocator of the filter objects to protect against deeply nested destruction of chains of nested filters.
(cherry picked from commit 66aa78cbe6)
Co-authored-by: Marta Gómez Macías <mgmacias@google.com>