mirror of
https://github.com/python/cpython.git
synced 2025-08-03 08:34:29 +00:00
Issue #5016: FileIO.seekable() could return False if the file position
was negative when truncated to a C int. Patch by Victor Stinner.
This commit is contained in:
parent
0ae29cf617
commit
a28fcfdbda
3 changed files with 21 additions and 6 deletions
|
@ -66,6 +66,8 @@ _PyFileIO_closed(PyObject *self)
|
|||
static PyObject *
|
||||
portable_lseek(int fd, PyObject *posobj, int whence);
|
||||
|
||||
static PyObject *portable_lseek(int fd, PyObject *posobj, int whence);
|
||||
|
||||
/* Returns 0 on success, -1 with exception set on failure. */
|
||||
static int
|
||||
internal_close(PyFileIOObject *self)
|
||||
|
@ -441,14 +443,14 @@ fileio_seekable(PyFileIOObject *self)
|
|||
if (self->fd < 0)
|
||||
return err_closed();
|
||||
if (self->seekable < 0) {
|
||||
int ret;
|
||||
Py_BEGIN_ALLOW_THREADS
|
||||
ret = lseek(self->fd, 0, SEEK_CUR);
|
||||
Py_END_ALLOW_THREADS
|
||||
if (ret < 0)
|
||||
PyObject *pos = portable_lseek(self->fd, NULL, SEEK_CUR);
|
||||
if (pos == NULL) {
|
||||
PyErr_Clear();
|
||||
self->seekable = 0;
|
||||
else
|
||||
} else {
|
||||
Py_DECREF(pos);
|
||||
self->seekable = 1;
|
||||
}
|
||||
}
|
||||
return PyBool_FromLong((long) self->seekable);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue