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

ruby-changes:29545

From: charliesome <ko1@a...>
Date: Mon, 24 Jun 2013 20:31:34 +0900 (JST)
Subject: [ruby-changes:29545] charliesome:r41597 (trunk): * compile.c (make_name_for_block): use PRIsVALUE in format string

charliesome	2013-06-24 20:31:21 +0900 (Mon, 24 Jun 2013)

  New Revision: 41597

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

  Log:
    * compile.c (make_name_for_block): use PRIsVALUE in format string
      instead of %s and RSTRING_PTR to protect objects from being garbage
      collected too soon
    * encoding.c (str_to_encindex): ditto
    * hash.c (rb_hash_fetch_m): ditto
    * io.c (rb_io_reopen): ditto
    * parse.y (reg_fragment_check_gen): ditto
    * parse.y (reg_compile_gen): ditto
    * parse.y (ripper_assert_Qundef): ditto
    * re.c (rb_reg_raise): ditto
    * ruby.c (set_option_encoding_once): ditto
    * vm_eval.c (rb_throw_obj): ditto

  Modified files:
    trunk/ChangeLog
    trunk/compile.c
    trunk/encoding.c
    trunk/hash.c
    trunk/io.c
    trunk/parse.y
    trunk/re.c
    trunk/ruby.c
    trunk/vm_eval.c

Index: encoding.c
===================================================================
--- encoding.c	(revision 41596)
+++ encoding.c	(revision 41597)
@@ -179,7 +179,7 @@ str_to_encindex(VALUE enc) https://github.com/ruby/ruby/blob/trunk/encoding.c#L179
 {
     int idx = str_find_encindex(enc);
     if (idx < 0) {
-	rb_raise(rb_eArgError, "unknown encoding name - %s", RSTRING_PTR(enc));
+	rb_raise(rb_eArgError, "unknown encoding name - %"PRIsVALUE, enc);
     }
     return idx;
 }
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 41596)
+++ ChangeLog	(revision 41597)
@@ -1,3 +1,18 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Mon Jun 24 20:31:00 2013  Charlie Somerville  <charliesome@r...>
+
+	* compile.c (make_name_for_block): use PRIsVALUE in format string
+	  instead of %s and RSTRING_PTR to protect objects from being garbage
+	  collected too soon
+	* encoding.c (str_to_encindex): ditto
+	* hash.c (rb_hash_fetch_m): ditto
+	* io.c (rb_io_reopen): ditto
+	* parse.y (reg_fragment_check_gen): ditto
+	* parse.y (reg_compile_gen): ditto
+	* parse.y (ripper_assert_Qundef): ditto
+	* re.c (rb_reg_raise): ditto
+	* ruby.c (set_option_encoding_once): ditto
+	* vm_eval.c (rb_throw_obj): ditto
+
 Mon Jun 24 07:57:18 2013  Masaya Tarui  <tarui@r...>
 
 	* gc.c (after_gc_sweep): Have to record malloc info before reset.
Index: re.c
===================================================================
--- re.c	(revision 41596)
+++ re.c	(revision 41597)
@@ -610,7 +610,7 @@ rb_reg_raise(const char *s, long len, co https://github.com/ruby/ruby/blob/trunk/re.c#L610
 {
     volatile VALUE desc = rb_reg_desc(s, len, re);
 
-    rb_raise(rb_eRegexpError, "%s: %s", err, RSTRING_PTR(desc));
+    rb_raise(rb_eRegexpError, "%s: %"PRIsVALUE, err, desc);
 }
 
 static VALUE
Index: io.c
===================================================================
--- io.c	(revision 41596)
+++ io.c	(revision 41597)
@@ -6554,15 +6554,15 @@ rb_io_reopen(int argc, VALUE *argv, VALU https://github.com/ruby/ruby/blob/trunk/io.c#L6554
         rb_fd_fix_cloexec(fptr->fd);
 #ifdef USE_SETVBUF
         if (setvbuf(fptr->stdio_file, NULL, _IOFBF, 0) != 0)
-            rb_warn("setvbuf() can't be honoured for %s", RSTRING_PTR(fptr->pathv));
+            rb_warn("setvbuf() can't be honoured for %"PRIsVALUE, fptr->pathv);
 #endif
         if (fptr->stdio_file == stderr) {
             if (setvbuf(fptr->stdio_file, NULL, _IONBF, BUFSIZ) != 0)
-                rb_warn("setvbuf() can't be honoured for %s", RSTRING_PTR(fptr->pathv));
+                rb_warn("setvbuf() can't be honoured for %"PRIsVALUE, fptr->pathv);
         }
         else if (fptr->stdio_file == stdout && isatty(fptr->fd)) {
             if (setvbuf(fptr->stdio_file, NULL, _IOLBF, BUFSIZ) != 0)
-                rb_warn("setvbuf() can't be honoured for %s", RSTRING_PTR(fptr->pathv));
+                rb_warn("setvbuf() can't be honoured for %"PRIsVALUE, fptr->pathv);
         }
     }
     else {
Index: compile.c
===================================================================
--- compile.c	(revision 41596)
+++ compile.c	(revision 41597)
@@ -2999,10 +2999,10 @@ make_name_for_block(rb_iseq_t *iseq) https://github.com/ruby/ruby/blob/trunk/compile.c#L2999
     }
 
     if (level == 1) {
-	return rb_sprintf("block in %s", RSTRING_PTR(ip->location.label));
+	return rb_sprintf("block in %"PRIsVALUE, ip->location.label);
     }
     else {
-	return rb_sprintf("block (%d levels) in %s", level, RSTRING_PTR(ip->location.label));
+	return rb_sprintf("block (%d levels) in %"PRIsVALUE, level, ip->location.label);
     }
 }
 
