table: Make debug code unconditional.
authorBen Pfaff <blp@cs.stanford.edu>
Sun, 22 Jan 2023 18:41:03 +0000 (10:41 -0800)
committerBen Pfaff <blp@cs.stanford.edu>
Fri, 27 Jan 2023 19:48:29 +0000 (11:48 -0800)
The debugging code in table_vline() and table_hline() was in practice
always enabled, but because of the way it was written each of the tests
was being re-tested in an assertion.  It seems better to just enable it
all the time and avoid duplication.

src/output/table.c

index 523a5ea75ab1243d1a33a3117567c3a22771fe28..f67bf0a07822a1a8e11b92c43583d26a7a280444 100644 (file)
@@ -245,9 +245,6 @@ cell_style_dump (const struct cell_style *c)
           c->margin[TABLE_VERT][0], c->margin[TABLE_VERT][1]);
 }
 \f
-
-static const bool debugging = true;
-
 /* Creates and returns a new table with NC columns and NR rows and initially no
    header rows or columns.
 
@@ -282,21 +279,13 @@ table_create (int nc, int nr, int hl, int hr, int ht, int hb)
 void
 table_vline (struct table *t, int style, int x, int y1, int y2)
 {
-  if (debugging)
+  if (x < 0 || x > t->n[H] || y1 < 0 || y1 > y2 || y2 >= t->n[V])
     {
-      if (x < 0 || x > t->n[H]
-          || y1 < 0 || y1 >= t->n[V]
-          || y2 < 0 || y2 >= t->n[V])
-        {
-          printf ("bad vline: x=%d y=(%d,%d) in table size (%d,%d)\n",
-                  x, y1, y2, t->n[H], t->n[V]);
-          return;
-        }
+      printf ("bad vline: x=%d y=(%d,%d) in table size (%d,%d)\n",
+              x, y1, y2, t->n[H], t->n[V]);
+      abort ();
     }
 
-  assert (0 <= x && x <= t->n[H]);
-  assert (0 <= y1 && y1 <= y2 && y2 <= t->n[V]);
-
   for (int y = y1; y <= y2; y++)
     t->rv[x + (t->n[H] + 1) * y] = style;
 }
@@ -306,21 +295,13 @@ table_vline (struct table *t, int style, int x, int y1, int y2)
 void
 table_hline (struct table *t, int style, int x1, int x2, int y)
 {
-  if (debugging)
+  if (y < 0 || y > t->n[V] || x1 < 0 || x1 > x2 || x2 >= t->n[H])
     {
-      if (y < 0 || y > t->n[V]
-          || x1 < 0 || x1 >= t->n[H]
-          || x2 < 0 || x2 >= t->n[H])
-        {
-          printf ("bad hline: x=(%d,%d) y=%d in table size (%d,%d)\n",
-                  x1, x2, y, t->n[H], t->n[V]);
-          return;
-        }
+      printf ("bad hline: x=(%d,%d) y=%d in table size (%d,%d)\n",
+              x1, x2, y, t->n[H], t->n[V]);
+      abort ();
     }
 
-  assert (0 <= y && y <= t->n[V]);
-  assert (0 <= x1 && x1 <= x2 && x2 < t->n[H]);
-
   for (int x = x1; x <= x2; x++)
     t->rh[x + t->n[H] * y] = style;
 }