/ Check-in [ec052b4f]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Merge recent enhancements from trunk.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | apple-osx
Files: files | file ages | folders
SHA1: ec052b4f14a8a7019bfc1bbe474020abafa557f3
User & Date: drh 2016-03-18 00:58:39
Context
2016-03-18
11:03
Test case tweaks to better support the Apple configuration options. check-in: cb0ffe84 user: drh tags: apple-osx
00:58
Merge recent enhancements from trunk. check-in: ec052b4f user: drh tags: apple-osx
00:39
Fix FTS5 so that it works with SQLITE_OMIT_AUTORESET. check-in: b199637d user: drh tags: trunk
2016-03-16
01:09
Merge the SQLITE_OMIT_CODEC_FROM_TCL compile-time option from trunk. check-in: 161d91e4 user: drh tags: apple-osx
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to ext/fts5/fts5_expr.c.

  2496   2496     UNUSED_PARAM2(iUnused1, iUnused2);
  2497   2497   
  2498   2498     if( (tflags & FTS5_TOKEN_COLOCATED)==0 ) p->iOff++;
  2499   2499     for(i=0; i<pExpr->nPhrase; i++){
  2500   2500       Fts5ExprTerm *pTerm;
  2501   2501       if( p->aPopulator[i].bOk==0 ) continue;
  2502   2502       for(pTerm=&pExpr->apExprPhrase[i]->aTerm[0]; pTerm; pTerm=pTerm->pSynonym){
  2503         -      int nTerm = strlen(pTerm->zTerm);
         2503  +      int nTerm = (int)strlen(pTerm->zTerm);
  2504   2504         if( (nTerm==nToken || (nTerm<nToken && pTerm->bPrefix))
  2505   2505          && memcmp(pTerm->zTerm, pToken, nTerm)==0
  2506   2506         ){
  2507   2507           int rc = sqlite3Fts5PoslistWriterAppend(
  2508   2508               &pExpr->apExprPhrase[i]->poslist, &p->aPopulator[i].writer, p->iOff
  2509   2509           );
  2510   2510           if( rc ) return rc;

Changes to ext/fts5/fts5_storage.c.

   141    141         if( rc!=SQLITE_OK && pzErrMsg ){
   142    142           *pzErrMsg = sqlite3_mprintf("%s", sqlite3_errmsg(pC->db));
   143    143         }
   144    144       }
   145    145     }
   146    146   
   147    147     *ppStmt = p->aStmt[eStmt];
          148  +  sqlite3_reset(*ppStmt);
   148    149     return rc;
   149    150   }
   150    151   
   151    152   
   152    153   static int fts5ExecPrintf(
   153    154     sqlite3 *db,
   154    155     char **pzErr,
................................................................................
  1117   1118       rc = sqlite3Fts5IndexSetCookie(p->pIndex, iNew);
  1118   1119       if( rc==SQLITE_OK ){
  1119   1120         p->pConfig->iCookie = iNew;
  1120   1121       }
  1121   1122     }
  1122   1123     return rc;
  1123   1124   }
  1124         -
  1125         -

Changes to src/expr.c.

  1279   1279   */
  1280   1280   u32 sqlite3ExprListFlags(const ExprList *pList){
  1281   1281     int i;
  1282   1282     u32 m = 0;
  1283   1283     if( pList ){
  1284   1284       for(i=0; i<pList->nExpr; i++){
  1285   1285          Expr *pExpr = pList->a[i].pExpr;
  1286         -       if( ALWAYS(pExpr) ) m |= pExpr->flags;
         1286  +       assert( pExpr!=0 );
         1287  +       m |= pExpr->flags;
  1287   1288       }
  1288   1289     }
  1289   1290     return m;
  1290   1291   }
  1291   1292   
  1292   1293   /*
  1293   1294   ** These routines are Walker callbacks used to check expressions to
................................................................................
  3544   3545         break;
  3545   3546       }
  3546   3547       case TK_NOT: {
  3547   3548         testcase( jumpIfNull==0 );
  3548   3549         sqlite3ExprIfFalse(pParse, pExpr->pLeft, dest, jumpIfNull);
  3549   3550         break;
  3550   3551       }
         3552  +    case TK_IS:
         3553  +    case TK_ISNOT:
         3554  +      testcase( op==TK_IS );
         3555  +      testcase( op==TK_ISNOT );
         3556  +      op = (op==TK_IS) ? TK_EQ : TK_NE;
         3557  +      jumpIfNull = SQLITE_NULLEQ;
         3558  +      /* Fall thru */
  3551   3559       case TK_LT:
  3552   3560       case TK_LE:
  3553   3561       case TK_GT:
  3554   3562       case TK_GE:
  3555   3563       case TK_NE:
  3556   3564       case TK_EQ: {
  3557   3565         testcase( jumpIfNull==0 );
................................................................................
  3559   3567         r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, &regFree2);
  3560   3568         codeCompare(pParse, pExpr->pLeft, pExpr->pRight, op,
  3561   3569                     r1, r2, dest, jumpIfNull);
  3562   3570         assert(TK_LT==OP_Lt); testcase(op==OP_Lt); VdbeCoverageIf(v,op==OP_Lt);
  3563   3571         assert(TK_LE==OP_Le); testcase(op==OP_Le); VdbeCoverageIf(v,op==OP_Le);
  3564   3572         assert(TK_GT==OP_Gt); testcase(op==OP_Gt); VdbeCoverageIf(v,op==OP_Gt);
  3565   3573         assert(TK_GE==OP_Ge); testcase(op==OP_Ge); VdbeCoverageIf(v,op==OP_Ge);
  3566         -      assert(TK_EQ==OP_Eq); testcase(op==OP_Eq); VdbeCoverageIf(v,op==OP_Eq);
  3567         -      assert(TK_NE==OP_Ne); testcase(op==OP_Ne); VdbeCoverageIf(v,op==OP_Ne);
  3568         -      testcase( regFree1==0 );
  3569         -      testcase( regFree2==0 );
  3570         -      break;
  3571         -    }
  3572         -    case TK_IS:
  3573         -    case TK_ISNOT: {
  3574         -      testcase( op==TK_IS );
  3575         -      testcase( op==TK_ISNOT );
  3576         -      r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
  3577         -      r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, &regFree2);
  3578         -      op = (op==TK_IS) ? TK_EQ : TK_NE;
  3579         -      codeCompare(pParse, pExpr->pLeft, pExpr->pRight, op,
  3580         -                  r1, r2, dest, SQLITE_NULLEQ);
  3581         -      VdbeCoverageIf(v, op==TK_EQ);
  3582         -      VdbeCoverageIf(v, op==TK_NE);
         3574  +      assert(TK_EQ==OP_Eq); testcase(op==OP_Eq);
         3575  +      VdbeCoverageIf(v, op==OP_Eq && jumpIfNull==SQLITE_NULLEQ);
         3576  +      VdbeCoverageIf(v, op==OP_Eq && jumpIfNull!=SQLITE_NULLEQ);
         3577  +      assert(TK_NE==OP_Ne); testcase(op==OP_Ne);
         3578  +      VdbeCoverageIf(v, op==OP_Ne && jumpIfNull==SQLITE_NULLEQ);
         3579  +      VdbeCoverageIf(v, op==OP_Ne && jumpIfNull!=SQLITE_NULLEQ);
  3583   3580         testcase( regFree1==0 );
  3584   3581         testcase( regFree2==0 );
  3585   3582         break;
  3586   3583       }
  3587   3584       case TK_ISNULL:
  3588   3585       case TK_NOTNULL: {
  3589   3586         assert( TK_ISNULL==OP_IsNull );   testcase( op==TK_ISNULL );
................................................................................
  3700   3697         break;
  3701   3698       }
  3702   3699       case TK_NOT: {
  3703   3700         testcase( jumpIfNull==0 );
  3704   3701         sqlite3ExprIfTrue(pParse, pExpr->pLeft, dest, jumpIfNull);
  3705   3702         break;
  3706   3703       }
         3704  +    case TK_IS:
         3705  +    case TK_ISNOT:
         3706  +      testcase( pExpr->op==TK_IS );
         3707  +      testcase( pExpr->op==TK_ISNOT );
         3708  +      op = (pExpr->op==TK_IS) ? TK_NE : TK_EQ;
         3709  +      jumpIfNull = SQLITE_NULLEQ;
         3710  +      /* Fall thru */
  3707   3711       case TK_LT:
  3708   3712       case TK_LE:
  3709   3713       case TK_GT:
  3710   3714       case TK_GE:
  3711   3715       case TK_NE:
  3712   3716       case TK_EQ: {
  3713   3717         testcase( jumpIfNull==0 );
................................................................................
  3715   3719         r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, &regFree2);
  3716   3720         codeCompare(pParse, pExpr->pLeft, pExpr->pRight, op,
  3717   3721                     r1, r2, dest, jumpIfNull);
  3718   3722         assert(TK_LT==OP_Lt); testcase(op==OP_Lt); VdbeCoverageIf(v,op==OP_Lt);
  3719   3723         assert(TK_LE==OP_Le); testcase(op==OP_Le); VdbeCoverageIf(v,op==OP_Le);
  3720   3724         assert(TK_GT==OP_Gt); testcase(op==OP_Gt); VdbeCoverageIf(v,op==OP_Gt);
  3721   3725         assert(TK_GE==OP_Ge); testcase(op==OP_Ge); VdbeCoverageIf(v,op==OP_Ge);
  3722         -      assert(TK_EQ==OP_Eq); testcase(op==OP_Eq); VdbeCoverageIf(v,op==OP_Eq);
  3723         -      assert(TK_NE==OP_Ne); testcase(op==OP_Ne); VdbeCoverageIf(v,op==OP_Ne);
  3724         -      testcase( regFree1==0 );
  3725         -      testcase( regFree2==0 );
  3726         -      break;
  3727         -    }
  3728         -    case TK_IS:
  3729         -    case TK_ISNOT: {
  3730         -      testcase( pExpr->op==TK_IS );
  3731         -      testcase( pExpr->op==TK_ISNOT );
  3732         -      r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
  3733         -      r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, &regFree2);
  3734         -      op = (pExpr->op==TK_IS) ? TK_NE : TK_EQ;
  3735         -      codeCompare(pParse, pExpr->pLeft, pExpr->pRight, op,
  3736         -                  r1, r2, dest, SQLITE_NULLEQ);
  3737         -      VdbeCoverageIf(v, op==TK_EQ);
  3738         -      VdbeCoverageIf(v, op==TK_NE);
         3726  +      assert(TK_EQ==OP_Eq); testcase(op==OP_Eq);
         3727  +      VdbeCoverageIf(v, op==OP_Eq && jumpIfNull!=SQLITE_NULLEQ);
         3728  +      VdbeCoverageIf(v, op==OP_Eq && jumpIfNull==SQLITE_NULLEQ);
         3729  +      assert(TK_NE==OP_Ne); testcase(op==OP_Ne);
         3730  +      VdbeCoverageIf(v, op==OP_Ne && jumpIfNull!=SQLITE_NULLEQ);
         3731  +      VdbeCoverageIf(v, op==OP_Ne && jumpIfNull==SQLITE_NULLEQ);
  3739   3732         testcase( regFree1==0 );
  3740   3733         testcase( regFree2==0 );
  3741   3734         break;
  3742   3735       }
  3743   3736       case TK_ISNULL:
  3744   3737       case TK_NOTNULL: {
  3745   3738         r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);

