chiark / gitweb /
@@@ tvec and tty mess
[mLib] / test / tvec-types.c
index 70ce87aad71d29441d5c7482758c3935d9ae9c09..3c6005768f3175bc198e2b6d3af102154426b84c 100644 (file)
@@ -452,6 +452,7 @@ static int parse_szint(struct tvec_state *tv, unsigned long *u_out,
   unsigned f = 0;
 #define f_range 1u
 
+  d.a = &tv->p_test->a;
   if (tvec_readword(tv, &d, 0, delims, what)) { rc = -1; goto end; }
   p = d.buf;
   if (parse_unsigned_integer(&u, &p, p)) goto bad;
@@ -470,7 +471,6 @@ static int parse_szint(struct tvec_state *tv, unsigned long *u_out,
 
   *u_out = u; rc = 0;
 end:
-  dstr_destroy(&d);
   return (rc);
 
 bad:
@@ -680,6 +680,8 @@ static int parse_floating(double *x_out, const char **q_out, const char *p,
   double x;
   int olderr, rc;
 
+  d.a = &tv->p_test->a;
+
   /* Check for special tokens. */
   if (STRCMP(p, ==, "#nan")) {
 #ifdef NAN
@@ -770,7 +772,6 @@ static int parse_floating(double *x_out, const char **q_out, const char *p,
   /* All done. */
   *x_out = x; rc = 0;
 end:
-  dstr_destroy(&d);
   return (rc);
 }
 
@@ -1276,6 +1277,7 @@ static int read_compound_string(void **p_inout, size_t *sz_inout,
   int ch, err, rc;
 
   set_up_encoding(&ccl, &cdf, code); cdc = 0;
+  d.a = w.a = &tv->p_test->a;
 
   if (tvec_nexttoken(tv)) return (tvec_syntax(tv, fgetc(tv->fp), "string"));
   do {
@@ -1361,7 +1363,7 @@ static int read_compound_string(void **p_inout, size_t *sz_inout,
            dstr_ensure(&d, n);
            fill_pattern(d.buf + d.len, n, pp, sz); d.len += n;
          }
-         xfree(pp); pp = 0;
+         free(pp); pp = 0;
        }
 
        /* Anything else is an error. */
@@ -1410,7 +1412,7 @@ done:
 end:
   /* Clean up any debris. */
   if (cdc) cdc->ops->destroy(cdc);
-  if (pp) xfree(pp);
+  if (pp) free(pp);
   dstr_destroy(&d); dstr_destroy(&w);
   return (rc);
 }
@@ -1559,12 +1561,12 @@ static int parse_int(union tvec_regval *rv, const struct tvec_regdef *rd,
   dstr d = DSTR_INIT;
   int rc;
 
+  d.a = &tv->p_test->a;
   if (tvec_readword(tv, &d, 0, ";", "signed integer"))
     { rc = -1; goto end; }
   if (parse_signed(&rv->i, d.buf, rd->arg.p, tv)) { rc = -1; goto end; }
   rc = 0;
 end:
-  dstr_destroy(&d);
   return (rc);
 }
 
@@ -1574,12 +1576,12 @@ static int parse_uint(union tvec_regval *rv, const struct tvec_regdef *rd,
   dstr d = DSTR_INIT;
   int rc;
 
+  d.a = &tv->p_test->a;
   if (tvec_readword(tv, &d, 0, ";", "unsigned integer"))
     { rc = -1; goto end; }
   if (parse_unsigned(&rv->u, d.buf, rd->arg.p, tv)) { rc = -1; goto end; }
   rc = 0;
 end:
-  dstr_destroy(&d);
   return (rc);
 }
 
@@ -1922,13 +1924,13 @@ static int parse_float(union tvec_regval *rv, const struct tvec_regdef *rd,
   dstr d = DSTR_INIT;
   int rc;
 
+  d.a = &tv->p_test->a;
   if (tvec_readword(tv, &d, 0, ";", "floating-point number"))
     { rc = -1; goto end; }
   if (parse_floating(&rv->f, 0, d.buf, rd->arg.p, tv))
     { rc = -1; goto end; }
   rc = 0;
 end:
-  dstr_destroy(&d);
   return (rc);
 }
 
@@ -2173,6 +2175,7 @@ static int parse_duration(union tvec_regval *rv,
   double t;
   int rc;
 
+  d.a = &tv->p_test->a;
   if (tvec_readword(tv, &d, 0, ";", "duration")) { rc = -1; goto end; }
   if (parse_floating(&t, &q, d.buf,
                     rd->arg.p ? rd->arg.p : &tvflt_nonneg, tv))
@@ -2188,7 +2191,6 @@ static int parse_duration(union tvec_regval *rv,
 
   rv->f = t; rc = 0;
 end:
-  dstr_destroy(&d);
   return (rc);
 }
 
@@ -2470,6 +2472,7 @@ static int frombuf_penum(buf *b, union tvec_regval *rv,
     dstr d = DSTR_INIT;                                                        \
     int rc;                                                            \
                                                                        \
+    d.a = &tv->p_test->a;                                              \
     if (tvec_readword(tv, &d, 0,                                       \
                      ";", "%s tag or " LITSTR_##tag_, ei->name))       \
       { rc = -1; goto end; }                                           \
@@ -2479,7 +2482,6 @@ static int frombuf_penum(buf *b, union tvec_regval *rv,
     done:                                                              \
     rc = 0;                                                            \
   end:                                                                 \
-    dstr_destroy(&d);                                                  \
     return (rc);                                                       \
   }
 
@@ -2653,6 +2655,9 @@ static const struct tvec_iassoc cmp_assoc[] = {
 const struct tvec_ienuminfo tvenum_cmp =
   { "cmp", cmp_assoc, &tvrange_int };
 
+static const struct tvec_passoc dummy_assoc[] = { TVEC_ENDENUM };
+static const struct tvec_penuminfo dummy_peinfo = { "pointer", dummy_assoc };
+
 /* --- @tvec_claimeq_tenum@ --- *
  *
  * Arguments:  @struct tvec_state *tv@ = test-vector state
@@ -2680,21 +2685,31 @@ const struct tvec_ienuminfo tvenum_cmp =
          union tvec_misc arg;                                          \
          struct tvec_reg rval, rref;                                   \
                                                                        \
+         PREFLIGHT_##tag;                                              \
          arg.p = ei;                                                   \
          rval.f = rref.f = TVRF_LIVE;                                  \
          rval.v.slot = GET_##tag(e0); rref.v.slot = GET_##tag(e1);     \
          return (tvec_claimeq(tv, &tvty_##slot##enum, &arg,            \
                               &rval, &rref, file, lno, expr));         \
        }
+#define PREFLIGHT_INT do ; while (0)
 #define GET_INT(e) (e)
+#define PREFLIGHT_UINT do ; while (0)
 #define GET_UINT(e) (e)
+#define PREFLIGHT_FLT do ; while (0)
 #define GET_FLT(e) (e)
+#define PREFLIGHT_PTR                                                  \
+       if (!ei) ei = &dummy_peinfo
 #define GET_PTR(e) (UNCONST(void, (e)))
 TVEC_MISCSLOTS(DEFCLAIM)
 #undef DEFCLAIM
+#undef PREFLIGHT_INT
 #undef GET_INT
+#undef PREFLIGHT_UINT
 #undef GET_UINT
+#undef PREFLIGHT_FLT
 #undef GET_FLT
+#undef PREFLIGHT_PTR
 #undef GET_PTR
 
 /*----- Flag types --------------------------------------------------------*/
@@ -2729,6 +2744,8 @@ static int parse_flags(union tvec_regval *rv, const struct tvec_regdef *rd,
   dstr d = DSTR_INIT;
   int ch, rc;
 
+  d.a = &tv->p_test->a;
+
   for (;;) {
 
     /* Read the next item. */
@@ -2746,9 +2763,9 @@ static int parse_flags(union tvec_regval *rv, const struct tvec_regdef *rd,
       }
 
     /* Otherwise, try to parse it as a raw integer. */
-    if (parse_unsigned(&t, d.buf, fi->range, tv))
-      { rc = -1; goto end; }
-    v |= t;
+    if (parse_unsigned(&t, d.buf, fi->range, tv)) { rc = -1; goto end; }
+    if (m&t) { tvec_error(tv, "colliding flag setting"); rc = -1; goto end; }
+    v |= t; m |= t;
 
   next:
     /* Advance to the next token.  If it's a separator then consume it, and
@@ -2766,7 +2783,6 @@ static int parse_flags(union tvec_regval *rv, const struct tvec_regdef *rd,
   /* Done. */
   rv->u = v; rc = 0;
 end:
-  dstr_destroy(&d);
   return (rc);
 }
 
@@ -2853,6 +2869,7 @@ int tvec_claimeq_flags(struct tvec_state *tv,
   union tvec_misc arg;
   struct tvec_reg rval, rref;
 
+  arg.p = fi;
   rval.f = rref.f = TVRF_LIVE; rval.v.u = f0; rref.v.u = f1;
   return (tvec_claimeq(tv, &tvty_flags, &arg,
                       &rval, &rref, file, lno, expr));
@@ -2990,6 +3007,8 @@ static int parse_char(union tvec_regval *rv, const struct tvec_regdef *rd,
   unsigned f = 0;
 #define f_quote 1u
 
+  d.a = &tv->p_test->a;
+
   /* Advance until we find something. */
   if (tvec_nexttoken(tv))
     return (tvec_syntax(tv, fgetc(tv->fp), "character"));
@@ -3062,7 +3081,6 @@ static int parse_char(union tvec_regval *rv, const struct tvec_regdef *rd,
   /* Done. */
   rc = 0;
 end:
-  dstr_destroy(&d);
   return (rc);
 
 #undef f_quote