[ruby-core:82159] Re: [Ruby trunk Feature#13637] [PATCH] tool/runruby.rb: test with smallest possible machine stack

From: Eric Wong <normalperson@...>
Date: 2017-07-25 02:50:25 UTC
List: ruby-core #82159
Sorry, original patch was broken :x (yet "make exam" passed...)
(it leaked memory and used sizeof improperly)

Can you try the following, instead?

diff --git a/io.c b/io.c
index 60af120c18..0d5ca0d95b 100644
--- a/io.c
+++ b/io.c
@@ -10692,7 +10692,7 @@ nogvl_copy_stream_write(struct copy_stream_struct *stp, char *buf, size_t len)
 static void
 nogvl_copy_stream_read_write(struct copy_stream_struct *stp)
 {
-    char buf[1024*16];
+    char *buf;
     size_t len;
     ssize_t ss;
     int ret;
@@ -10700,8 +10700,14 @@ nogvl_copy_stream_read_write(struct copy_stream_struct *stp)
     int use_eof;
     off_t src_offset;
     int use_pread;
+    size_t alloc_size = 16384;
 
     copy_length = stp->copy_length;
+    if (copy_length > 0 && copy_length < alloc_size) {
+	alloc_size = copy_length;
+    }
+    buf = xmalloc(alloc_size);
+
     use_eof = copy_length == (off_t)-1;
     src_offset = stp->src_offset;
     use_pread = src_offset != (off_t)-1;
@@ -10713,18 +10719,18 @@ nogvl_copy_stream_read_write(struct copy_stream_struct *stp)
         if (r == (off_t)-1 && errno) {
             stp->syserr = "lseek";
             stp->error_no = errno;
-            return;
+	    goto out;
         }
         src_offset = (off_t)-1;
         use_pread = 0;
     }
 
     while (use_eof || 0 < copy_length) {
-        if (!use_eof && copy_length < (off_t)sizeof(buf)) {
+        if (!use_eof && copy_length < (off_t)alloc_size) {
             len = (size_t)copy_length;
         }
         else {
-            len = sizeof(buf);
+            len = alloc_size;
         }
         if (use_pread) {
             ss = maygvl_copy_stream_read(0, stp, buf, len, src_offset);
@@ -10735,15 +10741,17 @@ nogvl_copy_stream_read_write(struct copy_stream_struct *stp)
             ss = maygvl_copy_stream_read(0, stp, buf, len, (off_t)-1);
         }
         if (ss <= 0) /* EOF or error */
-            return;
+	    goto out;
 
         ret = nogvl_copy_stream_write(stp, buf, ss);
         if (ret < 0)
-            return;
+	    goto out;
 
         if (!use_eof)
             copy_length -= ss;
     }
+out:
+    free(buf);
 }
 
 static void *



Thanks.

Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

In This Thread

Prev Next