summaryrefslogtreecommitdiffstats
path: root/Objects/fileobject.c
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2006-11-12 18:24:26 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2006-11-12 18:24:26 (GMT)
commit056dac1bcfb9aa09e156cb79b111d73ac9a44ec1 (patch)
tree0a2862f0f113fd95ec2d326ea2f0829126a8edd2 /Objects/fileobject.c
parent065f0c8a06e20c0b4f8c500c237cbafa7af7bd18 (diff)
downloadcpython-056dac1bcfb9aa09e156cb79b111d73ac9a44ec1.zip
cpython-056dac1bcfb9aa09e156cb79b111d73ac9a44ec1.tar.gz
cpython-056dac1bcfb9aa09e156cb79b111d73ac9a44ec1.tar.bz2
Bug #1067760: Deprecate passing floats to file.seek.
Diffstat (limited to 'Objects/fileobject.c')
-rw-r--r--Objects/fileobject.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/Objects/fileobject.c b/Objects/fileobject.c
index ced0768..90c9687 100644
--- a/Objects/fileobject.c
+++ b/Objects/fileobject.c
@@ -540,7 +540,7 @@ file_seek(PyFileObject *f, PyObject *args)
int whence;
int ret;
Py_off_t offset;
- PyObject *offobj;
+ PyObject *offobj, *off_index;
if (f->f_fp == NULL)
return err_closed();
@@ -548,12 +548,25 @@ file_seek(PyFileObject *f, PyObject *args)
whence = 0;
if (!PyArg_ParseTuple(args, "O|i:seek", &offobj, &whence))
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)
- offset = PyInt_AsLong(offobj);
+ offset = PyInt_AsLong(off_index);
#else
- offset = PyLong_Check(offobj) ?
- PyLong_AsLongLong(offobj) : PyInt_AsLong(offobj);
+ offset = PyLong_Check(off_index) ?
+ PyLong_AsLongLong(off_index) : PyInt_AsLong(off_index);
#endif
+ Py_DECREF(off_index);
if (PyErr_Occurred())
return NULL;