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

ruby-changes:13597

From: wanabe <ko1@a...>
Date: Sat, 17 Oct 2009 00:12:48 +0900 (JST)
Subject: [ruby-changes:13597] Ruby:r25377 (trunk): * st.c (unpack_entries): save table->bins and never change the table

wanabe	2009-10-17 00:12:31 +0900 (Sat, 17 Oct 2009)

  New Revision: 25377

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

  Log:
    * st.c (unpack_entries): save table->bins and never change the table
      during unpacking. Because st_insert() may cause GC and refer the
      table, i.e. st_foreach().  [Bug #2196]

  Modified files:
    trunk/ChangeLog
    trunk/st.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 25376)
+++ ChangeLog	(revision 25377)
@@ -1,3 +1,9 @@
+Fri Oct 17 00:05:53 2009  wanabe  <s.wanabe@g...>
+
+	* st.c (unpack_entries): save table->bins and never change the table
+	  during unpacking. Because st_insert() may cause GC and refer the
+	  table, i.e. st_foreach().  [Bug #2196]
+
 Fri Oct 16 22:20:25 2009  Tanaka Akira  <akr@f...>
 
 	* prelude.rb (require_relative): defined as a module function of
Index: st.c
===================================================================
--- st.c	(revision 25376)
+++ st.c	(revision 25377)
@@ -418,15 +418,17 @@
 {
     int i;
     struct st_table_entry *packed_bins[MAX_PACKED_NUMHASH*2];
-    int num_entries = table->num_entries;
+    st_table tmp_table = *table;
 
-    memcpy(packed_bins, table->bins, sizeof(struct st_table_entry *) * num_entries*2);
-    table->entries_packed = 0;
-    table->num_entries = 0;
-    memset(table->bins, 0, sizeof(struct st_table_entry *) * table->num_bins);
-    for (i = 0; i < num_entries; i++) {
-        st_insert(table, (st_data_t)packed_bins[i*2], (st_data_t)packed_bins[i*2+1]);
+    memcpy(packed_bins, table->bins, sizeof(struct st_table_entry *) * table->num_entries*2);
+    table->bins = packed_bins;
+    tmp_table.entries_packed = 0;
+    tmp_table.num_entries = 0;
+    memset(tmp_table.bins, 0, sizeof(struct st_table_entry *) * tmp_table.num_bins);
+    for (i = 0; i < table->num_entries; i++) {
+        st_insert(&tmp_table, (st_data_t)packed_bins[i*2], (st_data_t)packed_bins[i*2+1]);
     }
+    *table = tmp_table;
 }
 
 int

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

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