Changes to src/os_unix.c.

  1652   1652   ** (3) The file has not been renamed or unlinked
  1653   1653   **
  1654   1654   ** Issue sqlite3_log(SQLITE_WARNING,...) messages if anything is not right.
  1655   1655   */
  1656   1656   static void verifyDbFile(unixFile *pFile){
  1657   1657     struct stat buf;
  1658   1658     int rc;
         1659  +
         1660  +  /* These verifications occurs for the main database only */
         1661  +  if( pFile->ctrlFlags & UNIXFILE_NOLOCK ) return;
         1662  +
  1659   1663     rc = osFstat(pFile->h, &buf);
  1660   1664     if( rc!=0 ){
  1661   1665       sqlite3_log(SQLITE_WARNING, "cannot fstat db file %s", pFile->zPath);
  1662   1666       return;
  1663   1667     }
  1664   1668     if( buf.st_nlink==0 && (pFile->ctrlFlags & UNIXFILE_DELETE)==0 ){
  1665   1669       sqlite3_log(SQLITE_WARNING, "file unlinked while open: %s", pFile->zPath);
................................................................................
  6989   6993   #endif
  6990   6994     }
  6991   6995   #if SQLITE_ENABLE_LOCKING_STYLE || defined(__APPLE__)
  6992   6996     else{
  6993   6997       p->openFlags = openFlags;
  6994   6998     }
  6995   6999   #endif
  6996         -
  6997         -  noLock = eType!=SQLITE_OPEN_MAIN_DB;
  6998         -
  6999   7000     
  7000   7001   #if defined(__APPLE__) || SQLITE_ENABLE_LOCKING_STYLE
  7001   7002     if( fstatfs(fd, &fsInfo) == -1 ){
  7002   7003       storeLastErrno(p, errno);
  7003   7004       robust_close(p, fd, __LINE__);
  7004   7005       return SQLITE_IOERR_ACCESS;
  7005   7006     }
................................................................................
  7010   7011       ((unixFile*)pFile)->fsFlags |= SQLITE_FSFLAGS_IS_MSDOS;
  7011   7012     }
  7012   7013   #endif
  7013   7014   
  7014   7015     /* Set up appropriate ctrlFlags */
  7015   7016     if( isDelete )                ctrlFlags |= UNIXFILE_DELETE;
  7016   7017     if( isReadonly )              ctrlFlags |= UNIXFILE_RDONLY;
         7018  +  noLock = eType!=SQLITE_OPEN_MAIN_DB;
  7017   7019     if( noLock )                  ctrlFlags |= UNIXFILE_NOLOCK;
  7018   7020     if( syncDir )                 ctrlFlags |= UNIXFILE_DIRSYNC;
  7019   7021     if( flags & SQLITE_OPEN_URI ) ctrlFlags |= UNIXFILE_URI;
  7020   7022   #if defined(SQLITE_ENABLE_PERSIST_WAL)
  7021   7023     if( eType==SQLITE_OPEN_MAIN_DB ) {
  7022   7024       ctrlFlags |= UNIXFILE_PERSIST_WAL;
  7023   7025     }

