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

ruby-changes:47631

From: nobu <ko1@a...>
Date: Tue, 5 Sep 2017 16:50:19 +0900 (JST)
Subject: [ruby-changes:47631] nobu:r59747 (trunk): st.c: fix false assertions

nobu	2017-09-05 16:50:13 +0900 (Tue, 05 Sep 2017)

  New Revision: 59747

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=59747

  Log:
    st.c: fix false assertions
    
    * st.c: split assertion conditions.
    
    * st.c (rb_hash_bulk_insert): the number of arguments should be
      even.

  Modified files:
    trunk/st.c
Index: st.c
===================================================================
--- st.c	(revision 59746)
+++ st.c	(revision 59747)
@@ -120,7 +120,7 @@ https://github.com/ruby/ruby/blob/trunk/st.c#L120
 #endif
 
 #ifdef ST_DEBUG
-#define st_assert(cond) assert(cond)
+#define st_assert assert
 #else
 #define st_assert(cond) ((void)(0 && (cond)))
 #endif
@@ -468,6 +468,12 @@ make_tab_empty(st_table *tab) https://github.com/ruby/ruby/blob/trunk/st.c#L468
 }
 
 #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
@@ -478,26 +484,24 @@ st_check(st_table *tab) https://github.com/ruby/ruby/blob/trunk/st.c#L484
     for (p = get_allocated_entries(tab), i = 0; p > 1; i++, p>>=1)
         ;
     p = i;
-    assert(p >= MINIMAL_POWER2);
-    assert(tab->entries_bound <= get_allocated_entries(tab)
-	   && tab->entries_start <= tab->entries_bound);
+    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++) {
-	    assert(tab->entries[i].hash != (st_hash_t) ST_INIT_VAL
-		   && tab->entries[i].key != ST_INIT_VAL
-		   && tab->entries[i].record != ST_INIT_VAL);
+	    st_assert_notinitial(tab->entries[i]);
 	    if (! DELETED_ENTRY_P(&tab->entries[i]))
 	        n++;
 	}
-    assert(n == tab->num_entries);
+    st_assert(n == tab->num_entries);
     if (tab->bins == NULL)
-        assert(p <= MAX_POWER2_FOR_TABLES_WITHOUT_BINS);
+        st_assert(p <= MAX_POWER2_FOR_TABLES_WITHOUT_BINS);
     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++) {
-	    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)) {
 	        d++;
 		continue;
@@ -506,14 +510,12 @@ st_check(st_table *tab) https://github.com/ruby/ruby/blob/trunk/st.c#L510
 	        continue;
 	    n++;
 	    e = get_bin(tab->bins, tab->size_ind, i) - ENTRY_BASE;
-	    assert(tab->entries_start <= e && e < tab->entries_bound);
-	    assert(! DELETED_ENTRY_P(&tab->entries[e]));
-	    assert(tab->entries[e].hash != (st_hash_t) ST_INIT_VAL
-		   && tab->entries[e].key != ST_INIT_VAL
-		   && tab->entries[e].record != ST_INIT_VAL);
+	    st_assert(tab->entries_start <= e && e < tab->entries_bound);
+	    st_assert(! DELETED_ENTRY_P(&tab->entries[e]));
+	    st_assert_notinitial(tab->entries[e]);
 	}
-	assert(n == tab->num_entries);
-	assert(n + d < get_bins_num(tab));
+	st_assert(n == tab->num_entries);
+	st_assert(n + d < get_bins_num(tab));
     }
 }
 #endif
@@ -770,9 +772,9 @@ rebuild_table(st_table *tab) https://github.com/ruby/ruby/blob/trunk/st.c#L772
 	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
-		      && (tab == new_tab || new_tab->rebuilds_num == 0)
-		      && IND_EMPTY_BIN_P(new_tab, bin_ind));
+	    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++;
@@ -782,7 +784,8 @@ rebuild_table(st_table *tab) https://github.com/ruby/ruby/blob/trunk/st.c#L784
         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 && new_tab->num_entries == ni);
+	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;
@@ -855,7 +858,8 @@ find_table_entry_ind(st_table *tab, st_h https://github.com/ruby/ruby/blob/trunk/st.c#L858
     st_index_t bin;
     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);
 #ifdef QUADRATIC_PROBE
     d = 1;
@@ -896,7 +900,8 @@ find_table_bin_ind(st_table *tab, st_has https://github.com/ruby/ruby/blob/trunk/st.c#L900
     st_index_t bin;
     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);
 #ifdef QUADRATIC_PROBE
     d = 1;
@@ -937,7 +942,8 @@ find_table_bin_ind_direct(st_table *tab, https://github.com/ruby/ruby/blob/trunk/st.c#L942
     st_index_t bin;
     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);
 #ifdef QUADRATIC_PROBE
     d = 1;
@@ -983,9 +989,10 @@ find_table_bin_ptr_and_reserve(st_table https://github.com/ruby/ruby/blob/trunk/st.c#L989
     st_index_t first_deleted_bin_ind;
     st_table_entry *entries;
 
-    st_assert(tab != NULL && tab->bins != NULL
-	      && tab->entries_bound <= get_allocated_entries(tab)
-	      && tab->entries_start <= tab->entries_bound);
+    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;
@@ -1202,8 +1209,8 @@ st_insert2(st_table *tab, st_data_t key, https://github.com/ruby/ruby/blob/trunk/st.c#L1209
         st_assert(tab->entries_bound < get_allocated_entries(tab));
         check = tab->rebuilds_num;
         key = (*func)(key);
-        st_assert(check == tab->rebuilds_num
-                  && do_hash(key, tab) == hash_value);
+        st_assert(check == tab->rebuilds_num);
+	st_assert(do_hash(key, tab) == hash_value);
         ind = tab->entries_bound++;
         entry = &tab->entries[ind];
         entry->hash = hash_value;
@@ -1339,14 +1346,14 @@ st_shift(st_table *tab, st_data_t *key, https://github.com/ruby/ruby/blob/trunk/st.c#L1346
 	    *key = curr_entry_ptr->key;
 	    if (tab->bins == NULL) {
 	        bin = find_entry(tab, curr_entry_ptr->hash, curr_entry_ptr->key);
-		st_assert(bin != UNDEFINED_ENTRY_IND
-			  && &entries[bin] == curr_entry_ptr);
+		st_assert(bin != UNDEFINED_ENTRY_IND);
+		st_assert(&entries[bin] == curr_entry_ptr);
 	    }
 	    else {
 	        bin_ind = find_table_bin_ind(tab, curr_entry_ptr->hash,
 					     curr_entry_ptr->key);
-		st_assert(bin_ind != UNDEFINED_BIN_IND
-			  && &entries[get_bin(tab->bins, get_size_ind(tab), bin_ind)
+		st_assert(bin_ind != UNDEFINED_BIN_IND);
+		st_assert(&entries[get_bin(tab->bins, get_size_ind(tab), bin_ind)
 				      - ENTRY_BASE] == curr_entry_ptr);
 		MARK_BIN_DELETED(tab, bin_ind);
 	    }
@@ -2162,7 +2169,7 @@ rb_hash_bulk_insert(long argc, const VAL https://github.com/ruby/ruby/blob/trunk/st.c#L2169
     st_index_t n;
     st_table *tab = RHASH(hash)->ntbl;
 
-    st_assert(argc % 2);
+    st_assert(argc % 2 == 0);
     if (! argc)
         return;
     if (! tab) {

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

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