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

ruby-changes:60197

From: =E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3 <ko1@a...>
Date: Wed, 26 Feb 2020 16:01:11 +0900 (JST)
Subject: [ruby-changes:60197] fbd7f08e92 (master): kill ST_DEBUG [Bug #16521]

https://git.ruby-lang.org/ruby.git/commit/?id=fbd7f08e92

From fbd7f08e922cdf1a4be7a71aa056659971c81dab Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3?=
 <shyouhei@r...>
Date: Wed, 26 Feb 2020 10:35:16 +0900
Subject: kill ST_DEBUG [Bug #16521]

This compile-time option has been broken for years (at least since
commit 4663c224fa6c925ce54af32fd1c1cbac9508f5ec, according to git
bisect). Let's delete codes that no longer work.

diff --git a/st.c b/st.c
index 9fababe..8202b4f 100644
--- a/st.c
+++ b/st.c
@@ -127,12 +127,6 @@ https://github.com/ruby/ruby/blob/trunk/st.c#L127
 #define ATTRIBUTE_UNUSED
 #endif
 
-#ifdef ST_DEBUG
-#define st_assert assert
-#else
-#define st_assert(cond) ((void)(0 && (cond)))
-#endif
-
 /* The type of hashes.  */
 typedef st_index_t st_hash_t;
 
@@ -408,8 +402,6 @@ set_bin(st_index_t *bins, int s, st_index_t n, st_index_t v) https://github.com/ruby/ruby/blob/trunk/st.c#L402
    corresponding to deleted entries. */
 #define MARK_BIN_DELETED(tab, i)				\
     do {                                                        \
-        st_assert(i != UNDEFINED_BIN_IND);			\
-	st_assert(! IND_EMPTY_OR_DELETED_BIN_P(tab, i)); 	\
         set_bin((tab)->bins, get_size_ind(tab), i, DELETED_BIN); \
     } while (0)
 
@@ -490,59 +482,6 @@ make_tab_empty(st_table *tab) https://github.com/ruby/ruby/blob/trunk/st.c#L482
         initialize_bins(tab);
 }
 
-#ifdef ST_DEBUG
-#define st_assert_notinitial(ent) \
-    do { \
-	st_assert(ent.hash != (st_hash_t) ST_INIT_VAL);  \
-	st_assert(ent.key != ST_INIT_VAL); \
-	st_assert(ent.record != ST_INIT_VAL); \
-    } while (0)
-/* Check the table T consistency.  It can be extremely slow.  So use
-   it only for debugging.  */
-static void
-st_check(st_table *tab)
-{
-    st_index_t d, e, i, n, p;
-
-    for (p = get_allocated_entries(tab), i = 0; p > 1; i++, p>>=1)
-        ;
-    p = i;
-    st_assert(p >= MINIMAL_POWER2);
-    st_assert(tab->entries_bound <= get_allocated_entries(tab));
-    st_assert(tab->entries_start <= tab->entries_bound);
-    n = 0;
-    return;
-    if (tab->entries_bound != 0)
-        for (i = tab->entries_start; i < tab->entries_bound; i++) {
-	    st_assert_notinitial(tab->entries[i]);
-	    if (! DELETED_ENTRY_P(&tab->entries[i]))
-	        n++;
-	}
-    st_assert(n == tab->num_entries);
-    if (tab->bins == NULL)
-        st_assert(p <= MAX_POWER2_FOR_TABLES_WITHOUT_BINS);
-    else {
-        st_assert(p > MAX_POWER2_FOR_TABLES_WITHOUT_BINS);
-	for (n = d = i = 0; i < get_bins_num(tab); i++) {
-	    st_assert(get_bin(tab->bins, tab->size_ind, i) != ST_INIT_VAL);
-	    if (IND_DELETED_BIN_P(tab, i)) {
-	        d++;
-		continue;
-	    }
-	    else if (IND_EMPTY_BIN_P(tab, i))
-	        continue;
-	    n++;
-	    e = get_bin(tab->bins, tab->size_ind, i) - ENTRY_BASE;
-	    st_assert(tab->entries_start <= e && e < tab->entries_bound);
-	    st_assert(! DELETED_ENTRY_P(&tab->entries[e]));
-	    st_assert_notinitial(tab->entries[e]);
-	}
-	st_assert(n == tab->num_entries);
-	st_assert(n + d < get_bins_num(tab));
-    }
-}
-#endif
-
 #ifdef HASH_LOG
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
@@ -628,17 +567,8 @@ st_init_table_with_size(const struct st_hash_type *type, st_index_t size) https://github.com/ruby/ruby/blob/trunk/st.c#L567
         return NULL;
     }
 #endif
