summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--numpy/core/include/numpy/npy_3kcompat.h13
-rw-r--r--numpy/core/tests/test_regression.py5
2 files changed, 18 insertions, 0 deletions
diff --git a/numpy/core/include/numpy/npy_3kcompat.h b/numpy/core/include/numpy/npy_3kcompat.h
index 185ae678f..af5ddd8c7 100644
--- a/numpy/core/include/numpy/npy_3kcompat.h
+++ b/numpy/core/include/numpy/npy_3kcompat.h
@@ -161,6 +161,7 @@ npy_PyFile_Dup(PyObject *file, char *mode)
{
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 @@ npy_PyFile_Dup(PyObject *file, char *mode)
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;
}
diff --git a/numpy/core/tests/test_regression.py b/numpy/core/tests/test_regression.py
index d5ba4849b..d9c43b496 100644
--- a/numpy/core/tests/test_regression.py
+++ b/numpy/core/tests/test_regression.py
@@ -1393,6 +1393,11 @@ class TestRegression(TestCase):
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__":