st.c: fix false assertions
* st.c: split assertion conditions. * st.c (rb_hash_bulk_insert): the number of arguments should be even. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59747 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
ce7f3e13c1
commit
4a09333b35
77
st.c
77
st.c
@ -120,7 +120,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ST_DEBUG
|
#ifdef ST_DEBUG
|
||||||
#define st_assert(cond) assert(cond)
|
#define st_assert assert
|
||||||
#else
|
#else
|
||||||
#define st_assert(cond) ((void)(0 && (cond)))
|
#define st_assert(cond) ((void)(0 && (cond)))
|
||||||
#endif
|
#endif
|
||||||
@ -468,6 +468,12 @@ make_tab_empty(st_table *tab)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ST_DEBUG
|
#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
|
/* Check the table T consistency. It can be extremely slow. So use
|
||||||
it only for debugging. */
|
it only for debugging. */
|
||||||
static void
|
static void
|
||||||
@ -478,26 +484,24 @@ st_check(st_table *tab)
|
|||||||
for (p = get_allocated_entries(tab), i = 0; p > 1; i++, p>>=1)
|
for (p = get_allocated_entries(tab), i = 0; p > 1; i++, p>>=1)
|
||||||
;
|
;
|
||||||
p = i;
|
p = i;
|
||||||
assert(p >= MINIMAL_POWER2);
|
st_assert(p >= MINIMAL_POWER2);
|
||||||
assert(tab->entries_bound <= get_allocated_entries(tab)
|
st_assert(tab->entries_bound <= get_allocated_entries(tab));
|
||||||
&& tab->entries_start <= tab->entries_bound);
|
st_assert(tab->entries_start <= tab->entries_bound);
|
||||||
n = 0;
|
n = 0;
|
||||||
return;
|
return;
|
||||||
if (tab->entries_bound != 0)
|
if (tab->entries_bound != 0)
|
||||||
for (i = tab->entries_start; i < tab->entries_bound; i++) {
|
for (i = tab->entries_start; i < tab->entries_bound; i++) {
|
||||||
assert(tab->entries[i].hash != (st_hash_t) ST_INIT_VAL
|
st_assert_notinitial(tab->entries[i]);
|
||||||
&& tab->entries[i].key != ST_INIT_VAL
|
|
||||||
&& tab->entries[i].record != ST_INIT_VAL);
|
|
||||||
if (! DELETED_ENTRY_P(&tab->entries[i]))
|
if (! DELETED_ENTRY_P(&tab->entries[i]))
|
||||||
n++;
|
n++;
|
||||||
}
|
}
|
||||||
assert(n == tab->num_entries);
|
st_assert(n == tab->num_entries);
|
||||||
if (tab->bins == NULL)
|
if (tab->bins == NULL)
|
||||||
assert(p <= MAX_POWER2_FOR_TABLES_WITHOUT_BINS);
|
st_assert(p <= MAX_POWER2_FOR_TABLES_WITHOUT_BINS);
|
||||||
else {
|
else {
|
||||||
assert(p > MAX_POWER2_FOR_TABLES_WITHOUT_BINS);
|
st_assert(p > MAX_POWER2_FOR_TABLES_WITHOUT_BINS);
|
||||||
for (n = d = i = 0; i < get_bins_num(tab); i++) {
|
for (n = d = i = 0; i < get_bins_num(tab); i++) {
|
||||||
assert(get_bin(tab->bins, tab->size_ind, i) != ST_INIT_VAL);
|
st_assert(get_bin(tab->bins, tab->size_ind, i) != ST_INIT_VAL);
|
||||||
if (IND_DELETED_BIN_P(tab, i)) {
|
if (IND_DELETED_BIN_P(tab, i)) {
|
||||||
d++;
|
d++;
|
||||||
continue;
|
continue;
|
||||||
@ -506,14 +510,12 @@ st_check(st_table *tab)
|
|||||||
continue;
|
continue;
|
||||||
n++;
|
n++;
|
||||||
e = get_bin(tab->bins, tab->size_ind, i) - ENTRY_BASE;
|
e = get_bin(tab->bins, tab->size_ind, i) - ENTRY_BASE;
|
||||||
assert(tab->entries_start <= e && e < tab->entries_bound);
|
st_assert(tab->entries_start <= e && e < tab->entries_bound);
|
||||||
assert(! DELETED_ENTRY_P(&tab->entries[e]));
|
st_assert(! DELETED_ENTRY_P(&tab->entries[e]));
|
||||||
assert(tab->entries[e].hash != (st_hash_t) ST_INIT_VAL
|
st_assert_notinitial(tab->entries[e]);
|
||||||
&& tab->entries[e].key != ST_INIT_VAL
|
|
||||||
&& tab->entries[e].record != ST_INIT_VAL);
|
|
||||||
}
|
}
|
||||||
assert(n == tab->num_entries);
|
st_assert(n == tab->num_entries);
|
||||||
assert(n + d < get_bins_num(tab));
|
st_assert(n + d < get_bins_num(tab));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -770,9 +772,9 @@ rebuild_table(st_table *tab)
|
|||||||
if (EXPECT(bins != NULL, 1)) {
|
if (EXPECT(bins != NULL, 1)) {
|
||||||
bin_ind = find_table_bin_ind_direct(new_tab, curr_entry_ptr->hash,
|
bin_ind = find_table_bin_ind_direct(new_tab, curr_entry_ptr->hash,
|
||||||
curr_entry_ptr->key);
|
curr_entry_ptr->key);
|
||||||
st_assert(bin_ind != UNDEFINED_BIN_IND
|
st_assert(bin_ind != UNDEFINED_BIN_IND);
|
||||||
&& (tab == new_tab || new_tab->rebuilds_num == 0)
|
st_assert(tab == new_tab || new_tab->rebuilds_num == 0);
|
||||||
&& IND_EMPTY_BIN_P(new_tab, bin_ind));
|
st_assert(IND_EMPTY_BIN_P(new_tab, bin_ind));
|
||||||
set_bin(bins, size_ind, bin_ind, ni + ENTRY_BASE);
|
set_bin(bins, size_ind, bin_ind, ni + ENTRY_BASE);
|
||||||
}
|
}
|
||||||
new_tab->num_entries++;
|
new_tab->num_entries++;
|
||||||
@ -782,7 +784,8 @@ rebuild_table(st_table *tab)
|
|||||||
tab->entry_power = new_tab->entry_power;
|
tab->entry_power = new_tab->entry_power;
|
||||||
tab->bin_power = new_tab->bin_power;
|
tab->bin_power = new_tab->bin_power;
|
||||||
tab->size_ind = new_tab->size_ind;
|
tab->size_ind = new_tab->size_ind;
|
||||||
st_assert (tab->num_entries == ni && new_tab->num_entries == ni);
|
st_assert(tab->num_entries == ni);
|
||||||
|
st_assert(new_tab->num_entries == ni);
|
||||||
if (tab->bins != NULL)
|
if (tab->bins != NULL)
|
||||||
free(tab->bins);
|
free(tab->bins);
|
||||||
tab->bins = new_tab->bins;
|
tab->bins = new_tab->bins;
|
||||||
@ -855,7 +858,8 @@ find_table_entry_ind(st_table *tab, st_hash_t hash_value, st_data_t key)
|
|||||||
st_index_t bin;
|
st_index_t bin;
|
||||||
st_table_entry *entries = tab->entries;
|
st_table_entry *entries = tab->entries;
|
||||||
|
|
||||||
st_assert(tab != NULL && tab->bins != NULL);
|
st_assert(tab != NULL);
|
||||||
|
st_assert(tab->bins != NULL);
|
||||||
ind = hash_bin(hash_value, tab);
|
ind = hash_bin(hash_value, tab);
|
||||||
#ifdef QUADRATIC_PROBE
|
#ifdef QUADRATIC_PROBE
|
||||||
d = 1;
|
d = 1;
|
||||||
@ -896,7 +900,8 @@ find_table_bin_ind(st_table *tab, st_hash_t hash_value, st_data_t key)
|
|||||||
st_index_t bin;
|
st_index_t bin;
|
||||||
st_table_entry *entries = tab->entries;
|
st_table_entry *entries = tab->entries;
|
||||||
|
|
||||||
st_assert(tab != NULL && tab->bins != NULL);
|
st_assert(tab != NULL);
|
||||||
|
st_assert(tab->bins != NULL);
|
||||||
ind = hash_bin(hash_value, tab);
|
ind = hash_bin(hash_value, tab);
|
||||||
#ifdef QUADRATIC_PROBE
|
#ifdef QUADRATIC_PROBE
|
||||||
d = 1;
|
d = 1;
|
||||||
@ -937,7 +942,8 @@ find_table_bin_ind_direct(st_table *tab, st_hash_t hash_value, st_data_t key)
|
|||||||
st_index_t bin;
|
st_index_t bin;
|
||||||
st_table_entry *entries = tab->entries;
|
st_table_entry *entries = tab->entries;
|
||||||
|
|
||||||
st_assert(tab != NULL && tab->bins != NULL);
|
st_assert(tab != NULL);
|
||||||
|
st_assert(tab->bins != NULL);
|
||||||
ind = hash_bin(hash_value, tab);
|
ind = hash_bin(hash_value, tab);
|
||||||
#ifdef QUADRATIC_PROBE
|
#ifdef QUADRATIC_PROBE
|
||||||
d = 1;
|
d = 1;
|
||||||
@ -983,9 +989,10 @@ find_table_bin_ptr_and_reserve(st_table *tab, st_hash_t *hash_value,
|
|||||||
st_index_t first_deleted_bin_ind;
|
st_index_t first_deleted_bin_ind;
|
||||||
st_table_entry *entries;
|
st_table_entry *entries;
|
||||||
|
|
||||||
st_assert(tab != NULL && tab->bins != NULL
|
st_assert(tab != NULL);
|
||||||
&& tab->entries_bound <= get_allocated_entries(tab)
|
st_assert(tab->bins != NULL);
|
||||||
&& tab->entries_start <= tab->entries_bound);
|
st_assert(tab->entries_bound <= get_allocated_entries(tab));
|
||||||
|
st_assert(tab->entries_start <= tab->entries_bound);
|
||||||
ind = hash_bin(curr_hash_value, tab);
|
ind = hash_bin(curr_hash_value, tab);
|
||||||
#ifdef QUADRATIC_PROBE
|
#ifdef QUADRATIC_PROBE
|
||||||
d = 1;
|
d = 1;
|
||||||
@ -1202,8 +1209,8 @@ st_insert2(st_table *tab, st_data_t key, st_data_t value,
|
|||||||
st_assert(tab->entries_bound < get_allocated_entries(tab));
|
st_assert(tab->entries_bound < get_allocated_entries(tab));
|
||||||
check = tab->rebuilds_num;
|
check = tab->rebuilds_num;
|
||||||
key = (*func)(key);
|
key = (*func)(key);
|
||||||
st_assert(check == tab->rebuilds_num
|
st_assert(check == tab->rebuilds_num);
|
||||||
&& do_hash(key, tab) == hash_value);
|
st_assert(do_hash(key, tab) == hash_value);
|
||||||
ind = tab->entries_bound++;
|
ind = tab->entries_bound++;
|
||||||
entry = &tab->entries[ind];
|
entry = &tab->entries[ind];
|
||||||
entry->hash = hash_value;
|
entry->hash = hash_value;
|
||||||
@ -1339,14 +1346,14 @@ st_shift(st_table *tab, st_data_t *key, st_data_t *value)
|
|||||||
*key = curr_entry_ptr->key;
|
*key = curr_entry_ptr->key;
|
||||||
if (tab->bins == NULL) {
|
if (tab->bins == NULL) {
|
||||||
bin = find_entry(tab, curr_entry_ptr->hash, curr_entry_ptr->key);
|
bin = find_entry(tab, curr_entry_ptr->hash, curr_entry_ptr->key);
|
||||||
st_assert(bin != UNDEFINED_ENTRY_IND
|
st_assert(bin != UNDEFINED_ENTRY_IND);
|
||||||
&& &entries[bin] == curr_entry_ptr);
|
st_assert(&entries[bin] == curr_entry_ptr);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
bin_ind = find_table_bin_ind(tab, curr_entry_ptr->hash,
|
bin_ind = find_table_bin_ind(tab, curr_entry_ptr->hash,
|
||||||
curr_entry_ptr->key);
|
curr_entry_ptr->key);
|
||||||
st_assert(bin_ind != UNDEFINED_BIN_IND
|
st_assert(bin_ind != UNDEFINED_BIN_IND);
|
||||||
&& &entries[get_bin(tab->bins, get_size_ind(tab), bin_ind)
|
st_assert(&entries[get_bin(tab->bins, get_size_ind(tab), bin_ind)
|
||||||
- ENTRY_BASE] == curr_entry_ptr);
|
- ENTRY_BASE] == curr_entry_ptr);
|
||||||
MARK_BIN_DELETED(tab, bin_ind);
|
MARK_BIN_DELETED(tab, bin_ind);
|
||||||
}
|
}
|
||||||
@ -2162,7 +2169,7 @@ rb_hash_bulk_insert(long argc, const VALUE *argv, VALUE hash)
|
|||||||
st_index_t n;
|
st_index_t n;
|
||||||
st_table *tab = RHASH(hash)->ntbl;
|
st_table *tab = RHASH(hash)->ntbl;
|
||||||
|
|
||||||
st_assert(argc % 2);
|
st_assert(argc % 2 == 0);
|
||||||
if (! argc)
|
if (! argc)
|
||||||
return;
|
return;
|
||||||
if (! tab) {
|
if (! tab) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user