diff options
author | Samuel Williams <[email protected]> | 2022-05-09 22:21:07 +1200 |
---|---|---|
committer | Samuel Williams <[email protected]> | 2022-05-28 15:44:18 +1200 |
commit | c6cd9e180e01f3c0c3258fae87cd55f5e9a219d4 (patch) | |
tree | 40ac22e2dbbf2dae2b87b7b0aacf75d293318498 /io.c | |
parent | 585e97142d4df1e27633afaf98ba589512215c58 (diff) |
Better handling of `error`.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/5419
Diffstat (limited to 'io.c')
-rw-r--r-- | io.c | 33 |
1 files changed, 20 insertions, 13 deletions
@@ -5252,7 +5252,7 @@ static void fptr_finalize_flush(rb_io_t *fptr, int noraise, int keepgvl, struct ccan_list_head *busy) { - VALUE err = Qnil; + VALUE error = Qnil; int fd = fptr->fd; FILE *stdio_file = fptr->stdio_file; int mode = fptr->mode; @@ -5262,10 +5262,10 @@ fptr_finalize_flush(rb_io_t *fptr, int noraise, int keepgvl, struct finish_writeconv_arg arg; arg.fptr = fptr; arg.noalloc = noraise; - err = rb_mutex_synchronize(fptr->write_lock, finish_writeconv_sync, (VALUE)&arg); + error = rb_mutex_synchronize(fptr->write_lock, finish_writeconv_sync, (VALUE)&arg); } else { - err = finish_writeconv(fptr, noraise); + error = finish_writeconv(fptr, noraise); } } if (fptr->wbuf.len) { @@ -5273,8 +5273,9 @@ fptr_finalize_flush(rb_io_t *fptr, int noraise, int keepgvl, io_flush_buffer_sync(fptr); } else { - if (io_fflush(fptr) < 0 && NIL_P(err)) - err = INT2NUM(errno); + if (io_fflush(fptr) < 0 && NIL_P(error)) { + error = INT2NUM(errno); + } } } @@ -5306,8 +5307,11 @@ fptr_finalize_flush(rb_io_t *fptr, int noraise, int keepgvl, if (!done && stdio_file) { // stdio_file is deallocated anyway even if fclose failed. - if ((maygvl_fclose(stdio_file, noraise) < 0) && NIL_P(err)) - if (!noraise) err = INT2NUM(errno); + if ((maygvl_fclose(stdio_file, noraise) < 0) && NIL_P(error)) { + if (!noraise) { + error = INT2NUM(errno); + } + } done = 1; } @@ -5318,17 +5322,20 @@ fptr_finalize_flush(rb_io_t *fptr, int noraise, int keepgvl, keepgvl |= !(mode & FMODE_WRITABLE); keepgvl |= noraise; - if ((maygvl_close(fd, keepgvl) < 0) && NIL_P(err)) - if (!noraise) err = INT2NUM(errno); + if ((maygvl_close(fd, keepgvl) < 0) && NIL_P(error)) { + if (!noraise) { + error = INT2NUM(errno); + } + } done = 1; } - if (!NIL_P(err) && !noraise) { - if (RB_INTEGER_TYPE_P(err)) - rb_syserr_fail_path(NUM2INT(err), fptr->pathv); + if (!NIL_P(error) && !noraise) { + if (RB_INTEGER_TYPE_P(error)) + rb_syserr_fail_path(NUM2INT(error), fptr->pathv); else - rb_exc_raise(err); + rb_exc_raise(error); } } |