summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPauli Virtanen <pav@iki.fi>2014-01-02 20:47:34 +0200
committerPauli Virtanen <pav@iki.fi>2014-01-09 10:36:42 +0200
commit3de3fdab02907194b0cf10ead1c82258ccfe02db (patch)
tree97c80cb14a702ebbf4d3a6daf761cc2b39c35f64
parent41690fcf9bff30cb3d49d8c147bca1f595bfa70b (diff)
downloadnumpy-3de3fdab02907194b0cf10ead1c82258ccfe02db.tar.gz
BUG: core: use correct Python format string for npy_off_t
-rw-r--r--numpy/core/include/numpy/npy_3kcompat.h2
-rw-r--r--numpy/core/include/numpy/npy_common.h24
-rw-r--r--numpy/core/setup.py3
3 files changed, 26 insertions, 3 deletions
diff --git a/numpy/core/include/numpy/npy_3kcompat.h b/numpy/core/include/numpy/npy_3kcompat.h
index de13bc860..f4078dad2 100644
--- a/numpy/core/include/numpy/npy_3kcompat.h
+++ b/numpy/core/include/numpy/npy_3kcompat.h
@@ -247,7 +247,7 @@ npy_PyFile_DupClose(PyObject *file, FILE* handle, npy_off_t orig_pos)
}
/* Seek Python-side handle to the FILE* handle position */
- ret = PyObject_CallMethod(file, "seek", NPY_SSIZE_T_PYFMT "i", position, 0);
+ ret = PyObject_CallMethod(file, "seek", NPY_OFF_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 17f233019..15961e853 100644
--- a/numpy/core/include/numpy/npy_common.h
+++ b/numpy/core/include/numpy/npy_common.h
@@ -56,18 +56,40 @@
#define NPY_INLINE
#endif
-/* Enable 64 bit file position support on win-amd64. Ticket #1660 */
+/* 64 bit file position support, also on win-amd64. Ticket #1660 */
#if defined(_MSC_VER) && defined(_WIN64) && (_MSC_VER > 1400)
#include <io.h>
#define npy_fseek _fseeki64
#define npy_ftell _ftelli64
#define npy_lseek _lseeki64
#define npy_off_t npy_int64
+
+ #if NPY_SIZEOF_INT == 8
+ #define NPY_OFF_T_PYFMT "i"
+ #elif NPY_SIZEOF_LONG == 8
+ #define NPY_OFF_T_PYFMT "l"
+ #elif NPY_SIZEOF_LONGLONG == 8
+ #define NPY_OFF_T_PYFMT "L"
+ #else
+ #error Unsupported size for type off_t
+ #endif
#else
#define npy_fseek fseek
#define npy_ftell ftell
#define npy_lseek lseek
#define npy_off_t off_t
+
+ #if NPY_SIZEOF_OFF_T == NPY_SIZEOF_SHORT
+ #define NPY_OFF_T_PYFMT "h"
+ #elif NPY_SIZEOF_OFF_T == NPY_SIZEOF_INT
+ #define NPY_OFF_T_PYFMT "i"
+ #elif NPY_SIZEOF_OFF_T == NPY_SIZEOF_LONG
+ #define NPY_OFF_T_PYFMT "l"
+ #elif NPY_SIZEOF_OFF_T == NPY_SIZEOF_LONGLONG
+ #define NPY_OFF_T_PYFMT "L"
+ #else
+ #error Unsupported size for type off_t
+ #endif
#endif
/* enums for detected endianness */
diff --git a/numpy/core/setup.py b/numpy/core/setup.py
index 465752a40..2cb2f3a8b 100644
--- a/numpy/core/setup.py
+++ b/numpy/core/setup.py
@@ -280,6 +280,7 @@ def check_types(config_cmd, ext, build_dir):
expected['Py_intptr_t'] = [4, 8]
expected['PY_LONG_LONG'] = [8]
expected['long long'] = [8]
+ expected['off_t'] = [4, 8]
# Check we have the python header (-dev* packages on Linux)
result = config_cmd.check_header('Python.h')
@@ -326,7 +327,7 @@ def check_types(config_cmd, ext, build_dir):
raise SystemError("Checking sizeof (%s) failed !" % complex_def)
- for type in ('Py_intptr_t',):
+ for type in ('Py_intptr_t', 'off_t'):
res = config_cmd.check_type_size(type, headers=["Python.h"],
library_dirs=[pythonlib_dir()],
expected=expected[type])