diff options
| author | Simon Graham <simon.graham@seequent.com> | 2020-10-22 08:30:27 +1300 |
|---|---|---|
| committer | Simon Graham <simon.graham@seequent.com> | 2020-10-29 15:31:05 +1300 |
| commit | a1059a3eb71e09cf39fc9c61fb3c5af754efaa79 (patch) | |
| tree | bb68330dd38bac25df9f30ce5ec29c7ea01f5a74 | |
| parent | f2ca85a03dcaed0b2e2571c687bfd78a7901c2ed (diff) | |
| download | numpy-a1059a3eb71e09cf39fc9c61fb3c5af754efaa79.tar.gz | |
Update numpy/core/src/multiarray/methods.c
Co-authored-by: Eric Wieser <wieser.eric@gmail.com>
| -rw-r--r-- | numpy/core/src/multiarray/methods.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/numpy/core/src/multiarray/methods.c b/numpy/core/src/multiarray/methods.c index 634dd9bc3..1835a770f 100644 --- a/numpy/core/src/multiarray/methods.c +++ b/numpy/core/src/multiarray/methods.c @@ -619,10 +619,18 @@ array_tofile(PyArrayObject *self, PyObject *args, PyObject *kwds) if (fd == NULL) { goto fail; } - res1 = PyArray_ToFile(self, fd, sep, format); - res2 = npy_PyFile_DupClose2(file, fd, orig_pos); - if (res1 < 0 || res2 < 0) { - goto fail; + int res_write = PyArray_ToFile(self, fd, sep, format); + { + PyObject *type, *value, *traceback; + PyErr_Fetch(&type, &value, &traceback); + int res_close = npy_PyFile_DupClose2(file, fd, orig_pos); + npy_PyErr_ChainExceptions(type, value, traceback); + if (res_close < 0) { + return NULL; + } + } + if (res_write < 0) { + return NULL; } if (own && npy_PyFile_CloseFile(file) < 0) { goto fail; |
