Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitddbd851

Browse files
committed
Address Serhiy's review
Raise SystemError if event is NULL or if "N" format is used.
1 parent232e611 commitddbd851

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
@@ -212,15 +212,15 @@ sys_audit_tstate(PyThreadState *ts, const char *event,
212212
}
213213

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

220220
/* N format is inappropriate, because you do not know
221221
whether the reference is consumed by the call. */
222222
if (argFormat!=NULL&&strchr(argFormat,'N')) {
223-
_PyErr_SetString(ts,PyExc_ValueError,
223+
_PyErr_SetString(ts,PyExc_SystemError,
224224
"N format must not be used in the format argument");
225225
return-1;
226226
}
@@ -355,18 +355,16 @@ PySys_Audit(const char *event, const char *argFormat, ...)
355355
int
356356
PySys_AuditTuple(constchar*event,PyObject*args)
357357
{
358-
if (args) {
359-
if (!PyTuple_Check(args)) {
360-
PyErr_Format(PyExc_TypeError,"args must be tuple, got %s",
361-
Py_TYPE(args)->tp_name);
362-
return-1;
363-
}
364-
365-
returnPySys_Audit(event,"O",args);
366-
}
367-
else {
358+
if (args==NULL) {
368359
returnPySys_Audit(event,NULL);
369360
}
361+
362+
if (!PyTuple_Check(args)) {
363+
PyErr_Format(PyExc_TypeError,"args must be tuple, got %s",
364+
Py_TYPE(args)->tp_name);
365+
return-1;
366+
}
367+
returnPySys_Audit(event,"O",args);
370368
}
371369

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp