Fix leftovers bug in reading.
authormdw <mdw>
Sat, 19 Oct 2002 11:59:04 +0000 (11:59 +0000)
committermdw <mdw>
Sat, 19 Oct 2002 11:59:04 +0000 (11:59 +0000)
mptext.c
tests/mptext

index fcdac51..3eb58cf 100644 (file)
--- a/mptext.c
+++ b/mptext.c
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: mptext.c,v 1.16 2002/10/15 22:57:43 mdw Exp $
+ * $Id: mptext.c,v 1.17 2002/10/19 11:59:04 mdw Exp $
  *
  * Textual representation of multiprecision numbers
  *
@@ -30,6 +30,9 @@
 /*----- Revision history --------------------------------------------------* 
  *
  * $Log: mptext.c,v $
+ * Revision 1.17  2002/10/19 11:59:04  mdw
+ * Fix leftovers bug in reading.
+ *
  * Revision 1.16  2002/10/15 22:57:43  mdw
  * Bug fix: prevent negative zero.
  *
@@ -348,6 +351,7 @@ restart:
       m->f &= ~MP_UNDEF;
       m = mp_lsr(m, m, (unsigned long)n * MPW_BITS + b);
     }
+    ops->unget(ch, p);
     goto done;
   }}
 
@@ -808,7 +812,8 @@ static int verify(dstr *v)
   int ok = 1;
   int ib = *(int *)v[0].buf, ob = *(int *)v[2].buf;
   dstr d = DSTR_INIT;
-  mp *m = mp_readdstr(MP_NEW, &v[1], 0, ib);
+  size_t off = 0;
+  mp *m = mp_readdstr(MP_NEW, &v[1], &off, ib);
   if (m) {
     if (!ob) {
       fprintf(stderr, "*** unexpected successful parse\n"
@@ -847,12 +852,12 @@ static int verify(dstr *v)
   } else {
     if (ob) {
       fprintf(stderr, "*** unexpected parse failure\n"
-                     "*** input [%i]    = ", ib);
+                     "*** input [%2i]    = ", ib);
       if (ib < 0)
        type_hex.dump(&v[1], stderr);
       else
        fputs(v[1].buf, stderr);
-      fprintf(stderr, "\n*** expected [%i]   = ", ob);
+      fprintf(stderr, "\n*** expected [%2i]   = ", ob);
       if (ob < 0)
        type_hex.dump(&v[3], stderr);
       else
@@ -862,6 +867,20 @@ static int verify(dstr *v)
     }
   }
 
+  if (v[1].len - off != v[4].len ||
+      memcmp(v[1].buf + off, v[4].buf, v[4].len) != 0) {
+    fprintf(stderr, "*** leftovers incorrect\n"
+                   "*** input [%2i]    = ", ib);
+    if (ib < 0)
+      type_hex.dump(&v[1], stderr);
+    else
+      fputs(v[1].buf, stderr);
+    fprintf(stderr, "\n*** expected `%s'\n"
+                   "*** found `%s'\n",
+           v[4].buf, v[1].buf + off);
+    ok = 0;
+  }
+           
   dstr_destroy(&d);
   assert(mparena_count(MPARENA_GLOBAL) == 0);
   return (ok);
@@ -869,11 +888,11 @@ static int verify(dstr *v)
 
 static test_chunk tests[] = {
   { "mptext-ascii", verify,
-    { &type_int, &type_string, &type_int, &type_string, 0 } },
+    { &type_int, &type_string, &type_int, &type_string, &type_string, 0 } },
   { "mptext-bin-in", verify,
-    { &type_int, &type_hex, &type_int, &type_string, 0 } },
+    { &type_int, &type_hex, &type_int, &type_string, &type_string, 0 } },
   { "mptext-bin-out", verify,
-    { &type_int, &type_string, &type_int, &type_hex, 0 } },
+    { &type_int, &type_string, &type_int, &type_hex, &type_string, 0 } },
   { 0, 0, { 0 } }
 };
 
index 71acb86..952f7e0 100644 (file)
@@ -1,87 +1,87 @@
 # Test vectors for MP textual I/O
 #
-# $Id: mptext,v 1.11 2002/10/15 22:57:43 mdw Exp $
+# $Id: mptext,v 1.12 2002/10/19 11:59:04 mdw Exp $
 
 mptext-ascii {
   # --- Perfectly valid things ---
 
-  10 0                                 10 0;
-  0 0                                  10 0;
-  10 52                                        10 52;
-  10 654365464655464577673765769678    10 654365464655464577673765769678;
-  10 654365464655464577673765769678    16 8425e6d06f272b9a2d73ed1ce;
-  10 596569802840985608098409867       8 366570443501403714657464766613;
-  16 8425E6D06F272B9A2D73ED1CE         10 654365464655464577673765769678;
-  0 654365464655464577673765769678     16 8425e6d06f272b9a2d73ed1ce;
-  0 16_8425E6D06F272B9A2D73ED1CE       10 654365464655464577673765769678;
-  0 -0x8425E6D06F272B9A2D73ED1CE       10 -654365464655464577673765769678;
-  0 -8_366570443501403714657464766613  10 -596569802840985608098409867;
-  8 -366570443501403714657464766613    10 -596569802840985608098409867;
-  0 0366570443501403714657464766613    10 596569802840985608098409867;
+  10 0                                 10 0 "";
+  0 0                                  10 0 "";
+  10 52                                        10 52 "";
+  10 654365464655464577673765769678    10 654365464655464577673765769678 "";
+  10 654365464655464577673765769678    16 8425e6d06f272b9a2d73ed1ce "";
+  10 596569802840985608098409867       8 366570443501403714657464766613 "";
+  16 8425E6D06F272B9A2D73ED1CE         10 654365464655464577673765769678 "";
+  0 654365464655464577673765769678     16 8425e6d06f272b9a2d73ed1ce "";
+  0 16_8425E6D06F272B9A2D73ED1CE       10 654365464655464577673765769678 "";
+  0 -0x8425E6D06F272B9A2D73ED1CE       10 -654365464655464577673765769678 "";
+  0 -8_366570443501403714657464766613  10 -596569802840985608098409867 "";
+  8 -366570443501403714657464766613    10 -596569802840985608098409867 "";
+  0 0366570443501403714657464766613    10 596569802840985608098409867 "";
 
   # --- Bogus things ---
 
-  10 "" 0 0;                   # Empty string fails
-  10 foo 0 0;                  # Non-numeric character
-  10 134f 10 134;              # Stop parsing when reaching `f'
-  4 12345 10 27;               # Stop parsing when reaching `4'
-  0 63_ 10 63;                 # 37 is an invalid base, so stop at `_'
-  0 36_ 0 0;                   # 36 is a valid base, so restart and fail
+  10 "" 0 0 "";                        # Empty string fails
+  10 foo 0 0 "foo";            # Non-numeric character
+  10 134f 10 134 "f";          # Stop parsing when reaching `f'
+  4 12345 10 27 "45";          # Stop parsing when reaching `4'
+  0 63_ 10 63 "_";             # 37 is an invalid base, so stop at `_'
+  0 36_ 0 0 "";                        # 36 is a valid base, so restart and fail
 
   # --- Big bases ---
 
-  62 0 10 0;
-  10 0 62 0;
-  36 A 10 10;
-  36 Z 10 35;
-  37 A 10 36;
-  10 36 37 A;
-  62 Z 10 61;
+  62 0 10 0 "";
+  10 0 62 0 "";
+  36 A 10 10 "";
+  36 Z 10 35 "";
+  37 A 10 36 "";
+  10 36 37 A "";
+  62 Z 10 61 "";
 
-  0 36_a 10 10;
-  0 36_A 10 10;
-  0 37_A 10 36;
+  0 36_a 10 10 "";
+  0 36_A 10 10 "";
+  0 37_A 10 36 "";
 
-  0 0x10 10 16;
-  0 0o10 10 8;
-  0 0b10 10 2;
-  0 010 10 8;
+  0 0x10 10 16 "";
+  0 0o10 10 8 "";
+  0 0b10 10 2 "";
+  0 010 10 8 "";
 
   # --- Word-boundary tests for binary-radix translation ---
 
-  0 0                                  16 0;
-  8 1234567012                         8 1234567012;
-  8 12345670123                                8 12345670123;
-  8 123456701234                       8 123456701234;
+  0 0                                  16 0 "";
+  8 1234567012                         8 1234567012 "";
+  8 12345670123                                8 12345670123 "";
+  8 123456701234                       8 123456701234 "";
 
-  16 1234567                           16 1234567;
-  16 12345678                          16 12345678;
-  16 123456789                         16 123456789;
+  16 1234567                           16 1234567 "";
+  16 12345678                          16 12345678 "";
+  16 123456789                         16 123456789 "";
 
-  10 -4009356060                       16 -eef9eb1c;
+  10 -4009356060                       16 -eef9eb1c "";
 
   # --- Cussidness ---
 
-  0 -0                                 10 0;
+  0 -0                                 10 0 "";
 
   # --- Bugs ---
 
   16 84d192cd06ae59691897fa409da6198d5269325d
-  16 84d192cd06ae59691897fa409da6198d5269325d;
+  16 84d192cd06ae59691897fa409da6198d5269325d "";
 
   16 -9802d5c5d5a73f9d4e694a8920f95231b4017f3ec6a4654ace3fa3d85879e5964dade0e051d57f13c275dab1df3da5331f39271efb2792d1dad4460fd5eb5c21fbf355456f523e5631e623074ff9b3e85cf5e0a9336c8d8b8621b24c4e625800ee0152d12c8e22658a66ade38cb4453ab6e4958114717355186649a6cc20d9f5ae2207f99814965035072a9f2121c8f9dd22ab134181378906291aae97287b62a2f592bbceb4198c9cd78e1968bf1e16865c3c6ce9c777232f186b5da240a24523a07faca9de44eba510c91917e099372e67a6a66e93fe7aaefcb9c5485e1a889eae721ab6407586880a95575a968b43bdf50323627aa0fcddfa4e198b0008
-  10 -74959454570640520505374182178324326240748657042677990093617716411759477136824854815262670168473667077524864904515489090301434501507378472350618141578200289566815110468728966378289347050752371322168328511598641143081017162500179880923097593329564317427467179672704707842937085621549781627579801356509572397210965270406925309382945647493757499822518272539171346319468210919037390479279679328187057939609889863122790083219768061816093131875491575840052493376341193028052061557296969558099473333023971577236615940525630787016398581105441977909848659239970133974969366933817929047771871736452423855320657946133173829640;
+  10 -74959454570640520505374182178324326240748657042677990093617716411759477136824854815262670168473667077524864904515489090301434501507378472350618141578200289566815110468728966378289347050752371322168328511598641143081017162500179880923097593329564317427467179672704707842937085621549781627579801356509572397210965270406925309382945647493757499822518272539171346319468210919037390479279679328187057939609889863122790083219768061816093131875491575840052493376341193028052061557296969558099473333023971577236615940525630787016398581105441977909848659239970133974969366933817929047771871736452423855320657946133173829640 "";
 
   10 687036505685680036980563991304827689190226068191165515873309582371531653761560838357887565473014960851061079052387145199258972778940173525017542879674305252823453991900595437468144352005006881129612951699750949026636206282574720840178116341517038998609517724307448384647380133273761360084019113505091720961437658149042479826982973196933684563380877276612883608481996579884762706391098995123384485837872544276099219443948234067623442105312332114374763392077663374681230289067615025968182722516808457505932863951619224171887832194148545132638772027329666389477813640620737624951105503846166715576529533580414958055708947608220960395455545922617914622611716584821091744228076205865701038484061060900340103461251087987631583104425599437283952841086221737575051158322973751353914369450945591184550003693808660890173148206999627057352641910478408389852121815588924208719373851205997267929487223022997903565246821511833717944887785333763131071163649350968541111796906733695518487580626938892775883629672280655177072837819344983336811201072380418330154409415723975489649421805372088286721361996667976678161505679350285875598457893785891475462099191282531966080162136450154198672623485698300307676277037616099696441730508788295411634665370788798384809584417102543248560317224205079917990766513568040641690632751952309869792602319263342525778046078743231821682847703178976601855555261436480615639995150308874740741630953255447186244703692652027199198662385455033073594432232250325046519267763604243367272471024553800469955272676941568451192546782745963075159357666087761637705388608592656535848292947073782242206595438203903079185128849386496430347274188109070907185471363018498891836986716946253163675821471661778024303689714601286352436391739170368727508436484115845640636653283093361670039386061546795520151041150800979484160765783927564359393959237330742523328888527872599693558141880251962681735003114604660394550415472363991770499647732372855076408144546777820449665557724138072899691283182780416000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
-  10 687036505685680036980563991304827689190226068191165515873309582371531653761560838357887565473014960851061079052387145199258972778940173525017542879674305252823453991900595437468144352005006881129612951699750949026636206282574720840178116341517038998609517724307448384647380133273761360084019113505091720961437658149042479826982973196933684563380877276612883608481996579884762706391098995123384485837872544276099219443948234067623442105312332114374763392077663374681230289067615025968182722516808457505932863951619224171887832194148545132638772027329666389477813640620737624951105503846166715576529533580414958055708947608220960395455545922617914622611716584821091744228076205865701038484061060900340103461251087987631583104425599437283952841086221737575051158322973751353914369450945591184550003693808660890173148206999627057352641910478408389852121815588924208719373851205997267929487223022997903565246821511833717944887785333763131071163649350968541111796906733695518487580626938892775883629672280655177072837819344983336811201072380418330154409415723975489649421805372088286721361996667976678161505679350285875598457893785891475462099191282531966080162136450154198672623485698300307676277037616099696441730508788295411634665370788798384809584417102543248560317224205079917990766513568040641690632751952309869792602319263342525778046078743231821682847703178976601855555261436480615639995150308874740741630953255447186244703692652027199198662385455033073594432232250325046519267763604243367272471024553800469955272676941568451192546782745963075159357666087761637705388608592656535848292947073782242206595438203903079185128849386496430347274188109070907185471363018498891836986716946253163675821471661778024303689714601286352436391739170368727508436484115845640636653283093361670039386061546795520151041150800979484160765783927564359393959237330742523328888527872599693558141880251962681735003114604660394550415472363991770499647732372855076408144546777820449665557724138072899691283182780416000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000;
+  10 687036505685680036980563991304827689190226068191165515873309582371531653761560838357887565473014960851061079052387145199258972778940173525017542879674305252823453991900595437468144352005006881129612951699750949026636206282574720840178116341517038998609517724307448384647380133273761360084019113505091720961437658149042479826982973196933684563380877276612883608481996579884762706391098995123384485837872544276099219443948234067623442105312332114374763392077663374681230289067615025968182722516808457505932863951619224171887832194148545132638772027329666389477813640620737624951105503846166715576529533580414958055708947608220960395455545922617914622611716584821091744228076205865701038484061060900340103461251087987631583104425599437283952841086221737575051158322973751353914369450945591184550003693808660890173148206999627057352641910478408389852121815588924208719373851205997267929487223022997903565246821511833717944887785333763131071163649350968541111796906733695518487580626938892775883629672280655177072837819344983336811201072380418330154409415723975489649421805372088286721361996667976678161505679350285875598457893785891475462099191282531966080162136450154198672623485698300307676277037616099696441730508788295411634665370788798384809584417102543248560317224205079917990766513568040641690632751952309869792602319263342525778046078743231821682847703178976601855555261436480615639995150308874740741630953255447186244703692652027199198662385455033073594432232250325046519267763604243367272471024553800469955272676941568451192546782745963075159357666087761637705388608592656535848292947073782242206595438203903079185128849386496430347274188109070907185471363018498891836986716946253163675821471661778024303689714601286352436391739170368727508436484115845640636653283093361670039386061546795520151041150800979484160765783927564359393959237330742523328888527872599693558141880251962681735003114604660394550415472363991770499647732372855076408144546777820449665557724138072899691283182780416000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 "";
 }
 
 mptext-bin-in {
-  -10 010203040506070809 10 123456789;
-  -100 01172d4359 10 123456789;
+  -10 010203040506070809 10 123456789 "";
+  -100 01172d4359 10 123456789 "";
 }
 
 mptext-bin-out {
-  10 123456789 -10 010203040506070809;
-  10 123456789 -100 01172d4359;
+  10 123456789 -10 010203040506070809 "";
+  10 123456789 -100 01172d4359 "";
 }