summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog9
-rw-r--r--st.c2
-rw-r--r--test/-ext-/st/test_update.rb12
3 files changed, 23 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 8508ff5..d7b912c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+Sat Nov 17 11:34:31 2012 Hiroshi Shirosaki <h.shirosaki@gmail.com>
+
+ * 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@tenderlovemaking.com>
* ext/psych/lib/psych/core_ext.rb: move Kernel#y so that it can
diff --git a/st.c b/st.c
index 91fcb7b..c5550bc 100644
--- a/st.c
+++ b/st.c
@@ -843,6 +843,7 @@ st_update(st_table *table, st_data_t key, st_update_callback_func *func, st_data
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 @@ st_update(st_table *table, st_data_t key, st_update_callback_func *func, st_data
FIND_ENTRY(table, ptr, hash_val, bin_pos);
if (ptr != 0) {
+ key = ptr->key;
value = ptr->record;
existing = 1;
}
diff --git a/test/-ext-/st/test_update.rb b/test/-ext-/st/test_update.rb
index 68625af..1b41d2b 100644
--- a/test/-ext-/st/test_update.rb
+++ b/test/-ext-/st/test_update.rb
@@ -34,5 +34,17 @@ class Bug::StTable
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