|
26 | 26 | #include "pycore_object.h" // _PyObject_IsFreed() |
27 | 27 | #include "pycore_pathconfig.h" // _PyPathConfig_ClearGlobal() |
28 | 28 | #include "pycore_pyerrors.h" // _PyErr_ChainExceptions1() |
29 | | -#include "pycore_pyerrors.h" // _Py_UTF8_Edit_Cost() |
30 | 29 | #include "pycore_pystate.h" // _PyThreadState_GET() |
31 | 30 |
|
32 | 31 | #include "interpreteridobject.h" // PyInterpreterID_LookUp() |
@@ -1448,6 +1447,37 @@ run_in_subinterp_with_config(PyObject *self, PyObject *args, PyObject *kwargs) |
1448 | 1447 | } |
1449 | 1448 |
|
1450 | 1449 |
|
| 1450 | +/*[clinic input] |
| 1451 | +_testinternalcapi.write_unraisable_exc |
| 1452 | + exception as exc: object |
| 1453 | + err_msg: object |
| 1454 | + obj: object |
| 1455 | + / |
| 1456 | +[clinic start generated code]*/ |
| 1457 | + |
| 1458 | +static PyObject * |
| 1459 | +_testinternalcapi_write_unraisable_exc_impl(PyObject *module, PyObject *exc, |
| 1460 | + PyObject *err_msg, PyObject *obj) |
| 1461 | +/*[clinic end generated code: output=a0f063cdd04aad83 input=274381b1a3fa5cd6]*/ |
| 1462 | +{ |
| 1463 | + |
| 1464 | + const char *err_msg_utf8; |
| 1465 | + if (err_msg != Py_None) { |
| 1466 | + err_msg_utf8 = PyUnicode_AsUTF8(err_msg); |
| 1467 | + if (err_msg_utf8 == NULL) { |
| 1468 | + return NULL; |
| 1469 | + } |
| 1470 | + } |
| 1471 | + else { |
| 1472 | + err_msg_utf8 = NULL; |
| 1473 | + } |
| 1474 | + |
| 1475 | + PyErr_SetObject((PyObject *)Py_TYPE(exc), exc); |
| 1476 | + _PyErr_WriteUnraisableMsg(err_msg_utf8, obj); |
| 1477 | + Py_RETURN_NONE; |
| 1478 | +} |
| 1479 | + |
| 1480 | + |
1451 | 1481 | static PyMethodDef module_functions[] = { |
1452 | 1482 | {"get_configs", get_configs, METH_NOARGS}, |
1453 | 1483 | {"get_recursion_depth", get_recursion_depth, METH_NOARGS}, |
@@ -1503,6 +1533,7 @@ static PyMethodDef module_functions[] = { |
1503 | 1533 | {"run_in_subinterp_with_config", |
1504 | 1534 | _PyCFunction_CAST(run_in_subinterp_with_config), |
1505 | 1535 | METH_VARARGS | METH_KEYWORDS}, |
| 1536 | + _TESTINTERNALCAPI_WRITE_UNRAISABLE_EXC_METHODDEF |
1506 | 1537 | {NULL, NULL} /* sentinel */ |
1507 | 1538 | }; |
1508 | 1539 |
|
|
0 commit comments