diff options
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/core/bscript | 6 | ||||
-rw-r--r-- | numpy/core/include/numpy/npy_3kcompat.h | 2 | ||||
-rw-r--r-- | numpy/core/include/numpy/npy_common.h | 4 | ||||
-rw-r--r-- | numpy/core/setup.py | 3 | ||||
-rw-r--r-- | numpy/core/src/multiarray/ctors.c | 6 | ||||
-rw-r--r-- | numpy/lib/bscript | 6 | ||||
-rw-r--r-- | numpy/lib/tests/test_format.py | 24 |
7 files changed, 43 insertions, 8 deletions
diff --git a/numpy/core/bscript b/numpy/core/bscript index a2222eb66..3f1ec149b 100644 --- a/numpy/core/bscript +++ b/numpy/core/bscript @@ -491,7 +491,11 @@ def pre_build(context): return context.default_builder(extension, includes=includes, source=sources, - use="npysort npymath") + use="npysort npymath", + defines=['_FILE_OFFSET_BITS=64', + '_LARGEFILE_SOURCE=1', + '_LARGEFILE64_SOURCE=1'] + ) context.register_builder("multiarray", builder_multiarray) def build_ufunc(extension): diff --git a/numpy/core/include/numpy/npy_3kcompat.h b/numpy/core/include/numpy/npy_3kcompat.h index f4078dad2..9c5d7d318 100644 --- a/numpy/core/include/numpy/npy_3kcompat.h +++ b/numpy/core/include/numpy/npy_3kcompat.h @@ -202,7 +202,7 @@ npy_PyFile_Dup(PyObject *file, char *mode, npy_off_t *orig_pos) fclose(handle); return NULL; } - pos = PyNumber_AsSsize_t(ret, PyExc_OverflowError); + pos = PyLong_AsLongLong(ret); Py_DECREF(ret); if (PyErr_Occurred()) { fclose(handle); diff --git a/numpy/core/include/numpy/npy_common.h b/numpy/core/include/numpy/npy_common.h index 15961e853..6353a93b1 100644 --- a/numpy/core/include/numpy/npy_common.h +++ b/numpy/core/include/numpy/npy_common.h @@ -74,8 +74,8 @@ #error Unsupported size for type off_t #endif #else - #define npy_fseek fseek - #define npy_ftell ftell + #define npy_fseek fseeko + #define npy_ftell ftello #define npy_lseek lseek #define npy_off_t off_t diff --git a/numpy/core/setup.py b/numpy/core/setup.py index 2cb2f3a8b..f9c668a92 100644 --- a/numpy/core/setup.py +++ b/numpy/core/setup.py @@ -629,6 +629,9 @@ def configuration(parent_package='',top_path=None): config.add_include_dirs(join('src', 'npysort')) config.add_define_macros([("HAVE_NPY_CONFIG_H", "1")]) + config.add_define_macros([("_FILE_OFFSET_BITS", "64")]) + config.add_define_macros([('_LARGEFILE_SOURCE', '1')]) + config.add_define_macros([('_LARGEFILE64_SOURCE', '1')]) config.numpy_include_dirs.extend(config.paths('include')) diff --git a/numpy/core/src/multiarray/ctors.c b/numpy/core/src/multiarray/ctors.c index a47b8625a..35f03ad33 100644 --- a/numpy/core/src/multiarray/ctors.c +++ b/numpy/core/src/multiarray/ctors.c @@ -3132,18 +3132,18 @@ static PyArrayObject * array_fromfile_binary(FILE *fp, PyArray_Descr *dtype, npy_intp num, size_t *nread) { PyArrayObject *r; - npy_intp start, numbytes; + npy_off_t start, numbytes; if (num < 0) { int fail = 0; - start = (npy_intp) npy_ftell(fp); + start = npy_ftell(fp); if (start < 0) { fail = 1; } if (npy_fseek(fp, 0, SEEK_END) < 0) { fail = 1; } - numbytes = (npy_intp) npy_ftell(fp); + numbytes = npy_ftell(fp); if (numbytes < 0) { fail = 1; } diff --git a/numpy/lib/bscript b/numpy/lib/bscript index a9200d043..61debfe41 100644 --- a/numpy/lib/bscript +++ b/numpy/lib/bscript @@ -4,4 +4,8 @@ from bento.commands import hooks def build(context): context.tweak_extension("_compiled_base", includes=["../core/include", "../core/include/numpy", "../core", - "../core/src/private"]) + "../core/src/private"], + defines=['_FILE_OFFSET_BITS=64', + '_LARGEFILE_SOURCE=1', + '_LARGEFILE64_SOURCE=1'] + ) diff --git a/numpy/lib/tests/test_format.py b/numpy/lib/tests/test_format.py index b9be643c8..73b1e7c12 100644 --- a/numpy/lib/tests/test_format.py +++ b/numpy/lib/tests/test_format.py @@ -620,5 +620,29 @@ def test_bad_header(): format.write_array_header_1_0(s, d) assert_raises(ValueError, format.read_array_header_1_0, s) + +def test_large_file_support(): + from nose import SkipTest + # try creating a large sparse file + with tempfile.NamedTemporaryFile() as tf: + try: + import subprocess as sp + sp.check_call(["truncate", "-s", "5368709120", tf.name]) + except: + raise SkipTest("Could not create 5GB large file") + # write a small array to the end + f = open(tf.name, "wb") + f.seek(5368709120) + d = np.arange(5) + np.save(f, d) + f.close() + # read it back + f = open(tf.name, "rb") + f.seek(5368709120) + r = np.load(f) + f.close() + assert_array_equal(r, d) + + if __name__ == "__main__": run_module_suite() |