-#ifdef ST_DEBUG
-    memset(tab->entries, ST_INIT_VAL_BYTE,
-	   get_allocated_entries(tab) * sizeof(st_table_entry));
-    if (tab->bins != NULL)
-        memset(tab->bins, ST_INIT_VAL_BYTE, bins_size(tab));
-#endif
     make_tab_empty(tab);
     tab->rebuilds_num = 0;
-#ifdef ST_DEBUG
-    st_check(tab);
-#endif
     return tab;
 }
 
@@ -702,9 +632,6 @@ st_clear(st_table *tab) https://github.com/ruby/ruby/blob/trunk/st.c#L632
 {
     make_tab_empty(tab);
     tab->rebuilds_num++;
-#ifdef ST_DEBUG
-    st_check(tab);
-#endif
 }
 
 /* Free table TAB space.  */
@@ -787,7 +714,6 @@ rebuild_table(st_table *tab) https://github.com/ruby/ruby/blob/trunk/st.c#L714
     st_index_t *bins;
     st_index_t bin_ind;
 
-    st_assert(tab != NULL);
     bound = tab->entries_bound;
     entries = tab->entries;
     if ((2 * tab->num_entries <= get_allocated_entries(tab)
@@ -818,9 +744,6 @@ rebuild_table(st_table *tab) https://github.com/ruby/ruby/blob/trunk/st.c#L744
 	if (EXPECT(bins != NULL, 1)) {
 	    bin_ind = find_table_bin_ind_direct(new_tab, curr_entry_ptr->hash,
 						curr_entry_ptr->key);
-	    st_assert(bin_ind != UNDEFINED_BIN_IND);
-	    st_assert(tab == new_tab || new_tab->rebuilds_num == 0);
-	    st_assert(IND_EMPTY_BIN_P(new_tab, bin_ind));
 	    set_bin(bins, size_ind, bin_ind, ni + ENTRY_BASE);
 	}
 	new_tab->num_entries++;
@@ -830,8 +753,6 @@ rebuild_table(st_table *tab) https://github.com/ruby/ruby/blob/trunk/st.c#L753
         tab->entry_power = new_tab->entry_power;
 	tab->bin_power = new_tab->bin_power;
 	tab->size_ind = new_tab->size_ind;
-	st_assert(tab->num_entries == ni);
-	st_assert(new_tab->num_entries == ni);
 	if (tab->bins != NULL)
 	    free(tab->bins);
 	tab->bins = new_tab->bins;
@@ -842,9 +763,6 @@ rebuild_table(st_table *tab) https://github.com/ruby/ruby/blob/trunk/st.c#L763
     tab->entries_start = 0;
     tab->entries_bound = tab->num_entries;
     tab->rebuilds_num++;
-#ifdef ST_DEBUG
-    st_check(tab);
-#endif
 }
 
 /* Return the next secondary hash index for table TAB using previous
@@ -911,8 +829,6 @@ find_table_entry_ind(st_table *tab, st_hash_t hash_value, st_data_t key) https://github.com/ruby/ruby/blob/trunk/st.c#L829
     st_index_t bin;
     st_table_entry *entries = tab->entries;
 
-    st_assert(tab != NULL);
-    st_assert(tab->bins != NULL);
     ind = hash_bin(hash_value, tab);
 #ifdef QUADRATIC_PROBE
     d = 1;
@@ -958,8 +874,6 @@ find_table_bin_ind(st_table *tab, st_hash_t hash_value, st_data_t key) https://github.com/ruby/ruby/blob/trunk/st.c#L874
     st_index_t bin;
     st_table_entry *entries = tab->entries;
 
-    st_assert(tab != NULL);
-    st_assert(tab->bins != NULL);
     ind = hash_bin(hash_value, tab);
 #ifdef QUADRATIC_PROBE
     d = 1;
@@ -1001,10 +915,7 @@ find_table_bin_ind_direct(st_table *tab, st_hash_t hash_value, st_data_t key) https://github.com/ruby/ruby/blob/trunk/st.c#L915
     st_index_t peterb;
 #endif
     st_index_t bin;
-    st_table_entry *entries = tab->entries;
 
-    st_assert(tab != NULL);
-    st_assert(tab->bins != NULL);
     ind = hash_bin(hash_value, tab);
 #ifdef QUADRATIC_PROBE
     d = 1;
@@ -1016,7 +927,6 @@ find_table_bin_ind_direct(st_table *tab, st_hash_t hash_value, st_data_t key) https://github.com/ruby/ruby/blob/trunk/st.c#L927
         bin = get_bin(tab->bins, get_size_ind(tab), ind);
         if (EMPTY_OR_DELETED_BIN_P(bin))
 	    return ind;
-	st_assert (entries[bin - ENTRY_BASE].hash != hash_value);
 #ifdef QUADRATIC_PROBE
 	ind = hash_bin(ind + d, tab);
 	d++;
@@ -1052,10 +962,6 @@ find_table_bin_ptr_and_reserve(st_table *tab, st_hash_t *hash_value, https://github.com/ruby/ruby/blob/trunk/st.c#L962
     st_index_t first_deleted_bin_ind;
     st_table_entry *entries;
 
-    st_assert(tab != NULL);
-    st_assert(tab->bins != NULL);
-    st_assert(tab->entries_bound <= get_allocated_entries(tab));
-    st_assert(tab->entries_start <= tab->entries_bound);
     ind = hash_bin(curr_hash_value, tab);
 #ifdef QUADRATIC_PROBE
     d = 1;
@@ -1164,7 +1070,6 @@ rebuild_table_if_necessary (st_table *tab) https://github.com/ruby/ruby/blob/trunk/st.c#L1070
 
     if (bound == get_allocated_entries(tab))
         rebuild_table(tab);
-    st_assert(tab->entries_bound < get_allocated_entries(tab));
 }
 
 /* Insert (KEY, VALUE) into table TAB and return zero.  If there is
@@ -1201,7 +1106,6 @@ st_insert(st_table *tab, st_data_t key, st_data_t value) https://github.com/ruby/ruby/blob/trunk/st.c#L1106
 	bin -= ENTRY_BASE;
     }
     if (new_p) {
-        st_assert(tab->entries_bound < get_allocated_entries(tab));
 	ind = tab->entries_bound++;
         entry = &tab->entries[ind];
         entry->hash = hash_value;
@@ -1209,15 +1113,9 @@ st_insert(st_table *tab, st_data_t key, st_data_t value) https://github.com/ruby/ruby/blob/trunk/st.c#L1113
         entry->record = value;
 	if (bin_ind != UNDEFINED_BIN_IND)
 	    set_bin(tab->bins, get_size_ind(tab), bin_ind, ind + ENTRY_BASE);
-#ifdef ST_DEBUG
-	st_check(tab);
-#endif
         return 0;
     }
     tab->entries[bin].record = value;
-#ifdef ST_DEBUG
-    st_check(tab);
-#endif
     return 1;
 }
 
@@ -1240,12 +1138,8 @@ st_add_direct_with_hash(st_table *tab, https://github.com/ruby/ruby/blob/trunk/st.c#L1138
     tab->num_entries++;
     if (tab->bins != NULL) {
         bin_ind = find_table_bin_ind_direct(tab, hash, key);
-	st_assert (bin_ind != UNDEFINED_BIN_IND);
 	set_bin(tab->bins, get_size_ind(tab), bin_ind, ind + ENTRY_BASE);
     }
-#ifdef ST_DEBUG
-    st_check(tab);
-#endif
 }
 
 /* Insert (KEY, VALUE) into table TAB.  The table should not have
@@ -1294,10 +1188,8 @@ st_insert2(st_table *tab, st_data_t key, st_data_t value, https://github.com/ruby/ruby/blob/trunk/st.c#L1188
 	bin -= ENTRY_BASE;
     }
     if (new_p) {
-        st_assert(tab->entries_bound < get_allocated_entries(tab));
         check = tab->rebuilds_num;
         key = (*func)(key);
-        st_assert(check == tab->rebuilds_num);
         ind = tab->entries_bound++;
         entry = &tab->entries[ind];
         entry->hash = hash_value;
@@ -1305,16 +1197,9 @@ st_insert2(st_table *tab, st_data_t key, st_data_t value, https://github.com/ruby/ruby/blob/trunk/st.c#L1197
         entry->record = value;
 	if (bin_ind != UNDEFINED_BIN_IND)
 	    set_bin(tab->bins, get_size_ind(tab), bin_ind, ind + ENTRY_BASE);
-	st_assert(do_hash(key, tab) == hash_value);
-#ifdef ST_DEBUG
-	st_check(tab);
-#endif
         return 0;
     }
     tab->entries[bin].record = value;
-#ifdef ST_DEBUG
-    st_check(tab);
-#endif
     return 1;
 }
 
@@ -1353,9 +1238,6 @@ st_copy(st_table *old_tab) https://github.com/ruby/ruby/blob/trunk/st.c#L1238
 	   get_allocated_entries(old_tab));
     if (old_tab->bins ! (... truncated)

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

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