Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[3.14] gh-143547: Fix PyErr_FormatUnraisable() fallback (#143557)#143603

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
vstinner merged 1 commit intopython:3.14fromvstinner:unraisablehook14
Jan 9, 2026
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletionsLib/test/test_sys.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1480,6 +1480,7 @@ def hook_func(args):
def test_custom_unraisablehook_fail(self):
_testcapi = import_helper.import_module('_testcapi')
from _testcapi import err_writeunraisable

def hook_func(*args):
raise Exception("hook_func failed")

Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
Fix :func:`sys.unraisablehook` when the hook raises an exception and changes
:func:`sys.unraisablehook`: hold a strong reference to the old hook. Patch
by Victor Stinner.
6 changes: 2 additions & 4 deletionsPython/errors.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1632,6 +1632,7 @@ format_unraisable_v(const char *format, va_list va, PyObject *obj)
_Py_EnsureTstateNotNULL(tstate);

PyObject *err_msg = NULL;
PyObject *hook = NULL;
PyObject *exc_type, *exc_value, *exc_tb;
_PyErr_Fetch(tstate, &exc_type, &exc_value, &exc_tb);

Expand DownExpand Up@@ -1676,7 +1677,6 @@ format_unraisable_v(const char *format, va_list va, PyObject *obj)
goto error;
}

PyObject *hook;
if (_PySys_GetOptionalAttr(&_Py_ID(unraisablehook), &hook) < 0) {
Py_DECREF(hook_args);
err_msg_str = NULL;
Expand All@@ -1689,21 +1689,18 @@ format_unraisable_v(const char *format, va_list va, PyObject *obj)
}

if (_PySys_Audit(tstate, "sys.unraisablehook", "OO", hook, hook_args) < 0) {
Py_DECREF(hook);
Py_DECREF(hook_args);
err_msg_str = "Exception ignored in audit hook";
obj = NULL;
goto error;
}

if (hook == Py_None) {
Py_DECREF(hook);
Py_DECREF(hook_args);
goto default_hook;
}

PyObject *res = PyObject_CallOneArg(hook, hook_args);
Py_DECREF(hook);
Py_DECREF(hook_args);
if (res != NULL) {
Py_DECREF(res);
Expand DownExpand Up@@ -1733,6 +1730,7 @@ format_unraisable_v(const char *format, va_list va, PyObject *obj)
Py_XDECREF(exc_value);
Py_XDECREF(exc_tb);
Py_XDECREF(err_msg);
Py_XDECREF(hook);
_PyErr_Clear(tstate); /* Just in case */
}

Expand Down
Loading

[8]ページ先頭

©2009-2026 Movatter.jp