bpo-38920: Add audit hooks for when sys.excepthook and sys.unraisablehook are invoked (GH-17392)
Also fixes some potential segfaults in unraisable hook handling.
diff --git a/Python/sysmodule.c b/Python/sysmodule.c
index 5b0fb81..1255665 100644
--- a/Python/sysmodule.c
+++ b/Python/sysmodule.c
@@ -293,8 +293,8 @@
/* Cannot invoke hooks until we are initialized */
if (Py_IsInitialized()) {
if (PySys_Audit("sys.addaudithook", NULL) < 0) {
- if (PyErr_ExceptionMatches(PyExc_Exception)) {
- /* We do not report errors derived from Exception */
+ if (PyErr_ExceptionMatches(PyExc_RuntimeError)) {
+ /* We do not report errors derived from RuntimeError */
PyErr_Clear();
return 0;
}