/ Check-in [65fe7b62]
Login

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

Overview
Comment:Continuing work on the new memory allocation subsystem. Added routines for temporary memory allocation. Right the btree balance mechanism to only do one temporary allocation at a time. (CVS 5220)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 65fe7b62cfe7d11cd667681a64c96fe7b2fe5685
User & Date: drh 2008-06-15 02:51:47
Context
2008-06-16
06:31
Add a test to verify that IN(...) WHERE clause terms are not handled by virtual table implemetations. (CVS 5221) check-in: 85483c8f user: danielk1977 tags: trunk
2008-06-15
02:51
Continuing work on the new memory allocation subsystem. Added routines for temporary memory allocation. Right the btree balance mechanism to only do one temporary allocation at a time. (CVS 5220) check-in: 65fe7b62 user: drh tags: trunk
2008-06-14
16:56
Continuing progress on the new memory allocation subsystem. Added the sqlite3_mem_methods structure for defining new memory allocators at run-time. (CVS 5219) check-in: f00305f4 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

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.75 2008/04/17 17:02:01 drh Exp $
           14  +** $Id: attach.c,v 1.76 2008/06/15 02:51:47 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
................................................................................
   108    108       }
   109    109     }
   110    110   
   111    111     /* Allocate the new entry in the db->aDb[] array and initialise the schema
   112    112     ** hash tables.
   113    113     */
   114    114     if( db->aDb==db->aDbStatic ){
   115         -    aNew = sqlite3_malloc( sizeof(db->aDb[0])*3 );
   116         -    if( aNew==0 ){
   117         -      db->mallocFailed = 1;
   118         -      return;
   119         -    }
          115  +    aNew = sqlite3DbMallocRaw(db, sizeof(db->aDb[0])*3 );
          116  +    if( aNew==0 ) return;
   120    117       memcpy(aNew, db->aDb, sizeof(db->aDb[0])*2);
   121    118     }else{
   122         -    aNew = sqlite3_realloc(db->aDb, sizeof(db->aDb[0])*(db->nDb+1) );
   123         -    if( aNew==0 ){
   124         -      db->mallocFailed = 1;
   125         -      return;
   126         -    } 
          119  +    aNew = sqlite3DbRealloc(db, db->aDb, sizeof(db->aDb[0])*(db->nDb+1) );
          120  +    if( aNew==0 ) return;
   127    121     }
   128    122     db->aDb = aNew;
   129    123     aNew = &db->aDb[db->nDb++];
   130    124     memset(aNew, 0, sizeof(*aNew));
   131    125   
   132    126     /* Open the database file. If the btree is successfully opened, use
   133    127     ** it to obtain the database schema. At this point the schema may

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.463 2008/06/11 18:27:55 danielk1977 Exp $
           12  +** $Id: btree.c,v 1.464 2008/06/15 02:51:47 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   
................................................................................
   296    296     /* If this is an intKey table, then the above call to BtreeKeySize()
   297    297     ** stores the integer key in pCur->nKey. In this case this value is
   298    298     ** all that is required. Otherwise, if pCur is not open on an intKey
   299    299     ** table, then malloc space for and store the pCur->nKey bytes of key 
   300    300     ** data.
   301    301     */
   302    302     if( rc==SQLITE_OK && 0==pCur->pPage->intKey){
   303         -    void *pKey = sqlite3_malloc(pCur->nKey);
          303  +    void *pKey = sqlite3Malloc(pCur->nKey);
   304    304       if( pKey ){
   305    305         rc = sqlite3BtreeKey(pCur, 0, pCur->nKey, pKey);
   306    306         if( rc==SQLITE_OK ){
   307    307           pCur->pKey = pKey;
   308    308         }else{
   309    309           sqlite3_free(pKey);
   310    310         }
................................................................................
  1186   1186     if( (flags & BTREE_PRIVATE)==0
  1187   1187      && isMemdb==0
  1188   1188      && (db->flags & SQLITE_Vtab)==0
  1189   1189      && zFilename && zFilename[0]
  1190   1190     ){
  1191   1191       if( sqlite3SharedCacheEnabled ){
  1192   1192         int nFullPathname = pVfs->mxPathname+1;
  1193         -      char *zFullPathname = (char *)sqlite3_malloc(nFullPathname);
         1193  +      char *zFullPathname = sqlite3Malloc(nFullPathname);
  1194   1194         sqlite3_mutex *mutexShared;
  1195   1195         p->sharable = 1;
  1196   1196         if( db ){
  1197   1197           db->flags |= SQLITE_SharedCache;
  1198   1198         }
  1199   1199         if( !zFullPathname ){
  1200   1200           sqlite3_free(p);
................................................................................
  1263   1263       pBt->pPage1 = 0;
  1264   1264       pBt->readOnly = sqlite3PagerIsreadonly(pBt->pPager);
  1265   1265       pBt->pageSize = get2byte(&zDbHeader[16]);
  1266   1266       if( pBt->pageSize<512 || pBt->pageSize>SQLITE_MAX_PAGE_SIZE
  1267   1267            || ((pBt->pageSize-1)&pBt->pageSize)!=0 ){
  1268   1268         pBt->pageSize = 0;
  1269   1269         sqlite3PagerSetPagesize(pBt->pPager, &pBt->pageSize);
  1270         -      pBt->maxEmbedFrac = 64;   /* 25% */
  1271         -      pBt->minEmbedFrac = 32;   /* 12.5% */
  1272         -      pBt->minLeafFrac = 32;    /* 12.5% */
  1273   1270   #ifndef SQLITE_OMIT_AUTOVACUUM
  1274   1271         /* If the magic name ":memory:" will create an in-memory database, then
  1275   1272         ** leave the autoVacuum mode at 0 (do not auto-vacuum), even if
  1276   1273         ** SQLITE_DEFAULT_AUTOVACUUM is true. On the other hand, if
  1277   1274         ** SQLITE_OMIT_MEMORYDB has been defined, then ":memory:" is just a
  1278   1275         ** regular file-name. In this case the auto-vacuum applies as per normal.
  1279   1276         */
................................................................................
  1281   1278           pBt->autoVacuum = (SQLITE_DEFAULT_AUTOVACUUM ? 1 : 0);
  1282   1279           pBt->incrVacuum = (SQLITE_DEFAULT_AUTOVACUUM==2 ? 1 : 0);
  1283   1280         }
  1284   1281   #endif
  1285   1282         nReserve = 0;
  1286   1283       }else{
  1287   1284         nReserve = zDbHeader[20];
  1288         -      pBt->maxEmbedFrac = zDbHeader[21];
  1289         -      pBt->minEmbedFrac = zDbHeader[22];
  1290         -      pBt->minLeafFrac = zDbHeader[23];
  1291   1285         pBt->pageSizeFixed = 1;
  1292   1286   #ifndef SQLITE_OMIT_AUTOVACUUM
  1293   1287         pBt->autoVacuum = (get4byte(&zDbHeader[36 + 4*4])?1:0);
  1294   1288         pBt->incrVacuum = (get4byte(&zDbHeader[36 + 7*4])?1:0);
  1295   1289   #endif
  1296   1290       }
  1297   1291       pBt->usableSize = pBt->pageSize - nReserve;
................................................................................
  1673   1667       }
  1674   1668       if( page1[18]>1 ){
  1675   1669         pBt->readOnly = 1;
  1676   1670       }
  1677   1671       if( page1[19]>1 ){
  1678   1672         goto page1_init_failed;
  1679   1673       }
         1674  +
         1675  +    /* The maximum embedded fraction must be exactly 25%.  And the minimum
         1676  +    ** embedded fraction must be 12.5% for both leaf-data and non-leaf-data.
         1677  +    ** The original design allowed these amounts to vary, but as of
         1678  +    ** version 3.6.0, we require them to be fixed.
         1679  +    */
         1680  +    if( memcmp(&page1[21], "\100\040\040",3)!=0 ){
         1681  +      goto page1_init_failed;
         1682  +    }
  1680   1683       pageSize = get2byte(&page1[16]);
  1681   1684       if( ((pageSize-1)&pageSize)!=0 || pageSize<512 ||
  1682   1685           (SQLITE_MAX_PAGE_SIZE<32768 && pageSize>SQLITE_MAX_PAGE_SIZE)
  1683   1686       ){
  1684   1687         goto page1_init_failed;
  1685   1688       }
  1686   1689       assert( (pageSize & 7)==0 );
................................................................................
  1701   1704         return SQLITE_OK;
  1702   1705       }
  1703   1706       if( usableSize<500 ){
  1704   1707         goto page1_init_failed;
  1705   1708       }
  1706   1709       pBt->pageSize = pageSize;
  1707   1710       pBt->usableSize = usableSize;
  1708         -    pBt->maxEmbedFrac = page1[21];
  1709         -    pBt->minEmbedFrac = page1[22];
  1710         -    pBt->minLeafFrac = page1[23];
  1711   1711   #ifndef SQLITE_OMIT_AUTOVACUUM
  1712   1712       pBt->autoVacuum = (get4byte(&page1[36 + 4*4])?1:0);
  1713   1713       pBt->incrVacuum = (get4byte(&page1[36 + 7*4])?1:0);
  1714   1714   #endif
  1715   1715     }
  1716   1716   
  1717   1717     /* maxLocal is the maximum amount of payload to store locally for
................................................................................
  1723   1723     **     9-byte nKey value
  1724   1724     **     4-byte nData value
  1725   1725     **     4-byte overflow page pointer
  1726   1726     ** So a cell consists of a 2-byte poiner, a header which is as much as
  1727   1727     ** 17 bytes long, 0 to N bytes of payload, and an optional 4 byte overflow
  1728   1728     ** page pointer.
  1729   1729     */
  1730         -  pBt->maxLocal = (pBt->usableSize-12)*pBt->maxEmbedFrac/255 - 23;
  1731         -  pBt->minLocal = (pBt->usableSize-12)*pBt->minEmbedFrac/255 - 23;
         1730  +  pBt->maxLocal = (pBt->usableSize-12)*64/255 - 23;
         1731  +  pBt->minLocal = (pBt->usableSize-12)*32/255 - 23;
  1732   1732     pBt->maxLeaf = pBt->usableSize - 35;
  1733         -  pBt->minLeaf = (pBt->usableSize-12)*pBt->minLeafFrac/255 - 23;
         1733  +  pBt->minLeaf = (pBt->usableSize-12)*32/255 - 23;
  1734   1734     if( pBt->minLocal>pBt->maxLocal || pBt->maxLocal<0 ){
  1735   1735       goto page1_init_failed;
  1736   1736     }
  1737   1737     assert( pBt->maxLeaf + 23 <= MX_CELL_SIZE(pBt) );
  1738   1738     pBt->pPage1 = pPage1;
  1739   1739     return SQLITE_OK;
  1740   1740   
................................................................................
  1819   1819     if( rc ) return rc;
  1820   1820     memcpy(data, zMagicHeader, sizeof(zMagicHeader));
  1821   1821     assert( sizeof(zMagicHeader)==16 );
  1822   1822     put2byte(&data[16], pBt->pageSize);
  1823   1823     data[18] = 1;
  1824   1824     data[19] = 1;
  1825   1825     data[20] = pBt->pageSize - pBt->usableSize;
  1826         -  data[21] = pBt->maxEmbedFrac;
  1827         -  data[22] = pBt->minEmbedFrac;
  1828         -  data[23] = pBt->minLeafFrac;
         1826  +  data[21] = 64;
         1827  +  data[22] = 32;
         1828  +  data[23] = 32;
  1829   1829     memset(&data[24], 0, 100-24);
  1830   1830     zeroPage(pP1, PTF_INTKEY|PTF_LEAF|PTF_LEAFDATA );
  1831   1831     pBt->pageSizeFixed = 1;
  1832   1832   #ifndef SQLITE_OMIT_AUTOVACUUM
  1833   1833     assert( pBt->autoVacuum==1 || pBt->autoVacuum==0 );
  1834   1834     assert( pBt->incrVacuum==1 || pBt->incrVacuum==0 );
  1835   1835     put4byte(&data[36 + 4*4], pBt->autoVacuum);
................................................................................
  3715   3715         }else{
  3716   3716           int available;
  3717   3717           pCellKey = (void *)fetchPayload(pCur, &available, 0);
  3718   3718           nCellKey = pCur->info.nKey;
  3719   3719           if( available>=nCellKey ){
  3720   3720             c = sqlite3VdbeRecordCompare(nCellKey, pCellKey, pUnKey);
  3721   3721           }else{
  3722         -          pCellKey = sqlite3_malloc( nCellKey );
         3722  +          pCellKey = sqlite3TempMalloc( nCellKey );
  3723   3723             if( pCellKey==0 ){
  3724   3724               rc = SQLITE_NOMEM;
  3725   3725               goto moveto_finish;
  3726   3726             }
  3727   3727             rc = sqlite3BtreeKey(pCur, 0, nCellKey, (void *)pCellKey);
  3728   3728             c = sqlite3VdbeRecordCompare(nCellKey, pCellKey, pUnKey);
  3729         -          sqlite3_free(pCellKey);
         3729  +          sqlite3TempFree(pCellKey);
  3730   3730             if( rc ) goto moveto_finish;
  3731   3731           }
  3732   3732         }
  3733   3733         if( c==0 ){
  3734   3734           pCur->info.nKey = nCellKey;
  3735   3735           if( pPage->leafData && !pPage->leaf ){
  3736   3736             lwr = pCur->idx;
................................................................................
  4854   4854     int nxDiv;                   /* Next divider slot in pParent->aCell[] */
  4855   4855     int rc;                      /* The return code */
  4856   4856     int leafCorrection;          /* 4 if pPage is a leaf.  0 if not */
  4857   4857     int leafData;                /* True if pPage is a leaf of a LEAFDATA tree */
  4858   4858     int usableSpace;             /* Bytes in pPage beyond the header */
  4859   4859     int pageFlags;               /* Value of pPage->aData[0] */
  4860   4860     int subtotal;                /* Subtotal of bytes in cells on one page */
  4861         -  int iSpace = 0;              /* First unused byte of aSpace[] */
         4861  +  int iSpace1 = 0;             /* First unused byte of aSpace1[] */
         4862  +  int iSpace2 = 0;             /* First unused byte of aSpace2[] */
  4862   4863     MemPage *apOld[NB];          /* pPage and up to two siblings */
  4863   4864     Pgno pgnoOld[NB];            /* Page numbers for each page in apOld[] */
  4864   4865     MemPage *apCopy[NB];         /* Private copies of apOld[] pages */
  4865   4866     MemPage *apNew[NB+2];        /* pPage and up to NB siblings after balancing */
  4866   4867     Pgno pgnoNew[NB+2];          /* Page numbers for each page in apNew[] */
  4867   4868     u8 *apDiv[NB];               /* Divider cells in pParent */
  4868   4869     int cntNew[NB+2];            /* Index in aCell[] of cell after i-th page */
  4869   4870     int szNew[NB+2];             /* Combined size of cells place on i-th page */
  4870   4871     u8 **apCell = 0;             /* All cells begin balanced */
  4871   4872     u16 *szCell;                 /* Local size of all cells in apCell[] */
  4872         -  u8 *aCopy[NB];               /* Space for holding data of apCopy[] */
  4873         -  u8 *aSpace;                  /* Space to hold copies of dividers cells */
         4873  +  u8 *aCopy[NB];         /* Space for holding data of apCopy[] */
         4874  +  u8 *aSpace1;           /* Space for copies of dividers cells before balance */
         4875  +  u8 *aSpace2 = 0;       /* Space for overflow dividers cells after balance */
  4874   4876   #ifndef SQLITE_OMIT_AUTOVACUUM
  4875   4877     u8 *aFrom = 0;
  4876   4878   #endif
  4877   4879   
  4878   4880     assert( sqlite3_mutex_held(pPage->pBt->mutex) );
  4879   4881   
  4880   4882     /* 
................................................................................
  4984   4986     /* Make nMaxCells a multiple of 4 in order to preserve 8-byte
  4985   4987     ** alignment */
  4986   4988     nMaxCells = (nMaxCells + 3)&~3;
  4987   4989   
  4988   4990     /*
  4989   4991     ** Allocate space for memory structures
  4990   4992     */
  4991         -  apCell = sqlite3_malloc( 
         4993  +  apCell = sqlite3TempMalloc( 
  4992   4994          nMaxCells*sizeof(u8*)                       /* apCell */
  4993   4995        + nMaxCells*sizeof(u16)                       /* szCell */
  4994   4996        + (ROUND8(sizeof(MemPage))+pBt->pageSize)*NB  /* aCopy */
  4995         -     + pBt->pageSize*5                             /* aSpace */
         4997  +     + pBt->pageSize                               /* aSpace1 */
  4996   4998        + (ISAUTOVACUUM ? nMaxCells : 0)              /* aFrom */
  4997   4999     );
  4998   5000     if( apCell==0 ){
  4999   5001       rc = SQLITE_NOMEM;
  5000   5002       goto balance_cleanup;
  5001   5003     }
  5002   5004     szCell = (u16*)&apCell[nMaxCells];
  5003   5005     aCopy[0] = (u8*)&szCell[nMaxCells];
  5004   5006     assert( ((aCopy[0] - (u8*)apCell) & 7)==0 ); /* 8-byte alignment required */
  5005   5007     for(i=1; i<NB; i++){
  5006   5008       aCopy[i] = &aCopy[i-1][pBt->pageSize+ROUND8(sizeof(MemPage))];
  5007   5009       assert( ((aCopy[i] - (u8*)apCell) & 7)==0 ); /* 8-byte alignment required */
  5008   5010     }
  5009         -  aSpace = &aCopy[NB-1][pBt->pageSize+ROUND8(sizeof(MemPage))];
  5010         -  assert( ((aSpace - (u8*)apCell) & 7)==0 ); /* 8-byte alignment required */
         5011  +  aSpace1 = &aCopy[NB-1][pBt->pageSize+ROUND8(sizeof(MemPage))];
         5012  +  assert( ((aSpace1 - (u8*)apCell) & 7)==0 ); /* 8-byte alignment required */
  5011   5013   #ifndef SQLITE_OMIT_AUTOVACUUM
  5012   5014     if( pBt->autoVacuum ){
  5013         -    aFrom = &aSpace[5*pBt->pageSize];
         5015  +    aFrom = &aSpace1[pBt->pageSize];
  5014   5016     }
  5015   5017   #endif
         5018  +  aSpace2 = sqlite3Malloc(pBt->pageSize);
         5019  +  if( aSpace2==0 ){
         5020  +    rc = SQLITE_NOMEM;
         5021  +    goto balance_cleanup;
         5022  +  }
  5016   5023     
  5017   5024     /*
  5018   5025     ** Make copies of the content of pPage and its siblings into aOld[].
  5019   5026     ** The rest of this function will use data from the copies rather
  5020   5027     ** that the original pages since the original pages will be in the
  5021   5028     ** process of being overwritten.
  5022   5029     */
................................................................................
  5026   5033       p->aData = (void*)&p[1];
  5027   5034       memcpy(p->aData, apOld[i]->aData, pBt->pageSize);
  5028   5035     }
  5029   5036   
  5030   5037     /*
  5031   5038     ** Load pointers to all cells on sibling pages and the divider cells
  5032   5039     ** into the local apCell[] array.  Make copies of the divider cells
  5033         -  ** into space obtained form aSpace[] and remove the the divider Cells
         5040  +  ** into space obtained form aSpace1[] and remove the the divider Cells
  5034   5041     ** from pParent.
  5035   5042     **
  5036   5043     ** If the siblings are on leaf pages, then the child pointers of the
  5037   5044     ** divider cells are stripped from the cells before they are copied
  5038         -  ** into aSpace[].  In this way, all cells in apCell[] are without
         5045  +  ** into aSpace1[].  In this way, all cells in apCell[] are without
  5039   5046     ** child pointers.  If siblings are not leaves, then all cell in
  5040   5047     ** apCell[] include child pointers.  Either way, all cells in apCell[]
  5041   5048     ** are alike.
  5042   5049     **
  5043   5050     ** leafCorrection:  4 if pPage is a leaf.  0 if pPage is not a leaf.
  5044   5051     **       leafData:  1 if pPage holds key+data and pParent holds only keys.
  5045   5052     */
................................................................................
  5076   5083           ** added to apCell[] because they are duplicates of child cells.
  5077   5084           */
  5078   5085           dropCell(pParent, nxDiv, sz);
  5079   5086         }else{
  5080   5087           u8 *pTemp;
  5081   5088           assert( nCell<nMaxCells );
  5082   5089           szCell[nCell] = sz;
  5083         -        pTemp = &aSpace[iSpace];
  5084         -        iSpace += sz;
  5085         -        assert( iSpace<=pBt->pageSize*5 );
         5090  +        pTemp = &aSpace1[iSpace1];
         5091  +        iSpace1 += sz;
         5092  +        assert( sz<=pBt->pageSize/4 );
         5093  +        assert( iSpace1<=pBt->pageSize );
  5086   5094           memcpy(pTemp, apDiv[i], sz);
  5087   5095           apCell[nCell] = pTemp+leafCorrection;
  5088   5096   #ifndef SQLITE_OMIT_AUTOVACUUM
  5089   5097           if( pBt->autoVacuum ){
  5090   5098             aFrom[nCell] = 0xFF;
  5091   5099           }
  5092   5100   #endif
................................................................................
  5299   5307         u8 *pCell;
  5300   5308         u8 *pTemp;
  5301   5309         int sz;
  5302   5310   
  5303   5311         assert( j<nMaxCells );
  5304   5312         pCell = apCell[j];
  5305   5313         sz = szCell[j] + leafCorrection;
         5314  +      pTemp = &aSpace2[iSpace2];
  5306   5315         if( !pNew->leaf ){
  5307   5316           memcpy(&pNew->aData[8], pCell, 4);
  5308         -        pTemp = 0;
  5309   5317         }else if( leafData ){
  5310   5318           /* If the tree is a leaf-data tree, and the siblings are leaves, 
  5311   5319           ** then there is no divider cell in apCell[]. Instead, the divider 
  5312   5320           ** cell consists of the integer key for the right-most cell of 
  5313   5321           ** the sibling-page assembled above only.
  5314   5322           */
  5315   5323           CellInfo info;
  5316   5324           j--;
  5317   5325           sqlite3BtreeParseCellPtr(pNew, apCell[j], &info);
  5318         -        pCell = &aSpace[iSpace];
         5326  +        pCell = pTemp;
  5319   5327           fillInCell(pParent, pCell, 0, info.nKey, 0, 0, 0, &sz);
  5320         -        iSpace += sz;
  5321         -        assert( iSpace<=pBt->pageSize*5 );
  5322   5328           pTemp = 0;
  5323   5329         }else{
  5324   5330           pCell -= 4;
  5325         -        pTemp = &aSpace[iSpace];
  5326         -        iSpace += sz;
  5327         -        assert( iSpace<=pBt->pageSize*5 );
  5328   5331           /* Obscure case for non-leaf-data trees: If the cell at pCell was
  5329   5332           ** previously stored on a leaf node, and its reported size was 4
  5330   5333           ** bytes, then it may actually be smaller than this 
  5331   5334           ** (see sqlite3BtreeParseCellPtr(), 4 bytes is the minimum size of
  5332   5335           ** any cell). But it is important to pass the correct size to 
  5333   5336           ** insertCell(), so reparse the cell now.
  5334   5337           **
................................................................................
  5337   5340           ** to evaluate "IN (SELECT ...)" and similar clauses.
  5338   5341           */
  5339   5342           if( szCell[j]==4 ){
  5340   5343             assert(leafCorrection==4);
  5341   5344             sz = cellSizePtr(pParent, pCell);
  5342   5345           }
  5343   5346         }
         5347  +      iSpace2 += sz;
         5348  +      assert( sz<=pBt->pageSize/4 );
         5349  +      assert( iSpace2<=pBt->pageSize );
  5344   5350         rc = insertCell(pParent, nxDiv, pCell, sz, pTemp, 4);
  5345   5351         if( rc!=SQLITE_OK ) goto balance_cleanup;
  5346   5352         put4byte(findOverflowCell(pParent,nxDiv), pNew->pgno);
  5347   5353   #ifndef SQLITE_OMIT_AUTOVACUUM
  5348   5354         /* If this is an auto-vacuum database, and not a leaf-data tree,
  5349   5355         ** then update the pointer map with an entry for the overflow page
  5350   5356         ** that the cell just inserted points to (if any).
................................................................................
  5387   5393   
  5388   5394     /*
  5389   5395     ** Balance the parent page.  Note that the current page (pPage) might
  5390   5396     ** have been added to the freelist so it might no longer be initialized.
  5391   5397     ** But the parent page will always be initialized.
  5392   5398     */
  5393   5399     assert( pParent->isInit );
         5400  +  sqlite3TempFree(apCell);
         5401  +  apCell = 0;
  5394   5402     rc = balance(pParent, 0);
  5395   5403     
  5396   5404     /*
  5397   5405     ** Cleanup before returning.
  5398   5406     */
  5399   5407   balance_cleanup:
  5400         -  sqlite3_free(apCell);
         5408  +  sqlite3_free(aSpace2);
         5409  +  sqlite3TempFree(apCell);
  5401   5410     for(i=0; i<nOld; i++){
  5402   5411       releasePage(apOld[i]);
  5403   5412     }
  5404   5413     for(i=0; i<nNew; i++){
  5405   5414       releasePage(apNew[i]);
  5406   5415     }
  5407   5416     releasePage(pParent);
................................................................................
  5425   5434     u16 *szCell;                 /* Local size of all cells */
  5426   5435   
  5427   5436     assert( pPage->pParent==0 );
  5428   5437     assert( pPage->nCell==0 );
  5429   5438     assert( sqlite3_mutex_held(pPage->pBt->mutex) );
  5430   5439     pBt = pPage->pBt;
  5431   5440     mxCellPerPage = MX_CELL(pBt);
  5432         -  apCell = sqlite3_malloc( mxCellPerPage*(sizeof(u8*)+sizeof(u16)) );
         5441  +  apCell = sqlite3Malloc( mxCellPerPage*(sizeof(u8*)+sizeof(u16)) );
  5433   5442     if( apCell==0 ) return SQLITE_NOMEM;
  5434   5443     szCell = (u16*)&apCell[mxCellPerPage];
  5435   5444     if( pPage->leaf ){
  5436   5445       /* The table is completely empty */
  5437   5446       TRACE(("BALANCE: empty table %d\n", pPage->pgno));
  5438   5447     }else{
  5439   5448       /* The root page is empty but has one child.  Transfer the
................................................................................
  5669   5678   
  5670   5679   /*
  5671   5680   ** Make sure pBt->pTmpSpace points to an allocation of 
  5672   5681   ** MX_CELL_SIZE(pBt) bytes.
  5673   5682   */
  5674   5683   static void allocateTempSpace(BtShared *pBt){
  5675   5684     if( !pBt->pTmpSpace ){
  5676         -    pBt->pTmpSpace = sqlite3_malloc(MX_CELL_SIZE(pBt));
         5685  +    pBt->pTmpSpace = sqlite3Malloc(MX_CELL_SIZE(pBt));
  5677   5686     }
  5678   5687   }
  5679   5688   
  5680   5689   /*
  5681   5690   ** Insert a new record into the BTree.  The key is given by (pKey,nKey)
  5682   5691   ** and the data is given by (pData,nData).  The cursor is used only to
  5683   5692   ** define what table the record should be inserted into.  The cursor
................................................................................
  6725   6734     }
  6726   6735   #endif
  6727   6736     if( sCheck.nPage==0 ){
  6728   6737       unlockBtreeIfUnused(pBt);
  6729   6738       sqlite3BtreeLeave(p);
  6730   6739       return 0;
  6731   6740     }
  6732         -  sCheck.anRef = sqlite3_malloc( (sCheck.nPage+1)*sizeof(sCheck.anRef[0]) );
         6741  +  sCheck.anRef = sqlite3Malloc( (sCheck.nPage+1)*sizeof(sCheck.anRef[0]) );
  6733   6742     if( !sCheck.anRef ){
  6734   6743       unlockBtreeIfUnused(pBt);
  6735   6744       *pnErr = 1;
  6736   6745       sqlite3BtreeLeave(p);
  6737   6746       return sqlite3MPrintf(p->db, "Unable to malloc %d bytes", 
  6738   6747           (sCheck.nPage+1)*sizeof(sCheck.anRef[0]));
  6739   6748     }

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.21 2008/04/24 19:15:10 shane Exp $
           12  +** $Id: btreeInt.h,v 1.22 2008/06/15 02:51:47 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.
................................................................................
   367    367   struct BtShared {
   368    368     Pager *pPager;        /* The page cache */
   369    369     sqlite3 *db;          /* Database connection currently using this Btree */
   370    370     BtCursor *pCursor;    /* A list of all open cursors */
   371    371     MemPage *pPage1;      /* First page of the database */
   372    372     u8 inStmt;            /* True if we are in a statement subtransaction */
   373    373     u8 readOnly;          /* True if the underlying file is readonly */
   374         -  u8 maxEmbedFrac;      /* Maximum payload as % of total page size */
   375         -  u8 minEmbedFrac;      /* Minimum payload as % of total page size */
   376         -  u8 minLeafFrac;       /* Minimum leaf payload as % of total page size */
   377    374     u8 pageSizeFixed;     /* True if the page size can no longer be changed */
   378    375   #ifndef SQLITE_OMIT_AUTOVACUUM
   379    376     u8 autoVacuum;        /* True if auto-vacuum is enabled */
   380    377     u8 incrVacuum;        /* True if incr-vacuum is enabled */
   381    378     Pgno nTrunc;          /* Non-zero if the db will be truncated (incr vacuum) */
   382    379   #endif
   383    380     u16 pageSize;         /* Total number of bytes on a page */

Changes to src/build.c.

    18     18   **     CREATE INDEX
    19     19   **     DROP INDEX
    20     20   **     creating ID lists
    21     21   **     BEGIN TRANSACTION
    22     22   **     COMMIT
    23     23   **     ROLLBACK
    24     24   **
    25         -** $Id: build.c,v 1.484 2008/05/01 17:16:53 drh Exp $
           25  +** $Id: build.c,v 1.485 2008/06/15 02:51:47 drh Exp $
    26     26   */
    27     27   #include "sqliteInt.h"
    28     28   #include <ctype.h>
    29     29   
    30     30   /*
    31     31   ** This routine is called when a new SQL statement is beginning to
    32     32   ** be parsed.  Initialize the pParse structure as needed.
................................................................................
  1363   1363       zEnd = ")";
  1364   1364     }else{
  1365   1365       zSep = "\n  ";
  1366   1366       zSep2 = ",\n  ";
  1367   1367       zEnd = "\n)";
  1368   1368     }
  1369   1369     n += 35 + 6*p->nCol;
  1370         -  zStmt = sqlite3_malloc( n );
         1370  +  zStmt = sqlite3Malloc( n );
  1371   1371     if( zStmt==0 ){
  1372   1372       db->mallocFailed = 1;
  1373   1373       return 0;
  1374   1374     }
  1375   1375     sqlite3_snprintf(n, zStmt,
  1376   1376                     !OMIT_TEMPDB&&isTemp ? "CREATE TEMP TABLE ":"CREATE TABLE ");
  1377   1377     k = strlen(zStmt);

Changes to src/date.c.

    12     12   ** This file contains the C functions that implement date and time
    13     13   ** functions for SQLite.  
    14     14   **
    15     15   ** There is only one exported symbol in this file - the function
    16     16   ** sqlite3RegisterDateTimeFunctions() found at the bottom of the file.
    17     17   ** All other code has file scope.
    18     18   **
    19         -** $Id: date.c,v 1.83 2008/06/12 16:35:38 drh Exp $
           19  +** $Id: date.c,v 1.84 2008/06/15 02:51:47 drh Exp $
    20     20   **
    21     21   ** SQLite processes all times and dates as Julian Day numbers.  The
    22     22   ** dates and times are stored as the number of days since noon
    23     23   ** in Greenwich on November 24, 4714 B.C. according to the Gregorian
    24     24   ** calendar system. 
    25     25   **
    26     26   ** 1970-01-01 00:00:00 is JD 2440587.5
................................................................................
   884    884     }
   885    885     if( n<sizeof(zBuf) ){
   886    886       z = zBuf;
   887    887     }else if( n>sqlite3_context_db_handle(context)->aLimit[SQLITE_LIMIT_LENGTH] ){
   888    888       sqlite3_result_error_toobig(context);
   889    889       return;
   890    890     }else{
   891         -    z = sqlite3_malloc( n );
          891  +    z = sqlite3Malloc( n );
   892    892       if( z==0 ){
   893    893         sqlite3_result_error_nomem(context);
   894    894         return;
   895    895       }
   896    896     }
   897    897     computeJD(&x);
   898    898     computeYMD_HMS(&x);

Changes to src/func.c.

    12     12   ** This file contains the C functions that implement various SQL
    13     13   ** functions of SQLite.  
    14     14   **
    15     15   ** There is only one exported symbol in this file - the function
    16     16   ** sqliteRegisterBuildinFunctions() found at the bottom of the file.
    17     17   ** All other code has file scope.
    18     18   **
    19         -** $Id: func.c,v 1.192 2008/04/27 18:40:12 drh Exp $
           19  +** $Id: func.c,v 1.193 2008/06/15 02:51:47 drh Exp $
    20     20   */
    21     21   #include "sqliteInt.h"
    22     22   #include <ctype.h>
    23     23   #include <stdlib.h>
    24     24   #include <assert.h>
    25     25   #include "vdbeInt.h"
    26     26   
................................................................................
   245    245   */
   246    246   static void *contextMalloc(sqlite3_context *context, i64 nByte){
   247    247     char *z;
   248    248     if( nByte>sqlite3_context_db_handle(context)->aLimit[SQLITE_LIMIT_LENGTH] ){
   249    249       sqlite3_result_error_toobig(context);
   250    250       z = 0;
   251    251     }else{
   252         -    z = sqlite3_malloc(nByte);
          252  +    z = sqlite3Malloc(nByte);
   253    253       if( !z && nByte>0 ){
   254    254         sqlite3_result_error_nomem(context);
   255    255       }
   256    256     }
   257    257     return z;
   258    258   }
   259    259   

Changes to src/hash.c.

     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 is the implementation of generic hash-tables
    13     13   ** used in SQLite.
    14     14   **
    15         -** $Id: hash.c,v 1.28 2008/05/13 13:27:34 drh Exp $
           15  +** $Id: hash.c,v 1.29 2008/06/15 02:51:47 drh Exp $
    16     16   */
    17     17   #include "sqliteInt.h"
    18     18   #include <assert.h>
    19     19   
    20     20   /* Turn bulk memory into a hash table object by initializing the
    21     21   ** fields of the Hash structure.
    22     22   **
................................................................................
   383    383           }
   384    384           assert(nKey==elem->nKey);
   385    385         }
   386    386         return old_data;
   387    387       }
   388    388     }
   389    389     if( data==0 ) return 0;
   390         -  new_elem = (HashElem*)sqlite3_malloc( sizeof(HashElem) );
          390  +  new_elem = (HashElem*)sqlite3Malloc( sizeof(HashElem) );
   391    391     if( new_elem==0 ) return data;
   392    392     if( pH->copyKey && pKey!=0 ){
   393         -    new_elem->pKey = sqlite3_malloc( nKey );
          393  +    new_elem->pKey = sqlite3Malloc( nKey );
   394    394       if( new_elem->pKey==0 ){
   395    395         sqlite3_free(new_elem);
   396    396         return data;
   397    397       }
   398    398       memcpy((void*)new_elem->pKey, pKey, nKey);
   399    399     }else{
   400    400       new_elem->pKey = (void*)pKey;

Changes to src/legacy.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: legacy.c,v 1.26 2008/05/20 15:44:31 drh Exp $
           17  +** $Id: legacy.c,v 1.27 2008/06/15 02:51:47 drh Exp $
    18     18   */
    19     19   
    20     20   #include "sqliteInt.h"
    21     21   #include <ctype.h>
    22     22   
    23     23   /*
    24     24   ** Execute SQL code.  Return one of the SQLITE_ success/failure
................................................................................
   129    129   exec_out:
   130    130     if( pStmt ) sqlite3_finalize(pStmt);
   131    131     if( azCols ) sqlite3_free(azCols);
   132    132   
   133    133     rc = sqlite3ApiExit(db, rc);
   134    134     if( rc!=SQLITE_OK && rc==sqlite3_errcode(db) && pzErrMsg ){
   135    135       int nErrMsg = 1 + strlen(sqlite3_errmsg(db));
   136         -    *pzErrMsg = sqlite3_malloc(nErrMsg);
          136  +    *pzErrMsg = sqlite3Malloc(nErrMsg);
   137    137       if( *pzErrMsg ){
   138    138         memcpy(*pzErrMsg, sqlite3_errmsg(db), nErrMsg);
   139    139       }
   140    140     }else if( pzErrMsg ){
   141    141       *pzErrMsg = 0;
   142    142     }
   143    143   
   144    144     assert( (rc&db->errMask)==rc );
   145    145     sqlite3_mutex_leave(db->mutex);
   146    146     return rc;
   147    147   }

Changes to src/malloc.c.

     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   **
    13     13   ** Memory allocation functions used throughout sqlite.
    14     14   **
    15         -** $Id: malloc.c,v 1.16 2008/06/14 16:56:22 drh Exp $
           15  +** $Id: malloc.c,v 1.17 2008/06/15 02:51:48 drh Exp $
    16     16   */
    17     17   #include "sqliteInt.h"
    18     18   #include <stdarg.h>
    19     19   #include <ctype.h>
    20     20   
    21     21   /*
    22     22   ** This routine runs when the memory allocator sees that the
................................................................................
    86     86     int alarmBusy;
    87     87   
    88     88     /*
    89     89     ** Performance statistics
    90     90     */
    91     91     sqlite3_int64 nowUsed;  /* Main memory currently in use */
    92     92     sqlite3_int64 mxUsed;   /* Highwater mark for nowUsed */
    93         -  int mxReq;              /* maximum request size for main or page-cache mem */
           93  +  int mxReq;              /* Max request size for ordinary mallocs */
           94  +  int mxTempReq;          /* Max request size for xTemp mallocs */
    94     95   } mem0;
    95     96   
    96     97   /*
    97     98   ** Initialize the memory allocation subsystem.
    98     99   */
    99    100   int sqlite3MallocInit(void){
   100    101     if( sqlite3Config.m.xMalloc==0 ){
................................................................................
   221    222   */
   222    223   void *sqlite3_malloc(int n){
   223    224   #ifndef SQLITE_OMIT_AUTOINIT
   224    225     if( sqlite3_initialize() ) return 0;
   225    226   #endif
   226    227     return sqlite3Malloc(n);
   227    228   }
          229  +
          230  +/*
          231  +** Each thread may only have a single outstanding allocation from
          232  +** xTempMalloc().  We verify this constraint in the single-threaded
          233  +** case by setting tempAllocOut to 1 when an allocation
          234  +** is outstanding clearing it when the allocation is freed.
          235  +*/
          236  +#if SQLITE_THREADSAFE==0 && !defined(NDEBUG)
          237  +static int tempAllocOut = 0;
          238  +#endif
          239  +
          240  +
          241  +/*
          242  +** Allocate memory that is to be used and released right away.
          243  +** This routine is similar to alloca() in that it is not intended
          244  +** for situations where the memory might be held long-term.  This
          245  +** routine is intended to get memory to old large transient data
          246  +** structures that would not normally fit on the stack of an
          247  +** embedded processor.
          248  +*/
          249  +void *sqlite3TempMalloc(int n){
          250  +  void *p;
          251  +  assert( n>0 );
          252  +  if( sqlite3FaultStep(SQLITE_FAULTINJECTOR_MALLOC) ){
          253  +    return 0;
          254  +  }
          255  +#if SQLITE_THREADSAFE==0 && !defined(NDEBUG)
          256  +  assert( tempAllocOut==0 );
          257  +  tempAllocOut = 1;
          258  +#endif
          259  +  if( sqlite3Config.bMemstat ){
          260  +    sqlite3_mutex_enter(mem0.mutex);
          261  +    if( n>mem0.mxTempReq ) mem0.mxTempReq = n;
          262  +    p = sqlite3Config.m.xTempMalloc(n);
          263  +    sqlite3_mutex_leave(mem0.mutex);
          264  +  }else{
          265  +    p = sqlite3Config.m.xTempMalloc(n);
          266  +  }
          267  +  return p;
          268  +}
          269  +void sqlite3TempFree(void *p){
          270  +  if( p ){
          271  +#if SQLITE_THREADSAFE==0 && !defined(NDEBUG)
          272  +    assert( tempAllocOut==1 );
          273  +    tempAllocOut = 0;
          274  +#endif
          275  +    sqlite3Config.m.xTempFree(p);
          276  +  }
          277  +}
   228    278   
   229    279   /*
   230    280   ** Return the size of a memory allocation previously obtained from
   231    281   ** sqlite3Malloc() or sqlite3_malloc().
   232    282   */
   233    283   int sqlite3MallocSize(void *p){
   234    284     return sqlite3Config.m.xSize(p);
................................................................................
   382    432   ** ThreadData structure.
   383    433   */
   384    434   char *sqlite3StrDup(const char *z){
   385    435     char *zNew;
   386    436     int n;
   387    437     if( z==0 ) return 0;
   388    438     n = strlen(z)+1;
   389         -  zNew = sqlite3_malloc(n);
          439  +  zNew = sqlite3Malloc(n);
   390    440     if( zNew ) memcpy(zNew, z, n);
   391    441     return zNew;
   392    442   }
   393    443   char *sqlite3StrNDup(const char *z, int n){
   394    444     char *zNew;
   395    445     if( z==0 ) return 0;
   396         -  zNew = sqlite3_malloc(n+1);
          446  +  zNew = sqlite3Malloc(n+1);
   397    447     if( zNew ){
   398    448       memcpy(zNew, z, n);
   399    449       zNew[n] = 0;
   400    450     }
   401    451     return zNew;
   402    452   }
   403    453   
................................................................................
   433    483     nByte = 1;
   434    484     va_start(ap, pz);
   435    485     while( (z = va_arg(ap, const char*))!=0 ){
   436    486       nByte += strlen(z);
   437    487     }
   438    488     va_end(ap);
   439    489     sqlite3_free(*pz);
   440         -  *pz = zResult = sqlite3_malloc(nByte);
          490  +  *pz = zResult = sqlite3Malloc(nByte);
   441    491     if( zResult==0 ){
   442    492       return;
   443    493     }
   444    494     *zResult = 0;
   445    495     va_start(ap, pz);
   446    496     while( (z = va_arg(ap, const char*))!=0 ){
   447    497       int n = strlen(z);

Changes to src/mem1.c.

    13     13   ** This file contains low-level memory allocation drivers for when
    14     14   ** SQLite will use the standard C-library malloc/realloc/free interface
    15     15   ** to obtain the memory it needs.
    16     16   **
    17     17   ** This file contains implementations of the low-level memory allocation
    18     18   ** routines specified in the sqlite3_mem_methods object.
    19     19   **
    20         -** $Id: mem1.c,v 1.19 2008/06/14 16:56:22 drh Exp $
           20  +** $Id: mem1.c,v 1.20 2008/06/15 02:51:48 drh Exp $
    21     21   */
    22     22   #include "sqliteInt.h"
    23     23   
    24     24   /*
    25     25   ** This version of the memory allocator is the default.  It is
    26     26   ** used when no other memory allocator is specified using compile-time
    27     27   ** macros.
................................................................................
   126    126   void sqlite3MemSetDefault(void){
   127    127     static const sqlite3_mem_methods defaultMethods = {
   128    128        sqlite3MemMalloc,
   129    129        sqlite3MemFree,
   130    130        sqlite3MemRealloc,
   131    131        sqlite3MemSize,
   132    132        sqlite3MemRoundup,
          133  +     sqlite3MemMalloc,
          134  +     sqlite3MemFree,
   133    135        sqlite3MemInit,
   134    136        sqlite3MemShutdown,
   135    137        0
   136    138     };
   137    139     sqlite3_config(SQLITE_CONFIG_MALLOC, &defaultMethods);
   138    140   }
   139    141   
   140    142   #endif /* SQLITE_SYSTEM_MALLOC */

Changes to src/mem2.c.

    15     15   ** to obtain the memory it needs while adding lots of additional debugging
    16     16   ** information to each allocation in order to help detect and fix memory
    17     17   ** leaks and memory usage errors.
    18     18   **
    19     19   ** This file contains implementations of the low-level memory allocation
    20     20   ** routines specified in the sqlite3_mem_methods object.
    21     21   **
    22         -** $Id: mem2.c,v 1.28 2008/06/14 16:56:22 drh Exp $
           22  +** $Id: mem2.c,v 1.29 2008/06/15 02:51:48 drh Exp $
    23     23   */
    24     24   #include "sqliteInt.h"
    25     25   
    26     26   /*
    27     27   ** This version of the memory allocator is used only if the
    28     28   ** SQLITE_MEMDEBUG macro is defined
    29     29   */
................................................................................
   308    308   void sqlite3MemSetDefault(void){
   309    309     static const sqlite3_mem_methods defaultMethods = {
   310    310        sqlite3MemMalloc,
   311    311        sqlite3MemFree,
   312    312        sqlite3MemRealloc,
   313    313        sqlite3MemSize,
   314    314        sqlite3MemRoundup,
          315  +     sqlite3MemMalloc,
          316  +     sqlite3MemFree,
   315    317        sqlite3MemInit,
   316    318        sqlite3MemShutdown,
   317    319        0
   318    320     };
   319    321     sqlite3_config(SQLITE_CONFIG_MALLOC, &defaultMethods);
   320    322   }
   321    323   

Changes to src/mutex.c.

    15     15   ** exclusion and is thus suitable for use only in applications
    16     16   ** that use SQLite in a single thread.  But this implementation
    17     17   ** does do a lot of error checking on mutexes to make sure they
    18     18   ** are called correctly and at appropriate times.  Hence, this
    19     19   ** implementation is suitable for testing.
    20     20   ** debugging purposes
    21     21   **
    22         -** $Id: mutex.c,v 1.19 2008/06/14 16:56:23 drh Exp $
           22  +** $Id: mutex.c,v 1.20 2008/06/15 02:51:48 drh Exp $
    23     23   */
    24     24   #include "sqliteInt.h"
    25     25   
    26     26   #ifdef SQLITE_MUTEX_NOOP_DEBUG
    27     27   /*
    28     28   ** In this implementation, mutexes do not provide any mutual exclusion.
    29     29   ** But the error checking is provided.  This implementation is useful
................................................................................
    51     51   */
    52     52   sqlite3_mutex *sqlite3_mutex_alloc(int id){
    53     53     static sqlite3_mutex aStatic[6];
    54     54     sqlite3_mutex *pNew = 0;
    55     55     switch( id ){
    56     56       case SQLITE_MUTEX_FAST:
    57     57       case SQLITE_MUTEX_RECURSIVE: {
    58         -      pNew = sqlite3_malloc(sizeof(*pNew));
           58  +      pNew = sqlite3Malloc(sizeof(*pNew));
    59     59         if( pNew ){
    60     60           pNew->id = id;
    61     61           pNew->cnt = 0;
    62     62         }
    63     63         break;
    64     64       }
    65     65       default: {

Changes to src/mutex.h.

    15     15   ** to all source files.  We break it out in an effort to keep the code
    16     16   ** better organized.
    17     17   **
    18     18   ** NOTE:  source files should *not* #include this header file directly.
    19     19   ** Source files should #include the sqliteInt.h file and let that file
    20     20   ** include this one indirectly.
    21     21   **
    22         -** $Id: mutex.h,v 1.3 2008/06/13 18:24:27 drh Exp $
           22  +** $Id: mutex.h,v 1.4 2008/06/15 02:51:48 drh Exp $
    23     23   */
    24     24   
    25     25   
    26     26   #ifdef SQLITE_MUTEX_APPDEF
    27     27   /*
    28     28   ** If SQLITE_MUTEX_APPDEF is defined, then this whole module is
    29     29   ** omitted and equivalent functionality must be provided by the
................................................................................
    73     73   #define sqlite3_mutex_alloc(X)    ((sqlite3_mutex*)8)
    74     74   #define sqlite3_mutex_free(X)
    75     75   #define sqlite3_mutex_enter(X)
    76     76   #define sqlite3_mutex_try(X)      SQLITE_OK
    77     77   #define sqlite3_mutex_leave(X)
    78     78   #define sqlite3_mutex_held(X)     1
    79     79   #define sqlite3_mutex_notheld(X)  1
    80         -#define sqlite3_mutex_init()
           80  +#define sqlite3_mutex_init()      SQLITE_OK
    81     81   #define sqlite3_mutex_end()
    82     82   #endif
    83     83   
    84     84   #endif /* SQLITE_MUTEX_APPDEF */

Changes to src/os.c.

     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   ******************************************************************************
    12     12   **
    13     13   ** This file contains OS interface code that is common to all
    14     14   ** architectures.
    15     15   **
    16         -** $Id: os.c,v 1.112 2008/06/13 18:24:27 drh Exp $
           16  +** $Id: os.c,v 1.113 2008/06/15 02:51:48 drh Exp $
    17     17   */
    18     18   #define _SQLITE_OS_C_ 1
    19     19   #include "sqliteInt.h"
    20     20   #undef _SQLITE_OS_C_
    21     21   
    22     22   /*
    23     23   ** The default SQLite sqlite3_vfs implementations do not allocate
................................................................................
    34     34   **     sqlite3OsWrite()
    35     35   **     sqlite3OsSync()
    36     36   **     sqlite3OsLock()
    37     37   **
    38     38   */
    39     39   #if defined(SQLITE_TEST) && (OS_WIN==0)
    40     40     #define DO_OS_MALLOC_TEST if (1) {            \
    41         -    void *pTstAlloc = sqlite3_malloc(10);       \
           41  +    void *pTstAlloc = sqlite3Malloc(10);       \
    42     42       if (!pTstAlloc) return SQLITE_IOERR_NOMEM;  \
    43     43       sqlite3_free(pTstAlloc);                    \
    44     44     }
    45     45   #else
    46     46     #define DO_OS_MALLOC_TEST
    47     47   #endif
    48     48   
................................................................................
   164    164     const char *zFile, 
   165    165     sqlite3_file **ppFile, 
   166    166     int flags,
   167    167     int *pOutFlags
   168    168   ){
   169    169     int rc = SQLITE_NOMEM;
   170    170     sqlite3_file *pFile;
   171         -  pFile = (sqlite3_file *)sqlite3_malloc(pVfs->szOsFile);
          171  +  pFile = (sqlite3_file *)sqlite3Malloc(pVfs->szOsFile);
   172    172     if( pFile ){
   173    173       rc = sqlite3OsOpen(pVfs, zFile, pFile, flags, pOutFlags);
   174    174       if( rc!=SQLITE_OK ){
   175    175         sqlite3_free(pFile);
   176    176       }else{
   177    177         *ppFile = pFile;
   178    178       }

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.456 2008/06/07 08:58:22 danielk1977 Exp $
           21  +** @(#) $Id: pager.c,v 1.457 2008/06/15 02:51:48 drh Exp $
    22     22   */
    23     23   #ifndef SQLITE_OMIT_DISKIO
    24     24   #include "sqliteInt.h"
    25     25   #include <assert.h>
    26     26   #include <string.h>
    27     27   
    28     28   /*
................................................................................
  1646   1646     sqlite3_file *pJournal;
  1647   1647     char *zMasterJournal = 0; /* Contents of master journal file */
  1648   1648     i64 nMasterJournal;       /* Size of master journal file */
  1649   1649   
  1650   1650     /* Open the master journal file exclusively in case some other process
  1651   1651     ** is running this routine also. Not that it makes too much difference.
  1652   1652     */
  1653         -  pMaster = (sqlite3_file *)sqlite3_malloc(pVfs->szOsFile * 2);
         1653  +  pMaster = (sqlite3_file *)sqlite3Malloc(pVfs->szOsFile * 2);
  1654   1654     pJournal = (sqlite3_file *)(((u8 *)pMaster) + pVfs->szOsFile);
  1655   1655     if( !pMaster ){
  1656   1656       rc = SQLITE_NOMEM;
  1657   1657     }else{
  1658   1658       int flags = (SQLITE_OPEN_READONLY|SQLITE_OPEN_MASTER_JOURNAL);
  1659   1659       rc = sqlite3OsOpen(pVfs, zMaster, pMaster, flags, 0);
  1660   1660     }
................................................................................
  1668   1668       char *zJournal;
  1669   1669       char *zMasterPtr = 0;
  1670   1670       int nMasterPtr = pPager->pVfs->mxPathname+1;
  1671   1671   
  1672   1672       /* Load the entire master journal file into space obtained from
  1673   1673       ** sqlite3_malloc() and pointed to by zMasterJournal. 
  1674   1674       */
  1675         -    zMasterJournal = (char *)sqlite3_malloc(nMasterJournal + nMasterPtr);
         1675  +    zMasterJournal = (char *)sqlite3Malloc(nMasterJournal + nMasterPtr);
  1676   1676       if( !zMasterJournal ){
  1677   1677         rc = SQLITE_NOMEM;
  1678   1678         goto delmaster_out;
  1679   1679       }
  1680   1680       zMasterPtr = &zMasterJournal[nMasterJournal];
  1681   1681       rc = sqlite3OsRead(pMaster, zMasterJournal, nMasterJournal, 0);
  1682   1682       if( rc!=SQLITE_OK ) goto delmaster_out;
................................................................................
  2189   2189   
  2190   2190     /* Compute and store the full pathname in an allocated buffer pointed
  2191   2191     ** to by zPathname, length nPathname. Or, if this is a temporary file,
  2192   2192     ** leave both nPathname and zPathname set to 0.
  2193   2193     */
  2194   2194     if( zFilename && zFilename[0] ){
  2195   2195       nPathname = pVfs->mxPathname+1;
  2196         -    zPathname = sqlite3_malloc(nPathname*2);
         2196  +    zPathname = sqlite3Malloc(nPathname*2);
  2197   2197       if( zPathname==0 ){
  2198   2198         return SQLITE_NOMEM;
  2199   2199       }
  2200   2200   #ifndef SQLITE_OMIT_MEMORYDB
  2201   2201       if( strcmp(zFilename,":memory:")==0 ){
  2202   2202         memDb = 1;
  2203   2203         zPathname[0] = 0;
................................................................................
  2417   2417   int sqlite3PagerSetPagesize(Pager *pPager, u16 *pPageSize){
  2418   2418     int rc = SQLITE_OK;
  2419   2419     u16 pageSize = *pPageSize;
  2420   2420     assert( pageSize==0 || (pageSize>=512 && pageSize<=SQLITE_MAX_PAGE_SIZE) );
  2421   2421     if( pageSize && pageSize!=pPager->pageSize 
  2422   2422      && !pPager->memDb && pPager->nRef==0 
  2423   2423     ){
  2424         -    char *pNew = (char *)sqlite3_malloc(pageSize);
         2424  +    char *pNew = (char *)sqlite3Malloc(pageSize);
  2425   2425       if( !pNew ){
  2426   2426         rc = SQLITE_NOMEM;
  2427   2427       }else{
  2428   2428         pagerEnter(pPager);
  2429   2429         pager_reset(pPager);
  2430   2430         pPager->pageSize = pageSize;
  2431   2431         setSectorSize(pPager);
................................................................................
  3643   3643           rc = SQLITE_NOMEM;
  3644   3644           goto pager_allocate_out;
  3645   3645         }
  3646   3646       }
  3647   3647       pagerLeave(pPager);
  3648   3648       nByteHdr = sizeof(*pPg) + sizeof(u32) + pPager->nExtra
  3649   3649                 + MEMDB*sizeof(PgHistory);
  3650         -    pPg = sqlite3_malloc( nByteHdr );
         3650  +    pPg = sqlite3Malloc( nByteHdr );
  3651   3651       if( pPg ){
  3652         -      pData = sqlite3_malloc( pPager->pageSize );
         3652  +      pData = sqlite3Malloc( pPager->pageSize );
  3653   3653         if( pData==0 ){
  3654   3654           sqlite3_free(pPg);
  3655   3655           pPg = 0;
  3656   3656         }
  3657   3657       }
  3658   3658       pagerEnter(pPager);
  3659   3659       if( pPg==0 ){
................................................................................
  4219   4219       */
  4220   4220       if( !pPg->inJournal && (pPager->journalOpen || MEMDB) ){
  4221   4221         if( (int)pPg->pgno <= pPager->origDbSize ){
  4222   4222           if( MEMDB ){
  4223   4223             PgHistory *pHist = PGHDR_TO_HIST(pPg, pPager);
  4224   4224             PAGERTRACE3("JOURNAL %d page %d\n", PAGERID(pPager), pPg->pgno);
  4225   4225             assert( pHist->pOrig==0 );
  4226         -          pHist->pOrig = sqlite3_malloc( pPager->pageSize );
         4226  +          pHist->pOrig = sqlite3Malloc( pPager->pageSize );
  4227   4227             if( !pHist->pOrig ){
  4228   4228               return SQLITE_NOMEM;
  4229   4229             }
  4230   4230             memcpy(pHist->pOrig, PGHDR_TO_DATA(pPg), pPager->pageSize);
  4231   4231           }else{
  4232   4232             u32 cksum;
  4233   4233             char *pData2;
................................................................................
  4289   4289        && !pageInStatement(pPg) 
  4290   4290        && (int)pPg->pgno<=pPager->stmtSize 
  4291   4291       ){
  4292   4292         assert( pPg->inJournal || (int)pPg->pgno>pPager->origDbSize );
  4293   4293         if( MEMDB ){
  4294   4294           PgHistory *pHist = PGHDR_TO_HIST(pPg, pPager);
  4295   4295           assert( pHist->pStmt==0 );
  4296         -        pHist->pStmt = sqlite3_malloc( pPager->pageSize );
         4296  +        pHist->pStmt = sqlite3Malloc( pPager->pageSize );
  4297   4297           if( pHist->pStmt ){
  4298   4298             memcpy(pHist->pStmt, PGHDR_TO_DATA(pPg), pPager->pageSize);
  4299   4299           }
  4300   4300           PAGERTRACE3("STMT-JOURNAL %d page %d\n", PAGERID(pPager), pPg->pgno);
  4301   4301           page_add_to_stmt_list(pPg);
  4302   4302         }else{
  4303   4303           i64 offset = pPager->stmtNRec*(4+pPager->pageSize);

Changes to src/prepare.c.

     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains the implementation of the sqlite3_prepare()
    13     13   ** interface, and routines that contribute to loading the database schema
    14     14   ** from disk.
    15     15   **
    16         -** $Id: prepare.c,v 1.86 2008/05/23 14:49:49 drh Exp $
           16  +** $Id: prepare.c,v 1.87 2008/06/15 02:51:48 drh Exp $
    17     17   */
    18     18   #include "sqliteInt.h"
    19     19   #include <ctype.h>
    20     20   
    21     21   /*
    22     22   ** Fill the InitData structure with an error message that indicates
    23     23   ** that the database is corrupt.
................................................................................
   444    444   static int schemaIsValid(sqlite3 *db){
   445    445     int iDb;
   446    446     int rc;
   447    447     BtCursor *curTemp;
   448    448     int cookie;
   449    449     int allOk = 1;
   450    450   
   451         -  curTemp = (BtCursor *)sqlite3_malloc(sqlite3BtreeCursorSize());
          451  +  curTemp = (BtCursor *)sqlite3Malloc(sqlite3BtreeCursorSize());
   452    452     if( curTemp ){
   453    453       assert( sqlite3_mutex_held(db->mutex) );
   454    454       for(iDb=0; allOk && iDb<db->nDb; iDb++){
   455    455         Btree *pBt;
   456    456         pBt = db->aDb[iDb].pBt;
   457    457         if( pBt==0 ) continue;
   458    458         memset(curTemp, 0, sqlite3BtreeCursorSize());

Changes to src/printf.c.

     1      1   /*
     2      2   ** The "printf" code that follows dates from the 1980's.  It is in
     3      3   ** the public domain.  The original comments are included here for
     4      4   ** completeness.  They are very out-of-date but might be useful as
     5      5   ** an historical reference.  Most of the "enhancements" have been backed
     6      6   ** out so that the functionality is now the same as standard printf().
     7      7   **
     8         -** $Id: printf.c,v 1.85 2008/05/16 04:51:55 danielk1977 Exp $
            8  +** $Id: printf.c,v 1.86 2008/06/15 02:51:48 drh Exp $
     9      9   **
    10     10   **************************************************************************
    11     11   **
    12     12   ** The following modules is an enhanced replacement for the "printf" subroutines
    13     13   ** found in the standard C library.  The following enhancements are
    14     14   ** supported:
    15     15   **
................................................................................
   646    646           if( isnull ) escarg = (xtype==etSQLESCAPE2 ? "NULL" : "(NULL)");
   647    647           for(i=n=0; (ch=escarg[i])!=0; i++){
   648    648             if( ch==q )  n++;
   649    649           }
   650    650           needQuote = !isnull && xtype==etSQLESCAPE2;
   651    651           n += i + 1 + needQuote*2;
   652    652           if( n>etBUFSIZE ){
   653         -          bufpt = zExtra = sqlite3_malloc( n );
          653  +          bufpt = zExtra = sqlite3Malloc( n );
   654    654             if( bufpt==0 ) return;
   655    655           }else{
   656    656             bufpt = buf;
   657    657           }
   658    658           j = 0;
   659    659           if( needQuote ) bufpt[j++] = q;
   660    660           for(i=0; (ch=escarg[i])!=0; i++){
................................................................................
   748    748             sqlite3StrAccumReset(p);
   749    749             p->tooBig = 1;
   750    750             return;
   751    751           }
   752    752         }else{
   753    753           p->nAlloc = szNew;
   754    754         }
   755         -      zNew = sqlite3_malloc( p->nAlloc );
          755  +      zNew = sqlite3Malloc( p->nAlloc );
   756    756         if( zNew ){
   757    757           memcpy(zNew, p->zText, p->nChar);
   758    758           sqlite3StrAccumReset(p);
   759    759           p->zText = zNew;
   760    760         }else{
   761    761           p->mallocFailed = 1;
   762    762           sqlite3StrAccumReset(p);
................................................................................
   773    773   ** Return a pointer to the resulting string.  Return a NULL
   774    774   ** pointer if any kind of error was encountered.
   775    775   */
   776    776   char *sqlite3StrAccumFinish(StrAccum *p){
   777    777     if( p->zText ){
   778    778       p->zText[p->nChar] = 0;
   779    779       if( p->useMalloc && p->zText==p->zBase ){
   780         -      p->zText = sqlite3_malloc( p->nChar+1 );
          780  +      p->zText = sqlite3Malloc( p->nChar+1 );
   781    781         if( p->zText ){
   782    782           memcpy(p->zText, p->zBase, p->nChar+1);
   783    783         }else{
   784    784           p->mallocFailed = 1;
   785    785         }
   786    786       }
   787    787     }

Changes to src/sqlite.h.in.

    26     26   ** on how SQLite interfaces are suppose to operate.
    27     27   **
    28     28   ** The name of this file under configuration management is "sqlite.h.in".
    29     29   ** The makefile makes some minor changes to this file (such as inserting
    30     30   ** the version number) and changes its name to "sqlite3.h" as
    31     31   ** part of the build process.
    32     32   **
    33         -** @(#) $Id: sqlite.h.in,v 1.327 2008/06/14 16:56:23 drh Exp $
           33  +** @(#) $Id: sqlite.h.in,v 1.328 2008/06/15 02:51:48 drh Exp $
    34     34   */
    35     35   #ifndef _SQLITE3_H_
    36     36   #define _SQLITE3_H_
    37     37   #include <stdarg.h>     /* Needed for the definition of va_list */
    38     38   
    39     39   /*
    40     40   ** Make sure we can call this stuff from C++.
................................................................................
   972    972   ** previously obtained from xMalloc or xRealloc.  The allocated size
   973    973   ** is always at least as big as the requested size but may be larger.
   974    974   **
   975    975   ** The xRoundup method returns what would be the allocated size of
   976    976   ** a memory allocation given a particular requested size.  Most memory
   977    977   ** allocators round up memory allocations at least to the next multiple
   978    978   ** of 8.  Some round up to a larger multiple or to a power of 2. 
          979  +**
          980  +** The xTempMalloc and xTempFree methods are used to allocate a large
          981  +** chunk of temporary-use memory whose lifetime is a single procedure
          982  +** call.  These routines may be the same as xMalloc and xFree, if desired,
          983  +** though some specialized applications may benefit from using a different
          984  +** allocation algorithm in this case. 
          985  +** SQLite will never request more than one outstanding memory allocation
          986  +** per thread using xTempMalloc.
   979    987   **
   980    988   ** The xInit method initializes the memory allocator.  (For example,
   981    989   ** it might allocate any require mutexes or initialize internal data
   982    990   ** structures.  The xShutdown method is invoked (indirectly) by
   983    991   ** [sqlite3_shutdown()] and should deallocate any resources acquired
   984    992   ** by xInit.  The pAppData pointer is used as the only parameter to
   985    993   ** xInit and xShutdown.
................................................................................
   987    995   typedef struct sqlite3_mem_methods sqlite3_mem_methods;
   988    996   struct sqlite3_mem_methods {
   989    997     void *(*xMalloc)(int);         /* Memory allocation function */
   990    998     void (*xFree)(void*);          /* Free a prior allocation */
   991    999     void *(*xRealloc)(void*,int);  /* Resize an allocation */
   992   1000     int (*xSize)(void*);           /* Return the size of an allocation */
   993   1001     int (*xRoundup)(int);          /* Round up request size to allocation size */
         1002  +  void *(*xTempMalloc)(int);     /* Allocate temporary space */
         1003  +  void (*xTempFree)(void*);      /* Free space from xTempMalloc */
   994   1004     int (*xInit)(void*);           /* Initialize the memory allocator */
   995   1005     void (*xShutdown)(void*);      /* Deinitialize the memory allocator */
   996   1006     void *pAppData;                /* Argument to xInit() and xShutdown() */
   997   1007   };
   998   1008   
   999   1009   /*
  1000   1010   ** CAPI3REF: Configuration Options {F10160}

Changes to src/sqliteInt.h.

     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   ** Internal interface definitions for SQLite.
    13     13   **
    14         -** @(#) $Id: sqliteInt.h,v 1.709 2008/06/14 16:56:23 drh Exp $
           14  +** @(#) $Id: sqliteInt.h,v 1.710 2008/06/15 02:51:48 drh Exp $
    15     15   */
    16     16   #ifndef _SQLITEINT_H_
    17     17   #define _SQLITEINT_H_
    18     18   
    19     19   /*
    20     20   ** Include the configuration header output by 'configure' if we're using the
    21     21   ** autoconf-based build
................................................................................
  1787   1787   char *sqlite3StrNDup(const char*, int);
  1788   1788   char *sqlite3DbStrDup(sqlite3*,const char*);
  1789   1789   char *sqlite3DbStrNDup(sqlite3*,const char*, int);
  1790   1790   void *sqlite3Realloc(void*, int);
  1791   1791   void *sqlite3DbReallocOrFree(sqlite3 *, void *, int);
  1792   1792   void *sqlite3DbRealloc(sqlite3 *, void *, int);
  1793   1793   int sqlite3MallocSize(void *);
         1794  +void *sqlite3TempMalloc(int);
         1795  +void sqlite3TempFree(void*);
  1794   1796   void sqlite3MemSetDefault(void);
  1795   1797   
  1796   1798   int sqlite3IsNaN(double);
  1797   1799   
  1798   1800   char *sqlite3MPrintf(sqlite3*,const char*, ...);
  1799   1801   char *sqlite3VMPrintf(sqlite3*,const char*, va_list);
  1800   1802   #if defined(SQLITE_TEST) || defined(SQLITE_DEBUG)

Changes to src/tokenize.c.

    11     11   *************************************************************************
    12     12   ** An tokenizer for SQL
    13     13   **
    14     14   ** This file contains C code that splits an SQL input string up into
    15     15   ** individual tokens and sends those tokens one-by-one over to the
    16     16   ** parser for analysis.
    17     17   **
    18         -** $Id: tokenize.c,v 1.143 2008/06/02 13:00:33 danielk1977 Exp $
           18  +** $Id: tokenize.c,v 1.144 2008/06/15 02:51:48 drh Exp $
    19     19   */
    20     20   #include "sqliteInt.h"
    21     21   #include <ctype.h>
    22     22   #include <stdlib.h>
    23     23   
    24     24   /*
    25     25   ** The charMap() macro maps alphabetic characters into their
................................................................................
   389    389   
   390    390     if( db->activeVdbeCnt==0 ){
   391    391       db->u1.isInterrupted = 0;
   392    392     }
   393    393     pParse->rc = SQLITE_OK;
   394    394     pParse->zTail = pParse->zSql = zSql;
   395    395     i = 0;
   396         -  pEngine = sqlite3ParserAlloc((void*(*)(size_t))sqlite3_malloc);
          396  +  pEngine = sqlite3ParserAlloc((void*(*)(size_t))sqlite3Malloc);
   397    397     if( pEngine==0 ){
   398    398       db->mallocFailed = 1;
   399    399       return SQLITE_NOMEM;
   400    400     }
   401    401     assert( pParse->sLastToken.dyn==0 );
   402    402     assert( pParse->pNewTable==0 );
   403    403     assert( pParse->pNewTrigger==0 );

Changes to src/vdbe.c.

    39     39   **
    40     40   ** Various scripts scan this source file in order to generate HTML
    41     41   ** documentation, headers files, or other derived files.  The formatting
    42     42   ** of the code in this file is, therefore, important.  See other comments
    43     43   ** in this file for details.  If in doubt, do not deviate from existing
    44     44   ** commenting and indentation practices when changing or adding code.
    45     45   **
    46         -** $Id: vdbe.c,v 1.748 2008/06/07 08:58:22 danielk1977 Exp $
           46  +** $Id: vdbe.c,v 1.749 2008/06/15 02:51:48 drh Exp $
    47     47   */
    48     48   #include "sqliteInt.h"
    49     49   #include <ctype.h>
    50     50   #include "vdbeInt.h"
    51     51   
    52     52   /*
    53     53   ** The following global variable is incremented every time a cursor
................................................................................
  3376   3376         pC->pData = pData->z;
  3377   3377         if( !pC->ephemPseudoTable ){
  3378   3378           pData->flags &= ~MEM_Dyn;
  3379   3379           pData->flags |= MEM_Ephem;
  3380   3380           pData->zMalloc = 0;
  3381   3381         }
  3382   3382       }else{
  3383         -      pC->pData = sqlite3_malloc( pC->nData+2 );
         3383  +      pC->pData = sqlite3Malloc( pC->nData+2 );
  3384   3384         if( !pC->pData ) goto no_mem;
  3385   3385         memcpy(pC->pData, pData->z, pC->nData);
  3386   3386         pC->pData[pC->nData] = 0;
  3387   3387         pC->pData[pC->nData+1] = 0;
  3388   3388       }
  3389   3389       pC->nullRow = 0;
  3390   3390     }else{
................................................................................
  4136   4136     int j;          /* Loop counter */
  4137   4137     int nErr;       /* Number of errors reported */
  4138   4138     char *z;        /* Text of the error report */
  4139   4139     Mem *pnErr;     /* Register keeping track of errors remaining */
  4140   4140     
  4141   4141     nRoot = pOp->p2;
  4142   4142     assert( nRoot>0 );
  4143         -  aRoot = sqlite3_malloc( sizeof(int)*(nRoot+1) );
         4143  +  aRoot = sqlite3Malloc( sizeof(int)*(nRoot+1) );
  4144   4144     if( aRoot==0 ) goto no_mem;
  4145   4145     assert( pOp->p3>0 && pOp->p3<=p->nMem );
  4146   4146     pnErr = &p->aMem[pOp->p3];
  4147   4147     assert( (pnErr->flags & MEM_Int)!=0 );
  4148   4148     assert( (pnErr->flags & (MEM_Str|MEM_Blob))==0 );
  4149   4149     pIn1 = &p->aMem[pOp->p1];
  4150   4150     for(j=0; j<nRoot; j++){

Changes to src/vdbeaux.c.

    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains code used for creating, destroying, and populating
    13     13   ** a VDBE (or an "sqlite3_stmt" as it is known to the outside world.)  Prior
    14     14   ** to version 2.8.7, all this code was combined into the vdbe.c source file.
    15     15   ** But that file was getting too big so this subroutines were split out.
    16     16   **
    17         -** $Id: vdbeaux.c,v 1.386 2008/06/06 15:04:37 drh Exp $
           17  +** $Id: vdbeaux.c,v 1.387 2008/06/15 02:51:48 drh Exp $
    18     18   */
    19     19   #include "sqliteInt.h"
    20     20   #include <ctype.h>
    21     21   #include "vdbeInt.h"
    22     22   
    23     23   
    24     24   
................................................................................
   543    543       pOp->p4type = P4_NOTUSED;
   544    544     }else if( n==P4_KEYINFO ){
   545    545       KeyInfo *pKeyInfo;
   546    546       int nField, nByte;
   547    547   
   548    548       nField = ((KeyInfo*)zP4)->nField;
   549    549       nByte = sizeof(*pKeyInfo) + (nField-1)*sizeof(pKeyInfo->aColl[0]) + nField;
   550         -    pKeyInfo = sqlite3_malloc( nByte );
          550  +    pKeyInfo = sqlite3Malloc( nByte );
   551    551       pOp->p4.pKeyInfo = pKeyInfo;
   552    552       if( pKeyInfo ){
   553    553         memcpy(pKeyInfo, zP4, nByte);
   554    554         /* In the current implementation, P4_KEYINFO is only ever used on
   555    555         ** KeyInfo structures that have no aSortOrder component.  Elements
   556    556         ** with an aSortOrder always use P4_KEYINFO_HANDOFF.  So we do not
   557    557         ** need to bother with duplicating the aSortOrder. */

Changes to src/vdbefifo.c.

     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 implements a FIFO queue of rowids used for processing
    13     13   ** UPDATE and DELETE statements.
    14     14   **
    15         -** $Id: vdbefifo.c,v 1.6 2008/05/16 04:51:55 danielk1977 Exp $
           15  +** $Id: vdbefifo.c,v 1.7 2008/06/15 02:51:48 drh Exp $
    16     16   */
    17     17   #include "sqliteInt.h"
    18     18   #include "vdbeInt.h"
    19     19   
    20     20   /*
    21     21   ** Constants FIFOSIZE_FIRST and FIFOSIZE_MAX are the initial
    22     22   ** number of entries in a fifo page and the maximum number of
................................................................................
    34     34   ** we run out of memory.  Leave space on the page for nEntry entries.
    35     35   */
    36     36   static FifoPage *allocateFifoPage(int nEntry){
    37     37     FifoPage *pPage;
    38     38     if( nEntry>FIFOSIZE_MAX ){
    39     39       nEntry = FIFOSIZE_MAX;
    40     40     }
    41         -  pPage = sqlite3_malloc( sizeof(FifoPage) + sizeof(i64)*(nEntry-1) );
           41  +  pPage = sqlite3Malloc( sizeof(FifoPage) + sizeof(i64)*(nEntry-1) );
    42     42     if( pPage ){
    43     43       pPage->nSlot = nEntry;
    44     44       pPage->iWrite = 0;
    45     45       pPage->iRead = 0;
    46     46       pPage->pNext = 0;
    47     47     }
    48     48     return pPage;

Changes to src/where.c.

    12     12   ** This module contains C code that generates VDBE code used to process
    13     13   ** the WHERE clause of SQL statements.  This module is responsible for
    14     14   ** generating the code that loops through a table looking for applicable
    15     15   ** rows.  Indices are selected and used to speed the search when doing
    16     16   ** so is applicable.  Because this module is responsible for selecting
    17     17   ** indices, you might also think of this module as the "query optimizer".
    18     18   **
    19         -** $Id: where.c,v 1.308 2008/06/12 00:07:29 drh Exp $
           19  +** $Id: where.c,v 1.309 2008/06/15 02:51:48 drh Exp $
    20     20   */
    21     21   #include "sqliteInt.h"
    22     22   
    23     23   /*
    24     24   ** The number of bits in a Bitmask.  "BMS" means "BitMask Size".
    25     25   */
    26     26   #define BMS  (sizeof(Bitmask)*8)
................................................................................
   224    224   ** the pWC->a[] array.
   225    225   */
   226    226   static int whereClauseInsert(WhereClause *pWC, Expr *p, int flags){
   227    227     WhereTerm *pTerm;
   228    228     int idx;
   229    229     if( pWC->nTerm>=pWC->nSlot ){
   230    230       WhereTerm *pOld = pWC->a;
   231         -    pWC->a = sqlite3_malloc( sizeof(pWC->a[0])*pWC->nSlot*2 );
          231  +    pWC->a = sqlite3Malloc( sizeof(pWC->a[0])*pWC->nSlot*2 );
   232    232       if( pWC->a==0 ){
   233    233         pWC->pParse->db->mallocFailed = 1;
   234    234         if( flags & TERM_DYNAMIC ){
   235    235           sqlite3ExprDelete(p);
   236    236         }
   237    237         pWC->a = pOld;
   238    238         return 0;