mirror of
https://github.com/python/cpython.git
synced 2025-12-10 11:00:14 +00:00
Bug #1067760: Deprecate passing floats to file.seek.
This commit is contained in:
parent
065f0c8a06
commit
056dac1bcf
3 changed files with 20 additions and 4 deletions
|
|
@ -1689,6 +1689,7 @@ flush the read-ahead buffer.
|
||||||
behavior.
|
behavior.
|
||||||
|
|
||||||
Note that not all file objects are seekable.
|
Note that not all file objects are seekable.
|
||||||
|
\versionchanged{Passing float values as offset has been deprecated}[2.6]
|
||||||
\end{methoddesc}
|
\end{methoddesc}
|
||||||
|
|
||||||
\begin{methoddesc}[file]{tell}{}
|
\begin{methoddesc}[file]{tell}{}
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,8 @@ What's New in Python 2.6 alpha 1?
|
||||||
Core and builtins
|
Core and builtins
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
|
- Bug #1067760: Deprecate passing floats to file.seek.
|
||||||
|
|
||||||
- Bug #1591996: Correctly forward exception in instance_contains().
|
- Bug #1591996: Correctly forward exception in instance_contains().
|
||||||
|
|
||||||
- Bug #1588287: fix invalid assertion for `1,2` in debug builds.
|
- Bug #1588287: fix invalid assertion for `1,2` in debug builds.
|
||||||
|
|
|
||||||
|
|
@ -540,7 +540,7 @@ file_seek(PyFileObject *f, PyObject *args)
|
||||||
int whence;
|
int whence;
|
||||||
int ret;
|
int ret;
|
||||||
Py_off_t offset;
|
Py_off_t offset;
|
||||||
PyObject *offobj;
|
PyObject *offobj, *off_index;
|
||||||
|
|
||||||
if (f->f_fp == NULL)
|
if (f->f_fp == NULL)
|
||||||
return err_closed();
|
return err_closed();
|
||||||
|
|
@ -548,12 +548,25 @@ file_seek(PyFileObject *f, PyObject *args)
|
||||||
whence = 0;
|
whence = 0;
|
||||||
if (!PyArg_ParseTuple(args, "O|i:seek", &offobj, &whence))
|
if (!PyArg_ParseTuple(args, "O|i:seek", &offobj, &whence))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
off_index = PyNumber_Index(offobj);
|
||||||
|
if (!off_index) {
|
||||||
|
if (!PyFloat_Check(offobj))
|
||||||
|
return NULL;
|
||||||
|
/* Deprecated in 2.6 */
|
||||||
|
PyErr_Clear();
|
||||||
|
if (PyErr_Warn(PyExc_DeprecationWarning,
|
||||||
|
"integer argument expected, got float"))
|
||||||
|
return NULL;
|
||||||
|
off_index = offobj;
|
||||||
|
Py_INCREF(offobj);
|
||||||
|
}
|
||||||
#if !defined(HAVE_LARGEFILE_SUPPORT)
|
#if !defined(HAVE_LARGEFILE_SUPPORT)
|
||||||
offset = PyInt_AsLong(offobj);
|
offset = PyInt_AsLong(off_index);
|
||||||
#else
|
#else
|
||||||
offset = PyLong_Check(offobj) ?
|
offset = PyLong_Check(off_index) ?
|
||||||
PyLong_AsLongLong(offobj) : PyInt_AsLong(offobj);
|
PyLong_AsLongLong(off_index) : PyInt_AsLong(off_index);
|
||||||
#endif
|
#endif
|
||||||
|
Py_DECREF(off_index);
|
||||||
if (PyErr_Occurred())
|
if (PyErr_Occurred())
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue