summaryrefslogtreecommitdiffstats
path: root/Programs/_testembed.c
diff options
context:
space:
mode:
authorSteve Dower <steve.dower@python.org>2020-07-03 23:04:22 (GMT)
committerGitHub <noreply@github.com>2020-07-03 23:04:22 (GMT)
commitb9e288cc1bfd583e887f784e38d9c511b43c0c3a (patch)
tree7fedd13907d72e5b3ccd862a05a15cac9ecc577b /Programs/_testembed.c
parentc1d916595eb6979d4d87cc3e5216e26b3c6fac25 (diff)
downloadcpython-b9e288cc1bfd583e887f784e38d9c511b43c0c3a.zip
cpython-b9e288cc1bfd583e887f784e38d9c511b43c0c3a.tar.gz
cpython-b9e288cc1bfd583e887f784e38d9c511b43c0c3a.tar.bz2
bpo-41162: Clear audit hooks later during finalization (GH-21222)
Co-authored-by: Konge <zkonge@outlook.com>
Diffstat (limited to 'Programs/_testembed.c')
-rw-r--r--Programs/_testembed.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/Programs/_testembed.c b/Programs/_testembed.c
index b98a38a..460d70c 100644
--- a/Programs/_testembed.c
+++ b/Programs/_testembed.c
@@ -1106,8 +1106,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;
@@ -1116,6 +1119,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;
}
@@ -1161,6 +1166,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;
}