mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Rob Hooft (Patch #101046): use PyArg_ParseTuple everywhere.
This commit is contained in:
parent
3b96d0b199
commit
a2214c37fd
1 changed files with 27 additions and 21 deletions
|
@ -37,7 +37,7 @@ fcntl_fcntl(PyObject *self, PyObject *args)
|
||||||
int len;
|
int len;
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
|
|
||||||
if (PyArg_Parse(args, "(iis#)", &fd, &code, &str, &len)) {
|
if (PyArg_ParseTuple(args, "iis#:fcntl", &fd, &code, &str, &len)) {
|
||||||
if (len > sizeof buf) {
|
if (len > sizeof buf) {
|
||||||
PyErr_SetString(PyExc_ValueError,
|
PyErr_SetString(PyExc_ValueError,
|
||||||
"fcntl string arg too long");
|
"fcntl string arg too long");
|
||||||
|
@ -55,11 +55,9 @@ fcntl_fcntl(PyObject *self, PyObject *args)
|
||||||
}
|
}
|
||||||
|
|
||||||
PyErr_Clear();
|
PyErr_Clear();
|
||||||
if (PyArg_Parse(args, "(ii)", &fd, &code))
|
|
||||||
arg = 0;
|
arg = 0;
|
||||||
else {
|
if (!PyArg_ParseTuple(args, "ii|i;fcntl requires 2 integers and optionally a third integer or a string",
|
||||||
PyErr_Clear();
|
&fd, &code, &arg)) {
|
||||||
if (!PyArg_Parse(args, "(iii)", &fd, &code, &arg))
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
Py_BEGIN_ALLOW_THREADS
|
Py_BEGIN_ALLOW_THREADS
|
||||||
|
@ -79,7 +77,12 @@ static char fcntl_doc [] =
|
||||||
Perform the requested operation on file descriptor fd. The operation\n\
|
Perform the requested operation on file descriptor fd. The operation\n\
|
||||||
is defined by op and is operating system dependent. Typically these\n\
|
is defined by op and is operating system dependent. Typically these\n\
|
||||||
codes can be retrieved from the library module FCNTL. The argument arg\n\
|
codes can be retrieved from the library module FCNTL. The argument arg\n\
|
||||||
is optional, and defaults to 0; it may be an int or a string.";
|
is optional, and defaults to 0; it may be an int or a string. If arg is\n\
|
||||||
|
given as a string, the return value of fcntl is a string of that length,\n\
|
||||||
|
containing the resulting value put in the arg buffer by the operating system.\n\
|
||||||
|
The length of the arg string is not allowed to exceed 1024 bytes. If the arg\n\
|
||||||
|
given is an integer or if none is specified, the result value is an integer\n\
|
||||||
|
corresponding to the return value of the fcntl call in the C code.";
|
||||||
|
|
||||||
|
|
||||||
/* ioctl(fd, opt, [arg]) */
|
/* ioctl(fd, opt, [arg]) */
|
||||||
|
@ -95,7 +98,7 @@ fcntl_ioctl(PyObject *self, PyObject *args)
|
||||||
int len;
|
int len;
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
|
|
||||||
if (PyArg_Parse(args, "(iis#)", &fd, &code, &str, &len)) {
|
if (PyArg_ParseTuple(args, "iis#:ioctl", &fd, &code, &str, &len)) {
|
||||||
if (len > sizeof buf) {
|
if (len > sizeof buf) {
|
||||||
PyErr_SetString(PyExc_ValueError,
|
PyErr_SetString(PyExc_ValueError,
|
||||||
"ioctl string arg too long");
|
"ioctl string arg too long");
|
||||||
|
@ -113,11 +116,9 @@ fcntl_ioctl(PyObject *self, PyObject *args)
|
||||||
}
|
}
|
||||||
|
|
||||||
PyErr_Clear();
|
PyErr_Clear();
|
||||||
if (PyArg_Parse(args, "(ii)", &fd, &code))
|
|
||||||
arg = 0;
|
arg = 0;
|
||||||
else {
|
if (!PyArg_ParseTuple(args, "ii|i;ioctl requires 2 integers and optionally a third integer or a string",
|
||||||
PyErr_Clear();
|
&fd, &code, &arg)) {
|
||||||
if (!PyArg_Parse(args, "(iii)", &fd, &code, &arg))
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
Py_BEGIN_ALLOW_THREADS
|
Py_BEGIN_ALLOW_THREADS
|
||||||
|
@ -136,7 +137,12 @@ static char ioctl_doc [] =
|
||||||
Perform the requested operation on file descriptor fd. The operation\n\
|
Perform the requested operation on file descriptor fd. The operation\n\
|
||||||
is defined by op and is operating system dependent. Typically these\n\
|
is defined by op and is operating system dependent. Typically these\n\
|
||||||
codes can be retrieved from the library module IOCTL. The argument arg\n\
|
codes can be retrieved from the library module IOCTL. The argument arg\n\
|
||||||
is optional, and defaults to 0; it may be an int or a string.";
|
is optional, and defaults to 0; it may be an int or a string. If arg is\n\
|
||||||
|
given as a string, the return value of ioctl is a string of that length,\n\
|
||||||
|
containing the resulting value put in the arg buffer by the operating system.\n\
|
||||||
|
The length of the arg string is not allowed to exceed 1024 bytes. If the arg\n\
|
||||||
|
given is an integer or if none is specified, the result value is an integer\n\
|
||||||
|
corresponding to the return value of the ioctl call in the C code.";
|
||||||
|
|
||||||
|
|
||||||
/* flock(fd, operation) */
|
/* flock(fd, operation) */
|
||||||
|
@ -148,7 +154,7 @@ fcntl_flock(PyObject *self, PyObject *args)
|
||||||
int code;
|
int code;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (!PyArg_Parse(args, "(ii)", &fd, &code))
|
if (!PyArg_ParseTuple(args, "ii:flock", &fd, &code))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
#ifdef HAVE_FLOCK
|
#ifdef HAVE_FLOCK
|
||||||
|
@ -273,10 +279,10 @@ calls. See the Unix manual for details.";
|
||||||
/* List of functions */
|
/* List of functions */
|
||||||
|
|
||||||
static PyMethodDef fcntl_methods[] = {
|
static PyMethodDef fcntl_methods[] = {
|
||||||
{"fcntl", fcntl_fcntl, 0, fcntl_doc},
|
{"fcntl", fcntl_fcntl, METH_VARARGS, fcntl_doc},
|
||||||
{"ioctl", fcntl_ioctl, 0, ioctl_doc},
|
{"ioctl", fcntl_ioctl, METH_VARARGS, ioctl_doc},
|
||||||
{"flock", fcntl_flock, 0, flock_doc},
|
{"flock", fcntl_flock, METH_VARARGS, flock_doc},
|
||||||
{"lockf", fcntl_lockf, 1, lockf_doc},
|
{"lockf", fcntl_lockf, METH_VARARGS, lockf_doc},
|
||||||
{NULL, NULL} /* sentinel */
|
{NULL, NULL} /* sentinel */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue