This commit is contained in:
Samuel Williams 2022-05-09 22:21:07 +12:00
Родитель 585e97142d
Коммит c6cd9e180e
1 изменённых файлов: 20 добавлений и 13 удалений

33
io.c
Просмотреть файл

@ -5252,7 +5252,7 @@ static void
fptr_finalize_flush(rb_io_t *fptr, int noraise, int keepgvl, fptr_finalize_flush(rb_io_t *fptr, int noraise, int keepgvl,
struct ccan_list_head *busy) struct ccan_list_head *busy)
{ {
VALUE err = Qnil; VALUE error = Qnil;
int fd = fptr->fd; int fd = fptr->fd;
FILE *stdio_file = fptr->stdio_file; FILE *stdio_file = fptr->stdio_file;
int mode = fptr->mode; int mode = fptr->mode;
@ -5262,10 +5262,10 @@ fptr_finalize_flush(rb_io_t *fptr, int noraise, int keepgvl,
struct finish_writeconv_arg arg; struct finish_writeconv_arg arg;
arg.fptr = fptr; arg.fptr = fptr;
arg.noalloc = noraise; 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 { else {
err = finish_writeconv(fptr, noraise); error = finish_writeconv(fptr, noraise);
} }
} }
if (fptr->wbuf.len) { if (fptr->wbuf.len) {
@ -5273,8 +5273,9 @@ fptr_finalize_flush(rb_io_t *fptr, int noraise, int keepgvl,
io_flush_buffer_sync(fptr); io_flush_buffer_sync(fptr);
} }
else { else {
if (io_fflush(fptr) < 0 && NIL_P(err)) if (io_fflush(fptr) < 0 && NIL_P(error)) {
err = INT2NUM(errno); error = INT2NUM(errno);
}
} }
} }
@ -5306,8 +5307,11 @@ fptr_finalize_flush(rb_io_t *fptr, int noraise, int keepgvl,
if (!done && stdio_file) { if (!done && stdio_file) {
// stdio_file is deallocated anyway even if fclose failed. // stdio_file is deallocated anyway even if fclose failed.
if ((maygvl_fclose(stdio_file, noraise) < 0) && NIL_P(err)) if ((maygvl_fclose(stdio_file, noraise) < 0) && NIL_P(error)) {
if (!noraise) err = INT2NUM(errno); if (!noraise) {
error = INT2NUM(errno);
}
}
done = 1; done = 1;
} }
@ -5318,17 +5322,20 @@ fptr_finalize_flush(rb_io_t *fptr, int noraise, int keepgvl,
keepgvl |= !(mode & FMODE_WRITABLE); keepgvl |= !(mode & FMODE_WRITABLE);
keepgvl |= noraise; keepgvl |= noraise;
if ((maygvl_close(fd, keepgvl) < 0) && NIL_P(err)) if ((maygvl_close(fd, keepgvl) < 0) && NIL_P(error)) {
if (!noraise) err = INT2NUM(errno); if (!noraise) {
error = INT2NUM(errno);
}
}
done = 1; done = 1;
} }
if (!NIL_P(err) && !noraise) { if (!NIL_P(error) && !noraise) {
if (RB_INTEGER_TYPE_P(err)) if (RB_INTEGER_TYPE_P(error))
rb_syserr_fail_path(NUM2INT(err), fptr->pathv); rb_syserr_fail_path(NUM2INT(error), fptr->pathv);
else else
rb_exc_raise(err); rb_exc_raise(error);
} }
} }