diff options
author | Guido van Rossum <guido@python.org> | 1999-01-04 17:22:18 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1999-01-04 17:22:18 (GMT) |
commit | 88303194a5579647b30243ab85f3f3acfd610d3c (patch) | |
tree | 2c972e92100e0215382bd0b80e998b0bf304d157 /Objects | |
parent | e89d4506c14fdfbd3963b99ed3d7199846a94a7c (diff) | |
download | cpython-88303194a5579647b30243ab85f3f3acfd610d3c.zip cpython-88303194a5579647b30243ab85f3f3acfd610d3c.tar.gz cpython-88303194a5579647b30243ab85f3f3acfd610d3c.tar.bz2 |
Fix two places (seek and truncate) where a cascade of PyArg_Parse
calls was used instead of a single PyArg_ParseTuple call with an
optional argument.
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/fileobject.c | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/Objects/fileobject.c b/Objects/fileobject.c index b9fa0fc..c57232c 100644 --- a/Objects/fileobject.c +++ b/Objects/fileobject.c @@ -256,11 +256,8 @@ file_seek(f, args) if (f->f_fp == NULL) return err_closed(); whence = 0; - if (!PyArg_Parse(args, "l", &offset)) { - PyErr_Clear(); - if (!PyArg_Parse(args, "(li)", &offset, &whence)) - return NULL; - } + if (!PyArg_ParseTuple(args, "l|i", &offset, &whence)) + return NULL; Py_BEGIN_ALLOW_THREADS errno = 0; ret = fseek(f->f_fp, offset, whence); @@ -285,10 +282,11 @@ file_truncate(f, args) if (f->f_fp == NULL) return err_closed(); - if (!PyArg_Parse(args, "l", &newsize)) { - PyErr_Clear(); - if (!PyArg_NoArgs(args)) - return NULL; + newsize = -1; + if (!PyArg_ParseTuple(args, "|l", &newsize)) { + return NULL; + } + if (newsize < 0) { Py_BEGIN_ALLOW_THREADS errno = 0; newsize = ftell(f->f_fp); /* default to current position*/ @@ -870,9 +868,9 @@ static PyMethodDef file_methods[] = { {"read", (PyCFunction)file_read, 1}, {"write", (PyCFunction)file_write, 0}, {"fileno", (PyCFunction)file_fileno, 0}, - {"seek", (PyCFunction)file_seek, 0}, + {"seek", (PyCFunction)file_seek, 1}, #ifdef HAVE_FTRUNCATE - {"truncate", (PyCFunction)file_truncate, 0}, + {"truncate", (PyCFunction)file_truncate, 1}, #endif {"tell", (PyCFunction)file_tell, 0}, {"readinto", (PyCFunction)file_readinto, 0}, |