8000 Address Serhiy's review · python/cpython@1324111 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1324111

Browse files
committed
Address Serhiy's review
Raise SystemError if event is NULL or if "N" format is used.
1 parent 47ef8f0 commit 1324111

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

Doc/c-api/sys.rst

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -298,16 +298,18 @@ accessible to C code. They all work with the current interpreter thread's
298298
as used in :c:func:`Py_BuildValue` are available. If the built value is not
299299
a tuple, it will be added into a single-element tuple.
300300
301-
:exc:`ValueError` is raised if the ``N`` format is used in *format*. The
302-
``N`` format option consumes a reference, but since there is no way to know
303-
whether arguments to this function will be consumed, using it may cause
304-
reference leaks.
301+
The ``N`` format option must not be used. It consumes a reference, but since
302+
there is no way to know whether arguments to this function will be consumed,
303+
using it may cause reference leaks.
305304
306305
Note that ``#`` format characters should always be treated as
307306
:c:type:`Py_ssize_t`, regardless of whether ``PY_SSIZE_T_CLEAN`` was defined.
308307
309308
:func:`sys.audit` performs the same function from Python code.
310309
310+
Raise :exc:`SystemError` and return *NULL* if *event* is *NULL* or if the
311+
``N`` format option is used.
312+
311313
See also :c:func:`PySys_AuditTuple`.
312314
313315
.. versionadded:: 3.8

Python/sysmodule.c

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -214,15 +214,15 @@ sys_audit_tstate(PyThreadState *ts, const char *event,
214214
}
215215

216216
if (event == NULL) {
217-
_PyErr_SetString(ts, PyExc_ValueError,
217+
_PyErr_SetString(ts, PyExc_SystemError,
218218
"event argument must not be NULL");
219219
return -1;
220220
}
221221

222222
/* N format is inappropriate, because you do not know
223223
whether the reference is consumed by the call. */
224224
if (argFormat != NULL && strchr(argFormat, 'N')) {
225-
_PyErr_SetString(ts, PyExc_ValueError,
225+
_PyErr_SetString(ts, PyExc_SystemError,
226226
"N format must not be used in the format argument");
227227
return -1;
228228
}
@@ -357,18 +357,16 @@ PySys_Audit(const char *event, const char *argFormat, ...)
357357
int
358358
PySys_AuditTuple(const char *event, PyObject *args)
359359
{
360-
if (args) {
361-
if (!PyTuple_Check(args)) {
362-
PyErr_Format(PyExc_TypeError, "args must be tuple, got %s",
363-
Py_TYPE(args)->tp_name);
364-
return -1;
365-
}
366-
367-
return PySys_Audit(event, "O", args);
368-
}
369-
else {
360+
if (args == NULL) {
370361
return PySys_Audit(event, NULL);
371362
}
363+
364+
if (!PyTuple_Check(args)) {
365+
PyErr_Format(PyExc_TypeError, "args must be tuple, got %s",
366+
Py_TYPE(args)->tp_name);
367+
return -1;
368+
}
369+
return PySys_Audit(event, "O", args);
372370
}
373371

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

0 commit comments

Comments
 (0)
0