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

ruby-changes:20973

From: nagachika <ko1@a...>
Date: Mon, 22 Aug 2011 23:48:29 +0900 (JST)
Subject: [ruby-changes:20973] nagachika:r33021 (trunk): * sprintf.c (rb_str_format): add RB_GC_GUARD to prevent temporary

nagachika	2011-08-22 23:48:10 +0900 (Mon, 22 Aug 2011)

  New Revision: 33021

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

  Log:
    * sprintf.c (rb_str_format): add RB_GC_GUARD to prevent temporary
      strings from GC.

  Modified files:
    trunk/ChangeLog
    trunk/sprintf.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 33020)
+++ ChangeLog	(revision 33021)
@@ -1,3 +1,8 @@
+Mon Aug 22 23:43:33 2011  CHIKANAGA Tomoyuki  <nagachika00@g...>
+
+	* sprintf.c (rb_str_format): add RB_GC_GUARD to prevent temporary
+	  strings from GC.
+
 Sun Aug 21 17:49:53 2011  Kazuki Tsujimoto  <kazuki@c...>
 
 	* iseq.c (iseq_s_disasm): remove variable which is no longer used
Index: sprintf.c
===================================================================
--- sprintf.c	(revision 33020)
+++ sprintf.c	(revision 33021)
@@ -641,6 +641,7 @@
 			rb_raise(rb_eArgError, "%%c requires a character");
 		    }
 		    c = rb_enc_codepoint_len(RSTRING_PTR(tmp), RSTRING_END(tmp), &n, enc);
+		    RB_GC_GUARD(tmp);
 		}
 		else {
 		    c = NUM2INT(val);
@@ -711,6 +712,7 @@
 			}
 			CHECK(len);
 			memcpy(&buf[blen], RSTRING_PTR(str), len);
+			RB_GC_GUARD(str);
 			blen += len;
 			if (flags&FMINUS) {
 			    CHECK(width);
@@ -723,6 +725,7 @@
 		    }
 		}
 		PUSH(RSTRING_PTR(str), len);
+		RB_GC_GUARD(str);
 		rb_enc_associate(result, enc);
 	    }
 	    break;
@@ -736,7 +739,6 @@
 	  case 'B':
 	  case 'u':
 	    {
-		volatile VALUE tmp1;
 		volatile VALUE val = GETARG();
 		char fbuf[32], nbuf[64], *s;
 		const char *prefix = 0;
@@ -887,7 +889,7 @@
 			    val = rb_big_clone(val);
 			    rb_big_2comp(val);
 			}
-			tmp1 = tmp = rb_big2str0(val, base, RBIGNUM_SIGN(val));
+			tmp = rb_big2str0(val, base, RBIGNUM_SIGN(val));
 			s = RSTRING_PTR(tmp);
 			if (*s == '-') {
 			    dots = 1;
@@ -981,6 +983,7 @@
 		    }
 		}
 		PUSH(s, len);
+		RB_GC_GUARD(tmp);
 		CHECK(width);
 		while (width-- > 0) {
 		    buf[blen++] = ' ';
@@ -1065,6 +1068,7 @@
     }
 
   sprint_exit:
+    RB_GC_GUARD(fmt);
     /* XXX - We cannot validate the number of arguments if (digit)$ style used.
      */
     if (posarg >= 0 && nextarg < argc) {

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

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