aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonge <zkonge@outlook.com>2020-07-04 05:06:46 +0800
committerGitHub <noreply@github.com>2020-07-03 22:06:46 +0100
commitdaa0fe03a517d335d48e65ace8e5da636e265a8f (patch)
treed6504f9bc7ae8a6c8d14c0da18e6e46c138231fb /Programs
parentbpo-41180: Audit code.__new__ when unmarshalling (GH-21271) (diff)
downloadcpython-daa0fe03a517d335d48e65ace8e5da636e265a8f.tar.gz
cpython-daa0fe03a517d335d48e65ace8e5da636e265a8f.tar.bz2
cpython-daa0fe03a517d335d48e65ace8e5da636e265a8f.zip
bpo-41162: Clear audit hooks later during finalization (GH-21222)
Diffstat (limited to 'Programs')
-rw-r--r--Programs/_testembed.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/Programs/_testembed.c b/Programs/_testembed.c
index b60d70be5f..5aad16a6f7 100644
--- a/Programs/_testembed.c
+++ b/Programs/_testembed.c
@@ -1112,8 +1112,11 @@ static int test_open_code_hook(void)
return result;
}
+static int _audit_hook_clear_count = 0;
+
static int _audit_hook(const char *event, PyObject *args, void *userdata)
{
+ assert(args && PyTuple_CheckExact(args));
if (strcmp(event, "_testembed.raise") == 0) {
PyErr_SetString(PyExc_RuntimeError, "Intentional error");
return -1;
@@ -1122,6 +1125,8 @@ static int _audit_hook(const char *event, PyObject *args, void *userdata)
return -1;
}
return 0;
+ } else if (strcmp(event, "cpython._PySys_ClearAuditHooks") == 0) {
+ _audit_hook_clear_count += 1;
}
return 0;
}
@@ -1167,6 +1172,9 @@ static int test_audit(void)
{
int result = _test_audit(42);
Py_Finalize();
+ if (_audit_hook_clear_count != 1) {
+ return 0x1000 | _audit_hook_clear_count;
+ }
return result;
}