]> granicus.if.org Git - graphviz/commitdiff
replace RBTree assertion calls with libc assert() calls
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sun, 12 Jul 2020 03:00:27 +0000 (20:00 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Tue, 14 Jul 2020 14:07:19 +0000 (07:07 -0700)
This change uses the idiom `assert(expression && "message")`. This is a way to
attach readable messages to assertion failures in C, as the libc assert
interface has no way to do this natively. Related to #1742.

lib/rbtree/red_black_tree.c

index cc9c6dea107d4b6a4b7c328cf35384da023a5978..028ef7d3a9f958445a07c1f8d6c721cb792e6182 100644 (file)
@@ -7,6 +7,7 @@
 
 #include "config.h"
 
+#include <assert.h>
 #include "red_black_tree.h"
 #include "stdio.h"
 
@@ -115,9 +116,7 @@ static void LeftRotate(rb_red_blk_tree* tree, rb_red_blk_node* x) {
   y->left=x;
   x->parent=y;
 
-#ifdef DEBUG_ASSERT
-  Assert(!tree->nil->red,"nil not red in LeftRotate");
-#endif
+  assert(!tree->nil->red && "nil not red in LeftRotate");
 }
 
 
@@ -169,9 +168,7 @@ static void RightRotate(rb_red_blk_tree* tree, rb_red_blk_node* y) {
   x->right=y;
   y->parent=x;
 
-#ifdef DEBUG_ASSERT
-  Assert(!tree->nil->red,"nil not red in RightRotate");
-#endif
+  assert(!tree->nil->red && "nil not red in RightRotate");
 }
 
 /***********************************************************************/
@@ -214,9 +211,7 @@ static void TreeInsertHelp(rb_red_blk_tree* tree, rb_red_blk_node* z) {
     y->right=z;
   }
 
-#ifdef DEBUG_ASSERT
-  Assert(!tree->nil->red,"nil not red in TreeInsertHelp");
-#endif
+  assert(!tree->nil->red && "nil not red in TreeInsertHelp");
 }
 
 /*  Before calling Insert RBTree the node x should have its key set */
@@ -291,10 +286,8 @@ rb_red_blk_node * RBTreeInsert(rb_red_blk_tree* tree, void* key, void* info) {
   tree->root->left->red=0;
   return(newNode);
 
-#ifdef DEBUG_ASSERT
-  Assert(!tree->nil->red,"nil not red in RBTreeInsert");
-  Assert(!tree->root->red,"root not red in RBTreeInsert");
-#endif
+  assert(!tree->nil->red && "nil not red in RBTreeInsert");
+  assert(!tree->root->red && "root not red in RBTreeInsert");
 }
 
 /***********************************************************************/
@@ -576,9 +569,7 @@ static void RBDeleteFixUp(rb_red_blk_tree* tree, rb_red_blk_node* x) {
   }
   x->red=0;
 
-#ifdef DEBUG_ASSERT
-  Assert(!tree->nil->red,"nil not black in RBDeleteFixUp");
-#endif
+  assert(!tree->nil->red && "nil not black in RBDeleteFixUp");
 }
 
 
@@ -617,9 +608,7 @@ void RBDelete(rb_red_blk_tree* tree, rb_red_blk_node* z){
   }
   if (y != z) { /* y should not be nil in this case */
 
-#ifdef DEBUG_ASSERT
-    Assert( (y!=tree->nil),"y is nil in RBDelete\n");
-#endif
+    assert(y!=tree->nil && "y is nil in RBDelete");
     /* y is the node to splice out and x is its child */
 
     if (!(y->red)) RBDeleteFixUp(tree,x);
@@ -644,9 +633,7 @@ void RBDelete(rb_red_blk_tree* tree, rb_red_blk_node* z){
     free(y);
   }
   
-#ifdef DEBUG_ASSERT
-  Assert(!tree->nil->red,"nil not black in RBDelete");
-#endif
+  assert(!tree->nil->red && "nil not black in RBDelete");
 }