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

ruby-changes:32604

From: naruse <ko1@a...>
Date: Thu, 23 Jan 2014 11:17:46 +0900 (JST)
Subject: [ruby-changes:32604] naruse:r44683 (ruby_2_1): merge revision(s) 44358, 44359, 44360, 44363: [Backport #9275]

naruse	2014-01-23 11:17:40 +0900 (Thu, 23 Jan 2014)

  New Revision: 44683

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

  Log:
    merge revision(s) 44358,44359,44360,44363: [Backport #9275]
    
            hash.c: reword
    
            * hash.c (HAS_EXTRA_STATES, rb_hash_reject): use words "extra states".
            * hash.c (HAS_EXTRA_STATES): warn extra states only when something
              differ.  [ruby-core:59254] [Bug #9275]

  Modified directories:
    branches/ruby_2_1/
  Modified files:
    branches/ruby_2_1/ChangeLog
    branches/ruby_2_1/hash.c
    branches/ruby_2_1/test/ruby/test_hash.rb
    branches/ruby_2_1/version.h
Index: ruby_2_1/ChangeLog
===================================================================
--- ruby_2_1/ChangeLog	(revision 44682)
+++ ruby_2_1/ChangeLog	(revision 44683)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/ChangeLog#L1
+Thu Jan 23 10:37:24 2014  Nobuyoshi Nakada  <nobu@r...>
+
+	* hash.c (HAS_EXTRA_STATES): warn extra states only when something
+	  differ.  [ruby-core:59254] [Bug #9275]
+
 Thu Jan  9 14:05:24 2014  NAKAMURA Usaku  <usa@r...>
 
 	* win32/{setup.mak,Makefile.sub}: update fake.rb like
Index: ruby_2_1/hash.c
===================================================================
--- ruby_2_1/hash.c	(revision 44682)
+++ ruby_2_1/hash.c	(revision 44683)
@@ -27,12 +27,24 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/hash.c#L27
 # endif
 #endif
 
-#define HAS_MISC_ATTRIBUTES(hash, klass) ( \
-    (klass = rb_obj_class(hash)) != rb_cHash || \
-    (klass = 0, \
-     FL_TEST((hash), FL_EXIVAR|FL_TAINT|HASH_PROC_DEFAULT) ||	\
-     !NIL_P(RHASH_IFNONE(hash))))
-#define HASH_REJECT_COPY_MISC_ATTRIBUTES 1
+#define HAS_EXTRA_STATES(hash, klass) ( \
+    ((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;
+	c = RCLASS_SUPER(c);
+    }
+    return 0;
+}
 
 static VALUE rb_hash_s_try_convert(VALUE, VALUE);
 
@@ -1133,11 +1145,11 @@ rb_hash_reject(VALUE hash) https://github.com/ruby/ruby/blob/trunk/ruby_2_1/hash.c#L1145
     RETURN_SIZED_ENUMERATOR(hash, 0, 0, hash_enum_size);
     if (RTEST(ruby_verbose)) {
 	VALUE klass;
-	if (HAS_MISC_ATTRIBUTES(hash, klass)) {
-#if HASH_REJECT_COPY_MISC_ATTRIBUTES
-	    rb_warn("copying unguaranteed attributes: %+"PRIsVALUE, hash);
-	    rb_warn("following atributes will not be copied in the future version:");
-	    if (klass != rb_cHash) {
+	if (HAS_EXTRA_STATES(hash, klass)) {
+#if HASH_REJECT_COPY_EXTRA_STATES
+	    rb_warn("copying extra states: %+"PRIsVALUE, hash);
+	    rb_warn("following states will not be copied in the future version:");
+	    if (klass) {
 		rb_warn("  subclass: %+"PRIsVALUE, klass);
 	    }
 	    if (FL_TEST(hash, FL_EXIVAR)) {
@@ -1153,8 +1165,7 @@ rb_hash_reject(VALUE hash) https://github.com/ruby/ruby/blob/trunk/ruby_2_1/hash.c#L1165
 	    else if (!NIL_P(RHASH_IFNONE(hash)))
 		rb_warn("  default value: %+"PRIsVALUE, RHASH_IFNONE(hash));
 #else
-	    rb_warn("unguaranteed attributes are not copied: %+"PRIsVALUE, hash);
-	    rb_warn("following atributes are ignored now:");
+	    rb_warn("extra states are no longer copied: %+"PRIsVALUE, hash);
 #endif
 	}
     }
Index: ruby_2_1/version.h
===================================================================
--- ruby_2_1/version.h	(revision 44682)
+++ ruby_2_1/version.h	(revision 44683)
@@ -1,10 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/version.h#L1
 #define RUBY_VERSION "2.1.1"
-#define RUBY_RELEASE_DATE "2014-01-15"
-#define RUBY_PATCHLEVEL 7
+#define RUBY_RELEASE_DATE "2014-01-23"
+#define RUBY_PATCHLEVEL 8
 
 #define RUBY_RELEASE_YEAR 2014
 #define RUBY_RELEASE_MONTH 1
-#define RUBY_RELEASE_DAY 15
+#define RUBY_RELEASE_DAY 23
 
 #include "ruby/version.h"
 
Index: ruby_2_1/test/ruby/test_hash.rb
===================================================================
--- ruby_2_1/test/ruby/test_hash.rb	(revision 44682)
+++ ruby_2_1/test/ruby/test_hash.rb	(revision 44683)
@@ -558,12 +558,23 @@ class TestHash < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_1/test/ruby/test_hash.rb#L558
     assert_equal(h3, h.reject {|k,v| v })
     assert_equal(base, h)
 
-    return unless RUBY_VERSION >= "2.2.0" # [ruby-core:59154] [Bug #9223]
+    unless RUBY_VERSION >= "2.2.0"
+      # [ruby-core:59154] [Bug #9223]
+      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 +1230,9 @@ class TestHash < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_1/test/ruby/test_hash.rb#L1230
 
   class TestSubHash < TestHash
     class SubHash < Hash
+      def reject(*)
+        super
+      end
     end
 
     def setup

Property changes on: ruby_2_1
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r44358-44360,44363


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

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