summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2023-11-03 07:45:53 (GMT)
committerGitHub <noreply@github.com>2023-11-03 07:45:53 (GMT)
commit26c0e5e03a8603eccfd98045bc69fde2e24682e3 (patch)
tree01d7dc811329b0387323350fa881a3301affe461 /Modules
parent0d3df272fbd131bff7f02d4d4279ad1e35081121 (diff)
downloadcpython-26c0e5e03a8603eccfd98045bc69fde2e24682e3.zip
cpython-26c0e5e03a8603eccfd98045bc69fde2e24682e3.tar.gz
cpython-26c0e5e03a8603eccfd98045bc69fde2e24682e3.tar.bz2
gh-108082: Remove _PyErr_WriteUnraisableMsg() (GH-111643)
Replace the remaining calls with PyErr_FormatUnraisable().
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_ctypes/callbacks.c20
-rw-r--r--Modules/_testinternalcapi.c32
-rw-r--r--Modules/_threadmodule.c4
-rw-r--r--Modules/atexitmodule.c4
-rw-r--r--Modules/clinic/_testinternalcapi.c.h34
5 files changed, 16 insertions, 78 deletions
diff --git a/Modules/_ctypes/callbacks.c b/Modules/_ctypes/callbacks.c
index 1bd8fec..154e9f4 100644
--- a/Modules/_ctypes/callbacks.c
+++ b/Modules/_ctypes/callbacks.c
@@ -9,7 +9,6 @@
#endif
#include "pycore_call.h" // _PyObject_CallNoArgs()
-#include "pycore_pyerrors.h" // _PyErr_WriteUnraisableMsg()
#include "pycore_runtime.h" // _Py_ID()
#include <stdbool.h>
@@ -216,8 +215,9 @@ static void _CallPythonObject(void *mem,
result = PyObject_Vectorcall(callable, args, nargs, NULL);
if (result == NULL) {
- _PyErr_WriteUnraisableMsg("on calling ctypes callback function",
- callable);
+ PyErr_FormatUnraisable(
+ "Exception ignored on calling ctypes callback function %R",
+ callable);
}
#ifdef MS_WIN32
@@ -258,9 +258,10 @@ static void _CallPythonObject(void *mem,
if (keep == NULL) {
/* Could not convert callback result. */
- _PyErr_WriteUnraisableMsg("on converting result "
- "of ctypes callback function",
- callable);
+ PyErr_FormatUnraisable(
+ "Exception ignored on converting result "
+ "of ctypes callback function %R",
+ callable);
}
else if (setfunc != _ctypes_get_fielddesc("O")->setfunc) {
if (keep == Py_None) {
@@ -270,9 +271,10 @@ static void _CallPythonObject(void *mem,
else if (PyErr_WarnEx(PyExc_RuntimeWarning,
"memory leak in callback function.",
1) == -1) {
- _PyErr_WriteUnraisableMsg("on converting result "
- "of ctypes callback function",
- callable);
+ PyErr_FormatUnraisable(
+ "Exception ignored on converting result "
+ "of ctypes callback function %R",
+ callable);
}
}
}
diff --git a/Modules/_testinternalcapi.c b/Modules/_testinternalcapi.c
index a71e7e1..7dba29a 100644
--- a/Modules/_testinternalcapi.c
+++ b/Modules/_testinternalcapi.c
@@ -1518,37 +1518,6 @@ restore_crossinterp_data(PyObject *self, PyObject *args)
}
-/*[clinic input]
-_testinternalcapi.write_unraisable_exc
- exception as exc: object
- err_msg: object
- obj: object
- /
-[clinic start generated code]*/
-
-static PyObject *
-_testinternalcapi_write_unraisable_exc_impl(PyObject *module, PyObject *exc,
- PyObject *err_msg, PyObject *obj)
-/*[clinic end generated code: output=a0f063cdd04aad83 input=274381b1a3fa5cd6]*/
-{
-
- const char *err_msg_utf8;
- if (err_msg != Py_None) {
- err_msg_utf8 = PyUnicode_AsUTF8(err_msg);
- if (err_msg_utf8 == NULL) {
- return NULL;
- }
- }
- else {
- err_msg_utf8 = NULL;
- }
-
- PyErr_SetObject((PyObject *)Py_TYPE(exc), exc);
- _PyErr_WriteUnraisableMsg(err_msg_utf8, obj);
- Py_RETURN_NONE;
-}
-
-
static PyObject *
raiseTestError(const char* test_name, const char* msg)
{
@@ -1699,7 +1668,6 @@ static PyMethodDef module_functions[] = {
{"perf_trampoline_set_persist_after_fork", perf_trampoline_set_persist_after_fork, METH_VARARGS},
{"get_crossinterp_data", get_crossinterp_data, METH_VARARGS},
{"restore_crossinterp_data", restore_crossinterp_data, METH_VARARGS},
- _TESTINTERNALCAPI_WRITE_UNRAISABLE_EXC_METHODDEF
_TESTINTERNALCAPI_TEST_LONG_NUMBITS_METHODDEF
{NULL, NULL} /* sentinel */
};
diff --git a/Modules/_threadmodule.c b/Modules/_threadmodule.c
index a849a20..9eecebd 100644
--- a/Modules/_threadmodule.c
+++ b/Modules/_threadmodule.c
@@ -5,7 +5,6 @@
#include "Python.h"
#include "pycore_interp.h" // _PyInterpreterState.threads.count
#include "pycore_moduleobject.h" // _PyModule_GetState()
-#include "pycore_pyerrors.h" // _PyErr_WriteUnraisableMsg()
#include "pycore_pylifecycle.h"
#include "pycore_pystate.h" // _PyThreadState_SetCurrent()
#include "pycore_sysmodule.h" // _PySys_GetAttr()
@@ -1071,7 +1070,8 @@ thread_run(void *boot_raw)
/* SystemExit is ignored silently */
PyErr_Clear();
else {
- _PyErr_WriteUnraisableMsg("in thread started by", boot->func);
+ PyErr_FormatUnraisable(
+ "Exception ignored in thread started by %R", boot->func);
}
}
else {
diff --git a/Modules/atexitmodule.c b/Modules/atexitmodule.c
index 57e2ea6..b6f1bcb 100644
--- a/Modules/atexitmodule.c
+++ b/Modules/atexitmodule.c
@@ -10,7 +10,6 @@
#include "pycore_atexit.h" // export _Py_AtExit()
#include "pycore_initconfig.h" // _PyStatus_NO_MEMORY
#include "pycore_interp.h" // PyInterpreterState.atexit
-#include "pycore_pyerrors.h" // _PyErr_WriteUnraisableMsg()
#include "pycore_pystate.h" // _PyInterpreterState_GET
/* ===================================================================== */
@@ -137,7 +136,8 @@ atexit_callfuncs(struct atexit_state *state)
PyObject* the_func = Py_NewRef(cb->func);
PyObject *res = PyObject_Call(cb->func, cb->args, cb->kwargs);
if (res == NULL) {
- _PyErr_WriteUnraisableMsg("in atexit callback", the_func);
+ PyErr_FormatUnraisable(
+ "Exception ignored in atexit callback %R", the_func);
}
else {
Py_DECREF(res);
diff --git a/Modules/clinic/_testinternalcapi.c.h b/Modules/clinic/_testinternalcapi.c.h
index 10374e0..cba2a94 100644
--- a/Modules/clinic/_testinternalcapi.c.h
+++ b/Modules/clinic/_testinternalcapi.c.h
@@ -266,38 +266,6 @@ exit:
return return_value;
}
-PyDoc_STRVAR(_testinternalcapi_write_unraisable_exc__doc__,
-"write_unraisable_exc($module, exception, err_msg, obj, /)\n"
-"--\n"
-"\n");
-
-#define _TESTINTERNALCAPI_WRITE_UNRAISABLE_EXC_METHODDEF \
- {"write_unraisable_exc", _PyCFunction_CAST(_testinternalcapi_write_unraisable_exc), METH_FASTCALL, _testinternalcapi_write_unraisable_exc__doc__},
-
-static PyObject *
-_testinternalcapi_write_unraisable_exc_impl(PyObject *module, PyObject *exc,
- PyObject *err_msg, PyObject *obj);
-
-static PyObject *
-_testinternalcapi_write_unraisable_exc(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
-{
- PyObject *return_value = NULL;
- PyObject *exc;
- PyObject *err_msg;
- PyObject *obj;
-
- if (!_PyArg_CheckPositional("write_unraisable_exc", nargs, 3, 3)) {
- goto exit;
- }
- exc = args[0];
- err_msg = args[1];
- obj = args[2];
- return_value = _testinternalcapi_write_unraisable_exc_impl(module, exc, err_msg, obj);
-
-exit:
- return return_value;
-}
-
PyDoc_STRVAR(_testinternalcapi_test_long_numbits__doc__,
"test_long_numbits($module, /)\n"
"--\n"
@@ -314,4 +282,4 @@ _testinternalcapi_test_long_numbits(PyObject *module, PyObject *Py_UNUSED(ignore
{
return _testinternalcapi_test_long_numbits_impl(module);
}
-/*[clinic end generated code: output=3425f97821fc7462 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=679bf53bbae20085 input=a9049054013a1b77]*/