[Numpy-svn] r8707 - in trunk/numpy/core: include/numpy tests

numpy-svn@scip... numpy-svn@scip...
Sat Sep 11 11:56:14 CDT 2010


Author: ptvirtan
Date: 2010-09-11 11:56:14 -0500 (Sat, 11 Sep 2010)
New Revision: 8707

Modified:
   trunk/numpy/core/include/numpy/npy_3kcompat.h
   trunk/numpy/core/tests/test_regression.py
Log:
BUG: core: on Python3, seek file handle to the current position in npy_PyFile_Dup (fixing #1610)

Modified: trunk/numpy/core/include/numpy/npy_3kcompat.h
===================================================================
--- trunk/numpy/core/include/numpy/npy_3kcompat.h	2010-09-11 16:09:49 UTC (rev 8706)
+++ trunk/numpy/core/include/numpy/npy_3kcompat.h	2010-09-11 16:56:14 UTC (rev 8707)
@@ -161,6 +161,7 @@
 {
     int fd, fd2;
     PyObject *ret, *os;
+    Py_ssize_t pos;
     FILE *handle;
     /* Flush first to ensure things end up in the file in the correct order */
     ret = PyObject_CallMethod(file, "flush", "");
@@ -192,6 +193,18 @@
         PyErr_SetString(PyExc_IOError,
                         "Getting a FILE* from a Python file object failed");
     }
+    ret = PyObject_CallMethod(file, "tell", "");
+    if (ret == NULL) {
+        fclose(handle);
+        return NULL;
+    }
+    pos = PyNumber_AsSsize_t(ret, PyExc_OverflowError);
+    Py_DECREF(ret);
+    if (PyErr_Occurred()) {
+        fclose(handle);
+        return NULL;
+    }
+    fseek(handle, pos, SEEK_SET);
     return handle;
 }
 

Modified: trunk/numpy/core/tests/test_regression.py
===================================================================
--- trunk/numpy/core/tests/test_regression.py	2010-09-11 16:09:49 UTC (rev 8706)
+++ trunk/numpy/core/tests/test_regression.py	2010-09-11 16:56:14 UTC (rev 8707)
@@ -1393,6 +1393,11 @@
         data = f.read(3)
         assert_equal(data, asbytes("\x01\x02\x03"))
 
+        f.seek(80)
+        f.read(4)
+        data = np.fromfile(f, dtype='u1', count=4)
+        assert_equal(data, np.array([84, 85, 86, 87], dtype='u1'))
+
         f.close()
 
 if __name__ == "__main__":



More information about the Numpy-svn mailing list