summaryrefslogtreecommitdiff
path: root/io.c
diff options
context:
space:
mode:
authorSamuel Williams <samuel.williams@oriontransfer.co.nz>2022-05-09 22:21:07 +1200
committerSamuel Williams <samuel.williams@oriontransfer.co.nz>2022-05-28 15:44:18 +1200
commitc6cd9e180e01f3c0c3258fae87cd55f5e9a219d4 (patch)
tree40ac22e2dbbf2dae2b87b7b0aacf75d293318498 /io.c
parent585e97142d4df1e27633afaf98ba589512215c58 (diff)
downloadruby-c6cd9e180e01f3c0c3258fae87cd55f5e9a219d4.tar.gz
Better handling of `error`.
Diffstat (limited to 'io.c')
-rw-r--r--io.c33
1 files changed, 20 insertions, 13 deletions
diff --git a/io.c b/io.c
index 2f4d1db5f8..a6bb0ec473 100644
--- a/io.c
+++ b/io.c
@@ -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);
}
}