mirror of
https://github.com/python/cpython.git
synced 2025-10-11 09:23:31 +00:00
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.
This commit is contained in:
parent
e89d4506c1
commit
88303194a5
1 changed files with 9 additions and 11 deletions
|
@ -256,11 +256,8 @@ file_seek(f, args)
|
||||||
if (f->f_fp == NULL)
|
if (f->f_fp == NULL)
|
||||||
return err_closed();
|
return err_closed();
|
||||||
whence = 0;
|
whence = 0;
|
||||||
if (!PyArg_Parse(args, "l", &offset)) {
|
if (!PyArg_ParseTuple(args, "l|i", &offset, &whence))
|
||||||
PyErr_Clear();
|
|
||||||
if (!PyArg_Parse(args, "(li)", &offset, &whence))
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
Py_BEGIN_ALLOW_THREADS
|
Py_BEGIN_ALLOW_THREADS
|
||||||
errno = 0;
|
errno = 0;
|
||||||
ret = fseek(f->f_fp, offset, whence);
|
ret = fseek(f->f_fp, offset, whence);
|
||||||
|
@ -285,10 +282,11 @@ file_truncate(f, args)
|
||||||
|
|
||||||
if (f->f_fp == NULL)
|
if (f->f_fp == NULL)
|
||||||
return err_closed();
|
return err_closed();
|
||||||
if (!PyArg_Parse(args, "l", &newsize)) {
|
newsize = -1;
|
||||||
PyErr_Clear();
|
if (!PyArg_ParseTuple(args, "|l", &newsize)) {
|
||||||
if (!PyArg_NoArgs(args))
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
if (newsize < 0) {
|
||||||
Py_BEGIN_ALLOW_THREADS
|
Py_BEGIN_ALLOW_THREADS
|
||||||
errno = 0;
|
errno = 0;
|
||||||
newsize = ftell(f->f_fp); /* default to current position*/
|
newsize = ftell(f->f_fp); /* default to current position*/
|
||||||
|
@ -870,9 +868,9 @@ static PyMethodDef file_methods[] = {
|
||||||
{"read", (PyCFunction)file_read, 1},
|
{"read", (PyCFunction)file_read, 1},
|
||||||
{"write", (PyCFunction)file_write, 0},
|
{"write", (PyCFunction)file_write, 0},
|
||||||
{"fileno", (PyCFunction)file_fileno, 0},
|
{"fileno", (PyCFunction)file_fileno, 0},
|
||||||
{"seek", (PyCFunction)file_seek, 0},
|
{"seek", (PyCFunction)file_seek, 1},
|
||||||
#ifdef HAVE_FTRUNCATE
|
#ifdef HAVE_FTRUNCATE
|
||||||
{"truncate", (PyCFunction)file_truncate, 0},
|
{"truncate", (PyCFunction)file_truncate, 1},
|
||||||
#endif
|
#endif
|
||||||
{"tell", (PyCFunction)file_tell, 0},
|
{"tell", (PyCFunction)file_tell, 0},
|
||||||
{"readinto", (PyCFunction)file_readinto, 0},
|
{"readinto", (PyCFunction)file_readinto, 0},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue