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

ruby-changes:25639

From: shirosaki <ko1@a...>
Date: Sat, 17 Nov 2012 11:46:23 +0900 (JST)
Subject: [ruby-changes:25639] shirosaki:r37696 (trunk): st_update passes the key in st_table

shirosaki	2012-11-17 11:46:13 +0900 (Sat, 17 Nov 2012)

  New Revision: 37696

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

  Log:
    st_update passes the key in st_table
    
    * st.c (st_update): pass the key in st_table so that we can free
      memory of the key in st_table when deleting.
      [ruby-core:49220] [Bug #7330]
    
    * test/-ext-/st/test_update.rb
      (Bug::StTable#test_pass_objects_in_st_table): add a test.

  Modified files:
    trunk/ChangeLog
    trunk/st.c
    trunk/test/-ext-/st/test_update.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 37695)
+++ ChangeLog	(revision 37696)
@@ -1,3 +1,12 @@
+Sat Nov 17 11:34:31 2012  Hiroshi Shirosaki  <h.shirosaki@g...>
+
+	* st.c (st_update): pass the key in st_table so that we can free
+	  memory of the key in st_table when deleting.
+	  [ruby-core:49220] [Bug #7330]
+
+	* test/-ext-/st/test_update.rb
+	  (Bug::StTable#test_pass_objects_in_st_table): add a test.
+
 Sat Nov 17 11:26:36 2012  Aaron Patterson <aaron@t...>
 
 	* ext/psych/lib/psych/core_ext.rb: move Kernel#y so that it can
Index: st.c
===================================================================
--- st.c	(revision 37695)
+++ st.c	(revision 37696)
@@ -843,6 +843,7 @@
     if (table->entries_packed) {
 	st_index_t i = find_packed_index(table, hash_val, key);
 	if (i < table->real_entries) {
+	    key = PKEY(table, i);
 	    value = PVAL(table, i);
 	    existing = 1;
 	}
@@ -871,6 +872,7 @@
     FIND_ENTRY(table, ptr, hash_val, bin_pos);
 
     if (ptr != 0) {
+	key = ptr->key;
 	value = ptr->record;
 	existing = 1;
     }
Index: test/-ext-/st/test_update.rb
===================================================================
--- test/-ext-/st/test_update.rb	(revision 37695)
+++ test/-ext-/st/test_update.rb	(revision 37696)
@@ -34,5 +34,17 @@
       assert_equal({a: 3, b: 2}, @tbl, :a)
       assert_equal([:a, 1], args)
     end
+
+    def test_pass_objects_in_st_table
+      bug7330 = '[ruby-core:49220]'
+      key = "abc".freeze
+      value = "def"
+      @tbl[key] = value
+      @tbl.st_update("abc") {|*args|
+        assert_same(key, args[0], bug7330)
+        assert_same(value, args[1], bug7330)
+        nil
+      }
+    end
   end
 end

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

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