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

ruby-changes:71988

From: Samuel <ko1@a...>
Date: Sat, 28 May 2022 12:44:43 +0900 (JST)
Subject: [ruby-changes:71988] ac499bb511 (master): Improve error handling in `finish_writeconv`.

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

From ac499bb511e88faa1e9a8566c6fd4821abb17457 Mon Sep 17 00:00:00 2001
From: Samuel Williams <samuel.williams@o...>
Date: Mon, 9 May 2022 22:21:47 +1200
Subject: Improve error handling in `finish_writeconv`.

---
 io.c | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/io.c b/io.c
index a6bb0ec473..c222dd5377 100644
--- a/io.c
+++ b/io.c
@@ -5143,7 +5143,6 @@ finish_writeconv(rb_io_t *fptr, int noalloc) https://github.com/ruby/ruby/blob/trunk/io.c#L5143
 
     if (!fptr->wbuf.ptr) {
         unsigned char buf[1024];
-        long r;
 
         res = econv_destination_buffer_full;
         while (res == econv_destination_buffer_full) {
@@ -5151,19 +5150,20 @@ finish_writeconv(rb_io_t *fptr, int noalloc) https://github.com/ruby/ruby/blob/trunk/io.c#L5150
             de = buf + sizeof(buf);
             res = rb_econv_convert(fptr->writeconv, NULL, NULL, &dp, de, 0);
             while (dp-ds) {
-              retry:
-                r = rb_write_internal(fptr, ds, dp-ds);
-                if (r == dp-ds)
-                    break;
-                if (0 <= r) {
-                    ds += r;
+                size_t remaining = dp-ds;
+                long result = rb_write_internal(fptr, ds, remaining);
+
+                if (result >= 0) {
+                    ds += result;
+                    if ((size_t)result == remaining) break;
                 }
-                if (rb_io_maybe_wait_writable(errno, fptr->self, Qnil)) {
+                else if (rb_io_maybe_wait_writable(errno, fptr->self, Qnil)) {
                     if (fptr->fd < 0)
                         return noalloc ? Qtrue : rb_exc_new3(rb_eIOError, rb_str_new_cstr(closed_stream));
-                    goto retry;
                 }
-                return noalloc ? Qtrue : INT2NUM(errno);
+                else {
+                    return noalloc ? Qtrue : INT2NUM(errno);
+                }
             }
             if (res == econv_invalid_byte_sequence ||
                 res == econv_incomplete_input ||
@@ -5178,8 +5178,9 @@ finish_writeconv(rb_io_t *fptr, int noalloc) https://github.com/ruby/ruby/blob/trunk/io.c#L5178
     res = econv_destination_buffer_full;
     while (res == econv_destination_buffer_full) {
         if (fptr->wbuf.len == fptr->wbuf.capa) {
-            if (io_fflush(fptr) < 0)
+            if (io_fflush(fptr) < 0) {
                 return noalloc ? Qtrue : INT2NUM(errno);
+            }
         }
 
         ds = dp = (unsigned char *)fptr->wbuf.ptr + fptr->wbuf.off + fptr->wbuf.len;
-- 
cgit v1.2.1


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

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