]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Adjust the lemon implementation so that it always computes the same PDA
authordrh <drh@noemail.net>
Tue, 3 Nov 2009 13:02:25 +0000 (13:02 +0000)
committerdrh <drh@noemail.net>
Tue, 3 Nov 2009 13:02:25 +0000 (13:02 +0000)
regardless of qsort() implementation on the host platform.  In other words,
make all sorts in lemon stable.

FossilOrigin-Name: d66a0f31ebcc56e6f0f462b3db6aab54f7fab816

manifest
manifest.uuid
tool/lemon.c

index 2c9f65adfea809cb099befd3edfc25474256405e..908bd94438f5cca5ad47b314585d01b9efacd891 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,8 +1,8 @@
 -----BEGIN PGP SIGNED MESSAGE-----
 Hash: SHA1
 
-C All\sSQLITE_MAX_VARIABLE_NUMBER\sto\sexceed\s32767.\s\sThe\ssizes\sof\ssome\sstructures\nincrease\swhen\sthe\scompile-time\sparameter\sis\sconfigured\sthis\sway.
-D 2009-11-03T01:22:08
+C Adjust\sthe\slemon\simplementation\sso\sthat\sit\salways\scomputes\sthe\ssame\sPDA\nregardless\sof\sqsort()\simplementation\son\sthe\shost\splatform.\s\sIn\sother\swords,\nmake\sall\ssorts\sin\slemon\sstable.
+D 2009-11-03T13:02:26
 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
 F Makefile.in a77dfde96ad86aafd3f71651a4333a104debe86a
 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -743,7 +743,7 @@ F tool/diffdb.c 7524b1b5df217c20cd0431f6789851a4e0cb191b
 F tool/fragck.tcl 5265a95126abcf6ab357f7efa544787e5963f439
 F tool/genfkey.README cf68fddd4643bbe3ff8e31b8b6d8b0a1b85e20f4
 F tool/genfkey.test 4196a8928b78f51d54ef58e99e99401ab2f0a7e5
-F tool/lemon.c 0eb9829c494dfcea449de36ad677efe7f0742801
+F tool/lemon.c ee5e39ce2b344ce7c81306b27a59da7698114a2d
 F tool/lempar.c 2ed70b3fc896a47e07fedfe543324f008f53d223
 F tool/mkkeywordhash.c 8c9f8e3253555101aaa4bf7a0459cbfc8ddc41cc
 F tool/mkopts.tcl 66ac10d240cc6e86abd37dc908d50382f84ff46e
@@ -764,14 +764,14 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
 F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
 F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
-P 6610cac435428434bc978d5e4df92aa1e431240b
-R ccaf6a810237127b03d8c2dda40d5c18
+P 16a24b4485420bdf30d3c8e22cfbaf008e07df02
+R e72225eb55d8736569f8031586282767
 U drh
-Z 75578a720b6342c3a297305a01e4e12a
+Z 9ed57d7b7fd138a4562a0f8b4ab054bf
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.4.6 (GNU/Linux)
 
-iD8DBQFK74XEoxKgR168RlERAoE0AJ0ReiaY3L/Gf3rz2iTVUhp4M+MNCACePwqQ
-9jr/776w6kq808+th2eWh+E=
-=478y
+iD8DBQFK8CnloxKgR168RlERAvvEAJ4zARLPnrRgcFCLL+urqSma1EJWFACghoK5
+rpncZKK3rz8eBtrxBY7ZVmw=
+=tZsO
 -----END PGP SIGNATURE-----
index ebf6c0b487349eeffc5bf2fcd444c8849380b4db..4a7aa0d1bf8dc4d6c03fa819a05cd3f180650459 100644 (file)
@@ -1 +1 @@
-16a24b4485420bdf30d3c8e22cfbaf008e07df02
\ No newline at end of file
+d66a0f31ebcc56e6f0f462b3db6aab54f7fab816
\ No newline at end of file
index 8336e9a1ba2b249e12a320de13cf3078cba8ee1c..bde65362bc9693195f7ee60d5eab4b0023ed344f 100644 (file)
@@ -369,6 +369,9 @@ static int actioncmp(
   if( rc==0 && ap1->type==REDUCE ){
     rc = ap1->x.rp->index - ap2->x.rp->index;
   }
+  if( rc==0 ){
+    rc = ap2 - ap1;
+  }
   return rc;
 }
 
@@ -1578,7 +1581,7 @@ static char *merge(
   }else if( b==0 ){
     head = a;
   }else{
-    if( (*cmp)(a,b)<0 ){
+    if( (*cmp)(a,b)<=0 ){
       ptr = a;
       a = NEXT(a);
     }else{
@@ -1587,7 +1590,7 @@ static char *merge(
     }
     head = ptr;
     while( a && b ){
-      if( (*cmp)(a,b)<0 ){
+      if( (*cmp)(a,b)<=0 ){
         NEXT(ptr) = a;
         ptr = a;
         a = NEXT(a);
@@ -1639,7 +1642,7 @@ static char *msort(
     set[i] = ep;
   }
   ep = 0;
-  for(i=0; i<LISTSIZE; i++) if( set[i] ) ep = merge(ep,set[i],cmp,offset);
+  for(i=0; i<LISTSIZE; i++) if( set[i] ) ep = merge(set[i],ep,cmp,offset);
   return ep;
 }
 /************************ From the file "option.c" **************************/
@@ -3516,6 +3519,7 @@ struct axset {
   struct state *stp;   /* A pointer to a state */
   int isTkn;           /* True to use tokens.  False for non-terminals */
   int nAction;         /* Number of actions */
+  int iOrder;          /* Original order of action sets */
 };
 
 /*
@@ -3524,7 +3528,13 @@ struct axset {
 static int axset_compare(const void *a, const void *b){
   struct axset *p1 = (struct axset*)a;
   struct axset *p2 = (struct axset*)b;
-  return p2->nAction - p1->nAction;
+  int c;
+  c = p2->nAction - p1->nAction;
+  if( c==0 ){
+    c = p2->iOrder - p1->iOrder;
+  }
+  assert( c!=0 || p1==p2 );
+  return c;
 }
 
 /*
@@ -3684,6 +3694,7 @@ int mhflag;     /* Output in makeheaders format if true */
   ** action table to a minimum, the heuristic of placing the largest action
   ** sets first is used.
   */
+  for(i=0; i<lemp->nstate*2; i++) ax[i].iOrder = i;
   qsort(ax, lemp->nstate*2, sizeof(ax[0]), axset_compare);
   pActtab = acttab_alloc();
   for(i=0; i<lemp->nstate*2 && ax[i].nAction>0; i++){
@@ -4097,7 +4108,11 @@ static int stateResortCompare(const void *a, const void *b){
   n = pB->nNtAct - pA->nNtAct;
   if( n==0 ){
     n = pB->nTknAct - pA->nTknAct;
+    if( n==0 ){
+      n = pB->statenum - pA->statenum;
+    }
   }
+  assert( n!=0 );
   return n;
 }
 
@@ -4401,6 +4416,7 @@ char *x;
 int Symbolcmpp(struct symbol **a, struct symbol **b){
   int i1 = (**a).index + 10000000*((**a).name[0]>'Z');
   int i2 = (**b).index + 10000000*((**b).name[0]>'Z');
+  assert( i1!=i2 || strcmp((**a).name,(**b).name)==0 );
   return i1-i2;
 }