Changes to src/pragma.c.

  1702   1702     /*
  1703   1703     **   PRAGMA [schema.]schema_version
  1704   1704     **   PRAGMA [schema.]schema_version = <integer>
  1705   1705     **
  1706   1706     **   PRAGMA [schema.]user_version
  1707   1707     **   PRAGMA [schema.]user_version = <integer>
  1708   1708     **
  1709         -  **   PRAGMA [schema.]freelist_count = <integer>
         1709  +  **   PRAGMA [schema.]freelist_count
         1710  +  **
         1711  +  **   PRAGMA [schema.]data_version
  1710   1712     **
  1711   1713     **   PRAGMA [schema.]application_id
  1712   1714     **   PRAGMA [schema.]application_id = <integer>
  1713   1715     **
  1714   1716     ** The pragma's schema_version and user_version are used to set or get
  1715   1717     ** the value of the schema-version and user-version, respectively. Both
  1716   1718     ** the schema-version and the user-version are 32-bit signed integers
................................................................................
  1758   1760         aOp = sqlite3VdbeAddOpList(v, ArraySize(readCookie),readCookie,0);
  1759   1761         if( ONLY_IF_REALLOC_STRESS(aOp==0) ) break;
  1760   1762         aOp[0].p1 = iDb;
  1761   1763         aOp[1].p1 = iDb;
  1762   1764         aOp[1].p3 = iCookie;
  1763   1765         sqlite3VdbeSetNumCols(v, 1);
  1764   1766         sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLeft, SQLITE_TRANSIENT);
         1767  +      sqlite3VdbeReusable(v);
  1765   1768       }
  1766   1769     }
  1767   1770     break;
  1768   1771   #endif /* SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS */
  1769   1772   
  1770   1773   #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
  1771   1774     /*
................................................................................
  1779   1782       const char *zOpt;
  1780   1783       pParse->nMem = 1;
  1781   1784       setOneColumnName(v, "compile_option");
  1782   1785       while( (zOpt = sqlite3_compileoption_get(i++))!=0 ){
  1783   1786         sqlite3VdbeLoadString(v, 1, zOpt);
  1784   1787         sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
  1785   1788       }
         1789  +    sqlite3VdbeReusable(v);
  1786   1790     }
  1787   1791     break;
  1788   1792   #endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */
  1789   1793   
  1790   1794   #ifndef SQLITE_OMIT_WAL
  1791   1795     /*
  1792   1796     **   PRAGMA [schema.]wal_checkpoint = passive|full|restart|truncate

Changes to src/test1.c.

  1898   1898     int objc,              /* Number of arguments */
  1899   1899     Tcl_Obj *CONST objv[]  /* Command arguments */
  1900   1900   ){
  1901   1901     Tcl_CmdInfo cmdInfo;
  1902   1902     sqlite3 *db;
  1903   1903     int rc;
  1904   1904     char *zDb;
  1905         -#ifndef SQLITE_OMIT_LOAD_EXTENSION
  1906   1905     char *zFile;
  1907   1906     char *zProc = 0;
  1908         -#endif
  1909   1907     char *zErr = 0;
  1910   1908   
  1911   1909     if( objc!=4 && objc!=3 ){
  1912   1910       Tcl_WrongNumArgs(interp, 1, objv, "DB-HANDLE FILE ?PROC?");
  1913   1911       return TCL_ERROR;
  1914   1912     }
  1915   1913     zDb = Tcl_GetString(objv[1]);
  1916         -#ifndef SQLITE_OMIT_LOAD_EXTENSION
  1917   1914     zFile = Tcl_GetString(objv[2]);
  1918   1915     if( objc==4 ){
  1919   1916       zProc = Tcl_GetString(objv[3]);
  1920   1917     }
  1921         -#endif
  1922   1918   
  1923   1919     /* Extract the C database handle from the Tcl command name */
  1924   1920     if( !Tcl_GetCommandInfo(interp, zDb, &cmdInfo) ){
  1925   1921       Tcl_AppendResult(interp, "command not found: ", zDb, (char*)0);
  1926   1922       return TCL_ERROR;
  1927   1923     }
  1928   1924     db = ((struct SqliteDb*)cmdInfo.objClientData)->db;
................................................................................
  1931   1927     /* Call the underlying C function. If an error occurs, set rc to 
  1932   1928     ** TCL_ERROR and load any error string into the interpreter. If no 
  1933   1929     ** error occurs, set rc to TCL_OK.
  1934   1930     */
  1935   1931   #ifdef SQLITE_OMIT_LOAD_EXTENSION
  1936   1932     rc = SQLITE_ERROR;
  1937   1933     zErr = sqlite3_mprintf("this build omits sqlite3_load_extension()");
         1934  +  (void)zProc;
         1935  +  (void)zFile;
  1938   1936   #else
  1939   1937     rc = sqlite3_load_extension(db, zFile, zProc, &zErr);
  1940   1938   #endif
  1941   1939     if( rc!=SQLITE_OK ){
  1942   1940       Tcl_SetResult(interp, zErr ? zErr : "", TCL_VOLATILE);
  1943   1941       rc = TCL_ERROR;
  1944   1942     }else{

Changes to src/test_config.c.

    74     74   #endif
    75     75   
    76     76   #ifdef SQLITE_DEBUG
    77     77     Tcl_SetVar2(interp, "sqlite_options", "debug", "1", TCL_GLOBAL_ONLY);
    78     78   #else
    79     79     Tcl_SetVar2(interp, "sqlite_options", "debug", "0", TCL_GLOBAL_ONLY);
    80     80   #endif
           81  +
           82  +#ifdef SQLITE_DEFAULT_CKPTFULLFSYNC
           83  +  Tcl_SetVar2(interp, "sqlite_options", "default_ckptfullfsync", 
           84  +              SQLITE_DEFAULT_CKPTFULLFSYNC ? "1" : "0", TCL_GLOBAL_ONLY);
           85  +#else
           86  +  Tcl_SetVar2(interp, "sqlite_options", "default_ckptfullfsync", "0", TCL_GLOBAL_ONLY);
           87  +#endif
    81     88   
    82     89   #ifdef SQLITE_DIRECT_OVERFLOW_READ
    83     90     Tcl_SetVar2(interp, "sqlite_options", "direct_read", "1", TCL_GLOBAL_ONLY);
    84     91   #else
    85     92     Tcl_SetVar2(interp, "sqlite_options", "direct_read", "0", TCL_GLOBAL_ONLY);
    86     93   #endif
    87     94   
................................................................................
    92     99   #endif
    93    100   
    94    101   #ifdef SQLITE_DISABLE_LFS
    95    102     Tcl_SetVar2(interp, "sqlite_options", "lfs", "0", TCL_GLOBAL_ONLY);
    96    103   #else
    97    104     Tcl_SetVar2(interp, "sqlite_options", "lfs", "1", TCL_GLOBAL_ONLY);
    98    105   #endif
          106  +
          107  +#ifdef SQLITE_DISABLE_PAGECACHE_OVERFLOW_STATS
          108  +  Tcl_SetVar2(interp, "sqlite_options", "pagecache_overflow_stats","0",TCL_GLOBAL_ONLY);
          109  +#else
          110  +  Tcl_SetVar2(interp, "sqlite_options", "pagecache_overflow_stats","1",TCL_GLOBAL_ONLY);
          111  +#endif
    99    112   
   100    113   #if SQLITE_MAX_MMAP_SIZE>0
   101    114     Tcl_SetVar2(interp, "sqlite_options", "mmap", "1", TCL_GLOBAL_ONLY);
   102    115   #else
   103    116     Tcl_SetVar2(interp, "sqlite_options", "mmap", "0", TCL_GLOBAL_ONLY);
   104    117   #endif
   105    118   
................................................................................
   586    599   #ifdef SQLITE_OMIT_TCL_VARIABLE
   587    600     Tcl_SetVar2(interp, "sqlite_options", "tclvar", "0", TCL_GLOBAL_ONLY);
   588    601   #else
   589    602     Tcl_SetVar2(interp, "sqlite_options", "tclvar", "1", TCL_GLOBAL_ONLY);
   590    603   #endif
   591    604   
   592    605     Tcl_SetVar2(interp, "sqlite_options", "threadsafe", 
   593         -      STRINGVALUE(SQLITE_THREADSAFE), TCL_GLOBAL_ONLY);
          606  +      SQLITE_THREADSAFE ? "1" : "0", TCL_GLOBAL_ONLY);
          607  +  Tcl_SetVar2(interp, "sqlite_options", "threadsafe1", 
          608  +      SQLITE_THREADSAFE==1 ? "1" : "0", TCL_GLOBAL_ONLY);
          609  +  Tcl_SetVar2(interp, "sqlite_options", "threadsafe2", 
          610  +      SQLITE_THREADSAFE==2 ? "1" : "0", TCL_GLOBAL_ONLY);
   594    611     assert( sqlite3_threadsafe()==SQLITE_THREADSAFE );
   595    612   
   596    613   #ifdef SQLITE_OMIT_TEMPDB
   597    614     Tcl_SetVar2(interp, "sqlite_options", "tempdb", "0", TCL_GLOBAL_ONLY);
   598    615   #else
   599    616     Tcl_SetVar2(interp, "sqlite_options", "tempdb", "1", TCL_GLOBAL_ONLY);
   600    617   #endif

Changes to src/vdbe.h.

   198    198   int sqlite3VdbeDeletePriorOpcode(Vdbe*, u8 op);
   199    199   void sqlite3VdbeChangeP4(Vdbe*, int addr, const char *zP4, int N);
   200    200   void sqlite3VdbeSetP4KeyInfo(Parse*, Index*);
   201    201   void sqlite3VdbeUsesBtree(Vdbe*, int);
   202    202   VdbeOp *sqlite3VdbeGetOp(Vdbe*, int);
   203    203   int sqlite3VdbeMakeLabel(Vdbe*);
   204    204   void sqlite3VdbeRunOnlyOnce(Vdbe*);
          205  +void sqlite3VdbeReusable(Vdbe*);
   205    206   void sqlite3VdbeDelete(Vdbe*);
   206    207   void sqlite3VdbeClearObject(sqlite3*,Vdbe*);
   207    208   void sqlite3VdbeMakeReady(Vdbe*,Parse*);
   208    209   int sqlite3VdbeFinalize(Vdbe*);
   209    210   void sqlite3VdbeResolveLabel(Vdbe*, int);
   210    211   int sqlite3VdbeCurrentAddr(Vdbe*);
   211    212   #ifdef SQLITE_DEBUG

Changes to src/vdbeaux.c.

   386    386   
   387    387   /*
   388    388   ** Mark the VDBE as one that can only be run one time.
   389    389   */
   390    390   void sqlite3VdbeRunOnlyOnce(Vdbe *p){
   391    391     p->runOnlyOnce = 1;
   392    392   }
          393  +
          394  +/*
          395  +** Mark the VDBE as one that can only be run multiple times.
          396  +*/
          397  +void sqlite3VdbeReusable(Vdbe *p){
          398  +  p->runOnlyOnce = 0;
          399  +}
   393    400   
   394    401   #ifdef SQLITE_DEBUG /* sqlite3AssertMayAbort() logic */
   395    402   
   396    403   /*
   397    404   ** The following type and function are used to iterate through all opcodes
   398    405   ** in a Vdbe main program and each of the sub-programs (triggers) it may 
   399    406   ** invoke directly or indirectly. It should be used as follows:

Changes to src/where.c.

   285    285     pScan->pOrigWC = pWC;
   286    286     pScan->pWC = pWC;
   287    287     pScan->pIdxExpr = 0;
   288    288     if( pIdx ){
   289    289       j = iColumn;
   290    290       iColumn = pIdx->aiColumn[j];
   291    291       if( iColumn==XN_EXPR ) pScan->pIdxExpr = pIdx->aColExpr->a[j].pExpr;
          292  +    if( iColumn==pIdx->pTable->iPKey ) iColumn = XN_ROWID;
   292    293     }
   293    294     if( pIdx && iColumn>=0 ){
   294    295       pScan->idxaff = pIdx->pTable->aCol[iColumn].affinity;
   295    296       pScan->zCollName = pIdx->azColl[j];
   296    297     }else{
   297    298       pScan->idxaff = 0;
   298    299       pScan->zCollName = 0;
................................................................................
  3925   3926     WhereClause *pWC;
  3926   3927     WhereTerm *pTerm;
  3927   3928     WhereLoop *pLoop;
  3928   3929     int iCur;
  3929   3930     int j;
  3930   3931     Table *pTab;
  3931   3932     Index *pIdx;
  3932         -  
         3933  +
  3933   3934     pWInfo = pBuilder->pWInfo;
  3934   3935     if( pWInfo->wctrlFlags & WHERE_FORCE_TABLE ) return 0;
  3935   3936     assert( pWInfo->pTabList->nSrc>=1 );
  3936   3937     pItem = pWInfo->pTabList->a;
  3937   3938     pTab = pItem->pTab;
  3938   3939     if( IsVirtual(pTab) ) return 0;
  3939   3940     if( pItem->fg.isIndexedBy ) return 0;

Changes to test/capi3.test.

   921    921   } {0 {}}
   922    922   do_test capi3-11.9.3 {
   923    923     sqlite3_get_autocommit $DB
   924    924   } 1
   925    925   do_test capi3-11.10 {
   926    926     sqlite3_step $STMT
   927    927   } {SQLITE_ROW}
   928         -ifcapable !autoreset {
   929         -  # If SQLITE_OMIT_AUTORESET is defined, then the statement must be
   930         -  # reset() before it can be passed to step() again.
   931         -  do_test capi3-11.11a { sqlite3_step $STMT } {SQLITE_MISUSE}
   932         -  do_test capi3-11.11b { sqlite3_reset $STMT } {SQLITE_ABORT}
   933         -}
   934    928   do_test capi3-11.11 {
   935    929     sqlite3_step $STMT
   936    930   } {SQLITE_DONE}
   937         -do_test capi3-11.12 {
   938         -  sqlite3_step $STMT
   939         -  sqlite3_step $STMT
   940         -} {SQLITE_ROW}
          931  +ifcapable api_armor {
          932  +  do_test capi3-11.12armor {
          933  +    sqlite3_step $STMT
          934  +    sqlite3_step $STMT
          935  +  } {SQLITE_MISUSE}
          936  +} else {
          937  +  do_test capi3-11.12 {
          938  +    sqlite3_step $STMT
          939  +    sqlite3_step $STMT
          940  +  } {SQLITE_ROW}
          941  +}
   941    942   do_test capi3-11.13 {
   942    943     sqlite3_finalize $STMT
   943    944   } {SQLITE_OK}
   944    945   do_test capi3-11.14 {
   945    946     execsql {
   946    947       SELECT a FROM t2;
   947    948     }

Changes to test/capi3c.test.

   861    861   } {0 {}}
   862    862   do_test capi3c-11.9.3 {
   863    863     sqlite3_get_autocommit $DB
   864    864   } 1
   865    865   do_test capi3c-11.10 {
   866    866     sqlite3_step $STMT
   867    867   } {SQLITE_ROW}
   868         -ifcapable !autoreset {
   869         -  # If SQLITE_OMIT_AUTORESET is defined, then the statement must be
   870         -  # reset() before it can be passed to step() again.
   871         -  do_test capi3-11.11a { sqlite3_step $STMT } {SQLITE_MISUSE}
   872         -  do_test capi3-11.11b { sqlite3_reset $STMT } {SQLITE_ABORT}
   873         -}
   874    868   do_test capi3c-11.11 {
   875    869     sqlite3_step $STMT
   876    870   } {SQLITE_DONE}
   877         -do_test capi3c-11.12 {
   878         -  sqlite3_step $STMT
   879         -  sqlite3_step $STMT
   880         -} {SQLITE_ROW}
          871  +ifcapable api_armor {
          872  +  do_test capi3c-11.12armor {
          873  +    sqlite3_step $STMT
          874  +    sqlite3_step $STMT
          875  +  } {SQLITE_MISUSE}
          876  +} else {
          877  +  do_test capi3c-11.12 {
          878  +    sqlite3_step $STMT
          879  +    sqlite3_step $STMT
          880  +  } {SQLITE_ROW}
          881  +}
   881    882   do_test capi3c-11.13 {
   882    883     sqlite3_finalize $STMT
   883    884   } {SQLITE_OK}
   884    885   do_test capi3c-11.14 {
   885    886     execsql {
   886    887       SELECT a FROM t2;
   887    888     }

Changes to test/intpkey.test.

   292    292       SELECT * FROM t1 WHERE c=='world';
   293    293     }
   294    294   } {5 hello world 11 hello world 5}
   295    295   do_test intpkey-3.8 {
   296    296     count {
   297    297       SELECT * FROM t1 WHERE c=='world' AND a>7;
   298    298     }
   299         -} {11 hello world 4}
          299  +} {11 hello world 3}
   300    300   do_test intpkey-3.9 {
   301    301     count {
   302    302       SELECT * FROM t1 WHERE 7<a;
   303    303     }
   304    304   } {11 hello world 1}
   305    305   
   306    306   # Test inequality constraints on integer primary keys and rowids

Changes to test/memsubsys1.test.

    96     96   sqlite3_shutdown
    97     97   sqlite3_config_pagecache [expr 1024+$xtra_size] 20
    98     98   sqlite3_initialize
    99     99   reset_highwater_marks
   100    100   build_test_db memsubsys1-2 {PRAGMA page_size=1024; PRAGMA mmap_size=0}
   101    101   #show_memstats
   102    102   set MEMORY_MANAGEMENT $sqlite_options(memorymanage)
   103         -ifcapable !malloc_usable_size {
   104         -  if !$::sqlite_options(enable_purgeable_pcache) {
          103  +ifcapable pagecache_overflow_stats {
          104  +  ifcapable !malloc_usable_size {
   105    105       do_test memsubsys1-2.3 {
   106    106         set pg_ovfl [lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_OVERFLOW 0] 2]
   107    107       } [expr ($TEMP_STORE>1 || $MEMORY_MANAGEMENT==0)*1024]
   108    108     }
   109    109   }
   110    110   do_test memsubsys1-2.4 {
   111    111     set pg_used [lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_USED 0] 2]

Changes to test/mutex1.test.

    93     93   # Tests mutex1-2.* test the three thread-safety related modes that
    94     94   # can be selected using sqlite3_config:
    95     95   #
    96     96   #   * Serialized mode,
    97     97   #   * Multi-threaded mode,
    98     98   #   * Single-threaded mode.
    99     99   #
   100         -ifcapable threadsafe&&shared_cache {
          100  +ifcapable threadsafe1&&shared_cache {
   101    101     set enable_shared_cache [sqlite3_enable_shared_cache 1]
   102    102     foreach {mode mutexes} {
   103    103       singlethread {}
   104    104       multithread  {
   105    105         fast static_app1 static_app2 static_app3
   106    106         static_lru static_master static_mem static_open
   107    107         static_prng static_pmem static_vfs1 static_vfs2

Changes to test/releasetest.tcl.

   170    170       -DSQLITE_THREADSAFE=2
   171    171       --enable-json1 --enable-fts5
   172    172     }
   173    173     "Locking-Style" {
   174    174       -O2
   175    175       -DSQLITE_ENABLE_LOCKING_STYLE=1
   176    176     }
   177         -  "OS-X" {
          177  +  "Apple" {
   178    178       -O1   # Avoid a compiler bug in gcc 4.2.1 build 5658
   179         -    -DSQLITE_OMIT_LOAD_EXTENSION=1
   180         -    -DSQLITE_DEFAULT_MEMSTATUS=0
   181         -    -DSQLITE_THREADSAFE=2
   182         -    -DSQLITE_OS_UNIX=1
   183         -    -DSQLITE_ENABLE_JSON1=1
   184         -    -DSQLITE_ENABLE_LOCKING_STYLE=1
   185         -    -DUSE_PREAD=1
   186         -    -DSQLITE_ENABLE_RTREE=1
          179  +    -DHAVE_GMTIME_R=1
          180  +    -DHAVE_ISNAN=1
          181  +    -DHAVE_LOCALTIME_R=1
          182  +    -DHAVE_PREAD=1
          183  +    -DHAVE_PWRITE=1
          184  +    -DHAVE_USLEEP=1
          185  +    -DHAVE_USLEEP=1
          186  +    -DHAVE_UTIME=1
          187  +    -DSQLITE_DEFAULT_CACHE_SIZE=1000
          188  +    -DSQLITE_DEFAULT_CKPTFULLFSYNC=1
          189  +    -DSQLITE_DEFAULT_MEMSTATUS=1
          190  +    -DSQLITE_DEFAULT_PAGE_SIZE=1024
          191  +    -DSQLITE_DISABLE_PAGECACHE_OVERFLOW_STATS=1
          192  +    -DSQLITE_ENABLE_API_ARMOR=1
          193  +    -DSQLITE_ENABLE_AUTO_PROFILE=1
          194  +    -DSQLITE_ENABLE_FLOCKTIMEOUT=1
   187    195       -DSQLITE_ENABLE_FTS3=1
   188    196       -DSQLITE_ENABLE_FTS3_PARENTHESIS=1
   189         -    -DSQLITE_DEFAULT_CACHE_SIZE=1000
          197  +    -DSQLITE_ENABLE_FTS3_TOKENIZER=1
          198  +    if:os=="Darwin" -DSQLITE_ENABLE_LOCKING_STYLE=1
          199  +    -DSQLITE_ENABLE_PERSIST_WAL=1
          200  +    -DSQLITE_ENABLE_PURGEABLE_PCACHE=1
          201  +    -DSQLITE_ENABLE_RTREE=1
          202  +    -DSQLITE_ENABLE_SNAPSHOT=1
          203  +    # -DSQLITE_ENABLE_SQLLOG=1
          204  +    -DSQLITE_ENABLE_UPDATE_DELETE_LIMIT=1
   190    205       -DSQLITE_MAX_LENGTH=2147483645
   191    206       -DSQLITE_MAX_VARIABLE_NUMBER=500000
   192         -    -DSQLITE_DEBUG=1
          207  +    # -DSQLITE_MEMDEBUG=1
          208  +    -DSQLITE_NO_SYNC=1
          209  +    -DSQLITE_OMIT_AUTORESET=1
          210  +    -DSQLITE_OMIT_LOAD_EXTENSION=1
   193    211       -DSQLITE_PREFER_PROXY_LOCKING=1
   194         -    -DSQLITE_ENABLE_API_ARMOR=1
          212  +    -DSQLITE_SERIES_CONSTRAINT_VERIFY=1
          213  +    -DSQLITE_THREADSAFE=2
          214  +    -DSQLITE_USE_URI=1
          215  +    -DSQLITE_WRITE_WALFRAME_PREBUFFERED=1
          216  +    -DUSE_GUARDED_FD=1
          217  +    -DUSE_PREAD=1
   195    218       --enable-json1 --enable-fts5
   196    219     }
   197    220     "Extra-Robustness" {
   198    221       -DSQLITE_ENABLE_OVERSIZE_CELL_CHECK=1
   199    222       -DSQLITE_MAX_ATTACHED=62
   200    223     }
   201    224     "Devkit" {
................................................................................
   244    267       "Secure-Delete"           test
   245    268       "Unlock-Notify"           "QUICKTEST_INCLUDE=notify2.test test"
   246    269       "Update-Delete-Limit"     test
   247    270       "Extra-Robustness"        test
   248    271       "Device-Two"              test
   249    272       "No-lookaside"            test
   250    273       "Devkit"                  test
          274  +    "Apple"                   test
   251    275       "Sanitize"                {QUICKTEST_OMIT=func4.test,nan.test test}
   252    276       "Device-One"              fulltest
   253    277       "Default"                 "threadtest fulltest"
   254    278       "Valgrind"                valgrindtest
   255    279     }
   256    280     Linux-i686 {
   257    281       "Devkit"                  test
................................................................................
   260    284       "Device-One"              test
   261    285       "Device-Two"              test
   262    286       "Default"                 "threadtest fulltest"
   263    287     }
   264    288     Darwin-i386 {
   265    289       "Locking-Style"           "mptest test"
   266    290       "Have-Not"                test
   267         -    "OS-X"                    "threadtest fulltest"
          291  +    "Apple"                   "threadtest fulltest"
   268    292     }
   269    293     Darwin-x86_64 {
   270    294       "Locking-Style"           "mptest test"
   271    295       "Have-Not"                test
   272         -    "OS-X"                    "threadtest fulltest"
          296  +    "Apple"                   "threadtest fulltest"
   273    297     }
   274    298     "Windows NT-intel" {
   275    299       "Have-Not"                test
   276    300       "Default"                 "mptest fulltestonly"
   277    301     }
   278    302     "Windows NT-amd64" {
   279    303       "Have-Not"                test
................................................................................
   584    608     # CFLAGS is only passed to gcc.
   585    609     #
   586    610     set makeOpts ""
   587    611     set cflags [expr {$::MSVC ? "-Zi" : "-g"}]
   588    612     set opts ""
   589    613     set title ${name}($testtarget)
   590    614     set configOpts $::WITHTCL
          615  +  set skip 0
   591    616   
   592    617     regsub -all {#[^\n]*\n} $config \n config
   593    618     foreach arg $config {
          619  +    if {$skip} {
          620  +      set skip 0
          621  +      continue
          622  +    }
   594    623       if {[regexp {^-[UD]} $arg]} {
   595    624         lappend opts $arg
   596    625       } elseif {[regexp {^[A-Z]+=} $arg]} {
   597    626         lappend testtarget $arg
          627  +    } elseif {[regexp {^if:([a-z]+)(.*)} $arg all key tail]} {
          628  +      # Arguments of the form 'if:os=="Linux"' will cause the subsequent
          629  +      # argument to be skipped if the $tcl_platform(os) is not "Linux", for
          630  +      # example...
          631  +      set skip [expr !(\$::tcl_platform($key)$tail)]
   598    632       } elseif {[regexp {^--(enable|disable)-} $arg]} {
   599    633         if {$::MSVC} {
   600    634           if {$arg eq "--disable-amalgamation"} {
   601    635             lappend makeOpts USE_AMALGAMATION=0
   602    636             continue
   603    637           }
   604    638           if {$arg eq "--disable-shared"} {

Changes to test/wal2.test.

  1227   1227   # Test that "PRAGMA checkpoint_fullsync" appears to be working.
  1228   1228   #
  1229   1229   foreach {tn sql reslist} {
  1230   1230     1 { }                                 {10 0 4 0 6 0}
  1231   1231     2 { PRAGMA checkpoint_fullfsync = 1 } {10 4 4 2 6 2}
  1232   1232     3 { PRAGMA checkpoint_fullfsync = 0 } {10 0 4 0 6 0}
  1233   1233   } {
         1234  +  ifcapable default_ckptfullfsync {
         1235  +    if {[string trim $sql]==""} continue
         1236  +  }
  1234   1237     faultsim_delete_and_reopen
  1235   1238   
  1236   1239     execsql {PRAGMA auto_vacuum = 0; PRAGMA synchronous = FULL;}
  1237   1240     execsql $sql
  1238   1241     do_execsql_test wal2-14.$tn.0 { PRAGMA page_size = 4096 }   {}
  1239   1242     do_execsql_test wal2-14.$tn.1 { PRAGMA journal_mode = WAL } {wal}
  1240   1243   

Changes to test/wal3.test.

   219    219     
   220    220       testvfs T
   221    221       T filter {} 
   222    222       T script sync_counter
   223    223       sqlite3 db test.db -vfs T
   224    224     
   225    225       execsql "PRAGMA synchronous = $syncmode"
          226  +    execsql "PRAGMA checkpoint_fullfsync = 0"
   226    227       execsql { PRAGMA journal_mode = WAL }
   227    228       execsql { CREATE TABLE filler(a,b,c); }
   228    229   
   229    230       set ::syncs [list]
   230    231       T filter xSync
   231    232       execsql {
   232    233         CREATE TABLE x(y);

Changes to tool/lemon.c.

   286    286     const char **rhsalias;   /* An alias for each RHS symbol (NULL if none) */
   287    287     int line;                /* Line number at which code begins */
   288    288     const char *code;        /* The code executed when this rule is reduced */
   289    289     const char *codePrefix;  /* Setup code before code[] above */
   290    290     const char *codeSuffix;  /* Breakdown code after code[] above */
   291    291     struct symbol *precsym;  /* Precedence symbol for this rule */
   292    292     int index;               /* An index number for this rule */
          293  +  int iRule;               /* Rule number as used in the generated tables */
   293    294     Boolean canReduce;       /* True if this rule is ever reduced */
   294    295     struct rule *nextlhs;    /* Next rule with the same LHS */
   295    296     struct rule *next;       /* Next rule in the global list */
   296    297   };
   297    298   
   298    299   /* A configuration is a production rule of the grammar together with
   299    300   ** a mark (dot) showing how much of that rule has been processed so far.
................................................................................
   368    369   /* The state vector for the entire parser generator is recorded as
   369    370   ** follows.  (LEMON uses no global variables and makes little use of
   370    371   ** static variables.  Fields in the following structure can be thought
   371    372   ** of as begin global variables in the program.) */
   372    373   struct lemon {
   373    374     struct state **sorted;   /* Table of states sorted by state number */
   374    375     struct rule *rule;       /* List of all rules */
          376  +  struct rule *startRule;  /* First rule */
   375    377     int nstate;              /* Number of states */
   376    378     int nxstate;             /* nstate with tail degenerate states removed */
   377    379     int nrule;               /* Number of rules */
   378    380     int nsymbol;             /* Number of terminal and nonterminal symbols */
   379    381     int nterminal;           /* Number of terminal symbols */
   380    382     struct symbol **symbols; /* Sorted array of pointers to symbols */
   381    383     int errorcnt;            /* Number of errors */
................................................................................
   854    856     /* Find the start symbol */
   855    857     if( lemp->start ){
   856    858       sp = Symbol_find(lemp->start);
   857    859       if( sp==0 ){
   858    860         ErrorMsg(lemp->filename,0,
   859    861   "The specified start symbol \"%s\" is not \
   860    862   in a nonterminal of the grammar.  \"%s\" will be used as the start \
   861         -symbol instead.",lemp->start,lemp->rule->lhs->name);
          863  +symbol instead.",lemp->start,lemp->startRule->lhs->name);
   862    864         lemp->errorcnt++;
   863         -      sp = lemp->rule->lhs;
          865  +      sp = lemp->startRule->lhs;
   864    866       }
   865    867     }else{
   866         -    sp = lemp->rule->lhs;
          868  +    sp = lemp->startRule->lhs;
   867    869     }
   868    870   
   869    871     /* Make sure the start symbol doesn't occur on the right-hand side of
   870    872     ** any rule.  Report an error if it does.  (YACC would generate a new
   871    873     ** start symbol in this case.) */
   872    874     for(rp=lemp->rule; rp; rp=rp->next){
   873    875       int i;
................................................................................
  1113   1115         }
  1114   1116       }
  1115   1117     }
  1116   1118   
  1117   1119     /* Add the accepting token */
  1118   1120     if( lemp->start ){
  1119   1121       sp = Symbol_find(lemp->start);
  1120         -    if( sp==0 ) sp = lemp->rule->lhs;
         1122  +    if( sp==0 ) sp = lemp->startRule->lhs;
  1121   1123     }else{
  1122         -    sp = lemp->rule->lhs;
         1124  +    sp = lemp->startRule->lhs;
  1123   1125     }
  1124   1126     /* Add to the first state (which is always the starting state of the
  1125   1127     ** finite state machine) an action to ACCEPT if the lookahead is the
  1126   1128     ** start nonterminal.  */
  1127   1129     Action_add(&lemp->sorted[0]->ap,ACCEPT,sp,0);
  1128   1130   
  1129   1131     /* Resolve conflicts */
