diff options
-rw-r--r-- | numpy/core/include/numpy/npy_3kcompat.h | 8 | ||||
-rw-r--r-- | numpy/core/include/numpy/npy_common.h | 9 | ||||
-rw-r--r-- | numpy/core/src/multiarray/ctors.c | 28 |
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"); |