[ruby-core:60404] is RB_GC_GUARD needed in rb_io_syswrite?

From: Eric Wong <normalperson@...>
Date: 2014-02-01 09:19:18 UTC
List: ruby-core #60404
I haven't gotten it to crash as-is, but it seems like we need to
prevent the compiler from optimizing str away while rb_write_internal
is sleeping.

--- a/io.c
+++ b/io.c
@@ -4666,38 +4666,39 @@ static VALUE
 rb_io_syswrite(VALUE io, VALUE str)
 {
     rb_io_t *fptr;
     long n;
 
     if (!RB_TYPE_P(str, T_STRING))
 	str = rb_obj_as_string(str);
 
     io = GetWriteIO(io);
     GetOpenFile(io, fptr);
     rb_io_check_writable(fptr);
 
     str = rb_str_new_frozen(str);
 
     if (fptr->wbuf.len) {
 	rb_warn("syswrite for buffered IO");
     }
 
     n = rb_write_internal(fptr->fd, RSTRING_PTR(str), RSTRING_LEN(str));
+    RB_GC_GUARD(str);
 
     if (n == -1) rb_sys_fail_path(fptr->pathv);
 
     return LONG2FIX(n);
 }

In This Thread

Prev Next