summaryrefslogtreecommitdiff
path: root/st.c
diff options
context:
space:
mode:
author卜部昌平 <shyouhei@ruby-lang.org>2020-02-26 01:35:16 (GMT)
committer卜部昌平 <shyouhei@ruby-lang.org>2020-02-26 07:00:57 (GMT)
commitfbd7f08e922cdf1a4be7a71aa056659971c81dab (patch)
tree10e2a478cf410d0472b744aa22962b75e4356297 /st.c
parent62c2b8c74e47652fc5bbaf6150f4acd092dfd72b (diff)
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.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/2926
Diffstat (limited to 'st.c')
-rw-r--r--st.c153
1 files changed, 0 insertions, 153 deletions
diff --git a/st.c b/st.c
index 9fababe..8202b4f 100644
--- a/st.c
+++ b/st.c
@@ -127,12 +127,6 @@
#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)
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)
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)
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)
{
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)
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)
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)
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)
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)
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)
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)
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)
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,
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)
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)
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)
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,
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,
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,
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)
get_allocated_entries(old_tab));
if (old_tab->bins != NULL)
MEMCPY(new_tab->bins, old_tab->bins, char, bins_size(old_tab));
-#ifdef ST_DEBUG
- st_check(new_tab);
-#endif
return new_tab;
}
@@ -1382,7 +1264,6 @@ st_general_delete(st_table *tab, st_data_t *key, st_data_t *value)
st_index_t bin_ind;
st_hash_t hash;
- st_assert(tab != NULL);
hash = do_hash(*key, tab);
retry:
if (tab->bins == NULL) {
@@ -1411,9 +1292,6 @@ st_general_delete(st_table *tab, st_data_t *key, st_data_t *value)
MARK_ENTRY_DELETED(entry);
tab->num_entries--;
update_range_for_deleted(tab, bin);
-#ifdef ST_DEBUG
- st_check(tab);
-#endif
return 1;
}
@@ -1464,7 +1342,6 @@ st_shift(st_table *tab, st_data_t *key, st_data_t *value)
entries = tab->entries;
goto retry;
}
- st_assert(bin != UNDEFINED_ENTRY_IND);
curr_entry_ptr = &entries[bin];
}
else {
@@ -1473,22 +1350,16 @@ st_shift(st_table *tab, st_data_t *key, st_data_t *value)
entries = tab->entries;
goto retry;
}
- st_assert(bin_ind != UNDEFINED_BIN_IND);
curr_entry_ptr = &entries[get_bin(tab->bins, get_size_ind(tab), bin_ind)
- ENTRY_BASE];
MARK_BIN_DELETED(tab, bin_ind);
}
- st_assert(entry_hash != curr_entry_ptr->hash && entry_key == curr_entry_ptr->key);
MARK_ENTRY_DELETED(curr_entry_ptr);
tab->num_entries--;
update_range_for_deleted(tab, i);
-#ifdef ST_DEBUG
- st_check(tab);
-#endif
return 1;
}
}
- st_assert(tab->num_entries == 0);
tab->entries_start = tab->entries_bound = 0;
if (value != 0) *value = 0;
return 0;
@@ -1549,7 +1420,6 @@ st_update(st_table *tab, st_data_t key,
old_key = key;
check = tab->rebuilds_num;
retval = (*func)(&key, &value, arg, existing);
- st_assert(check == tab->rebuilds_num);
switch (retval) {
case ST_CONTINUE:
if (! existing) {
@@ -1568,15 +1438,9 @@ st_update(st_table *tab, st_data_t key,
MARK_ENTRY_DELETED(entry);
tab->num_entries--;
update_range_for_deleted(tab, bin);
-#ifdef ST_DEBUG
- st_check(tab);
-#endif
}
break;
}
-#ifdef ST_DEBUG
- st_check(tab);
-#endif
return existing;
}
@@ -1601,7 +1465,6 @@ st_general_foreach(st_table *tab, st_foreach_check_callback_func *func, st_updat
st_data_t key;
int error_p, packed_p = tab->bins == NULL;
- st_assert(tab->entries_start <= tab->entries_bound);
entries = tab->entries;
/* The bound can change inside the loop even without rebuilding
the table, e.g. by an entry inesrtion. */
@@ -1642,9 +1505,6 @@ st_general_foreach(st_table *tab, st_foreach_check_callback_func *func, st_updat
if (error_p && check_p) {
/* call func with error notice */
retval = (*func)(0, 0, arg, 1);
-#ifdef ST_DEBUG
- st_check(tab);
-#endif
return 1;
}
curr_entry_ptr = &entries[i];
@@ -1658,9 +1518,6 @@ st_general_foreach(st_table *tab, st_foreach_check_callback_func *func, st_updat
if (check_p)
break;
case ST_STOP:
-#ifdef ST_DEBUG
- st_check(tab);
-#endif
return 0;
case ST_DELETE: {
st_data_t key = curr_entry_ptr->key;
@@ -1686,16 +1543,10 @@ st_general_foreach(st_table *tab, st_foreach_check_callback_func *func, st_updat
MARK_ENTRY_DELETED(curr_entry_ptr);
tab->num_entries--;
update_range_for_deleted(tab, bin);
-#ifdef ST_DEBUG
- st_check(tab);
-#endif
break;
}
}
}
-#ifdef ST_DEBUG
- st_check(tab);
-#endif
return 0;
}
@@ -1782,7 +1633,6 @@ st_general_values(st_table *tab, st_data_t *values, st_index_t size)
values_start = values;
values_end = values + size;
bound = tab->entries_bound;
- st_assert(bound != 0);
for (i = tab->entries_start; i < bound; i++) {
if (values == values_end)
break;
@@ -2235,7 +2085,6 @@ st_rehash_linear(st_table *tab)
if (EXPECT(rebuilt_p, 0))
return TRUE;
if (eq_p) {
- st_assert(p < q);
*p = *q;
MARK_ENTRY_DELETED(q);
tab->num_entries--;
@@ -2256,7 +2105,6 @@ st_rehash_indexed(st_table *tab)
st_index_t const n = bins_size(tab);
unsigned int const size_ind = get_size_ind(tab);
st_index_t *bins = realloc(tab->bins, n);
- st_assert(bins != NULL);
tab->bins = bins;
initialize_bins(tab);
for (i = tab->entries_start; i < tab->entries_bound; i++) {
@@ -2286,7 +2134,6 @@ st_rehash_indexed(st_table *tab)
return TRUE;
if (eq_p) {
/* duplicated key; delete it */
- st_assert(q < p);
q->record = p->record;
MARK_ENTRY_DELETED(p);
tab->num_entries--;