ruby-changes:30275
From: usa <ko1@a...>
Date: Fri, 2 Aug 2013 20:40:05 +0900 (JST)
Subject: [ruby-changes:30275] usa:r42327 (ruby_1_9_3): merge revision(s) 42212,42214: [Backport #8669]
usa 2013-08-02 20:39:44 +0900 (Fri, 02 Aug 2013) New Revision: 42327 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=42327 Log: merge revision(s) 42212,42214: [Backport #8669] * string.c: add internal API rb_str_locktmp_ensure(). * io.c (io_fread): use rb_str_locktmp_ensure(). [ruby-core:56121] [Bug #8669] * test/ruby/test_io.rb: add a test for above. * io.c (io_getpartial): use rb_str_locktmp_ensure(). [ruby-core:56121] [Bug #8669] * io.c (rb_io_sysread): ditto. * test/ruby/test_io.rb: add tests for above. Modified directories: branches/ruby_1_9_3/ Modified files: branches/ruby_1_9_3/ChangeLog branches/ruby_1_9_3/internal.h branches/ruby_1_9_3/io.c branches/ruby_1_9_3/string.c branches/ruby_1_9_3/test/ruby/test_io.rb branches/ruby_1_9_3/version.h Index: ruby_1_9_3/ChangeLog =================================================================== --- ruby_1_9_3/ChangeLog (revision 42326) +++ ruby_1_9_3/ChangeLog (revision 42327) @@ -1,3 +1,21 @@ https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/ChangeLog#L1 +Fri Aug 2 20:34:06 2013 Masaki Matsushita <glass.saga@g...> + + * io.c (io_getpartial): use rb_str_locktmp_ensure(). + [ruby-core:56121] [Bug #8669] + + * io.c (rb_io_sysread): ditto. + + * test/ruby/test_io.rb: add tests for above. + +Fri Aug 2 20:34:06 2013 Masaki Matsushita <glass.saga@g...> + + * string.c: add internal API rb_str_locktmp_ensure(). + + * io.c (io_fread): use rb_str_locktmp_ensure(). + [ruby-core:56121] [Bug #8669] + + * test/ruby/test_io.rb: add a test for above. + Fri Aug 2 20:03:39 2013 Nobuyoshi Nakada <nobu@r...> * rational.c (f_round_common): Rational is expected to be returned by Index: ruby_1_9_3/string.c =================================================================== --- ruby_1_9_3/string.c (revision 42326) +++ ruby_1_9_3/string.c (revision 42327) @@ -1751,6 +1751,13 @@ rb_str_unlocktmp(VALUE str) https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/string.c#L1751 return str; } +VALUE +rb_str_locktmp_ensure(VALUE str, VALUE (*func)(VALUE), VALUE arg) +{ + rb_str_locktmp(str); + return rb_ensure(func, arg, rb_str_unlocktmp, str); +} + void rb_str_set_len(VALUE str, long len) { Index: ruby_1_9_3/io.c =================================================================== --- ruby_1_9_3/io.c (revision 42326) +++ ruby_1_9_3/io.c (revision 42327) @@ -1816,15 +1816,31 @@ io_bufread(char *ptr, long len, rb_io_t https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/io.c#L1816 return len - n; } +struct bufread_arg { + char *str_ptr; + long len; + rb_io_t *fptr; +}; + +static VALUE +bufread_call(VALUE arg) +{ + struct bufread_arg *p = (struct bufread_arg *)arg; + p->len = io_bufread(p->str_ptr, p->len, p->fptr); + return Qundef; +} + static long io_fread(VALUE str, long offset, rb_io_t *fptr) { long len; + struct bufread_arg arg; - rb_str_locktmp(str); - len = io_bufread(RSTRING_PTR(str) + offset, RSTRING_LEN(str) - offset, - fptr); - rb_str_unlocktmp(str); + arg.str_ptr = RSTRING_PTR(str) + offset; + arg.len = RSTRING_LEN(str) - offset; + arg.fptr = fptr; + rb_str_locktmp_ensure(str, bufread_call, (VALUE)&arg); + len = arg.len; if (len < 0) rb_sys_fail_path(fptr->pathv); return len; } @@ -2124,12 +2140,27 @@ rb_io_set_nonblock(rb_io_t *fptr) https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/io.c#L2140 } } +struct read_internal_arg { + int fd; + char *str_ptr; + long len; +}; + +static VALUE +read_internal_call(VALUE arg) +{ + struct read_internal_arg *p = (struct read_internal_arg *)arg; + p->len = rb_read_internal(p->fd, p->str_ptr, p->len); + return Qundef; +} + static VALUE io_getpartial(int argc, VALUE *argv, VALUE io, int nonblock) { rb_io_t *fptr; VALUE length, str; long n, len; + struct read_internal_arg arg; rb_scan_args(argc, argv, "11", &length, &str); @@ -2154,9 +2185,11 @@ io_getpartial(int argc, VALUE *argv, VAL https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/io.c#L2185 if (nonblock) { rb_io_set_nonblock(fptr); } - rb_str_locktmp(str); - n = rb_read_internal(fptr->fd, RSTRING_PTR(str), len); - rb_str_unlocktmp(str); + arg.fd = fptr->fd; + arg.str_ptr = RSTRING_PTR(str); + arg.len = len; + rb_str_locktmp_ensure(str, read_internal_call, (VALUE)&arg); + n = arg.len; if (n < 0) { if (!nonblock && rb_io_wait_readable(fptr->fd)) goto again; @@ -4203,6 +4236,7 @@ rb_io_sysread(int argc, VALUE *argv, VAL https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/io.c#L4236 VALUE len, str; rb_io_t *fptr; long n, ilen; + struct read_internal_arg arg; rb_scan_args(argc, argv, "11", &len, &str); ilen = NUM2LONG(len); @@ -4222,8 +4256,11 @@ rb_io_sysread(int argc, VALUE *argv, VAL https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/io.c#L4256 rb_io_check_closed(fptr); rb_str_locktmp(str); - n = rb_read_internal(fptr->fd, RSTRING_PTR(str), ilen); - rb_str_unlocktmp(str); + arg.fd = fptr->fd; + arg.str_ptr = RSTRING_PTR(str); + arg.len = ilen; + rb_ensure(read_internal_call, (VALUE)&arg, rb_str_unlocktmp, str); + n = arg.len; if (n == -1) { rb_sys_fail_path(fptr->pathv); Index: ruby_1_9_3/internal.h =================================================================== --- ruby_1_9_3/internal.h (revision 42326) +++ ruby_1_9_3/internal.h (revision 42327) @@ -165,6 +165,7 @@ size_t rb_strftime_timespec(char *s, siz https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/internal.h#L165 /* string.c */ int rb_str_buf_cat_escaped_char(VALUE result, unsigned int c, int unicode_p); +VALUE rb_str_locktmp_ensure(VALUE str, VALUE (*func)(VALUE), VALUE arg); /* struct.c */ VALUE rb_struct_init_copy(VALUE copy, VALUE s); Index: ruby_1_9_3/version.h =================================================================== --- ruby_1_9_3/version.h (revision 42326) +++ ruby_1_9_3/version.h (revision 42327) @@ -1,5 +1,5 @@ https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/version.h#L1 #define RUBY_VERSION "1.9.3" -#define RUBY_PATCHLEVEL 456 +#define RUBY_PATCHLEVEL 457 #define RUBY_RELEASE_DATE "2013-08-02" #define RUBY_RELEASE_YEAR 2013 Index: ruby_1_9_3/test/ruby/test_io.rb =================================================================== --- ruby_1_9_3/test/ruby/test_io.rb (revision 42326) +++ ruby_1_9_3/test/ruby/test_io.rb (revision 42327) @@ -2178,4 +2178,46 @@ End https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/test/ruby/test_io.rb#L2178 end; } end if /mswin|mingw/ =~ RUBY_PLATFORM + + def test_read_unlocktmp_ensure + bug8669 = '[ruby-core:56121] [Bug #8669]' + + str = "" + r, = IO.pipe + t = Thread.new { r.read(nil, str) } + sleep 0.1 until t.stop? + t.raise + sleep 0.1 while t.alive? + assert_nothing_raised(RuntimeError, bug8669) { str.clear } + ensure + t.kill + end + + def test_readpartial_unlocktmp_ensure + bug8669 = '[ruby-core:56121] [Bug #8669]' + + str = "" + r, = IO.pipe + t = Thread.new { r.readpartial(4096, str) } + sleep 0.1 until t.stop? + t.raise + sleep 0.1 while t.alive? + assert_nothing_raised(RuntimeError, bug8669) { str.clear } + ensure + t.kill + end + + def test_sysread_unlocktmp_ensure + bug8669 = '[ruby-core:56121] [Bug #8669]' + + str = "" + r, = IO.pipe + t = Thread.new { r.sysread(4096, str) } + sleep 0.1 until t.stop? + t.raise + sleep 0.1 while t.alive? + assert_nothing_raised(RuntimeError, bug8669) { str.clear } + ensure + t.kill + end end Property changes on: ruby_1_9_3 ___________________________________________________________________ Modified: svn:mergeinfo Merged /trunk:r42212,42214 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/