summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2012-07-13 08:37:49 -0700
committerCharles Harris <charlesr.harris@gmail.com>2012-07-13 08:37:49 -0700
commitafcc4cd5c645a4abdfa789f688a1e9f9f81762af (patch)
tree3e76b993ea73cae3efff3dc998592956de93b56b
parent24b74a21844f5398be0ae4e28e4191aa845547a2 (diff)
parent4e74a93e31371baed2fb027123d3cd16c8832ecc (diff)
downloadnumpy-afcc4cd5c645a4abdfa789f688a1e9f9f81762af.tar.gz
Merge pull request #354 from cgohlke/patch-2
Add numpy specific fseek, ftell to avoid potential problems with windows and amd64.
-rw-r--r--numpy/core/include/numpy/npy_3kcompat.h8
-rw-r--r--numpy/core/include/numpy/npy_common.h9
-rw-r--r--numpy/core/src/multiarray/ctors.c28
3 files changed, 17 insertions, 28 deletions
diff --git a/numpy/core/include/numpy/npy_3kcompat.h b/numpy/core/include/numpy/npy_3kcompat.h
index d3d5404f5..7bc94ebc8 100644
--- a/numpy/core/include/numpy/npy_3kcompat.h
+++ b/numpy/core/include/numpy/npy_3kcompat.h
@@ -204,7 +204,7 @@ npy_PyFile_Dup(PyObject *file, char *mode)
fclose(handle);
return NULL;
}
- fseek(handle, pos, SEEK_SET);
+ npy_fseek(handle, pos, SEEK_SET);
return handle;
}
@@ -215,11 +215,11 @@ static NPY_INLINE int
npy_PyFile_DupClose(PyObject *file, FILE* handle)
{
PyObject *ret;
- long position;
- position = ftell(handle);
+ Py_ssize_t position;
+ position = npy_ftell(handle);
fclose(handle);
- ret = PyObject_CallMethod(file, "seek", "li", position, 0);
+ ret = PyObject_CallMethod(file, "seek", NPY_SSIZE_T_PYFMT "i", position, 0);
if (ret == NULL) {
return -1;
}
diff --git a/numpy/core/include/numpy/npy_common.h b/numpy/core/include/numpy/npy_common.h
index 4f895e0a7..aecc88783 100644
--- a/numpy/core/include/numpy/npy_common.h
+++ b/numpy/core/include/numpy/npy_common.h
@@ -16,6 +16,15 @@
#define NPY_INLINE
#endif
+/* Enable 64 bit file position support on win-amd64. Ticket #1660 */
+#if defined(_MSC_VER) && defined(_WIN64) && (_MSC_VER > 1400)
+ #define npy_fseek _fseeki64
+ #define npy_ftell _ftelli64
+#else
+ #define npy_fseek fseek
+ #define npy_ftell ftell
+#endif
+
/* enums for detected endianness */
enum {
NPY_CPU_UNKNOWN_ENDIAN,
diff --git a/numpy/core/src/multiarray/ctors.c b/numpy/core/src/multiarray/ctors.c
index c9cdffb23..3da4c5294 100644
--- a/numpy/core/src/multiarray/ctors.c
+++ b/numpy/core/src/multiarray/ctors.c
@@ -3000,41 +3000,21 @@ array_fromfile_binary(FILE *fp, PyArray_Descr *dtype, npy_intp num, size_t *nrea
if (num < 0) {
int fail = 0;
-
-#if defined(_MSC_VER) && defined(_WIN64) && (_MSC_VER > 1400)
- /* Workaround Win64 fwrite() bug. Ticket #1660 */
- start = (npy_intp )_ftelli64(fp);
- if (start < 0) {
- fail = 1;
- }
- if (_fseeki64(fp, 0, SEEK_END) < 0) {
- fail = 1;
- }
- numbytes = (npy_intp) _ftelli64(fp);
- if (numbytes < 0) {
- fail = 1;
- }
- numbytes -= start;
- if (_fseeki64(fp, start, SEEK_SET) < 0) {
- fail = 1;
- }
-#else
- start = (npy_intp)ftell(fp);
+ start = (npy_intp) npy_ftell(fp);
if (start < 0) {
fail = 1;
}
- if (fseek(fp, 0, SEEK_END) < 0) {
+ if (npy_fseek(fp, 0, SEEK_END) < 0) {
fail = 1;
}
- numbytes = (npy_intp) ftell(fp);
+ numbytes = (npy_intp) npy_ftell(fp);
if (numbytes < 0) {
fail = 1;
}
numbytes -= start;
- if (fseek(fp, start, SEEK_SET) < 0) {
+ if (npy_fseek(fp, start, SEEK_SET) < 0) {
fail = 1;
}
-#endif
if (fail) {
PyErr_SetString(PyExc_IOError,
"could not seek in file");