Skip to content

Commit 01acad0

Browse files
committed
PySys_AuditTuple() now just calls PySys_Audit()
1 parent a1db71f commit 01acad0

File tree

3 files changed

+18
-39
lines changed

3 files changed

+18
-39
lines changed

Doc/c-api/sys.rst

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,9 +316,8 @@ accessible to C code. They all work with the current interpreter thread's
316316
317317
.. c:function:: int PySys_AuditTuple(const char *event, PyObject *args)
318318
319-
Similar to :c:func:`PySys_Audit`, but event pass arguments as a Python
320-
:class:`tuple` object. *args* can be *NULL* to pass no arguments: it is
321-
treated the same as passing an empty tuple.
319+
Similar to :c:func:`PySys_Audit`, but pass arguments as a Python object. To
320+
pass no arguments, *args* can be *NULL*.
322321
323322
.. versionadded:: 3.13
324323

Programs/_testembed.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1330,30 +1330,30 @@ static int test_audit_tuple(void)
13301330

13311331
assert(!PyErr_Occurred());
13321332

1333-
// pass tuple
1333+
// pass Python tuple object
13341334
PyObject *tuple = Py_BuildValue("(i)", 444);
13351335
if (tuple == NULL) {
13361336
goto error;
13371337
}
13381338
assert(PySys_AuditTuple("_testembed.set", tuple) == 0);
13391339
assert(!PyErr_Occurred());
1340-
Py_DECREF(tuple);
13411340
assert(sawSet == 444);
1341+
Py_DECREF(tuple);
1342+
1343+
// pass Python int object
1344+
PyObject *int_arg = PyLong_FromLong(555);
1345+
if (int_arg == NULL) {
1346+
goto error;
1347+
}
1348+
assert(PySys_AuditTuple("_testembed.set", int_arg) == 0);
1349+
assert(!PyErr_Occurred());
1350+
assert(sawSet == 555);
1351+
Py_DECREF(int_arg);
13421352

13431353
// NULL is accepted and means "no arguments"
13441354
assert(PySys_AuditTuple("_testembed.test_audit_tuple", NULL) == 0);
13451355
assert(!PyErr_Occurred());
13461356

1347-
// wrong argument type
1348-
PyObject *not_tuple = PyLong_FromLong(123);
1349-
if (not_tuple == NULL) {
1350-
goto error;
1351-
}
1352-
assert(PySys_AuditTuple("_testembed.test_audit_tuple", not_tuple) == -1);
1353-
assert(PyErr_ExceptionMatches(PyExc_TypeError));
1354-
PyErr_Clear();
1355-
Py_DECREF(not_tuple);
1356-
13571357
Py_Finalize();
13581358
return 0;
13591359

Python/sysmodule.c

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -378,32 +378,12 @@ PySys_Audit(const char *event, const char *format, ...)
378378
int
379379
PySys_AuditTuple(const char *event, PyObject *args)
380380
{
381-
PyThreadState *tstate = _PyThreadState_GET();
382-
// tstate can be NULL if the function is called before Py_Initialize()
383-
if (!should_audit_tstate(tstate)) {
384-
return 0;
385-
}
386-
387-
int delete_args = 0;
388-
if (args == NULL) {
389-
delete_args = 1;
390-
args = PyTuple_New(0);
391-
if (args == NULL) {
392-
return -1;
393-
}
381+
if (args) {
382+
return PySys_Audit(event, "O", args);
394383
}
395-
else if (!PyTuple_Check(args)) {
396-
_PyErr_Format(tstate, PyExc_TypeError,
397-
"expected tuple, got %s", Py_TYPE(args)->tp_name);
398-
return -1;
399-
}
400-
401-
int res = sys_audit_tuple(tstate, event, args);
402-
403-
if (delete_args) {
404-
Py_DECREF(args);
384+
else {
385+
return PySys_Audit(event, NULL);
405386
}
406-
return res;
407387
}
408388

409389
/* We expose this function primarily for our own cleanup during

0 commit comments

Comments
 (0)