Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Update sqlite to 3.8.8.2
Baptiste Daroussin committed 11 years ago
commit 51ffae86aaff2e42ab20a952f674c5f8e93acd3c
parent 1827e86
2 files changed +135 -92
modified external/sqlite/sqlite3.c
@@ -1,6 +1,6 @@
/******************************************************************************
** This file is an amalgamation of many separate C source files from SQLite
-
** version 3.8.8.  By combining all the individual C code files into this 
+
** version 3.8.8.2.  By combining all the individual C code files into this 
** single large file, the entire code can be compiled as a single translation
** unit.  This allows many compilers to do optimizations that would not be
** possible if the files were compiled separately.  Performance improvements
@@ -278,9 +278,9 @@ extern "C" {
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
** [sqlite_version()] and [sqlite_source_id()].
*/
-
#define SQLITE_VERSION        "3.8.8"
+
#define SQLITE_VERSION        "3.8.8.2"
#define SQLITE_VERSION_NUMBER 3008008
-
#define SQLITE_SOURCE_ID      "2015-01-16 12:08:06 7d68a42face3ab14ed88407d4331872f5b243fdf"
+
#define SQLITE_SOURCE_ID      "2015-01-30 14:30:45 7757fc721220e136620a89c9d28247f28bbbc098"

/*
** CAPI3REF: Run-Time Library Version Numbers
@@ -50197,7 +50197,7 @@ static int walCheckpoint(
  int sync_flags,                 /* Flags for OsSync() (or 0) */
  u8 *zBuf                        /* Temporary buffer to use */
){
-
  int rc;                         /* Return code */
+
  int rc = SQLITE_OK;             /* Return code */
  int szPage;                     /* Database page-size */
  WalIterator *pIter = 0;         /* Wal iterator context */
  u32 iDbpage = 0;                /* Next database page to write */
@@ -50211,104 +50211,107 @@ static int walCheckpoint(
  testcase( szPage<=32768 );
  testcase( szPage>=65536 );
  pInfo = walCkptInfo(pWal);
-
  if( pInfo->nBackfill>=pWal->hdr.mxFrame ) return SQLITE_OK;
+
  if( pInfo->nBackfill<pWal->hdr.mxFrame ){

-
  /* Allocate the iterator */
-
  rc = walIteratorInit(pWal, &pIter);
-
  if( rc!=SQLITE_OK ){
-
    return rc;
-
  }
-
  assert( pIter );
+
    /* Allocate the iterator */
+
    rc = walIteratorInit(pWal, &pIter);
+
    if( rc!=SQLITE_OK ){
+
      return rc;
+
    }
+
    assert( pIter );

-
  /* EVIDENCE-OF: R-62920-47450 The busy-handler callback is never invoked
-
  ** in the SQLITE_CHECKPOINT_PASSIVE mode. */
-
  assert( eMode!=SQLITE_CHECKPOINT_PASSIVE || xBusy==0 );
+
    /* EVIDENCE-OF: R-62920-47450 The busy-handler callback is never invoked
+
    ** in the SQLITE_CHECKPOINT_PASSIVE mode. */
+
    assert( eMode!=SQLITE_CHECKPOINT_PASSIVE || xBusy==0 );

-
  /* Compute in mxSafeFrame the index of the last frame of the WAL that is
-
  ** safe to write into the database.  Frames beyond mxSafeFrame might
-
  ** overwrite database pages that are in use by active readers and thus
-
  ** cannot be backfilled from the WAL.
-
  */
-
  mxSafeFrame = pWal->hdr.mxFrame;
-
  mxPage = pWal->hdr.nPage;
-
  for(i=1; i<WAL_NREADER; i++){
-
    u32 y = pInfo->aReadMark[i];
-
    if( mxSafeFrame>y ){
-
      assert( y<=pWal->hdr.mxFrame );
-
      rc = walBusyLock(pWal, xBusy, pBusyArg, WAL_READ_LOCK(i), 1);
-
      if( rc==SQLITE_OK ){
-
        pInfo->aReadMark[i] = (i==1 ? mxSafeFrame : READMARK_NOT_USED);
-
        walUnlockExclusive(pWal, WAL_READ_LOCK(i), 1);
-
      }else if( rc==SQLITE_BUSY ){
-
        mxSafeFrame = y;
-
        xBusy = 0;
-
      }else{
-
        goto walcheckpoint_out;
+
    /* Compute in mxSafeFrame the index of the last frame of the WAL that is
+
    ** safe to write into the database.  Frames beyond mxSafeFrame might
+
    ** overwrite database pages that are in use by active readers and thus
+
    ** cannot be backfilled from the WAL.
+
    */
+
    mxSafeFrame = pWal->hdr.mxFrame;
+
    mxPage = pWal->hdr.nPage;
+
    for(i=1; i<WAL_NREADER; i++){
+
      u32 y = pInfo->aReadMark[i];
+
      if( mxSafeFrame>y ){
+
        assert( y<=pWal->hdr.mxFrame );
+
        rc = walBusyLock(pWal, xBusy, pBusyArg, WAL_READ_LOCK(i), 1);
+
        if( rc==SQLITE_OK ){
+
          pInfo->aReadMark[i] = (i==1 ? mxSafeFrame : READMARK_NOT_USED);
+
          walUnlockExclusive(pWal, WAL_READ_LOCK(i), 1);
+
        }else if( rc==SQLITE_BUSY ){
+
          mxSafeFrame = y;
+
          xBusy = 0;
+
        }else{
+
          goto walcheckpoint_out;
+
        }
      }
    }
-
  }
-

-
  if( pInfo->nBackfill<mxSafeFrame
-
   && (rc = walBusyLock(pWal, xBusy, pBusyArg, WAL_READ_LOCK(0), 1))==SQLITE_OK
-
  ){
-
    i64 nSize;                    /* Current size of database file */
-
    u32 nBackfill = pInfo->nBackfill;

-
    /* Sync the WAL to disk */
-
    if( sync_flags ){
-
      rc = sqlite3OsSync(pWal->pWalFd, sync_flags);
-
    }
+
    if( pInfo->nBackfill<mxSafeFrame
+
     && (rc = walBusyLock(pWal, xBusy, pBusyArg, WAL_READ_LOCK(0),1))==SQLITE_OK
+
    ){
+
      i64 nSize;                    /* Current size of database file */
+
      u32 nBackfill = pInfo->nBackfill;

-
    /* If the database may grow as a result of this checkpoint, hint
-
    ** about the eventual size of the db file to the VFS layer.
-
    */
-
    if( rc==SQLITE_OK ){
-
      i64 nReq = ((i64)mxPage * szPage);
-
      rc = sqlite3OsFileSize(pWal->pDbFd, &nSize);
-
      if( rc==SQLITE_OK && nSize<nReq ){
-
        sqlite3OsFileControlHint(pWal->pDbFd, SQLITE_FCNTL_SIZE_HINT, &nReq);
+
      /* Sync the WAL to disk */
+
      if( sync_flags ){
+
        rc = sqlite3OsSync(pWal->pWalFd, sync_flags);
      }
-
    }

+
      /* If the database may grow as a result of this checkpoint, hint
+
      ** about the eventual size of the db file to the VFS layer.
+
      */
+
      if( rc==SQLITE_OK ){
+
        i64 nReq = ((i64)mxPage * szPage);
+
        rc = sqlite3OsFileSize(pWal->pDbFd, &nSize);
+
        if( rc==SQLITE_OK && nSize<nReq ){
+
          sqlite3OsFileControlHint(pWal->pDbFd, SQLITE_FCNTL_SIZE_HINT, &nReq);
+
        }
+
      }

-
    /* Iterate through the contents of the WAL, copying data to the db file. */
-
    while( rc==SQLITE_OK && 0==walIteratorNext(pIter, &iDbpage, &iFrame) ){
-
      i64 iOffset;
-
      assert( walFramePgno(pWal, iFrame)==iDbpage );
-
      if( iFrame<=nBackfill || iFrame>mxSafeFrame || iDbpage>mxPage ) continue;
-
      iOffset = walFrameOffset(iFrame, szPage) + WAL_FRAME_HDRSIZE;
-
      /* testcase( IS_BIG_INT(iOffset) ); // requires a 4GiB WAL file */
-
      rc = sqlite3OsRead(pWal->pWalFd, zBuf, szPage, iOffset);
-
      if( rc!=SQLITE_OK ) break;
-
      iOffset = (iDbpage-1)*(i64)szPage;
-
      testcase( IS_BIG_INT(iOffset) );
-
      rc = sqlite3OsWrite(pWal->pDbFd, zBuf, szPage, iOffset);
-
      if( rc!=SQLITE_OK ) break;
-
    }

-
    /* If work was actually accomplished... */
-
    if( rc==SQLITE_OK ){
-
      if( mxSafeFrame==walIndexHdr(pWal)->mxFrame ){
-
        i64 szDb = pWal->hdr.nPage*(i64)szPage;
-
        testcase( IS_BIG_INT(szDb) );
-
        rc = sqlite3OsTruncate(pWal->pDbFd, szDb);
-
        if( rc==SQLITE_OK && sync_flags ){
-
          rc = sqlite3OsSync(pWal->pDbFd, sync_flags);
+
      /* Iterate through the contents of the WAL, copying data to the db file */
+
      while( rc==SQLITE_OK && 0==walIteratorNext(pIter, &iDbpage, &iFrame) ){
+
        i64 iOffset;
+
        assert( walFramePgno(pWal, iFrame)==iDbpage );
+
        if( iFrame<=nBackfill || iFrame>mxSafeFrame || iDbpage>mxPage ){
+
          continue;
        }
+
        iOffset = walFrameOffset(iFrame, szPage) + WAL_FRAME_HDRSIZE;
+
        /* testcase( IS_BIG_INT(iOffset) ); // requires a 4GiB WAL file */
+
        rc = sqlite3OsRead(pWal->pWalFd, zBuf, szPage, iOffset);
+
        if( rc!=SQLITE_OK ) break;
+
        iOffset = (iDbpage-1)*(i64)szPage;
+
        testcase( IS_BIG_INT(iOffset) );
+
        rc = sqlite3OsWrite(pWal->pDbFd, zBuf, szPage, iOffset);
+
        if( rc!=SQLITE_OK ) break;
      }
+

+
      /* If work was actually accomplished... */
      if( rc==SQLITE_OK ){
-
        pInfo->nBackfill = mxSafeFrame;
+
        if( mxSafeFrame==walIndexHdr(pWal)->mxFrame ){
+
          i64 szDb = pWal->hdr.nPage*(i64)szPage;
+
          testcase( IS_BIG_INT(szDb) );
+
          rc = sqlite3OsTruncate(pWal->pDbFd, szDb);
+
          if( rc==SQLITE_OK && sync_flags ){
+
            rc = sqlite3OsSync(pWal->pDbFd, sync_flags);
+
          }
+
        }
+
        if( rc==SQLITE_OK ){
+
          pInfo->nBackfill = mxSafeFrame;
+
        }
      }
-
    }

-
    /* Release the reader lock held while backfilling */
-
    walUnlockExclusive(pWal, WAL_READ_LOCK(0), 1);
-
  }
+
      /* Release the reader lock held while backfilling */
+
      walUnlockExclusive(pWal, WAL_READ_LOCK(0), 1);
+
    }

-
  if( rc==SQLITE_BUSY ){
-
    /* Reset the return code so as not to report a checkpoint failure
-
    ** just because there are active readers.  */
-
    rc = SQLITE_OK;
+
    if( rc==SQLITE_BUSY ){
+
      /* Reset the return code so as not to report a checkpoint failure
+
      ** just because there are active readers.  */
+
      rc = SQLITE_OK;
+
    }
  }

  /* If this is an SQLITE_CHECKPOINT_RESTART or TRUNCATE operation, and the
@@ -50323,7 +50326,7 @@ static int walCheckpoint(
    }else if( eMode>=SQLITE_CHECKPOINT_RESTART ){
      u32 salt1;
      sqlite3_randomness(4, &salt1);
-
      assert( mxSafeFrame==pWal->hdr.mxFrame );
+
      assert( pInfo->nBackfill==pWal->hdr.mxFrame );
      rc = walBusyLock(pWal, xBusy, pBusyArg, WAL_READ_LOCK(1), WAL_NREADER-1);
      if( rc==SQLITE_OK ){
        if( eMode==SQLITE_CHECKPOINT_TRUNCATE ){
@@ -67498,6 +67501,41 @@ debugCompareEnd:
}
#endif

+
#if SQLITE_DEBUG
+
/*
+
** Count the number of fields (a.k.a. columns) in the record given by
+
** pKey,nKey.  The verify that this count is less than or equal to the
+
** limit given by pKeyInfo->nField + pKeyInfo->nXField.
+
**
+
** If this constraint is not satisfied, it means that the high-speed
+
** vdbeRecordCompareInt() and vdbeRecordCompareString() routines will
+
** not work correctly.  If this assert() ever fires, it probably means
+
** that the KeyInfo.nField or KeyInfo.nXField values were computed
+
** incorrectly.
+
*/
+
static void vdbeAssertFieldCountWithinLimits(
+
  int nKey, const void *pKey,   /* The record to verify */ 
+
  const KeyInfo *pKeyInfo       /* Compare size with this KeyInfo */
+
){
+
  int nField = 0;
+
  u32 szHdr;
+
  u32 idx;
+
  u32 notUsed;
+
  const unsigned char *aKey = (const unsigned char*)pKey;
+

+
  if( CORRUPT_DB ) return;
+
  idx = getVarint32(aKey, szHdr);
+
  assert( szHdr<=nKey );
+
  while( idx<szHdr ){
+
    idx += getVarint32(aKey+idx, notUsed);
+
    nField++;
+
  }
+
  assert( nField <= pKeyInfo->nField+pKeyInfo->nXField );
+
}
+
#else
+
# define vdbeAssertFieldCountWithinLimits(A,B,C)
+
#endif
+

/*
** Both *pMem1 and *pMem2 contain string values. Compare the two values
** using the collation sequence pColl. As usual, return a negative , zero
@@ -67909,6 +67947,7 @@ static int vdbeRecordCompareInt(
  i64 v = pPKey2->aMem[0].u.i;
  i64 lhs;

+
  vdbeAssertFieldCountWithinLimits(nKey1, pKey1, pPKey2->pKeyInfo);
  assert( (*(u8*)pKey1)<=0x3F || CORRUPT_DB );
  switch( serial_type ){
    case 1: { /* 1-byte signed integer */
@@ -67996,6 +68035,7 @@ static int vdbeRecordCompareString(
  int serial_type;
  int res;

+
  vdbeAssertFieldCountWithinLimits(nKey1, pKey1, pPKey2->pKeyInfo);
  getVarint32(&aKey1[1], serial_type);
  if( serial_type<12 ){
    res = pPKey2->r1;      /* (pKey1/nKey1) is a number or a null */
@@ -105797,7 +105837,9 @@ static void pushOntoSorter(
    pKI = pOp->p4.pKeyInfo;
    memset(pKI->aSortOrder, 0, pKI->nField); /* Makes OP_Jump below testable */
    sqlite3VdbeChangeP4(v, -1, (char*)pKI, P4_KEYINFO);
-
    pOp->p4.pKeyInfo = keyInfoFromExprList(pParse, pSort->pOrderBy, nOBSat, 1);
+
    testcase( pKI->nXField>2 );
+
    pOp->p4.pKeyInfo = keyInfoFromExprList(pParse, pSort->pOrderBy, nOBSat,
+
                                           pKI->nXField-1);
    addrJmp = sqlite3VdbeCurrentAddr(v);
    sqlite3VdbeAddOp3(v, OP_Jump, addrJmp+1, 0, addrJmp+1); VdbeCoverage(v);
    pSort->labelBkOut = sqlite3VdbeMakeLabel(v);
@@ -106308,7 +106350,7 @@ static KeyInfo *keyInfoFromExprList(
  int i;

  nExpr = pList->nExpr;
-
  pInfo = sqlite3KeyInfoAlloc(db, nExpr+nExtra-iStart, 1);
+
  pInfo = sqlite3KeyInfoAlloc(db, nExpr-iStart, nExtra+1);
  if( pInfo ){
    assert( sqlite3KeyInfoIsWriteable(pInfo) );
    for(i=iStart, pItem=pList->a+iStart; i<nExpr; i++, pItem++){
@@ -110178,7 +110220,7 @@ SQLITE_PRIVATE int sqlite3Select(
  */
  if( sSort.pOrderBy ){
    KeyInfo *pKeyInfo;
-
    pKeyInfo = keyInfoFromExprList(pParse, sSort.pOrderBy, 0, 0);
+
    pKeyInfo = keyInfoFromExprList(pParse, sSort.pOrderBy, 0, pEList->nExpr);
    sSort.iECursor = pParse->nTab++;
    sSort.addrSortIndex =
      sqlite3VdbeAddOp4(v, OP_OpenEphemeral,
@@ -110352,7 +110394,7 @@ SQLITE_PRIVATE int sqlite3Select(
      ** will be converted into a Noop.  
      */
      sAggInfo.sortingIdx = pParse->nTab++;
-
      pKeyInfo = keyInfoFromExprList(pParse, pGroupBy, 0, 0);
+
      pKeyInfo = keyInfoFromExprList(pParse, pGroupBy, 0, sAggInfo.nColumn);
      addrSortingIdx = sqlite3VdbeAddOp4(v, OP_SorterOpen, 
          sAggInfo.sortingIdx, sAggInfo.nSortingColumn, 
          0, (char*)pKeyInfo, P4_KEYINFO);
@@ -128330,6 +128372,7 @@ SQLITE_API int sqlite3_wal_checkpoint_v2(
    rc = SQLITE_ERROR;
    sqlite3ErrorWithMsg(db, SQLITE_ERROR, "unknown database: %s", zDb);
  }else{
+
    db->busyHandler.nBusy = 0;
    rc = sqlite3Checkpoint(db, iDb, eMode, pnLog, pnCkpt);
    sqlite3Error(db, rc);
  }
modified external/sqlite/sqlite3.h
@@ -107,9 +107,9 @@ extern "C" {
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
** [sqlite_version()] and [sqlite_source_id()].
*/
-
#define SQLITE_VERSION        "3.8.8"
+
#define SQLITE_VERSION        "3.8.8.2"
#define SQLITE_VERSION_NUMBER 3008008
-
#define SQLITE_SOURCE_ID      "2015-01-16 12:08:06 7d68a42face3ab14ed88407d4331872f5b243fdf"
+
#define SQLITE_SOURCE_ID      "2015-01-30 14:30:45 7757fc721220e136620a89c9d28247f28bbbc098"

/*
** CAPI3REF: Run-Time Library Version Numbers