summaryrefslogtreecommitdiffstats
path: root/Python/clinic
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2024-11-08 13:11:44 (GMT)
committerGitHub <noreply@github.com>2024-11-08 13:11:44 (GMT)
commita93fc0969e4d57a2ecfe18cbba7de2d5ee757e2c (patch)
tree8e8c7fdc5083b68738c5991f6f55c15879434003 /Python/clinic
parenta3e8e7bbc3d39e9e6cfa5605df9524076176a041 (diff)
downloadcpython-a93fc0969e4d57a2ecfe18cbba7de2d5ee757e2c.zip
cpython-a93fc0969e4d57a2ecfe18cbba7de2d5ee757e2c.tar.gz
cpython-a93fc0969e4d57a2ecfe18cbba7de2d5ee757e2c.tar.bz2
gh-126579: Adapt sys.audit() to Argument Clinic (GH-126580)
Diffstat (limited to 'Python/clinic')
-rw-r--r--Python/clinic/sysmodule.c.h51
1 files changed, 50 insertions, 1 deletions
diff --git a/Python/clinic/sysmodule.c.h b/Python/clinic/sysmodule.c.h
index 1777dbe..86c42ce 100644
--- a/Python/clinic/sysmodule.c.h
+++ b/Python/clinic/sysmodule.c.h
@@ -7,6 +7,7 @@ preserve
# include "pycore_runtime.h" // _Py_ID()
#endif
#include "pycore_modsupport.h" // _PyArg_UnpackKeywords()
+#include "pycore_tuple.h" // _PyTuple_FromArray()
PyDoc_STRVAR(sys_addaudithook__doc__,
"addaudithook($module, /, hook)\n"
@@ -64,6 +65,54 @@ exit:
return return_value;
}
+PyDoc_STRVAR(sys_audit__doc__,
+"audit($module, event, /, *args)\n"
+"--\n"
+"\n"
+"Passes the event to any audit hooks that are attached.");
+
+#define SYS_AUDIT_METHODDEF \
+ {"audit", _PyCFunction_CAST(sys_audit), METH_FASTCALL, sys_audit__doc__},
+
+static PyObject *
+sys_audit_impl(PyObject *module, const char *event, PyObject *args);
+
+static PyObject *
+sys_audit(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
+{
+ PyObject *return_value = NULL;
+ const char *event;
+ PyObject *__clinic_args = NULL;
+
+ if (!_PyArg_CheckPositional("audit", nargs, 1, PY_SSIZE_T_MAX)) {
+ goto exit;
+ }
+ if (!PyUnicode_Check(args[0])) {
+ _PyArg_BadArgument("audit", "argument 1", "str", args[0]);
+ goto exit;
+ }
+ Py_ssize_t event_length;
+ event = PyUnicode_AsUTF8AndSize(args[0], &event_length);
+ if (event == NULL) {
+ goto exit;
+ }
+ if (strlen(event) != (size_t)event_length) {
+ PyErr_SetString(PyExc_ValueError, "embedded null character");
+ goto exit;
+ }
+ __clinic_args = _PyTuple_FromArray(args + 1, nargs - 1);
+ if (__clinic_args == NULL) {
+ goto exit;
+ }
+ return_value = sys_audit_impl(module, event, __clinic_args);
+
+exit:
+ /* Cleanup for args */
+ Py_XDECREF(__clinic_args);
+
+ return return_value;
+}
+
PyDoc_STRVAR(sys_displayhook__doc__,
"displayhook($module, object, /)\n"
"--\n"
@@ -1619,4 +1668,4 @@ exit:
#ifndef SYS_GETANDROIDAPILEVEL_METHODDEF
#define SYS_GETANDROIDAPILEVEL_METHODDEF
#endif /* !defined(SYS_GETANDROIDAPILEVEL_METHODDEF) */
-/*[clinic end generated code: output=cf24c260a269a5d2 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=6d4f6cd20419b675 input=a9049054013a1b77]*/