[前][次][番号順一覧][スレッド一覧]

ruby-changes:71990

From: Samuel <ko1@a...>
Date: Sat, 28 May 2022 12:44:49 +0900 (JST)
Subject: [ruby-changes:71990] c6cd9e180e (master): Better handling of `error`.

https://git.ruby-lang.org/ruby.git/commit/?id=c6cd9e180e

From c6cd9e180e01f3c0c3258fae87cd55f5e9a219d4 Mon Sep 17 00:00:00 2001
From: Samuel Williams <samuel.williams@o...>
Date: Mon, 9 May 2022 22:21:07 +1200
Subject: Better handling of `error`.

---
 io.c | 33 ++++++++++++++++++++-------------
 1 file 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 https://github.com/ruby/ruby/blob/trunk/io.c#L5252
 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, https://github.com/ruby/ruby/blob/trunk/io.c#L5262
             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, https://github.com/ruby/ruby/blob/trunk/io.c#L5273
             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, https://github.com/ruby/ruby/blob/trunk/io.c#L5307
 
     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, https://github.com/ruby/ruby/blob/trunk/io.c#L5322
 
         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);
     }
 }
 
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]