Print this page
Address Robert's feedback

@@ -17,11 +17,11 @@
 #include <sys/sysmacros.h>
 #include <string.h>
 #include <errno.h>
 #include <stdlib.h>
 #include "sysdemangle_int.h"
-#include "cpp.h"
+#include "cxx.h"
 
 #define CHUNK_SIZE  (8U)
 
 /*
  * A name_t is essentially a stack of str_pair_t's.  Generally, the parsing

@@ -149,30 +149,28 @@
 
         return (B_TRUE);
 }
 
 str_pair_t *
-name_at(name_t *n, size_t idx)
+name_at(const name_t *n, size_t idx)
 {
-        if (n->nm_len == 0)
-                return (NULL);
-
-        ASSERT3U(idx, <=, n->nm_len);
+        VERIFY(!name_empty(n));
+        VERIFY3U(idx, <, n->nm_len);
         return (&n->nm_items[n->nm_len - idx - 1]);
 }
 
 str_pair_t *
 name_top(name_t *n)
 {
         return (name_at(n, 0));
 }
 
-str_pair_t *
+void
 name_pop(name_t *n, str_pair_t *sp)
 {
         if (n->nm_len == 0)
-                return (NULL);
+                return;
 
         str_pair_t *top = name_top(n);
 
         if (sp != NULL) {
                 *sp = *top;

@@ -180,21 +178,20 @@
         } else {
                 str_pair_fini(top);
         }
 
         n->nm_len--;
-        return (sp);
 }
 
 boolean_t
 name_join(name_t *n, size_t amt, const char *sep)
 {
         str_pair_t *sp = NULL;
         str_t res = { 0 };
         size_t seplen = strlen(sep);
 
-        ASSERT3U(amt, <=, n->nm_len);
+        VERIFY3U(amt, <=, n->nm_len);
 
         /*
          * A join of 0 elements places an empty string on the stack.  This
          * simplifies code that wants to do things like:
          *   name_join(...); name_fmt(.., "({0})", ...)

@@ -204,11 +201,11 @@
                 return (B_TRUE);
         }
         
         /* A join of 1 element just implies merging the top str_pair_t */
         if (amt == 1) {
-                ASSERT3U(name_len(n), >, 0);
+                VERIFY3U(name_len(n), >, 0);
                 return (str_pair_merge(name_top(n)));
         }
 
         (void) str_init(&res, n->nm_ops);
 

@@ -226,11 +223,11 @@
 
                 sp++;
         }
 
         for (size_t i = 0; i < amt; i++)
-                (void) name_pop(n, NULL);
+                name_pop(n, NULL);
 
         /* since we've removed at least 1 entry, this should always succeed */
         VERIFY(name_add_str(n, &res, NULL));
         return (B_TRUE);
 

@@ -256,12 +253,12 @@
 
                 errno = 0;
                 char *q = NULL;
                 long val = strtol(p + 1, &q, 10);
 
-                ASSERT(val != 0 || errno == 0);
-                ASSERT3U(val, <, n->nm_len);
+                VERIFY(val != 0 || errno == 0);
+                VERIFY3U(val, <, n->nm_len);
 
                 str_pair_t *sp = name_at(n, val);
 
                 if (val > max)
                         max = val;

@@ -297,11 +294,11 @@
 
         return (B_TRUE);
 }
 
 /*
- * replace a number of elements in the name stack with a formatted string
+ * Replace a number of elements in the name stack with a formatted string
  * for format is a plain string with optional {nnn} or {nnn:L|R} substitutions
  * where nnn is the stack position of an element and it's contents (both
  * left and right pieces) are inserted.  Optionally, only the left or
  * right piece can specified using :L|R e.g. {2:L}{3}{2:R} would insert
  * the left piece of element 2, all of element 3, then the right piece of

@@ -329,11 +326,11 @@
         if (!name_fmt_s(n, &res.strp_r, fmt_r, &max))
                 goto error;
 
         if (max >= 0) {
                 for (size_t i = 0; i <= max; i++)
-                        (void) name_pop(n, NULL);
+                        name_pop(n, NULL);
         }
 
         n->nm_items[n->nm_len++] = res;
         return (B_TRUE);
 

@@ -427,11 +424,11 @@
                 name_fini(dest);
                 sub->sub_len--;
                 return (B_FALSE);
         }
 
-        const str_pair_t *src_sp = name_at((name_t *)n, depth - 1);
+        const str_pair_t *src_sp = name_at(n, depth - 1);
 
         for (size_t i = 0; i < depth; i++, src_sp++) {
                 str_pair_t copy = { 0 };
                 str_pair_init(&copy, n->nm_ops);
                 if (!str_pair_copy(src_sp, &copy)) {

@@ -448,11 +445,11 @@
 
 /* push substitution idx onto n */
 boolean_t
 sub_substitute(const sub_t *sub, size_t idx, name_t *n)
 {
-        ASSERT3U(idx, <, sub->sub_len);
+        VERIFY3U(idx, <, sub->sub_len);
 
         const name_t *src = &sub->sub_items[idx];
         const str_pair_t *sp = src->nm_items;
         size_t save = name_len(n);
 

@@ -468,11 +465,11 @@
 
         return (B_TRUE);
 
 fail:
         for (size_t i = 0; i < name_len(n) - save; i++)
-                (void) name_pop(n, NULL);
+                name_pop(n, NULL);
         return (B_FALSE);
 }
 
 void
 sub_pop(sub_t *sub)

@@ -540,11 +537,11 @@
 }
 
 void
 templ_pop(templ_t *tpl)
 {
-        ASSERT(!templ_empty(tpl));
+        VERIFY(!templ_empty(tpl));
 
         sub_t *sub = &tpl->tpl_items[--tpl->tpl_len];
         sub_fini(sub);
 }
 

@@ -579,11 +576,11 @@
 }
 
 boolean_t
 templ_save(const name_t *n, size_t amt, templ_t *tpl)
 {
-        ASSERT3U(tpl->tpl_len, >, 0);
+        VERIFY3U(tpl->tpl_len, >, 0);
 
         sub_t *s = templ_top(tpl);
         boolean_t res = B_TRUE;
 
         /* a bit of a hack -- want an 'empty' entry when saving 0 params */