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

ruby-changes:26564

From: nobu <ko1@a...>
Date: Wed, 26 Dec 2012 07:31:26 +0900 (JST)
Subject: [ruby-changes:26564] nobu:r38615 (trunk): string.c: GC guard

nobu	2012-12-26 07:31:16 +0900 (Wed, 26 Dec 2012)

  New Revision: 38615

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=38615

  Log:
    string.c: GC guard
    
    * string.c (rb_str_enumerate_chars): prevent shared copy from GC.

  Modified files:
    trunk/ChangeLog
    trunk/string.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 38614)
+++ ChangeLog	(revision 38615)
@@ -1,3 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Dec 26 07:31:14 2012  Nobuyoshi Nakada  <nobu@r...>
+
+	* string.c (rb_str_enumerate_chars): prevent shared copy from GC.
+
 Wed Dec 26 01:31:16 2012  Keiju Ishitsuka  <keiju@i...>
 
 	* lib/irb/init.rb, lib/irb/context.rb: fix conf.debug_level=
Index: string.c
===================================================================
--- string.c	(revision 38614)
+++ string.c	(revision 38615)
@@ -6389,6 +6389,7 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/string.c#L6389
 rb_str_enumerate_chars(VALUE str, int wantarray)
 {
     VALUE orig = str;
+    VALUE substr;
     long i, len, n;
     const char *ptr;
     rb_encoding *enc;
@@ -6421,21 +6422,24 @@ rb_str_enumerate_chars(VALUE str, int wa https://github.com/ruby/ruby/blob/trunk/string.c#L6422
       case ENC_CODERANGE_7BIT:
 	for (i = 0; i < len; i += n) {
 	    n = rb_enc_fast_mbclen(ptr + i, ptr + len, enc);
+	    substr = rb_str_subseq(str, i, n);
 	    if (wantarray)
-		rb_ary_push(ary, rb_str_subseq(str, i, n));
+		rb_ary_push(ary, substr);
 	    else
-		rb_yield(rb_str_subseq(str, i, n));
+		rb_yield(substr);
 	}
 	break;
       default:
 	for (i = 0; i < len; i += n) {
 	    n = rb_enc_mbclen(ptr + i, ptr + len, enc);
+	    substr = rb_str_subseq(str, i, n);
 	    if (wantarray)
-		rb_ary_push(ary, rb_str_subseq(str, i, n));
+		rb_ary_push(ary, substr);
 	    else
-		rb_yield(rb_str_subseq(str, i, n));
+		rb_yield(substr);
 	}
     }
+    RB_GC_GUARD(str);
     if (wantarray)
 	return ary;
     else

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

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