ruby-changes:34637
From: nobu <ko1@a...>
Date: Sun, 6 Jul 2014 23:21:51 +0900 (JST)
Subject: [ruby-changes:34637] nobu:r46720 (trunk): st.c: update the key too if changed
nobu 2014-07-06 23:19:47 +0900 (Sun, 06 Jul 2014) New Revision: 46720 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=46720 Log: st.c: update the key too if changed * st.c (st_update): fix a bug that the key was not updated even if it was changed by the callback function. Modified files: trunk/st.c Index: st.c =================================================================== --- st.c (revision 46719) +++ st.c (revision 46720) @@ -834,6 +834,7 @@ st_update(st_table *table, st_data_t key https://github.com/ruby/ruby/blob/trunk/st.c#L834 existing = 1; } { + const st_data_t old_key = key; retval = (*func)(&key, &value, arg, existing); if (!table->entries_packed) { FIND_ENTRY(table, ptr, hash_val, bin_pos); @@ -845,6 +846,14 @@ st_update(st_table *table, st_data_t key https://github.com/ruby/ruby/blob/trunk/st.c#L846 add_packed_direct(table, key, value, hash_val); break; } + if (old_key != PKEY(table, i)) return -1; + if (old_key != key) { + if (do_hash(key, table) != hash_val && + !EQUAL(table, key, old_key)) { + return -1; + } + PKEY(table, i) = key; + } PVAL_SET(table, i, value); break; case ST_DELETE: @@ -863,6 +872,7 @@ st_update(st_table *table, st_data_t key https://github.com/ruby/ruby/blob/trunk/st.c#L872 existing = 1; } { + const st_data_t old_key = key; retval = (*func)(&key, &value, arg, existing); unpacked: switch (retval) { @@ -871,6 +881,14 @@ st_update(st_table *table, st_data_t key https://github.com/ruby/ruby/blob/trunk/st.c#L881 add_direct(table, key, value, hash_val, hash_pos(hash_val, table->num_bins)); break; } + if (old_key != ptr->key) return -1; + if (old_key != key) { + if (do_hash(key, table) != hash_val && + !EQUAL(table, key, old_key)) { + return -1; + } + ptr->key = key; + } ptr->record = value; break; case ST_DELETE: -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/