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

ruby-changes:54055

From: nobu <ko1@a...>
Date: Fri, 7 Dec 2018 21:03:22 +0900 (JST)
Subject: [ruby-changes:54055] nobu:r66274 (trunk): Adjust reserved hash values

nobu	2018-12-07 21:03:16 +0900 (Fri, 07 Dec 2018)

  New Revision: 66274

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=66274

  Log:
    Adjust reserved hash values
    
    The reserved hash values in hash.c must be consistend with st.c.
    [ruby-core:90356] [Bug #15389]

  Modified files:
    trunk/hash.c
    trunk/st.c
    trunk/test/ruby/test_hash.rb
Index: hash.c
===================================================================
--- hash.c	(revision 66273)
+++ hash.c	(revision 66274)
@@ -311,14 +311,16 @@ static const struct st_hash_type identha https://github.com/ruby/ruby/blob/trunk/hash.c#L311
 #define PTR_EQUAL(ptr, hash_val, key_) \
     ((ptr)->hash == (hash_val) && EQUAL((key_), (ptr)->key))
 
-#define RESERVED_HASH_VAL ((st_hash_t) 0)
-#define RESERVED_HASH_SUBSTITUTION_VAL (~(st_hash_t) 0)
+#define RESERVED_HASH_VAL (~(st_hash_t) 0)
+#define RESERVED_HASH_SUBSTITUTION_VAL ((st_hash_t) 0)
 
 #define SET_KEY(entry, _key) (entry)->key = (_key)
 #define SET_HASH(entry, _hash) (entry)->hash = (_hash)
 #define SET_RECORD(entry, _value) (entry)->record = (_value)
 
 typedef st_data_t st_hash_t;
+extern const st_hash_t st_reserved_hash_val;
+extern const st_hash_t st_reserved_hash_substitution_val;
 
 static inline st_hash_t
 do_hash(st_data_t key)
@@ -5792,6 +5794,9 @@ Init_Hash(void) https://github.com/ruby/ruby/blob/trunk/hash.c#L5794
 #undef rb_intern
 #define rb_intern(str) rb_intern_const(str)
 
+    RUBY_ASSERT(RESERVED_HASH_VAL == st_reserved_hash_val);
+    RUBY_ASSERT(RESERVED_HASH_SUBSTITUTION_VAL == st_reserved_hash_substitution_val);
+
     id_hash = rb_intern("hash");
     id_yield = rb_intern("yield");
     id_default = rb_intern("default");
Index: test/ruby/test_hash.rb
===================================================================
--- test/ruby/test_hash.rb	(revision 66273)
+++ test/ruby/test_hash.rb	(revision 66274)
@@ -1712,6 +1712,15 @@ class TestHash < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_hash.rb#L1712
     assert_equal(0, 1_000_000.times.count{a=Object.new.hash; b=Object.new.hash; 0 + a + b != 0 + b + a}, bug14218)
   end
 
+  def test_reserved_hash_val
+    s = Struct.new(:hash)
+    h = {}
+    keys = [*0..8]
+    keys.each {|i| h[s.new(i)]=true}
+    msg = proc {h.inspect}
+    assert_equal(keys, h.keys.map(&:hash), msg)
+  end
+
   class TestSubHash < TestHash
     class SubHash < Hash
       def reject(*)
Index: st.c
===================================================================
--- st.c	(revision 66273)
+++ st.c	(revision 66274)
@@ -315,6 +315,9 @@ static const struct st_features features https://github.com/ruby/ruby/blob/trunk/st.c#L315
 #define RESERVED_HASH_VAL (~(st_hash_t) 0)
 #define RESERVED_HASH_SUBSTITUTION_VAL ((st_hash_t) 0)
 
+const st_hash_t st_reserved_hash_val = RESERVED_HASH_VAL;
+const st_hash_t st_reserved_hash_substitution_val = RESERVED_HASH_SUBSTITUTION_VAL;
+
 /* Return hash value of KEY for table TAB.  */
 static inline st_hash_t
 do_hash(st_data_t key, st_table *tab)

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

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