/ Check-in [da1cbfa7]
Login

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

Overview
Comment:Add explicit casts to silence nuisance warnings from VC++. (CVS 6004)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:da1cbfa766f7f379c01f4ac9c1210462d8d7c590
User & Date: drh 2008-12-10 16:45:51
Context
2008-12-10
17:20
Remove or rename local variables that shadow other variables or parameters. (CVS 6005) check-in: e7e9fa4f user: drh tags: trunk
16:45
Add explicit casts to silence nuisance warnings from VC++. (CVS 6004) check-in: da1cbfa7 user: drh tags: trunk
11:49
Use memcpy() rather than "=" to copy a structure, in order to work around a bug in the XLC compiler on AIX. Ticket #3344. (CVS 6003) check-in: 18bbcafc user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/analyze.c.

     7      7   **    May you do good and not evil.
     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains code associated with the ANALYZE command.
    13     13   **
    14         -** @(#) $Id: analyze.c,v 1.46 2008/11/19 16:52:44 danielk1977 Exp $
           14  +** @(#) $Id: analyze.c,v 1.47 2008/12/10 16:45:51 drh Exp $
    15     15   */
    16     16   #ifndef SQLITE_OMIT_ANALYZE
    17     17   #include "sqliteInt.h"
    18     18   
    19     19   /*
    20     20   ** This routine generates code that opens the sqlite_stat1 table on cursor
    21     21   ** iStatCur.
................................................................................
    29     29     int iDb,                /* The database we are looking in */
    30     30     int iStatCur,           /* Open the sqlite_stat1 table on this cursor */
    31     31     const char *zWhere      /* Delete entries associated with this table */
    32     32   ){
    33     33     sqlite3 *db = pParse->db;
    34     34     Db *pDb;
    35     35     int iRootPage;
    36         -  int createStat1 = 0;
           36  +  u8 createStat1 = 0;
    37     37     Table *pStat;
    38     38     Vdbe *v = sqlite3GetVdbe(pParse);
    39     39   
    40     40     if( v==0 ) return;
    41     41     assert( sqlite3BtreeHoldsAllMutexes(db) );
    42     42     assert( sqlite3VdbeDb(v)==db );
    43     43     pDb = &db->aDb[iDb];

Changes to src/attach.c.

     7      7   **    May you do good and not evil.
     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains code used to implement the ATTACH and DETACH commands.
    13     13   **
    14         -** $Id: attach.c,v 1.80 2008/11/19 09:05:27 danielk1977 Exp $
           14  +** $Id: attach.c,v 1.81 2008/12/10 16:45:51 drh Exp $
    15     15   */
    16     16   #include "sqliteInt.h"
    17     17   
    18     18   #ifndef SQLITE_OMIT_ATTACH
    19     19   /*
    20     20   ** Resolve an expression that was part of an ATTACH or DETACH statement. This
    21     21   ** is slightly different from resolving a normal SQL expression, because simple
................................................................................
   331    331     sqlite3ExprCode(pParse, pFilename, regArgs);
   332    332     sqlite3ExprCode(pParse, pDbname, regArgs+1);
   333    333     sqlite3ExprCode(pParse, pKey, regArgs+2);
   334    334   
   335    335     assert( v || db->mallocFailed );
   336    336     if( v ){
   337    337       sqlite3VdbeAddOp3(v, OP_Function, 0, regArgs+3-pFunc->nArg, regArgs+3);
   338         -    sqlite3VdbeChangeP5(v, pFunc->nArg);
          338  +    assert( pFunc->nArg==-1 || (pFunc->nArg&0xff)==pFunc->nArg );
          339  +    sqlite3VdbeChangeP5(v, (u8)(pFunc->nArg));
   339    340       sqlite3VdbeChangeP4(v, -1, (char *)pFunc, P4_FUNCDEF);
   340    341   
   341    342       /* Code an OP_Expire. For an ATTACH statement, set P1 to true (expire this
   342    343       ** statement only). For DETACH, set it to false (expire all existing
   343    344       ** statements).
   344    345       */
   345    346       sqlite3VdbeAddOp1(v, OP_Expire, (type==SQLITE_ATTACH));

Changes to src/btree.c.

     5      5   ** a legal notice, here is a blessing:
     6      6   **
     7      7   **    May you do good and not evil.
     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12         -** $Id: btree.c,v 1.545 2008/12/05 22:40:08 drh Exp $
           12  +** $Id: btree.c,v 1.546 2008/12/10 16:45:51 drh Exp $
    13     13   **
    14     14   ** This file implements a external (disk-based) database using BTrees.
    15     15   ** See the header comment on "btreeInt.h" for additional information.
    16     16   ** Including a description of file format and an overview of operation.
    17     17   */
    18     18   #include "btreeInt.h"
    19     19   
................................................................................
   312    312     /* If this is an intKey table, then the above call to BtreeKeySize()
   313    313     ** stores the integer key in pCur->nKey. In this case this value is
   314    314     ** all that is required. Otherwise, if pCur is not open on an intKey
   315    315     ** table, then malloc space for and store the pCur->nKey bytes of key 
   316    316     ** data.
   317    317     */
   318    318     if( rc==SQLITE_OK && 0==pCur->apPage[0]->intKey){
   319         -    void *pKey = sqlite3Malloc(pCur->nKey);
          319  +    void *pKey = sqlite3Malloc( (int)pCur->nKey );
   320    320       if( pKey ){
   321         -      rc = sqlite3BtreeKey(pCur, 0, pCur->nKey, pKey);
          321  +      rc = sqlite3BtreeKey(pCur, 0, (int)pCur->nKey, pKey);
   322    322         if( rc==SQLITE_OK ){
   323    323           pCur->pKey = pKey;
   324    324         }else{
   325    325           sqlite3_free(pKey);
   326    326         }
   327    327       }else{
   328    328         rc = SQLITE_NOMEM;
................................................................................
   571    571   ** sqlite3BtreeParseCellPtr(). Using some compilers, this will be faster.
   572    572   */
   573    573   void sqlite3BtreeParseCellPtr(
   574    574     MemPage *pPage,         /* Page containing the cell */
   575    575     u8 *pCell,              /* Pointer to the cell text. */
   576    576     CellInfo *pInfo         /* Fill in this structure */
   577    577   ){
   578         -  int n;                  /* Number bytes in cell content header */
          578  +  u16 n;                  /* Number bytes in cell content header */
   579    579     u32 nPayload;           /* Number of bytes of cell payload */
   580    580   
   581    581     assert( sqlite3_mutex_held(pPage->pBt->mutex) );
   582    582   
   583    583     pInfo->pCell = pCell;
   584    584     assert( pPage->leaf==0 || pPage->leaf==1 );
   585    585     n = pPage->childPtrSize;
................................................................................
   586    586     assert( n==4-4*pPage->leaf );
   587    587     if( pPage->intKey ){
   588    588       if( pPage->hasData ){
   589    589         n += getVarint32(&pCell[n], nPayload);
   590    590       }else{
   591    591         nPayload = 0;
   592    592       }
   593         -    n += getVarint(&pCell[n], (u64*)&pInfo->nKey);
          593  +    n += (u16)getVarint(&pCell[n], (u64*)&pInfo->nKey);
   594    594       pInfo->nData = nPayload;
   595    595     }else{
   596    596       pInfo->nData = 0;
   597    597       n += getVarint32(&pCell[n], nPayload);
   598    598       pInfo->nKey = nPayload;
   599    599     }
   600    600     pInfo->nPayload = nPayload;
................................................................................
   601    601     pInfo->nHeader = n;
   602    602     if( likely(nPayload<=pPage->maxLocal) ){
   603    603       /* This is the (easy) common case where the entire payload fits
   604    604       ** on the local page.  No overflow is required.
   605    605       */
   606    606       int nSize;          /* Total size of cell content in bytes */
   607    607       nSize = nPayload + n;
   608         -    pInfo->nLocal = nPayload;
          608  +    pInfo->nLocal = (u16)nPayload;
   609    609       pInfo->iOverflow = 0;
   610    610       if( (nSize & ~3)==0 ){
   611    611         nSize = 4;        /* Minimum cell size is 4 */
   612    612       }
   613         -    pInfo->nSize = nSize;
          613  +    pInfo->nSize = (int)nSize;
   614    614     }else{
   615    615       /* If the payload will not fit completely on the local page, we have
   616    616       ** to decide how much to store locally and how much to spill onto
   617    617       ** overflow pages.  The strategy is to minimize the amount of unused
   618    618       ** space on overflow pages while keeping the amount of local storage
   619    619       ** in between minLocal and maxLocal.
   620    620       **
................................................................................
   625    625       int maxLocal;  /* Maximum amount of payload held locally */
   626    626       int surplus;   /* Overflow payload available for local storage */
   627    627   
   628    628       minLocal = pPage->minLocal;
   629    629       maxLocal = pPage->maxLocal;
   630    630       surplus = minLocal + (nPayload - minLocal)%(pPage->pBt->usableSize - 4);
   631    631       if( surplus <= maxLocal ){
   632         -      pInfo->nLocal = surplus;
          632  +      pInfo->nLocal = (u16)surplus;
   633    633       }else{
   634         -      pInfo->nLocal = minLocal;
          634  +      pInfo->nLocal = (u16)minLocal;
   635    635       }
   636         -    pInfo->iOverflow = pInfo->nLocal + n;
          636  +    pInfo->iOverflow = (u16)(pInfo->nLocal + n);
   637    637       pInfo->nSize = pInfo->iOverflow + 4;
   638    638     }
   639    639   }
   640    640   #define parseCell(pPage, iCell, pInfo) \
   641    641     sqlite3BtreeParseCellPtr((pPage), findCell((pPage), (iCell)), (pInfo))
   642    642   void sqlite3BtreeParseCell(
   643    643     MemPage *pPage,         /* Page containing the cell */
................................................................................
   785    785     data = pPage->aData;
   786    786     assert( sqlite3PagerIswriteable(pPage->pDbPage) );
   787    787     assert( pPage->pBt );
   788    788     assert( sqlite3_mutex_held(pPage->pBt->mutex) );
   789    789     assert( nByte>=0 );  /* Minimum cell size is 4 */
   790    790     assert( pPage->nFree>=nByte );
   791    791     assert( pPage->nOverflow==0 );
   792         -  pPage->nFree -= nByte;
          792  +  pPage->nFree -= (u16)nByte;
   793    793     hdr = pPage->hdrOffset;
   794    794   
   795    795     nFrag = data[hdr+7];
   796    796     if( nFrag<60 ){
   797    797       /* Search the freelist looking for a slot big enough to satisfy the
   798    798       ** space request. */
   799    799       addr = hdr+1;
   800    800       while( (pc = get2byte(&data[addr]))>0 ){
   801    801         size = get2byte(&data[pc+2]);
   802    802         if( size>=nByte ){
          803  +        int x = size - nByte;
   803    804           if( size<nByte+4 ){
   804    805             memcpy(&data[addr], &data[pc], 2);
   805         -          data[hdr+7] = nFrag + size - nByte;
          806  +          data[hdr+7] = (u8)(nFrag + x);
   806    807             return pc;
   807    808           }else{
   808         -          put2byte(&data[pc+2], size-nByte);
   809         -          return pc + size - nByte;
          809  +          put2byte(&data[pc+2], x);
          810  +          return pc + x;
   810    811           }
   811    812         }
   812    813         addr = pc;
   813    814       }
   814    815     }
   815    816   
   816    817     /* Allocate memory from the gap in between the cell pointer array
................................................................................
   868    869     if ( pbegin>pPage->pBt->usableSize-4 ) {
   869    870       return SQLITE_CORRUPT_BKPT;
   870    871     }
   871    872     assert( pbegin>addr || pbegin==0 );
   872    873     put2byte(&data[addr], start);
   873    874     put2byte(&data[start], pbegin);
   874    875     put2byte(&data[start+2], size);
   875         -  pPage->nFree += size;
          876  +  pPage->nFree += (u16)size;
   876    877   
   877    878     /* Coalesce adjacent free blocks */
   878    879     addr = pPage->hdrOffset + 1;
   879    880     while( (pbegin = get2byte(&data[addr]))>0 ){
   880         -    int pnext, psize;
          881  +    int pnext, psize, x;
   881    882       assert( pbegin>addr );
   882    883       assert( pbegin<=pPage->pBt->usableSize-4 );
   883    884       pnext = get2byte(&data[pbegin]);
   884    885       psize = get2byte(&data[pbegin+2]);
   885    886       if( pbegin + psize + 3 >= pnext && pnext>0 ){
   886    887         int frag = pnext - (pbegin+psize);
   887         -      if( (frag<0) || (frag>data[pPage->hdrOffset+7]) ){
          888  +      if( (frag<0) || (frag>(int)data[pPage->hdrOffset+7]) ){
   888    889           return SQLITE_CORRUPT_BKPT;
   889    890         }
   890         -      data[pPage->hdrOffset+7] -= frag;
   891         -      put2byte(&data[pbegin], get2byte(&data[pnext]));
   892         -      put2byte(&data[pbegin+2], pnext+get2byte(&data[pnext+2])-pbegin);
          891  +      data[pPage->hdrOffset+7] -= (u8)frag;
          892  +      x = get2byte(&data[pnext]);
          893  +      put2byte(&data[pbegin], x);
          894  +      x = pnext + get2byte(&data[pnext+2]) - pbegin;
          895  +      put2byte(&data[pbegin+2], x);
   893    896       }else{
   894    897         addr = pbegin;
   895    898       }
   896    899     }
   897    900   
   898    901     /* If the cell content area begins with a freeblock, remove it. */
   899    902     if( data[hdr+1]==data[hdr+5] && data[hdr+2]==data[hdr+6] ){
   900    903       int top;
   901    904       pbegin = get2byte(&data[hdr+1]);
   902    905       memcpy(&data[hdr+1], &data[pbegin], 2);
   903         -    top = get2byte(&data[hdr+5]);
   904         -    put2byte(&data[hdr+5], top + get2byte(&data[pbegin+2]));
          906  +    top = get2byte(&data[hdr+5]) + get2byte(&data[pbegin+2]);
          907  +    put2byte(&data[hdr+5], top);
   905    908     }
   906    909     assert( sqlite3PagerIswriteable(pPage->pDbPage) );
   907    910     return SQLITE_OK;
   908    911   }
   909    912   
   910    913   /*
   911    914   ** Decode the flags byte (the first byte of the header) for a page
................................................................................
   920    923   **         PTF_LEAFDATA | PTF_INTKEY | PTF_LEAF
   921    924   */
   922    925   static int decodeFlags(MemPage *pPage, int flagByte){
   923    926     BtShared *pBt;     /* A copy of pPage->pBt */
   924    927   
   925    928     assert( pPage->hdrOffset==(pPage->pgno==1 ? 100 : 0) );
   926    929     assert( sqlite3_mutex_held(pPage->pBt->mutex) );
   927         -  pPage->leaf = flagByte>>3;  assert( PTF_LEAF == 1<<3 );
          930  +  pPage->leaf = (u8)(flagByte>>3);  assert( PTF_LEAF == 1<<3 );
   928    931     flagByte &= ~PTF_LEAF;
   929    932     pPage->childPtrSize = 4-4*pPage->leaf;
   930    933     pBt = pPage->pBt;
   931    934     if( flagByte==(PTF_LEAFDATA | PTF_INTKEY) ){
   932    935       pPage->intKey = 1;
   933    936       pPage->hasData = pPage->leaf;
   934    937       pPage->maxLocal = pBt->maxLeaf;
................................................................................
   958    961     assert( pPage->pBt!=0 );
   959    962     assert( sqlite3_mutex_held(pPage->pBt->mutex) );
   960    963     assert( pPage->pgno==sqlite3PagerPagenumber(pPage->pDbPage) );
   961    964     assert( pPage == sqlite3PagerGetExtra(pPage->pDbPage) );
   962    965     assert( pPage->aData == sqlite3PagerGetData(pPage->pDbPage) );
   963    966   
   964    967     if( !pPage->isInit ){
   965         -    int pc;            /* Address of a freeblock within pPage->aData[] */
   966         -    int hdr;           /* Offset to beginning of page header */
          968  +    u16 pc;            /* Address of a freeblock within pPage->aData[] */
          969  +    u8 hdr;            /* Offset to beginning of page header */
   967    970       u8 *data;          /* Equal to pPage->aData */
   968    971       BtShared *pBt;        /* The main btree structure */
   969         -    int usableSize;    /* Amount of usable space on each page */
   970         -    int cellOffset;    /* Offset from start of page to first cell pointer */
   971         -    int nFree;         /* Number of unused bytes on the page */
   972         -    int top;           /* First byte of the cell content area */
          972  +    u16 usableSize;    /* Amount of usable space on each page */
          973  +    u16 cellOffset;    /* Offset from start of page to first cell pointer */
          974  +    u16 nFree;         /* Number of unused bytes on the page */
          975  +    u16 top;           /* First byte of the cell content area */
   973    976   
   974    977       pBt = pPage->pBt;
   975    978   
   976    979       hdr = pPage->hdrOffset;
   977    980       data = pPage->aData;
   978    981       if( decodeFlags(pPage, data[hdr]) ) return SQLITE_CORRUPT_BKPT;
   979    982       assert( pBt->pageSize>=512 && pBt->pageSize<=32768 );
................................................................................
  1002   1005         if( next>0 && next<=pc+size+3 ){
  1003   1006           /* Free blocks must be in accending order */
  1004   1007           return SQLITE_CORRUPT_BKPT; 
  1005   1008         }
  1006   1009         nFree += size;
  1007   1010         pc = next;
  1008   1011       }
  1009         -    pPage->nFree = nFree;
         1012  +    pPage->nFree = (u16)nFree;
  1010   1013       if( nFree>=usableSize ){
  1011   1014         /* Free space cannot exceed total page size */
  1012   1015         return SQLITE_CORRUPT_BKPT; 
  1013   1016       }
  1014   1017   
  1015   1018   #if 0
  1016   1019     /* Check that all the offsets in the cell offset array are within range. 
................................................................................
  1040   1043   /*
  1041   1044   ** Set up a raw page so that it looks like a database page holding
  1042   1045   ** no entries.
  1043   1046   */
  1044   1047   static void zeroPage(MemPage *pPage, int flags){
  1045   1048     unsigned char *data = pPage->aData;
  1046   1049     BtShared *pBt = pPage->pBt;
  1047         -  int hdr = pPage->hdrOffset;
  1048         -  int first;
         1050  +  u8 hdr = pPage->hdrOffset;
         1051  +  u16 first;
  1049   1052   
  1050   1053     assert( sqlite3PagerPagenumber(pPage->pDbPage)==pPage->pgno );
  1051   1054     assert( sqlite3PagerGetExtra(pPage->pDbPage) == (void*)pPage );
  1052   1055     assert( sqlite3PagerGetData(pPage->pDbPage) == data );
  1053   1056     assert( sqlite3PagerIswriteable(pPage->pDbPage) );
  1054   1057     assert( sqlite3_mutex_held(pBt->mutex) );
  1055   1058     /*memset(&data[hdr], 0, pBt->usableSize - hdr);*/
................................................................................
  1233   1236     int flags,              /* Options */
  1234   1237     int vfsFlags            /* Flags passed through to sqlite3_vfs.xOpen() */
  1235   1238   ){
  1236   1239     sqlite3_vfs *pVfs;      /* The VFS to use for this btree */
  1237   1240     BtShared *pBt = 0;      /* Shared part of btree structure */
  1238   1241     Btree *p;               /* Handle to return */
  1239   1242     int rc = SQLITE_OK;
  1240         -  int nReserve;
         1243  +  u8 nReserve;
  1241   1244     unsigned char zDbHeader[100];
  1242   1245   
  1243   1246     /* Set the variable isMemdb to true for an in-memory database, or 
  1244   1247     ** false for a file-based database. This symbol is only required if
  1245   1248     ** either of the shared-data or autovacuum features are compiled 
  1246   1249     ** into the library.
  1247   1250     */
................................................................................
  1630   1633   **
  1631   1634   ** If parameter nReserve is less than zero, then the number of reserved
  1632   1635   ** bytes per page is left unchanged.
  1633   1636   */
  1634   1637   int sqlite3BtreeSetPageSize(Btree *p, int pageSize, int nReserve){
  1635   1638     int rc = SQLITE_OK;
  1636   1639     BtShared *pBt = p->pBt;
         1640  +  assert( nReserve>=-1 && nReserve<=255 );
  1637   1641     sqlite3BtreeEnter(p);
  1638   1642     if( pBt->pageSizeFixed ){
  1639   1643       sqlite3BtreeLeave(p);
  1640   1644       return SQLITE_READONLY;
  1641   1645     }
  1642   1646     if( nReserve<0 ){
  1643   1647       nReserve = pBt->pageSize - pBt->usableSize;
  1644   1648     }
         1649  +  assert( nReserve>=0 && nReserve<=255 );
  1645   1650     if( pageSize>=512 && pageSize<=SQLITE_MAX_PAGE_SIZE &&
  1646   1651           ((pageSize-1)&pageSize)==0 ){
  1647   1652       assert( (pageSize & 7)==0 );
  1648   1653       assert( !pBt->pPage1 && !pBt->pCursor );
  1649   1654       pBt->pageSize = pageSize;
  1650   1655       freeTempSpace(pBt);
  1651   1656       rc = sqlite3PagerSetPagesize(pBt->pPager, &pBt->pageSize);
  1652   1657     }
  1653         -  pBt->usableSize = pBt->pageSize - nReserve;
         1658  +  pBt->usableSize = pBt->pageSize - (u16)nReserve;
  1654   1659     sqlite3BtreeLeave(p);
  1655   1660     return rc;
  1656   1661   }
  1657   1662   
  1658   1663   /*
  1659   1664   ** Return the currently defined page size
  1660   1665   */
................................................................................
  1691   1696   */
  1692   1697   int sqlite3BtreeSetAutoVacuum(Btree *p, int autoVacuum){
  1693   1698   #ifdef SQLITE_OMIT_AUTOVACUUM
  1694   1699     return SQLITE_READONLY;
  1695   1700   #else
  1696   1701     BtShared *pBt = p->pBt;
  1697   1702     int rc = SQLITE_OK;
  1698         -  int av = (autoVacuum?1:0);
         1703  +  u8 av = autoVacuum ?1:0;
  1699   1704   
  1700   1705     sqlite3BtreeEnter(p);
  1701   1706     if( pBt->pageSizeFixed && av!=pBt->autoVacuum ){
  1702   1707       rc = SQLITE_READONLY;
  1703   1708     }else{
  1704   1709       pBt->autoVacuum = av;
  1705   1710     }
................................................................................
  1789   1794         /* After reading the first page of the database assuming a page size
  1790   1795         ** of BtShared.pageSize, we have discovered that the page-size is
  1791   1796         ** actually pageSize. Unlock the database, leave pBt->pPage1 at
  1792   1797         ** zero and return SQLITE_OK. The caller will call this function
  1793   1798         ** again with the correct page-size.
  1794   1799         */
  1795   1800         releasePage(pPage1);
  1796         -      pBt->usableSize = usableSize;
  1797         -      pBt->pageSize = pageSize;
         1801  +      pBt->usableSize = (u16)usableSize;
         1802  +      pBt->pageSize = (u16)pageSize;
  1798   1803         freeTempSpace(pBt);
  1799   1804         sqlite3PagerSetPagesize(pBt->pPager, &pBt->pageSize);
  1800   1805         return SQLITE_OK;
  1801   1806       }
  1802   1807       if( usableSize<500 ){
  1803   1808         goto page1_init_failed;
  1804   1809       }
................................................................................
  1911   1916     rc = sqlite3PagerWrite(pP1->pDbPage);
  1912   1917     if( rc ) return rc;
  1913   1918     memcpy(data, zMagicHeader, sizeof(zMagicHeader));
  1914   1919     assert( sizeof(zMagicHeader)==16 );
  1915   1920     put2byte(&data[16], pBt->pageSize);
  1916   1921     data[18] = 1;
  1917   1922     data[19] = 1;
  1918         -  data[20] = pBt->pageSize - pBt->usableSize;
         1923  +  assert( pBt->usableSize<=pBt->pageSize && pBt->usableSize+255>=pBt->pageSize);
         1924  +  data[20] = (u8)(pBt->pageSize - pBt->usableSize);
  1919   1925     data[21] = 64;
  1920   1926     data[22] = 32;
  1921   1927     data[23] = 32;
  1922   1928     memset(&data[24], 0, 100-24);
  1923   1929     zeroPage(pP1, PTF_INTKEY|PTF_LEAF|PTF_LEAFDATA );
  1924   1930     pBt->pageSizeFixed = 1;
  1925   1931   #ifndef SQLITE_OMIT_AUTOVACUUM
................................................................................
  2066   2072   ** map entries for the overflow pages as well.
  2067   2073   */
  2068   2074   static int setChildPtrmaps(MemPage *pPage){
  2069   2075     int i;                             /* Counter variable */
  2070   2076     int nCell;                         /* Number of cells in page pPage */
  2071   2077     int rc;                            /* Return code */
  2072   2078     BtShared *pBt = pPage->pBt;
  2073         -  int isInitOrig = pPage->isInit;
         2079  +  u8 isInitOrig = pPage->isInit;
  2074   2080     Pgno pgno = pPage->pgno;
  2075   2081   
  2076   2082     assert( sqlite3_mutex_held(pPage->pBt->mutex) );
  2077   2083     rc = sqlite3BtreeInitPage(pPage);
  2078   2084     if( rc!=SQLITE_OK ){
  2079   2085       goto set_child_ptrmaps_out;
  2080   2086     }
................................................................................
  2126   2132     if( eType==PTRMAP_OVERFLOW2 ){
  2127   2133       /* The pointer is always the first 4 bytes of the page in this case.  */
  2128   2134       if( get4byte(pPage->aData)!=iFrom ){
  2129   2135         return SQLITE_CORRUPT_BKPT;
  2130   2136       }
  2131   2137       put4byte(pPage->aData, iTo);
  2132   2138     }else{
  2133         -    int isInitOrig = pPage->isInit;
         2139  +    u8 isInitOrig = pPage->isInit;
  2134   2140       int i;
  2135   2141       int nCell;
  2136   2142   
  2137   2143       sqlite3BtreeInitPage(pPage);
  2138   2144       nCell = pPage->nCell;
  2139   2145   
  2140   2146       for(i=0; i<nCell; i++){
................................................................................
  2809   2815     BtCursor *pCur                         /* Space for new cursor */
  2810   2816   ){
  2811   2817     int rc;
  2812   2818     Pgno nPage;
  2813   2819     BtShared *pBt = p->pBt;
  2814   2820   
  2815   2821     assert( sqlite3BtreeHoldsMutex(p) );
         2822  +  assert( wrFlag==0 || wrFlag==1 );
  2816   2823     if( wrFlag ){
  2817   2824       if( pBt->readOnly ){
  2818   2825         return SQLITE_READONLY;
  2819   2826       }
  2820   2827       if( checkReadLocks(p, iTable, 0, 0) ){
  2821   2828         return SQLITE_LOCKED;
  2822   2829       }
................................................................................
  2848   2855     /* Now that no other errors can occur, finish filling in the BtCursor
  2849   2856     ** variables, link the cursor into the BtShared list and set *ppCur (the
  2850   2857     ** output argument to this function).
  2851   2858     */
  2852   2859     pCur->pKeyInfo = pKeyInfo;
  2853   2860     pCur->pBtree = p;
  2854   2861     pCur->pBt = pBt;
  2855         -  pCur->wrFlag = wrFlag;
         2862  +  pCur->wrFlag = (u8)wrFlag;
  2856   2863     pCur->pNext = pBt->pCursor;
  2857   2864     if( pCur->pNext ){
  2858   2865       pCur->pNext->pPrev = pCur;
  2859   2866     }
  2860   2867     pBt->pCursor = pCur;
  2861   2868     pCur->eState = CURSOR_INVALID;
  2862   2869   
................................................................................
  3211   3218     assert( pPage );
  3212   3219     assert( pCur->eState==CURSOR_VALID );
  3213   3220     assert( pCur->aiIdx[pCur->iPage]<pPage->nCell );
  3214   3221     assert( cursorHoldsMutex(pCur) );
  3215   3222   
  3216   3223     getCellInfo(pCur);
  3217   3224     aPayload = pCur->info.pCell + pCur->info.nHeader;
  3218         -  nKey = (pPage->intKey ? 0 : pCur->info.nKey);
         3225  +  nKey = (pPage->intKey ? 0 : (int)pCur->info.nKey);
  3219   3226   
  3220   3227     if( skipKey ){
  3221   3228       offset += nKey;
  3222   3229     }
  3223   3230     if( offset+amt > nKey+pCur->info.nData 
  3224   3231      || &aPayload[pCur->info.nLocal] > &pPage->aData[pBt->usableSize]
  3225   3232     ){
................................................................................
  3418   3425     assert( pCur->aiIdx[pCur->iPage]<pPage->nCell );
  3419   3426     getCellInfo(pCur);
  3420   3427     aPayload = pCur->info.pCell;
  3421   3428     aPayload += pCur->info.nHeader;
  3422   3429     if( pPage->intKey ){
  3423   3430       nKey = 0;
  3424   3431     }else{
  3425         -    nKey = pCur->info.nKey;
         3432  +    nKey = (int)pCur->info.nKey;
  3426   3433     }
  3427   3434     if( skipKey ){
  3428   3435       aPayload += nKey;
  3429   3436       nLocal = pCur->info.nLocal - nKey;
  3430   3437     }else{
  3431   3438       nLocal = pCur->info.nLocal;
  3432   3439       if( nLocal>nKey ){
................................................................................
  3688   3695         assert( pCur->apPage[pCur->iPage]->nCell==0 );
  3689   3696         *pRes = 1;
  3690   3697       }else{
  3691   3698         assert( pCur->eState==CURSOR_VALID );
  3692   3699         *pRes = 0;
  3693   3700         rc = moveToRightmost(pCur);
  3694   3701         getCellInfo(pCur);
  3695         -      pCur->atLast = rc==SQLITE_OK;
         3702  +      pCur->atLast = rc==SQLITE_OK ?1:0;
  3696   3703       }
  3697   3704     }
  3698   3705     return rc;
  3699   3706   }
  3700   3707   
  3701   3708   /* Move the cursor so that it points to an entry near the key 
  3702   3709   ** specified by pIdxKey or intKey.   Return a success code.
................................................................................
  3772   3779       lwr = 0;
  3773   3780       upr = pPage->nCell-1;
  3774   3781       if( !pPage->intKey && pIdxKey==0 ){
  3775   3782         rc = SQLITE_CORRUPT_BKPT;
  3776   3783         goto moveto_finish;
  3777   3784       }
  3778   3785       if( biasRight ){
  3779         -      pCur->aiIdx[pCur->iPage] = upr;
         3786  +      pCur->aiIdx[pCur->iPage] = (u16)upr;
  3780   3787       }else{
  3781         -      pCur->aiIdx[pCur->iPage] = (upr+lwr)/2;
         3788  +      pCur->aiIdx[pCur->iPage] = (u16)((upr+lwr)/2);
  3782   3789       }
  3783   3790       if( lwr<=upr ) for(;;){
  3784   3791         void *pCellKey;
  3785   3792         i64 nCellKey;
  3786   3793         int idx = pCur->aiIdx[pCur->iPage];
  3787   3794         pCur->info.nSize = 0;
  3788   3795         pCur->validNKey = 1;
................................................................................
  3803   3810             c = +1;
  3804   3811           }
  3805   3812         }else{
  3806   3813           int available;
  3807   3814           pCellKey = (void *)fetchPayload(pCur, &available, 0);
  3808   3815           nCellKey = pCur->info.nKey;
  3809   3816           if( available>=nCellKey ){
  3810         -          c = sqlite3VdbeRecordCompare(nCellKey, pCellKey, pIdxKey);
         3817  +          c = sqlite3VdbeRecordCompare((int)nCellKey, pCellKey, pIdxKey);
  3811   3818           }else{
  3812         -          pCellKey = sqlite3Malloc( nCellKey );
         3819  +          pCellKey = sqlite3Malloc( (int)nCellKey );
  3813   3820             if( pCellKey==0 ){
  3814   3821               rc = SQLITE_NOMEM;
  3815   3822               goto moveto_finish;
  3816   3823             }
  3817         -          rc = sqlite3BtreeKey(pCur, 0, nCellKey, (void *)pCellKey);
         3824  +          rc = sqlite3BtreeKey(pCur, 0, (int)nCellKey, (void*)pCellKey);
  3818   3825             c = sqlite3VdbeRecordCompare(nCellKey, pCellKey, pIdxKey);
  3819   3826             sqlite3_free(pCellKey);
  3820   3827             if( rc ) goto moveto_finish;
  3821   3828           }
  3822   3829         }
  3823   3830         if( c==0 ){
  3824   3831           pCur->info.nKey = nCellKey;
................................................................................
  3837   3844         }else{
  3838   3845           upr = idx-1;
  3839   3846         }
  3840   3847         if( lwr>upr ){
  3841   3848           pCur->info.nKey = nCellKey;
  3842   3849           break;
  3843   3850         }
  3844         -      pCur->aiIdx[pCur->iPage] = (lwr+upr)/2;
         3851  +      pCur->aiIdx[pCur->iPage] = (u16)((lwr+upr)/2);
  3845   3852       }
  3846   3853       assert( lwr==upr+1 );
  3847   3854       assert( pPage->isInit );
  3848   3855       if( pPage->leaf ){
  3849   3856         chldPg = 0;
  3850   3857       }else if( lwr>=pPage->nCell ){
  3851   3858         chldPg = get4byte(&pPage->aData[pPage->hdrOffset+8]);
................................................................................
  3854   3861       }
  3855   3862       if( chldPg==0 ){
  3856   3863         assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell );
  3857   3864         if( pRes ) *pRes = c;
  3858   3865         rc = SQLITE_OK;
  3859   3866         goto moveto_finish;
  3860   3867       }
  3861         -    pCur->aiIdx[pCur->iPage] = lwr;
         3868  +    pCur->aiIdx[pCur->iPage] = (u16)lwr;
  3862   3869       pCur->info.nSize = 0;
  3863   3870       pCur->validNKey = 0;
  3864   3871       rc = moveToChild(pCur, chldPg);
  3865   3872       if( rc ) goto moveto_finish;
  3866   3873     }
  3867   3874   moveto_finish:
  3868   3875     return rc;
................................................................................
  3881   3888     int *pRes           /* Write search results here */
  3882   3889   ){
  3883   3890     int rc;                    /* Status code */
  3884   3891     UnpackedRecord *pIdxKey;   /* Unpacked index key */
  3885   3892     UnpackedRecord aSpace[16]; /* Temp space for pIdxKey - to avoid a malloc */
  3886   3893   
  3887   3894     if( pKey ){
  3888         -    pIdxKey = sqlite3VdbeRecordUnpack(pCur->pKeyInfo, nKey, pKey,
         3895  +    assert( nKey==(i64)(int)nKey );
         3896  +    pIdxKey = sqlite3VdbeRecordUnpack(pCur->pKeyInfo, (int)nKey, pKey,
  3889   3897                                         aSpace, sizeof(aSpace));
  3890   3898       if( pIdxKey==0 ) return SQLITE_NOMEM;
  3891   3899     }else{
  3892   3900       pIdxKey = 0;
  3893   3901     }
  3894   3902     rc = sqlite3BtreeMovetoUnpacked(pCur, pIdxKey, nKey, bias, pRes);
  3895   3903     if( pKey ){
................................................................................
  4509   4517     
  4510   4518     /* Fill in the payload */
  4511   4519     nPayload = nData + nZero;
  4512   4520     if( pPage->intKey ){
  4513   4521       pSrc = pData;
  4514   4522       nSrc = nData;
  4515   4523       nData = 0;
  4516         -  }else{
  4517         -    nPayload += nKey;
         4524  +  }else{ 
         4525  +    /* TBD:  Perhaps raise SQLITE_CORRUPT if nKey is larger than 31 bits? */
         4526  +    nPayload += (int)nKey;
  4518   4527       pSrc = pKey;
  4519         -    nSrc = nKey;
         4528  +    nSrc = (int)nKey;
  4520   4529     }
  4521   4530     *pnSize = info.nSize;
  4522   4531     spaceLeft = info.nLocal;
  4523   4532     pPayload = &pCell[nHeader];
  4524   4533     pPrior = &pCell[info.iOverflow];
  4525   4534   
  4526   4535     while( nPayload>0 ){
  4527   4536       if( spaceLeft==0 ){
  4528         -      int isExact = 0;
  4529   4537   #ifndef SQLITE_OMIT_AUTOVACUUM
  4530   4538         Pgno pgnoPtrmap = pgnoOvfl; /* Overflow page pointer-map entry page */
  4531   4539         if( pBt->autoVacuum ){
  4532   4540           do{
  4533   4541             pgnoOvfl++;
  4534   4542           } while( 
  4535   4543             PTRMAP_ISPAGE(pBt, pgnoOvfl) || pgnoOvfl==PENDING_BYTE_PAGE(pBt) 
  4536   4544           );
  4537         -        if( pgnoOvfl>1 ){
  4538         -          /* isExact = 1; */
  4539         -        }
  4540   4545         }
  4541   4546   #endif
  4542         -      rc = allocateBtreePage(pBt, &pOvfl, &pgnoOvfl, pgnoOvfl, isExact);
         4547  +      rc = allocateBtreePage(pBt, &pOvfl, &pgnoOvfl, pgnoOvfl, 0);
  4543   4548   #ifndef SQLITE_OMIT_AUTOVACUUM
  4544   4549         /* If the database supports auto-vacuum, and the second or subsequent
  4545   4550         ** overflow page is being allocated, add an entry to the pointer-map
  4546   4551         ** for that page now. 
  4547   4552         **
  4548   4553         ** If this is the first overflow page, then write a partial entry 
  4549   4554         ** to the pointer-map. If we write nothing to this pointer-map slot,
................................................................................
  4686   4691     int ins;          /* Index in data[] where new cell pointer is inserted */
  4687   4692     int hdr;          /* Offset into data[] of the page header */
  4688   4693     int cellOffset;   /* Address of first cell pointer in data[] */
  4689   4694     u8 *data;         /* The content of the whole page */
  4690   4695     u8 *ptr;          /* Used for moving information around in data[] */
  4691   4696   
  4692   4697     assert( i>=0 && i<=pPage->nCell+pPage->nOverflow );
         4698  +  assert( pPage->nCell<=MX_CELL(pPage->pBt) && MX_CELL(pPage->pBt)<=5460 );
         4699  +  assert( pPage->nOverflow<=ArraySize(pPage->aOvfl) );
  4693   4700     assert( sz==cellSizePtr(pPage, pCell) );
  4694   4701     assert( sqlite3_mutex_held(pPage->pBt->mutex) );
  4695   4702     if( pPage->nOverflow || sz+2>pPage->nFree ){
  4696   4703       if( pTemp ){
  4697   4704         memcpy(pTemp+nSkip, pCell+nSkip, sz-nSkip);
  4698   4705         pCell = pTemp;
  4699   4706       }
  4700   4707       j = pPage->nOverflow++;
  4701   4708       assert( j<(int)(sizeof(pPage->aOvfl)/sizeof(pPage->aOvfl[0])) );
  4702   4709       pPage->aOvfl[j].pCell = pCell;
  4703         -    pPage->aOvfl[j].idx = i;
         4710  +    pPage->aOvfl[j].idx = (u16)i;
  4704   4711       pPage->nFree = 0;
  4705   4712     }else{
  4706   4713       int rc = sqlite3PagerWrite(pPage->pDbPage);
  4707   4714       if( rc!=SQLITE_OK ){
  4708   4715         return rc;
  4709   4716       }
  4710   4717       assert( sqlite3PagerIswriteable(pPage->pDbPage) );
................................................................................
  4772   4779     int hdr;          /* Index of page header */
  4773   4780     int cellptr;      /* Address of next cell pointer */
  4774   4781     int cellbody;     /* Address of next cell body */
  4775   4782     u8 *data;         /* Data for the page */
  4776   4783   
  4777   4784     assert( pPage->nOverflow==0 );
  4778   4785     assert( sqlite3_mutex_held(pPage->pBt->mutex) );
         4786  +  assert( nCell>=0 && nCell<=MX_CELL(pPage->pBt) && MX_CELL(pPage->pBt)<=5460 );
  4779   4787     totalSize = 0;
  4780   4788     for(i=0; i<nCell; i++){
  4781   4789       totalSize += aSize[i];
  4782   4790     }
  4783   4791     assert( totalSize+2*nCell<=pPage->nFree );
  4784   4792     assert( pPage->nCell==0 );
  4785   4793     assert( sqlite3PagerIswriteable(pPage->pDbPage) );
................................................................................
  4796   4804         put2byte(&data[cellptr], cellbody);
  4797   4805         memcpy(&data[cellbody], apCell[i], aSize[i]);
  4798   4806         cellptr += 2;
  4799   4807         cellbody += aSize[i];
  4800   4808       }
  4801   4809       assert( cellbody==pPage->pBt->usableSize );
  4802   4810     }
  4803         -  pPage->nCell = nCell;
         4811  +  pPage->nCell = (u16)nCell;
  4804   4812   }
  4805   4813   
  4806   4814   /*
  4807   4815   ** The following parameters determine how many adjacent pages get involved
  4808   4816   ** in a balancing operation.  NN is the number of neighbors on either side
  4809   4817   ** of the page that participate in the balancing operation.  NB is the
  4810   4818   ** total number of pages that participate, including the target page and
................................................................................
  5169   5177       int limit = pOld->nCell+pOld->nOverflow;
  5170   5178       for(j=0; j<limit; j++){
  5171   5179         assert( nCell<nMaxCells );
  5172   5180         apCell[nCell] = findOverflowCell(pOld, j);
  5173   5181         szCell[nCell] = cellSizePtr(pOld, apCell[nCell]);
  5174   5182         if( ISAUTOVACUUM ){
  5175   5183           int a;
  5176         -        aFrom[nCell] = i;
         5184  +        aFrom[nCell] = (u8)i;   assert( i>=0 && i<6 );
  5177   5185           for(a=0; a<pOld->nOverflow; a++){
  5178   5186             if( pOld->aOvfl[a].pCell==apCell[nCell] ){
  5179   5187               aFrom[nCell] = 0xFF;
  5180   5188               break;
  5181   5189             }
  5182   5190           }
  5183   5191         }
................................................................................
  5202   5210           assert( iSpace1<=pBt->pageSize );
  5203   5211           memcpy(pTemp, apDiv[i], sz);
  5204   5212           apCell[nCell] = pTemp+leafCorrection;
  5205   5213           if( ISAUTOVACUUM ){
  5206   5214             aFrom[nCell] = 0xFF;
  5207   5215           }
  5208   5216           dropCell(pParent, nxDiv, sz);
  5209         -        szCell[nCell] -= leafCorrection;
         5217  +        assert( leafCorrection==0 || leafCorrection==4 );
         5218  +        szCell[nCell] -= (u16)leafCorrection;
  5210   5219           assert( get4byte(pTemp)==pgnoOld[i] );
  5211   5220           if( !pOld->leaf ){
  5212   5221             assert( leafCorrection==0 );
  5213   5222             /* The right pointer of the child page pOld becomes the left
  5214   5223             ** pointer of the divider cell */
  5215   5224             memcpy(apCell[nCell], &pOld->aData[pOld->hdrOffset+8], 4);
  5216   5225           }else{
................................................................................
  6594   6603       rc = sqlite3PagerWrite(pBt->pPage1->pDbPage);
  6595   6604       if( rc==SQLITE_OK ){
  6596   6605         put4byte(&pP1[36 + idx*4], iMeta);
  6597   6606   #ifndef SQLITE_OMIT_AUTOVACUUM
  6598   6607         if( idx==7 ){
  6599   6608           assert( pBt->autoVacuum || iMeta==0 );
  6600   6609           assert( iMeta==0 || iMeta==1 );
  6601         -        pBt->incrVacuum = iMeta;
         6610  +        pBt->incrVacuum = (u8)iMeta;
  6602   6611         }
  6603   6612   #endif
  6604   6613       }
  6605   6614     }
  6606   6615     sqlite3BtreeLeave(p);
  6607   6616     return rc;
  6608   6617   }
................................................................................
  6853   6862       /* Check payload overflow pages
  6854   6863       */
  6855   6864       sqlite3_snprintf(sizeof(zContext), zContext,
  6856   6865                "On tree page %d cell %d: ", iPage, i);
  6857   6866       pCell = findCell(pPage,i);
  6858   6867       sqlite3BtreeParseCellPtr(pPage, pCell, &info);
  6859   6868       sz = info.nData;
  6860         -    if( !pPage->intKey ) sz += info.nKey;
         6869  +    if( !pPage->intKey ) sz += (int)info.nKey;
  6861   6870       assert( sz==info.nPayload );
  6862   6871       if( sz>info.nLocal ){
  6863   6872         int nPage = (sz - info.nLocal + usableSize - 5)/(usableSize - 4);
  6864   6873         Pgno pgnoOvfl = get4byte(&pCell[info.iOverflow]);
  6865   6874   #ifndef SQLITE_OMIT_AUTOVACUUM
  6866   6875         if( pBt->autoVacuum ){
  6867   6876           checkPtrmap(pCheck, pgnoOvfl, PTRMAP_OVERFLOW1, iPage, zContext);
................................................................................
  7169   7178     nToPage = pagerPagecount(pBtTo);
  7170   7179     nFromPage = pagerPagecount(pBtFrom);
  7171   7180     iSkip = PENDING_BYTE_PAGE(pBtTo);
  7172   7181   
  7173   7182     /* Variable nNewPage is the number of pages required to store the
  7174   7183     ** contents of pFrom using the current page-size of pTo.
  7175   7184     */
  7176         -  nNewPage = ((i64)nFromPage * (i64)nFromPageSize + (i64)nToPageSize - 1) / 
  7177         -      (i64)nToPageSize;
         7185  +  nNewPage = (Pgno)
         7186  +     (((i64)nFromPage*(i64)nFromPageSize+(i64)nToPageSize-1)/(i64)nToPageSize);
  7178   7187   
  7179   7188     for(i=1; rc==SQLITE_OK && (i<=nToPage || i<=nNewPage); i++){
  7180   7189   
  7181   7190       /* Journal the original page.
  7182   7191       **
  7183   7192       ** iSkip is the page number of the locking page (PENDING_BYTE_PAGE)
  7184   7193       ** in database *pTo (before the copy). This page is never written 
................................................................................
  7219   7228   
  7220   7229         for(
  7221   7230           iOff=(i-1)*nToPageSize; 
  7222   7231           rc==SQLITE_OK && iOff<i*nToPageSize; 
  7223   7232           iOff += nFromPageSize
  7224   7233         ){
  7225   7234           DbPage *pFromPage = 0;
  7226         -        Pgno iFrom = (iOff/nFromPageSize)+1;
         7235  +        Pgno iFrom = (Pgno)(iOff/nFromPageSize)+1;
  7227   7236   
  7228   7237           if( iFrom==PENDING_BYTE_PAGE(pBtFrom) ){
  7229   7238             continue;
  7230   7239           }
  7231   7240   
  7232   7241           rc = sqlite3PagerGet(pBtFrom->pPager, iFrom, &pFromPage);
  7233   7242           if( rc==SQLITE_OK ){
................................................................................
  7300   7309           i64 iOff;
  7301   7310           for(
  7302   7311             iOff=iPending; 
  7303   7312             rc==SQLITE_OK && iOff<(iPending+nToPageSize); 
  7304   7313             iOff += nFromPageSize
  7305   7314           ){
  7306   7315             DbPage *pFromPage = 0;
  7307         -          Pgno iFrom = (iOff/nFromPageSize)+1;
         7316  +          Pgno iFrom = (Pgno)(iOff/nFromPageSize)+1;
  7308   7317     
  7309   7318             if( iFrom==PENDING_BYTE_PAGE(pBtFrom) || iFrom>nFromPage ){
  7310   7319               continue;
  7311   7320             }
  7312   7321     
  7313   7322             rc = sqlite3PagerGet(pBtFrom->pPager, iFrom, &pFromPage);
  7314   7323             if( rc==SQLITE_OK ){

Changes to src/btreeInt.h.

     5      5   ** a legal notice, here is a blessing:
     6      6   **
     7      7   **    May you do good and not evil.
     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12         -** $Id: btreeInt.h,v 1.36 2008/11/19 10:22:33 danielk1977 Exp $
           12  +** $Id: btreeInt.h,v 1.37 2008/12/10 16:45:51 drh Exp $
    13     13   **
    14     14   ** This file implements a external (disk-based) database using BTrees.
    15     15   ** For a detailed discussion of BTrees, refer to
    16     16   **
    17     17   **     Donald E. Knuth, THE ART OF COMPUTER PROGRAMMING, Volume 3:
    18     18   **     "Sorting And Searching", pages 473-480. Addison-Wesley
    19     19   **     Publishing Company, Reading, Massachusetts.
................................................................................
   371    371   #ifndef SQLITE_OMIT_AUTOVACUUM
   372    372     u8 autoVacuum;        /* True if auto-vacuum is enabled */
   373    373     u8 incrVacuum;        /* True if incr-vacuum is enabled */
   374    374     Pgno nTrunc;          /* Non-zero if the db will be truncated (incr vacuum) */
   375    375   #endif
   376    376     u16 pageSize;         /* Total number of bytes on a page */
   377    377     u16 usableSize;       /* Number of usable bytes on each page */
   378         -  int maxLocal;         /* Maximum local payload in non-LEAFDATA tables */
   379         -  int minLocal;         /* Minimum local payload in non-LEAFDATA tables */
   380         -  int maxLeaf;          /* Maximum local payload in a LEAFDATA table */
   381         -  int minLeaf;          /* Minimum local payload in a LEAFDATA table */
          378  +  u16 maxLocal;         /* Maximum local payload in non-LEAFDATA tables */
          379  +  u16 minLocal;         /* Minimum local payload in non-LEAFDATA tables */
          380  +  u16 maxLeaf;          /* Maximum local payload in a LEAFDATA table */
          381  +  u16 minLeaf;          /* Minimum local payload in a LEAFDATA table */
   382    382     u8 inTransaction;     /* Transaction state */
   383    383     int nTransaction;     /* Number of open transactions (read + write) */
   384    384     void *pSchema;        /* Pointer to space allocated by sqlite3BtreeSchema() */
   385    385     void (*xFreeSchema)(void*);  /* Destructor for BtShared.pSchema */
   386    386     sqlite3_mutex *mutex; /* Non-recursive mutex required to access this struct */
   387    387   #ifndef SQLITE_OMIT_SHARED_CACHE
   388    388     int nRef;             /* Number of references to this structure */
................................................................................
   616    616     StrAccum errMsg;  /* Accumulate the error message text here */
   617    617   };
   618    618   
   619    619   /*
   620    620   ** Read or write a two- and four-byte big-endian integer values.
   621    621   */
   622    622   #define get2byte(x)   ((x)[0]<<8 | (x)[1])
   623         -#define put2byte(p,v) ((p)[0] = (v)>>8, (p)[1] = (v))
          623  +#define put2byte(p,v) ((p)[0] = (u8)((v)>>8), (p)[1] = (u8)(v))
   624    624   #define get4byte sqlite3Get4byte
   625    625   #define put4byte sqlite3Put4byte
   626    626   
   627    627   /*
   628    628   ** Internal routines that should be accessed by the btree layer only.
   629    629   */
   630    630   int sqlite3BtreeGetPage(BtShared*, Pgno, MemPage**, int);

Changes to src/main.c.

    10     10   **
    11     11   *************************************************************************
    12     12   ** Main file for the SQLite library.  The routines in this file
    13     13   ** implement the programmer interface to the library.  Routines in
    14     14   ** other files are for internal use by SQLite and should not be
    15     15   ** accessed by users of the library.
    16     16   **
    17         -** $Id: main.c,v 1.516 2008/12/09 14:46:10 drh Exp $
           17  +** $Id: main.c,v 1.517 2008/12/10 16:45:51 drh Exp $
    18     18   */
    19     19   #include "sqliteInt.h"
    20     20   #include <ctype.h>
    21     21   
    22     22   #ifdef SQLITE_ENABLE_FTS3
    23     23   # include "fts3.h"
    24     24   #endif
................................................................................
  1197   1197   
  1198   1198   /*
  1199   1199   ** Return UTF-8 encoded English language explanation of the most recent
  1200   1200   ** error.
  1201   1201   */
  1202   1202   const char *sqlite3_errmsg(sqlite3 *db){
  1203   1203     const char *z;
  1204         -  if( !db || db->mallocFailed ){
         1204  +  if( !db ){
  1205   1205       return sqlite3ErrStr(SQLITE_NOMEM);
  1206   1206     }
  1207   1207     if( !sqlite3SafetyCheckSickOrOk(db) ){
  1208   1208       return sqlite3ErrStr(SQLITE_MISUSE);
  1209   1209     }
         1210  +  if( db->mallocFailed ){
         1211  +    return sqlite3ErrStr(SQLITE_NOMEM);
         1212  +  }
  1210   1213     sqlite3_mutex_enter(db->mutex);
  1211   1214     assert( !db->mallocFailed );
  1212   1215     z = (char*)sqlite3_value_text(db->pErr);
  1213   1216     assert( !db->mallocFailed );
  1214   1217     if( z==0 ){
  1215   1218       z = sqlite3ErrStr(db->errCode);
  1216   1219     }

Changes to src/pager.c.

    14     14   ** The pager is used to access a database disk file.  It implements
    15     15   ** atomic commit and rollback through the use of a journal file that
    16     16   ** is separate from the database file.  The pager also implements file
    17     17   ** locking to prevent two processes from writing the same database
    18     18   ** file simultaneously, or one process from reading the database while
    19     19   ** another is writing.
    20     20   **
    21         -** @(#) $Id: pager.c,v 1.510 2008/11/29 22:49:23 drh Exp $
           21  +** @(#) $Id: pager.c,v 1.511 2008/12/10 16:45:51 drh Exp $
    22     22   */
    23     23   #ifndef SQLITE_OMIT_DISKIO
    24     24   #include "sqliteInt.h"
    25     25   
    26     26   /*
    27     27   ** Macros for troubleshooting.  Normally turned off
    28     28   */
................................................................................
  3821   3821     return rc;
  3822   3822   }
  3823   3823   
  3824   3824   /*
  3825   3825   ** Return TRUE if the database file is opened read-only.  Return FALSE
  3826   3826   ** if the database is (in theory) writable.
  3827   3827   */
  3828         -int sqlite3PagerIsreadonly(Pager *pPager){
         3828  +u8 sqlite3PagerIsreadonly(Pager *pPager){
  3829   3829     return pPager->readOnly;
  3830   3830   }
  3831   3831   
  3832   3832   /*
  3833   3833   ** Return the number of references to the pager.
  3834   3834   */
  3835   3835   int sqlite3PagerRefcount(Pager *pPager){

Changes to src/pager.h.

     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This header file defines the interface that the sqlite page cache
    13     13   ** subsystem.  The page cache subsystem reads and writes a file a page
    14     14   ** at a time and provides a journal for rollback.
    15     15   **
    16         -** @(#) $Id: pager.h,v 1.87 2008/11/19 10:22:33 danielk1977 Exp $
           16  +** @(#) $Id: pager.h,v 1.88 2008/12/10 16:45:51 drh Exp $
    17     17   */
    18     18   
    19     19   #ifndef _PAGER_H_
    20     20   #define _PAGER_H_
    21     21   
    22     22   /*
    23     23   ** If defined as non-zero, auto-vacuum is enabled by default. Otherwise
................................................................................
    89     89   int sqlite3PagerWrite(DbPage*);
    90     90   int sqlite3PagerPagecount(Pager*, int*);
    91     91   int sqlite3PagerTruncate(Pager*,Pgno);
    92     92   int sqlite3PagerBegin(DbPage*, int exFlag);
    93     93   int sqlite3PagerCommitPhaseOne(Pager*,const char *zMaster, Pgno, int);
    94     94   int sqlite3PagerCommitPhaseTwo(Pager*);
    95     95   int sqlite3PagerRollback(Pager*);
    96         -int sqlite3PagerIsreadonly(Pager*);
           96  +u8 sqlite3PagerIsreadonly(Pager*);
    97     97   int sqlite3PagerStmtBegin(Pager*);
    98     98   int sqlite3PagerStmtCommit(Pager*);
    99     99   int sqlite3PagerStmtRollback(Pager*);
   100    100   void sqlite3PagerDontRollback(DbPage*);
   101    101   int sqlite3PagerDontWrite(DbPage*);
   102    102   int sqlite3PagerRefcount(Pager*);
   103    103   void sqlite3PagerSetSafetyLevel(Pager*,int,int);