................................................................................
  1492   1494   static void handle_T_option(char *z){
  1493   1495     user_templatename = (char *) malloc( lemonStrlen(z)+1 );
  1494   1496     if( user_templatename==0 ){
  1495   1497       memory_error();
  1496   1498     }
  1497   1499     lemon_strcpy(user_templatename, z);
  1498   1500   }
         1501  +
         1502  +/* Merge together to lists of rules order by rule.iRule */
         1503  +static struct rule *Rule_merge(struct rule *pA, struct rule *pB){
         1504  +  struct rule *pFirst = 0;
         1505  +  struct rule **ppPrev = &pFirst;
         1506  +  while( pA && pB ){
         1507  +    if( pA->iRule<pB->iRule ){
         1508  +      *ppPrev = pA;
         1509  +      ppPrev = &pA->next;
         1510  +      pA = pA->next;
         1511  +    }else{
         1512  +      *ppPrev = pB;
         1513  +      ppPrev = &pB->next;
         1514  +      pB = pB->next;
         1515  +    }
         1516  +  }
         1517  +  if( pA ){
         1518  +    *ppPrev = pA;
         1519  +  }else{
         1520  +    *ppPrev = pB;
         1521  +  }
         1522  +  return pFirst;
         1523  +}
         1524  +
         1525  +/*
         1526  +** Sort a list of rules in order of increasing iRule value
         1527  +*/
         1528  +static struct rule *Rule_sort(struct rule *rp){
         1529  +  int i;
         1530  +  struct rule *pNext;
         1531  +  struct rule *x[32];
         1532  +  memset(x, 0, sizeof(x));
         1533  +  while( rp ){
         1534  +    pNext = rp->next;
         1535  +    rp->next = 0;
         1536  +    for(i=0; i<sizeof(x)/sizeof(x[0]) && x[i]; i++){
         1537  +      rp = Rule_merge(x[i], rp);
         1538  +      x[i] = 0;
         1539  +    }
         1540  +    x[i] = rp;
         1541  +    rp = pNext;
         1542  +  }
         1543  +  rp = 0;
         1544  +  for(i=0; i<sizeof(x)/sizeof(x[0]); i++){
         1545  +    rp = Rule_merge(x[i], rp);
         1546  +  }
         1547  +  return rp;
         1548  +}
  1499   1549   
  1500   1550   /* forward reference */
  1501   1551   static const char *minimum_size_type(int lwr, int upr, int *pnByte);
  1502   1552   
  1503   1553   /* Print a single line of the "Parser Stats" output
  1504   1554   */
  1505   1555   static void stats_line(const char *zLabel, int iValue){
................................................................................
  1541   1591       {OPT_FSTR, "T", (char*)handle_T_option, "Specify a template file."},
  1542   1592       {OPT_FSTR, "W", 0, "Ignored.  (Placeholder for '-W' compiler options.)"},
  1543   1593       {OPT_FLAG,0,0,0}
  1544   1594     };
  1545   1595     int i;
  1546   1596     int exitcode;
  1547   1597     struct lemon lem;
         1598  +  struct rule *rp;
  1548   1599   
  1549   1600     OptInit(argv,options,stderr);
  1550   1601     if( version ){
  1551   1602        printf("Lemon version 1.0\n");
  1552   1603        exit(0); 
  1553   1604     }
  1554   1605     if( OptNArgs()!=1 ){
................................................................................
  1586   1637     qsort(lem.symbols,lem.nsymbol,sizeof(struct symbol*), Symbolcmpp);
  1587   1638     for(i=0; i<lem.nsymbol; i++) lem.symbols[i]->index = i;
  1588   1639     while( lem.symbols[i-1]->type==MULTITERMINAL ){ i--; }
  1589   1640     assert( strcmp(lem.symbols[i-1]->name,"{default}")==0 );
  1590   1641     lem.nsymbol = i - 1;
  1591   1642     for(i=1; ISUPPER(lem.symbols[i]->name[0]); i++);
  1592   1643     lem.nterminal = i;
         1644  +
         1645  +  /* Assign sequential rule numbers */
         1646  +  for(i=0, rp=lem.rule; rp; rp=rp->next){
         1647  +    rp->iRule = rp->code ? i++ : -1;
         1648  +  }
         1649  +  for(rp=lem.rule; rp; rp=rp->next){
         1650  +    if( rp->iRule<0 ) rp->iRule = i++;
         1651  +  }
         1652  +  lem.startRule = lem.rule;
         1653  +  lem.rule = Rule_sort(lem.rule);
  1593   1654   
  1594   1655     /* Generate a reprint of the grammar, if requested on the command line */
  1595   1656     if( rpflag ){
  1596   1657       Reprint(&lem);
  1597   1658     }else{
  1598   1659       /* Initialize the size for all follow and first sets */
  1599   1660       SetSize(lem.nterminal+1);
................................................................................
  3050   3111       case SHIFT: {
  3051   3112         struct state *stp = ap->x.stp;
  3052   3113         fprintf(fp,"%*s shift        %-7d",indent,ap->sp->name,stp->statenum);
  3053   3114         break;
  3054   3115       }
  3055   3116       case REDUCE: {
  3056   3117         struct rule *rp = ap->x.rp;
  3057         -      fprintf(fp,"%*s reduce       %-7d",indent,ap->sp->name,rp->index);
         3118  +      fprintf(fp,"%*s reduce       %-7d",indent,ap->sp->name,rp->iRule);
  3058   3119         RulePrint(fp, rp, -1);
  3059   3120         break;
  3060   3121       }
  3061   3122       case SHIFTREDUCE: {
  3062   3123         struct rule *rp = ap->x.rp;
  3063         -      fprintf(fp,"%*s shift-reduce %-7d",indent,ap->sp->name,rp->index);
         3124  +      fprintf(fp,"%*s shift-reduce %-7d",indent,ap->sp->name,rp->iRule);
  3064   3125         RulePrint(fp, rp, -1);
  3065   3126         break;
  3066   3127       }
  3067   3128       case ACCEPT:
  3068   3129         fprintf(fp,"%*s accept",indent,ap->sp->name);
  3069   3130         break;
  3070   3131       case ERROR:
  3071   3132         fprintf(fp,"%*s error",indent,ap->sp->name);
  3072   3133         break;
  3073   3134       case SRCONFLICT:
  3074   3135       case RRCONFLICT:
  3075   3136         fprintf(fp,"%*s reduce       %-7d ** Parsing conflict **",
  3076         -        indent,ap->sp->name,ap->x.rp->index);
         3137  +        indent,ap->sp->name,ap->x.rp->iRule);
  3077   3138         break;
  3078   3139       case SSCONFLICT:
  3079   3140         fprintf(fp,"%*s shift        %-7d ** Parsing conflict **", 
  3080   3141           indent,ap->sp->name,ap->x.stp->statenum);
  3081   3142         break;
  3082   3143       case SH_RESOLVED:
  3083   3144         if( showPrecedenceConflict ){
................................................................................
  3086   3147         }else{
  3087   3148           result = 0;
  3088   3149         }
  3089   3150         break;
  3090   3151       case RD_RESOLVED:
  3091   3152         if( showPrecedenceConflict ){
  3092   3153           fprintf(fp,"%*s reduce %-7d -- dropped by precedence",
  3093         -                indent,ap->sp->name,ap->x.rp->index);
         3154  +                indent,ap->sp->name,ap->x.rp->iRule);
  3094   3155         }else{
  3095   3156           result = 0;
  3096   3157         }
  3097   3158         break;
  3098   3159       case NOT_USED:
  3099   3160         result = 0;
  3100   3161         break;
