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

ruby-changes:32280

From: nobu <ko1@a...>
Date: Mon, 23 Dec 2013 15:54:02 +0900 (JST)
Subject: [ruby-changes:32280] nobu:r44359 (trunk): hash.c: reduce warning

nobu	2013-12-23 15:53:51 +0900 (Mon, 23 Dec 2013)

  New Revision: 44359

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

  Log:
    hash.c: reduce warning
    
    * hash.c (HAS_EXTRA_STATES): warn extra states only when something
      differ.  [ruby-core:59254] [Bug #9275]

  Modified files:
    trunk/ChangeLog
    trunk/hash.c
    trunk/test/ruby/test_hash.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 44358)
+++ ChangeLog	(revision 44359)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Mon Dec 23 15:53:45 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* hash.c (HAS_EXTRA_STATES): warn extra states only when something
+	  differ.  [ruby-core:59254] [Bug #9275]
+
 Mon Dec 23 12:42:13 2013  Marc-Andre Lafortune  <ruby-core@m...>
 
 	* array.c: Have to_h raise on elements that are not key-value pairs
Index: hash.c
===================================================================
--- hash.c	(revision 44358)
+++ hash.c	(revision 44359)
@@ -28,12 +28,23 @@ https://github.com/ruby/ruby/blob/trunk/hash.c#L28
 #endif
 
 #define HAS_EXTRA_STATES(hash, klass) ( \
-    (klass = rb_obj_class(hash)) != rb_cHash || \
-    (klass = 0, \
+    (klass = has_extra_methods(rb_obj_class(hash))) != 0 || \
      FL_TEST((hash), FL_EXIVAR|FL_TAINT|HASH_PROC_DEFAULT) || \
      !NIL_P(RHASH_IFNONE(hash))))
 #define HASH_REJECT_COPY_EXTRA_STATES 1
 
+static VALUE
+has_extra_methods(VALUE klass)
+{
+    const VALUE base = rb_cHash;
+    VALUE c = klass;
+    while (c != base) {
+	st_table *mtbl = RCLASS_M_TBL(c);
+	if (mtbl && mtbl->num_entries) return klass;
+    }
+    return 0;
+}
+
 static VALUE rb_hash_s_try_convert(VALUE, VALUE);
 
 /*
Index: test/ruby/test_hash.rb
===================================================================
--- test/ruby/test_hash.rb	(revision 44358)
+++ test/ruby/test_hash.rb	(revision 44359)
@@ -558,12 +558,22 @@ class TestHash < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_hash.rb#L558
     assert_equal(h3, h.reject {|k,v| v })
     assert_equal(base, h)
 
-    return unless RUBY_VERSION > "2.1.0"
+    unless RUBY_VERSION > "2.1.0"
+      if @cls == Hash
+        assert_empty(EnvUtil.verbose_warning {h.reject {false}})
+        bug9275 = '[ruby-core:59254] [Bug #9275]'
+        c = Class.new(Hash)
+        assert_empty(EnvUtil.verbose_warning {c.new.reject {false}}, bug9275)
+      else
+        assert_match(/extra states/, EnvUtil.verbose_warning {h.reject {false}})
+      end
+      return
+    end
 
     h.instance_variable_set(:@foo, :foo)
     h.default = 42
     h.taint
-    h = h.reject {false}
+    h = EnvUtil.suppress_warning {h.reject {false}}
     assert_instance_of(Hash, h)
     assert_not_predicate(h, :tainted?)
     assert_nil(h.default)
@@ -1219,6 +1229,9 @@ class TestHash < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_hash.rb#L1229
 
   class TestSubHash < TestHash
     class SubHash < Hash
+      def reject(*)
+        super
+      end
     end
 
     def setup

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

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