diff options
author | Victor Stinner <vstinner@python.org> | 2023-10-05 21:59:35 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-05 21:59:35 (GMT) |
commit | bb057b337008626139d97269485b1dddf70ae427 (patch) | |
tree | 72f3c3f1a9de9e5aff9926aba7c4def0c1053c44 /Python | |
parent | aaf297c048694cd9652790f8b74e69f7ddadfbde (diff) | |
download | cpython-bb057b337008626139d97269485b1dddf70ae427.zip cpython-bb057b337008626139d97269485b1dddf70ae427.tar.gz cpython-bb057b337008626139d97269485b1dddf70ae427.tar.bz2 |
gh-85283: Add PySys_AuditTuple() function (#108965)
sys.audit() now has assertions to check that the event argument is
not NULL and that the format argument does not use the "N" format.
Add tests on PySys_AuditTuple().
Diffstat (limited to 'Python')
-rw-r--r-- | Python/sysmodule.c | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/Python/sysmodule.c b/Python/sysmodule.c index b003017..a7ce07d 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -191,9 +191,7 @@ static int sys_audit_tstate(PyThreadState *ts, const char *event, const char *argFormat, va_list vargs) { - /* N format is inappropriate, because you do not know - whether the reference is consumed by the call. - Assert rather than exception for perf reasons */ + assert(event != NULL); assert(!argFormat || !strchr(argFormat, 'N')); if (!ts) { @@ -338,6 +336,21 @@ PySys_Audit(const char *event, const char *argFormat, ...) return res; } +int +PySys_AuditTuple(const char *event, PyObject *args) +{ + if (args == NULL) { + return PySys_Audit(event, NULL); + } + + if (!PyTuple_Check(args)) { + PyErr_Format(PyExc_TypeError, "args must be tuple, got %s", + Py_TYPE(args)->tp_name); + return -1; + } + return PySys_Audit(event, "O", args); +} + /* We expose this function primarily for our own cleanup during * finalization. In general, it should not need to be called, * and as such the function is not exported. @@ -509,6 +522,9 @@ sys_audit(PyObject *self, PyObject *const *args, Py_ssize_t argc) return NULL; } + assert(args[0] != NULL); + assert(PyUnicode_Check(args[0])); + if (!should_audit(tstate->interp)) { Py_RETURN_NONE; } |