diff options
author | Matti Picus <matti.picus@gmail.com> | 2023-05-17 20:38:41 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-17 20:38:41 +0300 |
commit | d9b38d687cd513aa6688f7fba805a908c0ac3979 (patch) | |
tree | 54cf382350c5b11491ef729914b0ef65616159e4 | |
parent | 0200e4a00c6ea90ab433962479f47a927a13ed3e (diff) | |
parent | 1c1779490376077b8fef643f65222bb4834567b1 (diff) | |
download | numpy-d9b38d687cd513aa6688f7fba805a908c0ac3979.tar.gz |
Merge pull request #23505 from cbrt64/fix-2256
BUG: Use 2GiB chunking code for fwrite() on mingw32/64
-rw-r--r-- | numpy/core/include/numpy/npy_common.h | 2 | ||||
-rw-r--r-- | numpy/core/src/multiarray/convert.c | 19 |
2 files changed, 14 insertions, 7 deletions
diff --git a/numpy/core/include/numpy/npy_common.h b/numpy/core/include/numpy/npy_common.h index 728cedbf1..fb976aa6a 100644 --- a/numpy/core/include/numpy/npy_common.h +++ b/numpy/core/include/numpy/npy_common.h @@ -137,7 +137,7 @@ #define NPY_STEALS_REF_TO_ARG(n) #endif -/* 64 bit file position support, also on win-amd64. Ticket #1660 */ +/* 64 bit file position support, also on win-amd64. Issue gh-2256 */ #if defined(_MSC_VER) && defined(_WIN64) && (_MSC_VER > 1400) || \ defined(__MINGW32__) || defined(__MINGW64__) #include <io.h> diff --git a/numpy/core/src/multiarray/convert.c b/numpy/core/src/multiarray/convert.c index d1f6e66af..aef78ff5e 100644 --- a/numpy/core/src/multiarray/convert.c +++ b/numpy/core/src/multiarray/convert.c @@ -157,11 +157,18 @@ PyArray_ToFile(PyArrayObject *self, FILE *fp, char *sep, char *format) size = PyArray_SIZE(self); NPY_BEGIN_ALLOW_THREADS; -#if defined (_MSC_VER) && defined(_WIN64) - /* Workaround Win64 fwrite() bug. Issue gh-2556 +#if defined(NPY_OS_WIN64) + /* + * Workaround Win64 fwrite() bug. Issue gh-2256 + * The native 64 windows runtime has this issue, the above will + * also trigger UCRT (which doesn't), so it could be more precise. + * * If you touch this code, please run this test which is so slow - * it was removed from the test suite + * it was removed from the test suite. Note that the original + * failure mode involves an infinite loop during tofile() * + * import tempfile, numpy as np + * from numpy.testing import (assert_) * fourgbplus = 2**32 + 2**16 * testbytes = np.arange(8, dtype=np.int8) * n = len(testbytes) @@ -177,8 +184,8 @@ PyArray_ToFile(PyArrayObject *self, FILE *fp, char *sep, char *format) * assert_((a[-n:] == testbytes).all()) */ { - npy_intp maxsize = 2147483648 / PyArray_DESCR(self)->elsize; - npy_intp chunksize; + size_t maxsize = 2147483648 / (size_t)PyArray_DESCR(self)->elsize; + size_t chunksize; n = 0; while (size > 0) { @@ -186,7 +193,7 @@ PyArray_ToFile(PyArrayObject *self, FILE *fp, char *sep, char *format) n2 = fwrite((const void *) ((char *)PyArray_DATA(self) + (n * PyArray_DESCR(self)->elsize)), (size_t) PyArray_DESCR(self)->elsize, - (size_t) chunksize, fp); + chunksize, fp); if (n2 < chunksize) { break; } |