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

ruby-changes:33401

From: nobu <ko1@a...>
Date: Mon, 31 Mar 2014 06:56:09 +0900 (JST)
Subject: [ruby-changes:33401] nobu:r45480 (trunk): gc.c: avoid inadvertent pin-down

nobu	2014-03-31 06:55:59 +0900 (Mon, 31 Mar 2014)

  New Revision: 45480

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

  Log:
    gc.c: avoid inadvertent pin-down
    
    * gc.c (gc_info_decode): get rid of inadvertent dynamic symbol
      pin-down, and preserve encoding in error messages.  also should
      not use RSTRING_PTR macro on function calls.

  Modified files:
    trunk/gc.c
    trunk/test/ruby/test_gc.rb
Index: gc.c
===================================================================
--- gc.c	(revision 45479)
+++ gc.c	(revision 45480)
@@ -5325,8 +5325,9 @@ gc_info_decode(int flags, VALUE hash_or_ https://github.com/ruby/ruby/blob/trunk/gc.c#L5325
     SET(immediate_sweep, (flags & GPR_FLAG_IMMEDIATE_SWEEP) ? Qtrue : Qfalse);
 #undef SET
 
-    if (key != Qnil) /* matched key should return above */
-	rb_raise(rb_eArgError, "unknown key: %s", RSTRING_PTR(rb_id2str(SYM2ID(key))));
+    if (!NIL_P(key)) {/* matched key should return above */
+	rb_raise(rb_eArgError, "unknown key: %"PRIsVALUE, rb_sym2str(key));
+    }
 
     return hash;
 }
@@ -5486,8 +5487,9 @@ gc_stat_internal(VALUE hash_or_sym, size https://github.com/ruby/ruby/blob/trunk/gc.c#L5487
 #endif /* USE_RGENGC */
 #undef SET
 
-    if (key != Qnil) /* matched key should return above */
-	rb_raise(rb_eArgError, "unknown key: %s", RSTRING_PTR(rb_id2str(SYM2ID(key))));
+    if (!NIL_P(key)) { /* matched key should return above */
+	rb_raise(rb_eArgError, "unknown key: %"PRIsVALUE, rb_sym2str(key));
+    }
 
 #if defined(RGENGC_PROFILE) && RGENGC_PROFILE >= 2
     if (hash != Qnil) {
Index: test/ruby/test_gc.rb
===================================================================
--- test/ruby/test_gc.rb	(revision 45479)
+++ test/ruby/test_gc.rb	(revision 45480)
@@ -95,6 +95,10 @@ class TestGc < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_gc.rb#L95
     assert_equal(count[:FREE], stat[:heap_free_slot])
   end
 
+  def test_stat_argument
+    assert_raise_with_message(ArgumentError, /\u{30eb 30d3 30fc}/) {GC.stat(:"\u{30eb 30d3 30fc}")}
+  end
+
   def test_stat_single
     stat = GC.stat
     assert_equal stat[:count], GC.stat(:count)
@@ -124,6 +128,7 @@ class TestGc < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_gc.rb#L128
     assert_not_empty info
     assert_equal info[:gc_by], GC.latest_gc_info(:gc_by)
     assert_raises(ArgumentError){ GC.latest_gc_info(:invalid) }
+    assert_raise_with_message(ArgumentError, /\u{30eb 30d3 30fc}/) {GC.latest_gc_info(:"\u{30eb 30d3 30fc}")}
   end
 
   def test_singleton_method

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

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