Index: vm_eval.c
===================================================================
--- vm_eval.c	(revision 41596)
+++ vm_eval.c	(revision 41597)
@@ -1740,8 +1740,7 @@ rb_throw_obj(VALUE tag, VALUE value) https://github.com/ruby/ruby/blob/trunk/vm_eval.c#L1740
     }
     if (!tt) {
 	VALUE desc = rb_inspect(tag);
-	RB_GC_GUARD(desc);
-	rb_raise(rb_eArgError, "uncaught throw %s", RSTRING_PTR(desc));
+	rb_raise(rb_eArgError, "uncaught throw %"PRIsVALUE, desc);
     }
     th->errinfo = NEW_THROW_OBJECT(tag, 0, TAG_THROW);
 
Index: parse.y
===================================================================
--- parse.y	(revision 41596)
+++ parse.y	(revision 41597)
@@ -9740,8 +9740,7 @@ reg_fragment_check_gen(struct parser_par https://github.com/ruby/ruby/blob/trunk/parse.y#L9740
     err = rb_reg_check_preprocess(str);
     if (err != Qnil) {
         err = rb_obj_as_string(err);
-        compile_error(PARSER_ARG "%s", RSTRING_PTR(err));
-	RB_GC_GUARD(err);
+        compile_error(PARSER_ARG "%"PRIsVALUE, err);
 	return 0;
     }
     return 1;
@@ -9844,7 +9843,7 @@ reg_compile_gen(struct parser_params* pa https://github.com/ruby/ruby/blob/trunk/parse.y#L9843
 	    rb_str_append(rb_str_cat(rb_attr_get(err, mesg), "\n", 1), m);
 	}
 	else {
-	    compile_error(PARSER_ARG "%s", RSTRING_PTR(m));
+	    compile_error(PARSER_ARG "%"PRIsVALUE, m);
 	}
 	return Qnil;
     }
@@ -11400,7 +11399,7 @@ ripper_assert_Qundef(VALUE self, VALUE o https://github.com/ruby/ruby/blob/trunk/parse.y#L11399
 {
     StringValue(msg);
     if (obj == Qundef) {
-        rb_raise(rb_eArgError, "%s", RSTRING_PTR(msg));
+        rb_raise(rb_eArgError, "%"PRIsVALUE, msg);
     }
     return Qnil;
 }
Index: hash.c
===================================================================
--- hash.c	(revision 41596)
+++ hash.c	(revision 41597)
@@ -716,7 +716,7 @@ rb_hash_fetch_m(int argc, VALUE *argv, V https://github.com/ruby/ruby/blob/trunk/hash.c#L716
 		desc = rb_any_to_s(key);
 	    }
 	    desc = rb_str_ellipsize(desc, 65);
-	    rb_raise(rb_eKeyError, "key not found: %s", RSTRING_PTR(desc));
+	    rb_raise(rb_eKeyError, "key not found: %"PRIsVALUE, desc);
 	}
 	return if_none;
     }
Index: ruby.c
===================================================================
--- ruby.c	(revision 41596)
+++ ruby.c	(revision 41597)
@@ -765,7 +765,7 @@ set_option_encoding_once(const char *typ https://github.com/ruby/ruby/blob/trunk/ruby.c#L765
     if (*name &&
 	rb_funcall(ename, rb_intern("casecmp"), 1, *name) != INT2FIX(0)) {
 	rb_raise(rb_eRuntimeError,
-		 "%s already set to %s", type, RSTRING_PTR(*name));
+		 "%s already set to %"PRIsVALUE, type, *name);
     }
     *name = ename;
 }

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

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