summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Graham <simon.graham@seequent.com>2020-10-22 08:30:27 +1300
committerCharles Harris <charlesr.harris@gmail.com>2020-11-14 16:35:51 -0700
commit5e3940515df87b6d90503311033f67011cfd3d26 (patch)
treea525fd1f87ab8e89fd8bae5b4a124d419c2e2d50
parent1ecb86900a88a31f8fc1f24edfd91b73b524d9e8 (diff)
downloadnumpy-5e3940515df87b6d90503311033f67011cfd3d26.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.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/numpy/core/src/multiarray/methods.c b/numpy/core/src/multiarray/methods.c
index abb5713ff..50eed4ed3 100644
--- a/numpy/core/src/multiarray/methods.c
+++ b/numpy/core/src/multiarray/methods.c
@@ -624,10 +624,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;