................................................................................
  3117   3178       stp = lemp->sorted[i];
  3118   3179       fprintf(fp,"State %d:\n",stp->statenum);
  3119   3180       if( lemp->basisflag ) cfp=stp->bp;
  3120   3181       else                  cfp=stp->cfp;
  3121   3182       while( cfp ){
  3122   3183         char buf[20];
  3123   3184         if( cfp->dot==cfp->rp->nrhs ){
  3124         -        lemon_sprintf(buf,"(%d)",cfp->rp->index);
         3185  +        lemon_sprintf(buf,"(%d)",cfp->rp->iRule);
  3125   3186           fprintf(fp,"    %5s ",buf);
  3126   3187         }else{
  3127   3188           fprintf(fp,"          ");
  3128   3189         }
  3129   3190         ConfigPrint(fp,cfp);
  3130   3191         fprintf(fp,"\n");
  3131   3192   #if 0
................................................................................
  3218   3279   ** Return negative if no action should be generated.
  3219   3280   */
  3220   3281   PRIVATE int compute_action(struct lemon *lemp, struct action *ap)
  3221   3282   {
  3222   3283     int act;
  3223   3284     switch( ap->type ){
  3224   3285       case SHIFT:  act = ap->x.stp->statenum;                        break;
  3225         -    case SHIFTREDUCE: act = ap->x.rp->index + lemp->nstate;        break;
  3226         -    case REDUCE: act = ap->x.rp->index + lemp->nstate+lemp->nrule; break;
         3286  +    case SHIFTREDUCE: act = ap->x.rp->iRule + lemp->nstate;        break;
         3287  +    case REDUCE: act = ap->x.rp->iRule + lemp->nstate+lemp->nrule; break;
  3227   3288       case ERROR:  act = lemp->nstate + lemp->nrule*2;               break;
  3228   3289       case ACCEPT: act = lemp->nstate + lemp->nrule*2 + 1;           break;
  3229   3290       default:     act = -1; break;
  3230   3291     }
  3231   3292     return act;
  3232   3293   }
  3233   3294   
................................................................................
  4237   4298     tplt_xfer(lemp->name,in,out,&lineno);
  4238   4299   
  4239   4300     /* Generate a table containing a text string that describes every
  4240   4301     ** rule in the rule set of the grammar.  This information is used
  4241   4302     ** when tracing REDUCE actions.
  4242   4303     */
  4243   4304     for(i=0, rp=lemp->rule; rp; rp=rp->next, i++){
  4244         -    assert( rp->index==i );
         4305  +    assert( rp->iRule==i );
  4245   4306       fprintf(out," /* %3d */ \"", i);
  4246   4307       writeRuleText(out, rp);
  4247   4308       fprintf(out,"\",\n"); lineno++;
  4248   4309     }
  4249   4310     tplt_xfer(lemp->name,in,out,&lineno);
  4250   4311   
  4251   4312     /* Generate code which executes every time a symbol is popped from
................................................................................
  4333   4394       fprintf(out,"        YYMINORTYPE yylhsminor;\n"); lineno++;
  4334   4395     }
  4335   4396     /* First output rules other than the default: rule */
  4336   4397     for(rp=lemp->rule; rp; rp=rp->next){
  4337   4398       struct rule *rp2;               /* Other rules with the same action */
  4338   4399       if( rp->code==0 ) continue;
  4339   4400       if( rp->code[0]=='\n' && rp->code[1]==0 ) continue; /* Will be default: */
  4340         -    fprintf(out,"      case %d: /* ", rp->index);
         4401  +    fprintf(out,"      case %d: /* ", rp->iRule);
  4341   4402       writeRuleText(out, rp);
  4342   4403       fprintf(out, " */\n"); lineno++;
  4343   4404       for(rp2=rp->next; rp2; rp2=rp2->next){
  4344   4405         if( rp2->code==rp->code ){
  4345         -        fprintf(out,"      case %d: /* ", rp2->index);
         4406  +        fprintf(out,"      case %d: /* ", rp2->iRule);
  4346   4407           writeRuleText(out, rp2);
  4347         -        fprintf(out," */ yytestcase(yyruleno==%d);\n", rp2->index); lineno++;
         4408  +        fprintf(out," */ yytestcase(yyruleno==%d);\n", rp2->iRule); lineno++;
  4348   4409           rp2->code = 0;
  4349   4410         }
  4350   4411       }
  4351   4412       emit_code(out,rp,lemp,&lineno);
  4352   4413       fprintf(out,"        break;\n"); lineno++;
  4353   4414       rp->code = 0;
  4354   4415     }
  4355   4416     /* Finally, output the default: rule.  We choose as the default: all
  4356   4417     ** empty actions. */
  4357   4418     fprintf(out,"      default:\n"); lineno++;
  4358   4419     for(rp=lemp->rule; rp; rp=rp->next){
  4359   4420       if( rp->code==0 ) continue;
  4360   4421       assert( rp->code[0]=='\n' && rp->code[1]==0 );
  4361         -    fprintf(out,"      /* (%d) ", rp->index);
         4422  +    fprintf(out,"      /* (%d) ", rp->iRule);
  4362   4423       writeRuleText(out, rp);
  4363         -    fprintf(out, " */ yytestcase(yyruleno==%d);\n", rp->index); lineno++;
         4424  +    fprintf(out, " */ yytestcase(yyruleno==%d);\n", rp->iRule); lineno++;
  4364   4425     }
  4365   4426     fprintf(out,"        break;\n"); lineno++;
  4366   4427     tplt_xfer(lemp->name,in,out,&lineno);
  4367   4428   
  4368   4429     /* Generate code which executes if a parse fails */
  4369   4430     tplt_print(out,lemp,lemp->failure,&lineno);
  4370   4431     tplt_xfer(lemp->name,in,out,&lineno);

Changes to tool/lempar.c.

   414    414   }
   415    415   #endif
   416    416   
   417    417   /*
   418    418   ** Find the appropriate action for a parser given the terminal
   419    419   ** look-ahead token iLookAhead.
   420    420   */
   421         -static int yy_find_shift_action(
          421  +static unsigned int yy_find_shift_action(
   422    422     yyParser *pParser,        /* The parser */
   423    423     YYCODETYPE iLookAhead     /* The look-ahead token */
   424    424   ){
   425    425     int i;
   426    426     int stateno = pParser->yystack[pParser->yyidx].stateno;
   427    427    
   428    428     if( stateno>=YY_MIN_REDUCE ) return stateno;
................................................................................
   602    602   
   603    603   /*
   604    604   ** Perform a reduce action and the shift that must immediately
   605    605   ** follow the reduce.
   606    606   */
   607    607   static void yy_reduce(
   608    608     yyParser *yypParser,         /* The parser */
   609         -  int yyruleno                 /* Number of the rule by which to reduce */
          609  +  unsigned int yyruleno        /* Number of the rule by which to reduce */
   610    610   ){
   611    611     int yygoto;                     /* The next state */
   612    612     int yyact;                      /* The next action */
   613    613     yyStackEntry *yymsp;            /* The top of the parser's stack */
   614    614     int yysize;                     /* Amount to pop the stack */
   615    615     ParseARG_FETCH;
   616    616     yymsp = &yypParser->yystack[yypParser->yyidx];
   617    617   #ifndef NDEBUG
   618         -  if( yyTraceFILE && yyruleno>=0 
   619         -        && yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){
          618  +  if( yyTraceFILE && yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){
   620    619       yysize = yyRuleInfo[yyruleno].nrhs;
   621    620       fprintf(yyTraceFILE, "%sReduce [%s], go to state %d.\n", yyTracePrompt,
   622    621         yyRuleName[yyruleno], yymsp[-yysize].stateno);
   623    622     }
   624    623   #endif /* NDEBUG */
   625    624   
   626    625     /* Check that the stack is large enough to grow by a single entry
................................................................................
   657    656     **  #line <lineno> <thisfile>
   658    657     **     break;
   659    658     */
   660    659   /********** Begin reduce actions **********************************************/
   661    660   %%
   662    661   /********** End reduce actions ************************************************/
   663    662     };
   664         -  assert( yyruleno>=0 && yyruleno<sizeof(yyRuleInfo)/sizeof(yyRuleInfo[0]) );
          663  +  assert( yyruleno<sizeof(yyRuleInfo)/sizeof(yyRuleInfo[0]) );
   665    664     yygoto = yyRuleInfo[yyruleno].lhs;
   666    665     yysize = yyRuleInfo[yyruleno].nrhs;
   667    666     yyact = yy_find_reduce_action(yymsp[-yysize].stateno,(YYCODETYPE)yygoto);
   668    667     if( yyact <= YY_MAX_SHIFTREDUCE ){
   669    668       if( yyact>YY_MAX_SHIFT ) yyact += YY_MIN_REDUCE - YY_MIN_SHIFTREDUCE;
   670    669       yypParser->yyidx -= yysize - 1;
   671    670       yymsp -= yysize-1;
................................................................................
   761    760   void Parse(
   762    761     void *yyp,                   /* The parser */
   763    762     int yymajor,                 /* The major token code number */
   764    763     ParseTOKENTYPE yyminor       /* The value for the token */
   765    764     ParseARG_PDECL               /* Optional %extra_argument parameter */
   766    765   ){
   767    766     YYMINORTYPE yyminorunion;
   768         -  int yyact;            /* The parser action. */
          767  +  unsigned int yyact;   /* The parser action. */
   769    768   #if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY)
   770    769     int yyendofinput;     /* True if we are at the end of input */
   771    770   #endif
   772    771   #ifdef YYERRORSYMBOL
   773    772     int yyerrorhit = 0;   /* True if yymajor has invoked an error */
   774    773   #endif
   775    774     yyParser *yypParser;  /* The parser */

Changes to tool/sqldiff.c.

  1753   1753     int rc;
  1754   1754     char *zErrMsg = 0;
  1755   1755     char *zSql;
  1756   1756     sqlite3_stmt *pStmt;
  1757   1757     char *zTab = 0;
  1758   1758     FILE *out = stdout;
  1759   1759     void (*xDiff)(const char*,FILE*) = diff_one_table;
         1760  +#ifndef SQLITE_OMIT_LOAD_EXTENSION
  1760   1761     int nExt = 0;
  1761   1762     char **azExt = 0;
         1763  +#endif
  1762   1764     int useTransaction = 0;
  1763   1765     int neverUseTransaction = 0;
  1764   1766   
  1765   1767     g.zArgv0 = argv[0];
  1766   1768     sqlite3_config(SQLITE_CONFIG_SINGLETHREAD);
  1767   1769     for(i=1; i<argc; i++){
  1768   1770       const char *z = argv[i];
................................................................................
  1837   1839     sqlite3_enable_load_extension(g.db, 1);
  1838   1840     for(i=0; i<nExt; i++){
  1839   1841       rc = sqlite3_load_extension(g.db, azExt[i], 0, &zErrMsg);
  1840   1842       if( rc || zErrMsg ){
  1841   1843         cmdlineError("error loading %s: %s", azExt[i], zErrMsg);
  1842   1844       }
  1843   1845     }
  1844         -#endif
  1845   1846     free(azExt);
         1847  +#endif
  1846   1848     zSql = sqlite3_mprintf("ATTACH %Q as aux;", zDb2);
  1847   1849     rc = sqlite3_exec(g.db, zSql, 0, 0, &zErrMsg);
  1848   1850     if( rc || zErrMsg ){
  1849   1851       cmdlineError("cannot attach database \"%s\"", zDb2);
  1850   1852     }
  1851   1853     rc = sqlite3_exec(g.db, "SELECT * FROM aux.sqlite_master", 0, 0, &zErrMsg);
  1852   1854     if( rc || zErrMsg ){