Index: src/attach.c ================================================================== --- src/attach.c +++ src/attach.c @@ -9,11 +9,11 @@ ** May you share freely, never taking more than you give. ** ************************************************************************* ** This file contains code used to implement the ATTACH and DETACH commands. ** -** $Id: attach.c,v 1.75 2008/04/17 17:02:01 drh Exp $ +** $Id: attach.c,v 1.76 2008/06/15 02:51:47 drh Exp $ */ #include "sqliteInt.h" #ifndef SQLITE_OMIT_ATTACH /* @@ -110,22 +110,16 @@ /* Allocate the new entry in the db->aDb[] array and initialise the schema ** hash tables. */ if( db->aDb==db->aDbStatic ){ - aNew = sqlite3_malloc( sizeof(db->aDb[0])*3 ); - if( aNew==0 ){ - db->mallocFailed = 1; - return; - } + aNew = sqlite3DbMallocRaw(db, sizeof(db->aDb[0])*3 ); + if( aNew==0 ) return; memcpy(aNew, db->aDb, sizeof(db->aDb[0])*2); }else{ - aNew = sqlite3_realloc(db->aDb, sizeof(db->aDb[0])*(db->nDb+1) ); - if( aNew==0 ){ - db->mallocFailed = 1; - return; - } + aNew = sqlite3DbRealloc(db, db->aDb, sizeof(db->aDb[0])*(db->nDb+1) ); + if( aNew==0 ) return; } db->aDb = aNew; aNew = &db->aDb[db->nDb++]; memset(aNew, 0, sizeof(*aNew)); Index: src/btree.c ================================================================== --- src/btree.c +++ src/btree.c @@ -7,11 +7,11 @@ ** May you do good and not evil. ** May you find forgiveness for yourself and forgive others. ** May you share freely, never taking more than you give. ** ************************************************************************* -** $Id: btree.c,v 1.463 2008/06/11 18:27:55 danielk1977 Exp $ +** $Id: btree.c,v 1.464 2008/06/15 02:51:47 drh Exp $ ** ** This file implements a external (disk-based) database using BTrees. ** See the header comment on "btreeInt.h" for additional information. ** Including a description of file format and an overview of operation. */ @@ -298,11 +298,11 @@ ** all that is required. Otherwise, if pCur is not open on an intKey ** table, then malloc space for and store the pCur->nKey bytes of key ** data. */ if( rc==SQLITE_OK && 0==pCur->pPage->intKey){ - void *pKey = sqlite3_malloc(pCur->nKey); + void *pKey = sqlite3Malloc(pCur->nKey); if( pKey ){ rc = sqlite3BtreeKey(pCur, 0, pCur->nKey, pKey); if( rc==SQLITE_OK ){ pCur->pKey = pKey; }else{ @@ -1188,11 +1188,11 @@ && (db->flags & SQLITE_Vtab)==0 && zFilename && zFilename[0] ){ if( sqlite3SharedCacheEnabled ){ int nFullPathname = pVfs->mxPathname+1; - char *zFullPathname = (char *)sqlite3_malloc(nFullPathname); + char *zFullPathname = sqlite3Malloc(nFullPathname); sqlite3_mutex *mutexShared; p->sharable = 1; if( db ){ db->flags |= SQLITE_SharedCache; } @@ -1265,13 +1265,10 @@ pBt->pageSize = get2byte(&zDbHeader[16]); if( pBt->pageSize<512 || pBt->pageSize>SQLITE_MAX_PAGE_SIZE || ((pBt->pageSize-1)&pBt->pageSize)!=0 ){ pBt->pageSize = 0; sqlite3PagerSetPagesize(pBt->pPager, &pBt->pageSize); - pBt->maxEmbedFrac = 64; /* 25% */ - pBt->minEmbedFrac = 32; /* 12.5% */ - pBt->minLeafFrac = 32; /* 12.5% */ #ifndef SQLITE_OMIT_AUTOVACUUM /* If the magic name ":memory:" will create an in-memory database, then ** leave the autoVacuum mode at 0 (do not auto-vacuum), even if ** SQLITE_DEFAULT_AUTOVACUUM is true. On the other hand, if ** SQLITE_OMIT_MEMORYDB has been defined, then ":memory:" is just a @@ -1283,13 +1280,10 @@ } #endif nReserve = 0; }else{ nReserve = zDbHeader[20]; - pBt->maxEmbedFrac = zDbHeader[21]; - pBt->minEmbedFrac = zDbHeader[22]; - pBt->minLeafFrac = zDbHeader[23]; pBt->pageSizeFixed = 1; #ifndef SQLITE_OMIT_AUTOVACUUM pBt->autoVacuum = (get4byte(&zDbHeader[36 + 4*4])?1:0); pBt->incrVacuum = (get4byte(&zDbHeader[36 + 7*4])?1:0); #endif @@ -1675,10 +1669,19 @@ pBt->readOnly = 1; } if( page1[19]>1 ){ goto page1_init_failed; } + + /* The maximum embedded fraction must be exactly 25%. And the minimum + ** embedded fraction must be 12.5% for both leaf-data and non-leaf-data. + ** The original design allowed these amounts to vary, but as of + ** version 3.6.0, we require them to be fixed. + */ + if( memcmp(&page1[21], "\100\040\040",3)!=0 ){ + goto page1_init_failed; + } pageSize = get2byte(&page1[16]); if( ((pageSize-1)&pageSize)!=0 || pageSize<512 || (SQLITE_MAX_PAGE_SIZE<32768 && pageSize>SQLITE_MAX_PAGE_SIZE) ){ goto page1_init_failed; @@ -1703,13 +1706,10 @@ if( usableSize<500 ){ goto page1_init_failed; } pBt->pageSize = pageSize; pBt->usableSize = usableSize; - pBt->maxEmbedFrac = page1[21]; - pBt->minEmbedFrac = page1[22]; - pBt->minLeafFrac = page1[23]; #ifndef SQLITE_OMIT_AUTOVACUUM pBt->autoVacuum = (get4byte(&page1[36 + 4*4])?1:0); pBt->incrVacuum = (get4byte(&page1[36 + 7*4])?1:0); #endif } @@ -1725,14 +1725,14 @@ ** 4-byte overflow page pointer ** So a cell consists of a 2-byte poiner, a header which is as much as ** 17 bytes long, 0 to N bytes of payload, and an optional 4 byte overflow ** page pointer. */ - pBt->maxLocal = (pBt->usableSize-12)*pBt->maxEmbedFrac/255 - 23; - pBt->minLocal = (pBt->usableSize-12)*pBt->minEmbedFrac/255 - 23; + pBt->maxLocal = (pBt->usableSize-12)*64/255 - 23; + pBt->minLocal = (pBt->usableSize-12)*32/255 - 23; pBt->maxLeaf = pBt->usableSize - 35; - pBt->minLeaf = (pBt->usableSize-12)*pBt->minLeafFrac/255 - 23; + pBt->minLeaf = (pBt->usableSize-12)*32/255 - 23; if( pBt->minLocal>pBt->maxLocal || pBt->maxLocal<0 ){ goto page1_init_failed; } assert( pBt->maxLeaf + 23 <= MX_CELL_SIZE(pBt) ); pBt->pPage1 = pPage1; @@ -1821,13 +1821,13 @@ assert( sizeof(zMagicHeader)==16 ); put2byte(&data[16], pBt->pageSize); data[18] = 1; data[19] = 1; data[20] = pBt->pageSize - pBt->usableSize; - data[21] = pBt->maxEmbedFrac; - data[22] = pBt->minEmbedFrac; - data[23] = pBt->minLeafFrac; + data[21] = 64; + data[22] = 32; + data[23] = 32; memset(&data[24], 0, 100-24); zeroPage(pP1, PTF_INTKEY|PTF_LEAF|PTF_LEAFDATA ); pBt->pageSizeFixed = 1; #ifndef SQLITE_OMIT_AUTOVACUUM assert( pBt->autoVacuum==1 || pBt->autoVacuum==0 ); @@ -3717,18 +3717,18 @@ pCellKey = (void *)fetchPayload(pCur, &available, 0); nCellKey = pCur->info.nKey; if( available>=nCellKey ){ c = sqlite3VdbeRecordCompare(nCellKey, pCellKey, pUnKey); }else{ - pCellKey = sqlite3_malloc( nCellKey ); + pCellKey = sqlite3TempMalloc( nCellKey ); if( pCellKey==0 ){ rc = SQLITE_NOMEM; goto moveto_finish; } rc = sqlite3BtreeKey(pCur, 0, nCellKey, (void *)pCellKey); c = sqlite3VdbeRecordCompare(nCellKey, pCellKey, pUnKey); - sqlite3_free(pCellKey); + sqlite3TempFree(pCellKey); if( rc ) goto moveto_finish; } } if( c==0 ){ pCur->info.nKey = nCellKey; @@ -4856,11 +4856,12 @@ int leafCorrection; /* 4 if pPage is a leaf. 0 if not */ int leafData; /* True if pPage is a leaf of a LEAFDATA tree */ int usableSpace; /* Bytes in pPage beyond the header */ int pageFlags; /* Value of pPage->aData[0] */ int subtotal; /* Subtotal of bytes in cells on one page */ - int iSpace = 0; /* First unused byte of aSpace[] */ + int iSpace1 = 0; /* First unused byte of aSpace1[] */ + int iSpace2 = 0; /* First unused byte of aSpace2[] */ MemPage *apOld[NB]; /* pPage and up to two siblings */ Pgno pgnoOld[NB]; /* Page numbers for each page in apOld[] */ MemPage *apCopy[NB]; /* Private copies of apOld[] pages */ MemPage *apNew[NB+2]; /* pPage and up to NB siblings after balancing */ Pgno pgnoNew[NB+2]; /* Page numbers for each page in apNew[] */ @@ -4867,12 +4868,13 @@ u8 *apDiv[NB]; /* Divider cells in pParent */ int cntNew[NB+2]; /* Index in aCell[] of cell after i-th page */ int szNew[NB+2]; /* Combined size of cells place on i-th page */ u8 **apCell = 0; /* All cells begin balanced */ u16 *szCell; /* Local size of all cells in apCell[] */ - u8 *aCopy[NB]; /* Space for holding data of apCopy[] */ - u8 *aSpace; /* Space to hold copies of dividers cells */ + u8 *aCopy[NB]; /* Space for holding data of apCopy[] */ + u8 *aSpace1; /* Space for copies of dividers cells before balance */ + u8 *aSpace2 = 0; /* Space for overflow dividers cells after balance */ #ifndef SQLITE_OMIT_AUTOVACUUM u8 *aFrom = 0; #endif assert( sqlite3_mutex_held(pPage->pBt->mutex) ); @@ -4986,15 +4988,15 @@ nMaxCells = (nMaxCells + 3)&~3; /* ** Allocate space for memory structures */ - apCell = sqlite3_malloc( + apCell = sqlite3TempMalloc( nMaxCells*sizeof(u8*) /* apCell */ + nMaxCells*sizeof(u16) /* szCell */ + (ROUND8(sizeof(MemPage))+pBt->pageSize)*NB /* aCopy */ - + pBt->pageSize*5 /* aSpace */ + + pBt->pageSize /* aSpace1 */ + (ISAUTOVACUUM ? nMaxCells : 0) /* aFrom */ ); if( apCell==0 ){ rc = SQLITE_NOMEM; goto balance_cleanup; @@ -5004,17 +5006,22 @@ assert( ((aCopy[0] - (u8*)apCell) & 7)==0 ); /* 8-byte alignment required */ for(i=1; ipageSize+ROUND8(sizeof(MemPage))]; assert( ((aCopy[i] - (u8*)apCell) & 7)==0 ); /* 8-byte alignment required */ } - aSpace = &aCopy[NB-1][pBt->pageSize+ROUND8(sizeof(MemPage))]; - assert( ((aSpace - (u8*)apCell) & 7)==0 ); /* 8-byte alignment required */ + aSpace1 = &aCopy[NB-1][pBt->pageSize+ROUND8(sizeof(MemPage))]; + assert( ((aSpace1 - (u8*)apCell) & 7)==0 ); /* 8-byte alignment required */ #ifndef SQLITE_OMIT_AUTOVACUUM if( pBt->autoVacuum ){ - aFrom = &aSpace[5*pBt->pageSize]; + aFrom = &aSpace1[pBt->pageSize]; } #endif + aSpace2 = sqlite3Malloc(pBt->pageSize); + if( aSpace2==0 ){ + rc = SQLITE_NOMEM; + goto balance_cleanup; + } /* ** Make copies of the content of pPage and its siblings into aOld[]. ** The rest of this function will use data from the copies rather ** that the original pages since the original pages will be in the @@ -5028,16 +5035,16 @@ } /* ** Load pointers to all cells on sibling pages and the divider cells ** into the local apCell[] array. Make copies of the divider cells - ** into space obtained form aSpace[] and remove the the divider Cells + ** into space obtained form aSpace1[] and remove the the divider Cells ** from pParent. ** ** If the siblings are on leaf pages, then the child pointers of the ** divider cells are stripped from the cells before they are copied - ** into aSpace[]. In this way, all cells in apCell[] are without + ** into aSpace1[]. In this way, all cells in apCell[] are without ** child pointers. If siblings are not leaves, then all cell in ** apCell[] include child pointers. Either way, all cells in apCell[] ** are alike. ** ** leafCorrection: 4 if pPage is a leaf. 0 if pPage is not a leaf. @@ -5078,13 +5085,14 @@ dropCell(pParent, nxDiv, sz); }else{ u8 *pTemp; assert( nCellpageSize*5 ); + pTemp = &aSpace1[iSpace1]; + iSpace1 += sz; + assert( sz<=pBt->pageSize/4 ); + assert( iSpace1<=pBt->pageSize ); memcpy(pTemp, apDiv[i], sz); apCell[nCell] = pTemp+leafCorrection; #ifndef SQLITE_OMIT_AUTOVACUUM if( pBt->autoVacuum ){ aFrom[nCell] = 0xFF; @@ -5301,32 +5309,27 @@ int sz; assert( jleaf ){ memcpy(&pNew->aData[8], pCell, 4); - pTemp = 0; }else if( leafData ){ /* If the tree is a leaf-data tree, and the siblings are leaves, ** then there is no divider cell in apCell[]. Instead, the divider ** cell consists of the integer key for the right-most cell of ** the sibling-page assembled above only. */ CellInfo info; j--; sqlite3BtreeParseCellPtr(pNew, apCell[j], &info); - pCell = &aSpace[iSpace]; + pCell = pTemp; fillInCell(pParent, pCell, 0, info.nKey, 0, 0, 0, &sz); - iSpace += sz; - assert( iSpace<=pBt->pageSize*5 ); pTemp = 0; }else{ pCell -= 4; - pTemp = &aSpace[iSpace]; - iSpace += sz; - assert( iSpace<=pBt->pageSize*5 ); /* Obscure case for non-leaf-data trees: If the cell at pCell was ** previously stored on a leaf node, and its reported size was 4 ** bytes, then it may actually be smaller than this ** (see sqlite3BtreeParseCellPtr(), 4 bytes is the minimum size of ** any cell). But it is important to pass the correct size to @@ -5339,10 +5342,13 @@ if( szCell[j]==4 ){ assert(leafCorrection==4); sz = cellSizePtr(pParent, pCell); } } + iSpace2 += sz; + assert( sz<=pBt->pageSize/4 ); + assert( iSpace2<=pBt->pageSize ); rc = insertCell(pParent, nxDiv, pCell, sz, pTemp, 4); if( rc!=SQLITE_OK ) goto balance_cleanup; put4byte(findOverflowCell(pParent,nxDiv), pNew->pgno); #ifndef SQLITE_OMIT_AUTOVACUUM /* If this is an auto-vacuum database, and not a leaf-data tree, @@ -5389,17 +5395,20 @@ ** Balance the parent page. Note that the current page (pPage) might ** have been added to the freelist so it might no longer be initialized. ** But the parent page will always be initialized. */ assert( pParent->isInit ); + sqlite3TempFree(apCell); + apCell = 0; rc = balance(pParent, 0); /* ** Cleanup before returning. */ balance_cleanup: - sqlite3_free(apCell); + sqlite3_free(aSpace2); + sqlite3TempFree(apCell); for(i=0; ipParent==0 ); assert( pPage->nCell==0 ); assert( sqlite3_mutex_held(pPage->pBt->mutex) ); pBt = pPage->pBt; mxCellPerPage = MX_CELL(pBt); - apCell = sqlite3_malloc( mxCellPerPage*(sizeof(u8*)+sizeof(u16)) ); + apCell = sqlite3Malloc( mxCellPerPage*(sizeof(u8*)+sizeof(u16)) ); if( apCell==0 ) return SQLITE_NOMEM; szCell = (u16*)&apCell[mxCellPerPage]; if( pPage->leaf ){ /* The table is completely empty */ TRACE(("BALANCE: empty table %d\n", pPage->pgno)); @@ -5671,11 +5680,11 @@ ** Make sure pBt->pTmpSpace points to an allocation of ** MX_CELL_SIZE(pBt) bytes. */ static void allocateTempSpace(BtShared *pBt){ if( !pBt->pTmpSpace ){ - pBt->pTmpSpace = sqlite3_malloc(MX_CELL_SIZE(pBt)); + pBt->pTmpSpace = sqlite3Malloc(MX_CELL_SIZE(pBt)); } } /* ** Insert a new record into the BTree. The key is given by (pKey,nKey) @@ -6727,11 +6736,11 @@ if( sCheck.nPage==0 ){ unlockBtreeIfUnused(pBt); sqlite3BtreeLeave(p); return 0; } - sCheck.anRef = sqlite3_malloc( (sCheck.nPage+1)*sizeof(sCheck.anRef[0]) ); + sCheck.anRef = sqlite3Malloc( (sCheck.nPage+1)*sizeof(sCheck.anRef[0]) ); if( !sCheck.anRef ){ unlockBtreeIfUnused(pBt); *pnErr = 1; sqlite3BtreeLeave(p); return sqlite3MPrintf(p->db, "Unable to malloc %d bytes", Index: src/btreeInt.h ================================================================== --- src/btreeInt.h +++ src/btreeInt.h @@ -7,11 +7,11 @@ ** May you do good and not evil. ** May you find forgiveness for yourself and forgive others. ** May you share freely, never taking more than you give. ** ************************************************************************* -** $Id: btreeInt.h,v 1.21 2008/04/24 19:15:10 shane Exp $ +** $Id: btreeInt.h,v 1.22 2008/06/15 02:51:47 drh Exp $ ** ** This file implements a external (disk-based) database using BTrees. ** For a detailed discussion of BTrees, refer to ** ** Donald E. Knuth, THE ART OF COMPUTER PROGRAMMING, Volume 3: @@ -369,13 +369,10 @@ sqlite3 *db; /* Database connection currently using this Btree */ BtCursor *pCursor; /* A list of all open cursors */ MemPage *pPage1; /* First page of the database */ u8 inStmt; /* True if we are in a statement subtransaction */ u8 readOnly; /* True if the underlying file is readonly */ - u8 maxEmbedFrac; /* Maximum payload as % of total page size */ - u8 minEmbedFrac; /* Minimum payload as % of total page size */ - u8 minLeafFrac; /* Minimum leaf payload as % of total page size */ u8 pageSizeFixed; /* True if the page size can no longer be changed */ #ifndef SQLITE_OMIT_AUTOVACUUM u8 autoVacuum; /* True if auto-vacuum is enabled */ u8 incrVacuum; /* True if incr-vacuum is enabled */ Pgno nTrunc; /* Non-zero if the db will be truncated (incr vacuum) */ Index: src/build.c ================================================================== --- src/build.c +++ src/build.c @@ -20,11 +20,11 @@ ** creating ID lists ** BEGIN TRANSACTION ** COMMIT ** ROLLBACK ** -** $Id: build.c,v 1.484 2008/05/01 17:16:53 drh Exp $ +** $Id: build.c,v 1.485 2008/06/15 02:51:47 drh Exp $ */ #include "sqliteInt.h" #include /* @@ -1365,11 +1365,11 @@ zSep = "\n "; zSep2 = ",\n "; zEnd = "\n)"; } n += 35 + 6*p->nCol; - zStmt = sqlite3_malloc( n ); + zStmt = sqlite3Malloc( n ); if( zStmt==0 ){ db->mallocFailed = 1; return 0; } sqlite3_snprintf(n, zStmt, Index: src/date.c ================================================================== --- src/date.c +++ src/date.c @@ -14,11 +14,11 @@ ** ** There is only one exported symbol in this file - the function ** sqlite3RegisterDateTimeFunctions() found at the bottom of the file. ** All other code has file scope. ** -** $Id: date.c,v 1.83 2008/06/12 16:35:38 drh Exp $ +** $Id: date.c,v 1.84 2008/06/15 02:51:47 drh Exp $ ** ** SQLite processes all times and dates as Julian Day numbers. The ** dates and times are stored as the number of days since noon ** in Greenwich on November 24, 4714 B.C. according to the Gregorian ** calendar system. @@ -886,11 +886,11 @@ z = zBuf; }else if( n>sqlite3_context_db_handle(context)->aLimit[SQLITE_LIMIT_LENGTH] ){ sqlite3_result_error_toobig(context); return; }else{ - z = sqlite3_malloc( n ); + z = sqlite3Malloc( n ); if( z==0 ){ sqlite3_result_error_nomem(context); return; } } Index: src/func.c ================================================================== --- src/func.c +++ src/func.c @@ -14,11 +14,11 @@ ** ** There is only one exported symbol in this file - the function ** sqliteRegisterBuildinFunctions() found at the bottom of the file. ** All other code has file scope. ** -** $Id: func.c,v 1.192 2008/04/27 18:40:12 drh Exp $ +** $Id: func.c,v 1.193 2008/06/15 02:51:47 drh Exp $ */ #include "sqliteInt.h" #include #include #include @@ -247,11 +247,11 @@ char *z; if( nByte>sqlite3_context_db_handle(context)->aLimit[SQLITE_LIMIT_LENGTH] ){ sqlite3_result_error_toobig(context); z = 0; }else{ - z = sqlite3_malloc(nByte); + z = sqlite3Malloc(nByte); if( !z && nByte>0 ){ sqlite3_result_error_nomem(context); } } return z; Index: src/hash.c ================================================================== --- src/hash.c +++ src/hash.c @@ -10,11 +10,11 @@ ** ************************************************************************* ** This is the implementation of generic hash-tables ** used in SQLite. ** -** $Id: hash.c,v 1.28 2008/05/13 13:27:34 drh Exp $ +** $Id: hash.c,v 1.29 2008/06/15 02:51:47 drh Exp $ */ #include "sqliteInt.h" #include /* Turn bulk memory into a hash table object by initializing the @@ -385,14 +385,14 @@ } return old_data; } } if( data==0 ) return 0; - new_elem = (HashElem*)sqlite3_malloc( sizeof(HashElem) ); + new_elem = (HashElem*)sqlite3Malloc( sizeof(HashElem) ); if( new_elem==0 ) return data; if( pH->copyKey && pKey!=0 ){ - new_elem->pKey = sqlite3_malloc( nKey ); + new_elem->pKey = sqlite3Malloc( nKey ); if( new_elem->pKey==0 ){ sqlite3_free(new_elem); return data; } memcpy((void*)new_elem->pKey, pKey, nKey); Index: src/legacy.c ================================================================== --- src/legacy.c +++ src/legacy.c @@ -12,11 +12,11 @@ ** Main file for the SQLite library. The routines in this file ** implement the programmer interface to the library. Routines in ** other files are for internal use by SQLite and should not be ** accessed by users of the library. ** -** $Id: legacy.c,v 1.26 2008/05/20 15:44:31 drh Exp $ +** $Id: legacy.c,v 1.27 2008/06/15 02:51:47 drh Exp $ */ #include "sqliteInt.h" #include @@ -131,11 +131,11 @@ if( azCols ) sqlite3_free(azCols); rc = sqlite3ApiExit(db, rc); if( rc!=SQLITE_OK && rc==sqlite3_errcode(db) && pzErrMsg ){ int nErrMsg = 1 + strlen(sqlite3_errmsg(db)); - *pzErrMsg = sqlite3_malloc(nErrMsg); + *pzErrMsg = sqlite3Malloc(nErrMsg); if( *pzErrMsg ){ memcpy(*pzErrMsg, sqlite3_errmsg(db), nErrMsg); } }else if( pzErrMsg ){ *pzErrMsg = 0; Index: src/malloc.c ================================================================== --- src/malloc.c +++ src/malloc.c @@ -10,11 +10,11 @@ ** ************************************************************************* ** ** Memory allocation functions used throughout sqlite. ** -** $Id: malloc.c,v 1.16 2008/06/14 16:56:22 drh Exp $ +** $Id: malloc.c,v 1.17 2008/06/15 02:51:48 drh Exp $ */ #include "sqliteInt.h" #include #include @@ -88,11 +88,12 @@ /* ** Performance statistics */ sqlite3_int64 nowUsed; /* Main memory currently in use */ sqlite3_int64 mxUsed; /* Highwater mark for nowUsed */ - int mxReq; /* maximum request size for main or page-cache mem */ + int mxReq; /* Max request size for ordinary mallocs */ + int mxTempReq; /* Max request size for xTemp mallocs */ } mem0; /* ** Initialize the memory allocation subsystem. */ @@ -223,10 +224,59 @@ #ifndef SQLITE_OMIT_AUTOINIT if( sqlite3_initialize() ) return 0; #endif return sqlite3Malloc(n); } + +/* +** Each thread may only have a single outstanding allocation from +** xTempMalloc(). We verify this constraint in the single-threaded +** case by setting tempAllocOut to 1 when an allocation +** is outstanding clearing it when the allocation is freed. +*/ +#if SQLITE_THREADSAFE==0 && !defined(NDEBUG) +static int tempAllocOut = 0; +#endif + + +/* +** Allocate memory that is to be used and released right away. +** This routine is similar to alloca() in that it is not intended +** for situations where the memory might be held long-term. This +** routine is intended to get memory to old large transient data +** structures that would not normally fit on the stack of an +** embedded processor. +*/ +void *sqlite3TempMalloc(int n){ + void *p; + assert( n>0 ); + if( sqlite3FaultStep(SQLITE_FAULTINJECTOR_MALLOC) ){ + return 0; + } +#if SQLITE_THREADSAFE==0 && !defined(NDEBUG) + assert( tempAllocOut==0 ); + tempAllocOut = 1; +#endif + if( sqlite3Config.bMemstat ){ + sqlite3_mutex_enter(mem0.mutex); + if( n>mem0.mxTempReq ) mem0.mxTempReq = n; + p = sqlite3Config.m.xTempMalloc(n); + sqlite3_mutex_leave(mem0.mutex); + }else{ + p = sqlite3Config.m.xTempMalloc(n); + } + return p; +} +void sqlite3TempFree(void *p){ + if( p ){ +#if SQLITE_THREADSAFE==0 && !defined(NDEBUG) + assert( tempAllocOut==1 ); + tempAllocOut = 0; +#endif + sqlite3Config.m.xTempFree(p); + } +} /* ** Return the size of a memory allocation previously obtained from ** sqlite3Malloc() or sqlite3_malloc(). */ @@ -384,18 +434,18 @@ char *sqlite3StrDup(const char *z){ char *zNew; int n; if( z==0 ) return 0; n = strlen(z)+1; - zNew = sqlite3_malloc(n); + zNew = sqlite3Malloc(n); if( zNew ) memcpy(zNew, z, n); return zNew; } char *sqlite3StrNDup(const char *z, int n){ char *zNew; if( z==0 ) return 0; - zNew = sqlite3_malloc(n+1); + zNew = sqlite3Malloc(n+1); if( zNew ){ memcpy(zNew, z, n); zNew[n] = 0; } return zNew; @@ -435,11 +485,11 @@ while( (z = va_arg(ap, const char*))!=0 ){ nByte += strlen(z); } va_end(ap); sqlite3_free(*pz); - *pz = zResult = sqlite3_malloc(nByte); + *pz = zResult = sqlite3Malloc(nByte); if( zResult==0 ){ return; } *zResult = 0; va_start(ap, pz); Index: src/mem1.c ================================================================== --- src/mem1.c +++ src/mem1.c @@ -15,11 +15,11 @@ ** to obtain the memory it needs. ** ** This file contains implementations of the low-level memory allocation ** routines specified in the sqlite3_mem_methods object. ** -** $Id: mem1.c,v 1.19 2008/06/14 16:56:22 drh Exp $ +** $Id: mem1.c,v 1.20 2008/06/15 02:51:48 drh Exp $ */ #include "sqliteInt.h" /* ** This version of the memory allocator is the default. It is @@ -128,13 +128,15 @@ sqlite3MemMalloc, sqlite3MemFree, sqlite3MemRealloc, sqlite3MemSize, sqlite3MemRoundup, + sqlite3MemMalloc, + sqlite3MemFree, sqlite3MemInit, sqlite3MemShutdown, 0 }; sqlite3_config(SQLITE_CONFIG_MALLOC, &defaultMethods); } #endif /* SQLITE_SYSTEM_MALLOC */ Index: src/mem2.c ================================================================== --- src/mem2.c +++ src/mem2.c @@ -17,11 +17,11 @@ ** leaks and memory usage errors. ** ** This file contains implementations of the low-level memory allocation ** routines specified in the sqlite3_mem_methods object. ** -** $Id: mem2.c,v 1.28 2008/06/14 16:56:22 drh Exp $ +** $Id: mem2.c,v 1.29 2008/06/15 02:51:48 drh Exp $ */ #include "sqliteInt.h" /* ** This version of the memory allocator is used only if the @@ -310,10 +310,12 @@ sqlite3MemMalloc, sqlite3MemFree, sqlite3MemRealloc, sqlite3MemSize, sqlite3MemRoundup, + sqlite3MemMalloc, + sqlite3MemFree, sqlite3MemInit, sqlite3MemShutdown, 0 }; sqlite3_config(SQLITE_CONFIG_MALLOC, &defaultMethods); Index: src/mutex.c ================================================================== --- src/mutex.c +++ src/mutex.c @@ -17,11 +17,11 @@ ** does do a lot of error checking on mutexes to make sure they ** are called correctly and at appropriate times. Hence, this ** implementation is suitable for testing. ** debugging purposes ** -** $Id: mutex.c,v 1.19 2008/06/14 16:56:23 drh Exp $ +** $Id: mutex.c,v 1.20 2008/06/15 02:51:48 drh Exp $ */ #include "sqliteInt.h" #ifdef SQLITE_MUTEX_NOOP_DEBUG /* @@ -53,11 +53,11 @@ static sqlite3_mutex aStatic[6]; sqlite3_mutex *pNew = 0; switch( id ){ case SQLITE_MUTEX_FAST: case SQLITE_MUTEX_RECURSIVE: { - pNew = sqlite3_malloc(sizeof(*pNew)); + pNew = sqlite3Malloc(sizeof(*pNew)); if( pNew ){ pNew->id = id; pNew->cnt = 0; } break; Index: src/mutex.h ================================================================== --- src/mutex.h +++ src/mutex.h @@ -17,11 +17,11 @@ ** ** NOTE: source files should *not* #include this header file directly. ** Source files should #include the sqliteInt.h file and let that file ** include this one indirectly. ** -** $Id: mutex.h,v 1.3 2008/06/13 18:24:27 drh Exp $ +** $Id: mutex.h,v 1.4 2008/06/15 02:51:48 drh Exp $ */ #ifdef SQLITE_MUTEX_APPDEF /* @@ -75,10 +75,10 @@ #define sqlite3_mutex_enter(X) #define sqlite3_mutex_try(X) SQLITE_OK #define sqlite3_mutex_leave(X) #define sqlite3_mutex_held(X) 1 #define sqlite3_mutex_notheld(X) 1 -#define sqlite3_mutex_init() +#define sqlite3_mutex_init() SQLITE_OK #define sqlite3_mutex_end() #endif #endif /* SQLITE_MUTEX_APPDEF */ Index: src/os.c ================================================================== --- src/os.c +++ src/os.c @@ -11,11 +11,11 @@ ****************************************************************************** ** ** This file contains OS interface code that is common to all ** architectures. ** -** $Id: os.c,v 1.112 2008/06/13 18:24:27 drh Exp $ +** $Id: os.c,v 1.113 2008/06/15 02:51:48 drh Exp $ */ #define _SQLITE_OS_C_ 1 #include "sqliteInt.h" #undef _SQLITE_OS_C_ @@ -36,11 +36,11 @@ ** sqlite3OsLock() ** */ #if defined(SQLITE_TEST) && (OS_WIN==0) #define DO_OS_MALLOC_TEST if (1) { \ - void *pTstAlloc = sqlite3_malloc(10); \ + void *pTstAlloc = sqlite3Malloc(10); \ if (!pTstAlloc) return SQLITE_IOERR_NOMEM; \ sqlite3_free(pTstAlloc); \ } #else #define DO_OS_MALLOC_TEST @@ -166,11 +166,11 @@ int flags, int *pOutFlags ){ int rc = SQLITE_NOMEM; sqlite3_file *pFile; - pFile = (sqlite3_file *)sqlite3_malloc(pVfs->szOsFile); + pFile = (sqlite3_file *)sqlite3Malloc(pVfs->szOsFile); if( pFile ){ rc = sqlite3OsOpen(pVfs, zFile, pFile, flags, pOutFlags); if( rc!=SQLITE_OK ){ sqlite3_free(pFile); }else{ Index: src/pager.c ================================================================== --- src/pager.c +++ src/pager.c @@ -16,11 +16,11 @@ ** is separate from the database file. The pager also implements file ** locking to prevent two processes from writing the same database ** file simultaneously, or one process from reading the database while ** another is writing. ** -** @(#) $Id: pager.c,v 1.456 2008/06/07 08:58:22 danielk1977 Exp $ +** @(#) $Id: pager.c,v 1.457 2008/06/15 02:51:48 drh Exp $ */ #ifndef SQLITE_OMIT_DISKIO #include "sqliteInt.h" #include #include @@ -1648,11 +1648,11 @@ i64 nMasterJournal; /* Size of master journal file */ /* Open the master journal file exclusively in case some other process ** is running this routine also. Not that it makes too much difference. */ - pMaster = (sqlite3_file *)sqlite3_malloc(pVfs->szOsFile * 2); + pMaster = (sqlite3_file *)sqlite3Malloc(pVfs->szOsFile * 2); pJournal = (sqlite3_file *)(((u8 *)pMaster) + pVfs->szOsFile); if( !pMaster ){ rc = SQLITE_NOMEM; }else{ int flags = (SQLITE_OPEN_READONLY|SQLITE_OPEN_MASTER_JOURNAL); @@ -1670,11 +1670,11 @@ int nMasterPtr = pPager->pVfs->mxPathname+1; /* Load the entire master journal file into space obtained from ** sqlite3_malloc() and pointed to by zMasterJournal. */ - zMasterJournal = (char *)sqlite3_malloc(nMasterJournal + nMasterPtr); + zMasterJournal = (char *)sqlite3Malloc(nMasterJournal + nMasterPtr); if( !zMasterJournal ){ rc = SQLITE_NOMEM; goto delmaster_out; } zMasterPtr = &zMasterJournal[nMasterJournal]; @@ -2191,11 +2191,11 @@ ** to by zPathname, length nPathname. Or, if this is a temporary file, ** leave both nPathname and zPathname set to 0. */ if( zFilename && zFilename[0] ){ nPathname = pVfs->mxPathname+1; - zPathname = sqlite3_malloc(nPathname*2); + zPathname = sqlite3Malloc(nPathname*2); if( zPathname==0 ){ return SQLITE_NOMEM; } #ifndef SQLITE_OMIT_MEMORYDB if( strcmp(zFilename,":memory:")==0 ){ @@ -2419,11 +2419,11 @@ u16 pageSize = *pPageSize; assert( pageSize==0 || (pageSize>=512 && pageSize<=SQLITE_MAX_PAGE_SIZE) ); if( pageSize && pageSize!=pPager->pageSize && !pPager->memDb && pPager->nRef==0 ){ - char *pNew = (char *)sqlite3_malloc(pageSize); + char *pNew = (char *)sqlite3Malloc(pageSize); if( !pNew ){ rc = SQLITE_NOMEM; }else{ pagerEnter(pPager); pager_reset(pPager); @@ -3645,13 +3645,13 @@ } } pagerLeave(pPager); nByteHdr = sizeof(*pPg) + sizeof(u32) + pPager->nExtra + MEMDB*sizeof(PgHistory); - pPg = sqlite3_malloc( nByteHdr ); + pPg = sqlite3Malloc( nByteHdr ); if( pPg ){ - pData = sqlite3_malloc( pPager->pageSize ); + pData = sqlite3Malloc( pPager->pageSize ); if( pData==0 ){ sqlite3_free(pPg); pPg = 0; } } @@ -4221,11 +4221,11 @@ if( (int)pPg->pgno <= pPager->origDbSize ){ if( MEMDB ){ PgHistory *pHist = PGHDR_TO_HIST(pPg, pPager); PAGERTRACE3("JOURNAL %d page %d\n", PAGERID(pPager), pPg->pgno); assert( pHist->pOrig==0 ); - pHist->pOrig = sqlite3_malloc( pPager->pageSize ); + pHist->pOrig = sqlite3Malloc( pPager->pageSize ); if( !pHist->pOrig ){ return SQLITE_NOMEM; } memcpy(pHist->pOrig, PGHDR_TO_DATA(pPg), pPager->pageSize); }else{ @@ -4291,11 +4291,11 @@ ){ assert( pPg->inJournal || (int)pPg->pgno>pPager->origDbSize ); if( MEMDB ){ PgHistory *pHist = PGHDR_TO_HIST(pPg, pPager); assert( pHist->pStmt==0 ); - pHist->pStmt = sqlite3_malloc( pPager->pageSize ); + pHist->pStmt = sqlite3Malloc( pPager->pageSize ); if( pHist->pStmt ){ memcpy(pHist->pStmt, PGHDR_TO_DATA(pPg), pPager->pageSize); } PAGERTRACE3("STMT-JOURNAL %d page %d\n", PAGERID(pPager), pPg->pgno); page_add_to_stmt_list(pPg); Index: src/prepare.c ================================================================== --- src/prepare.c +++ src/prepare.c @@ -11,11 +11,11 @@ ************************************************************************* ** This file contains the implementation of the sqlite3_prepare() ** interface, and routines that contribute to loading the database schema ** from disk. ** -** $Id: prepare.c,v 1.86 2008/05/23 14:49:49 drh Exp $ +** $Id: prepare.c,v 1.87 2008/06/15 02:51:48 drh Exp $ */ #include "sqliteInt.h" #include /* @@ -446,11 +446,11 @@ int rc; BtCursor *curTemp; int cookie; int allOk = 1; - curTemp = (BtCursor *)sqlite3_malloc(sqlite3BtreeCursorSize()); + curTemp = (BtCursor *)sqlite3Malloc(sqlite3BtreeCursorSize()); if( curTemp ){ assert( sqlite3_mutex_held(db->mutex) ); for(iDb=0; allOk && iDbnDb; iDb++){ Btree *pBt; pBt = db->aDb[iDb].pBt; Index: src/printf.c ================================================================== --- src/printf.c +++ src/printf.c @@ -3,11 +3,11 @@ ** the public domain. The original comments are included here for ** completeness. They are very out-of-date but might be useful as ** an historical reference. Most of the "enhancements" have been backed ** out so that the functionality is now the same as standard printf(). ** -** $Id: printf.c,v 1.85 2008/05/16 04:51:55 danielk1977 Exp $ +** $Id: printf.c,v 1.86 2008/06/15 02:51:48 drh Exp $ ** ************************************************************************** ** ** The following modules is an enhanced replacement for the "printf" subroutines ** found in the standard C library. The following enhancements are @@ -648,11 +648,11 @@ if( ch==q ) n++; } needQuote = !isnull && xtype==etSQLESCAPE2; n += i + 1 + needQuote*2; if( n>etBUFSIZE ){ - bufpt = zExtra = sqlite3_malloc( n ); + bufpt = zExtra = sqlite3Malloc( n ); if( bufpt==0 ) return; }else{ bufpt = buf; } j = 0; @@ -750,11 +750,11 @@ return; } }else{ p->nAlloc = szNew; } - zNew = sqlite3_malloc( p->nAlloc ); + zNew = sqlite3Malloc( p->nAlloc ); if( zNew ){ memcpy(zNew, p->zText, p->nChar); sqlite3StrAccumReset(p); p->zText = zNew; }else{ @@ -775,11 +775,11 @@ */ char *sqlite3StrAccumFinish(StrAccum *p){ if( p->zText ){ p->zText[p->nChar] = 0; if( p->useMalloc && p->zText==p->zBase ){ - p->zText = sqlite3_malloc( p->nChar+1 ); + p->zText = sqlite3Malloc( p->nChar+1 ); if( p->zText ){ memcpy(p->zText, p->zBase, p->nChar+1); }else{ p->mallocFailed = 1; } Index: src/sqlite.h.in ================================================================== --- src/sqlite.h.in +++ src/sqlite.h.in @@ -28,11 +28,11 @@ ** The name of this file under configuration management is "sqlite.h.in". ** The makefile makes some minor changes to this file (such as inserting ** the version number) and changes its name to "sqlite3.h" as ** part of the build process. ** -** @(#) $Id: sqlite.h.in,v 1.327 2008/06/14 16:56:23 drh Exp $ +** @(#) $Id: sqlite.h.in,v 1.328 2008/06/15 02:51:48 drh Exp $ */ #ifndef _SQLITE3_H_ #define _SQLITE3_H_ #include /* Needed for the definition of va_list */ @@ -974,10 +974,18 @@ ** ** The xRoundup method returns what would be the allocated size of ** a memory allocation given a particular requested size. Most memory ** allocators round up memory allocations at least to the next multiple ** of 8. Some round up to a larger multiple or to a power of 2. +** +** The xTempMalloc and xTempFree methods are used to allocate a large +** chunk of temporary-use memory whose lifetime is a single procedure +** call. These routines may be the same as xMalloc and xFree, if desired, +** though some specialized applications may benefit from using a different +** allocation algorithm in this case. +** SQLite will never request more than one outstanding memory allocation +** per thread using xTempMalloc. ** ** The xInit method initializes the memory allocator. (For example, ** it might allocate any require mutexes or initialize internal data ** structures. The xShutdown method is invoked (indirectly) by ** [sqlite3_shutdown()] and should deallocate any resources acquired @@ -989,10 +997,12 @@ void *(*xMalloc)(int); /* Memory allocation function */ void (*xFree)(void*); /* Free a prior allocation */ void *(*xRealloc)(void*,int); /* Resize an allocation */ int (*xSize)(void*); /* Return the size of an allocation */ int (*xRoundup)(int); /* Round up request size to allocation size */ + void *(*xTempMalloc)(int); /* Allocate temporary space */ + void (*xTempFree)(void*); /* Free space from xTempMalloc */ int (*xInit)(void*); /* Initialize the memory allocator */ void (*xShutdown)(void*); /* Deinitialize the memory allocator */ void *pAppData; /* Argument to xInit() and xShutdown() */ }; Index: src/sqliteInt.h ================================================================== --- src/sqliteInt.h +++ src/sqliteInt.h @@ -9,11 +9,11 @@ ** May you share freely, never taking more than you give. ** ************************************************************************* ** Internal interface definitions for SQLite. ** -** @(#) $Id: sqliteInt.h,v 1.709 2008/06/14 16:56:23 drh Exp $ +** @(#) $Id: sqliteInt.h,v 1.710 2008/06/15 02:51:48 drh Exp $ */ #ifndef _SQLITEINT_H_ #define _SQLITEINT_H_ /* @@ -1789,10 +1789,12 @@ char *sqlite3DbStrNDup(sqlite3*,const char*, int); void *sqlite3Realloc(void*, int); void *sqlite3DbReallocOrFree(sqlite3 *, void *, int); void *sqlite3DbRealloc(sqlite3 *, void *, int); int sqlite3MallocSize(void *); +void *sqlite3TempMalloc(int); +void sqlite3TempFree(void*); void sqlite3MemSetDefault(void); int sqlite3IsNaN(double); char *sqlite3MPrintf(sqlite3*,const char*, ...); Index: src/tokenize.c ================================================================== --- src/tokenize.c +++ src/tokenize.c @@ -13,11 +13,11 @@ ** ** This file contains C code that splits an SQL input string up into ** individual tokens and sends those tokens one-by-one over to the ** parser for analysis. ** -** $Id: tokenize.c,v 1.143 2008/06/02 13:00:33 danielk1977 Exp $ +** $Id: tokenize.c,v 1.144 2008/06/15 02:51:48 drh Exp $ */ #include "sqliteInt.h" #include #include @@ -391,11 +391,11 @@ db->u1.isInterrupted = 0; } pParse->rc = SQLITE_OK; pParse->zTail = pParse->zSql = zSql; i = 0; - pEngine = sqlite3ParserAlloc((void*(*)(size_t))sqlite3_malloc); + pEngine = sqlite3ParserAlloc((void*(*)(size_t))sqlite3Malloc); if( pEngine==0 ){ db->mallocFailed = 1; return SQLITE_NOMEM; } assert( pParse->sLastToken.dyn==0 ); Index: src/vdbe.c ================================================================== --- src/vdbe.c +++ src/vdbe.c @@ -41,11 +41,11 @@ ** documentation, headers files, or other derived files. The formatting ** of the code in this file is, therefore, important. See other comments ** in this file for details. If in doubt, do not deviate from existing ** commenting and indentation practices when changing or adding code. ** -** $Id: vdbe.c,v 1.748 2008/06/07 08:58:22 danielk1977 Exp $ +** $Id: vdbe.c,v 1.749 2008/06/15 02:51:48 drh Exp $ */ #include "sqliteInt.h" #include #include "vdbeInt.h" @@ -3378,11 +3378,11 @@ pData->flags &= ~MEM_Dyn; pData->flags |= MEM_Ephem; pData->zMalloc = 0; } }else{ - pC->pData = sqlite3_malloc( pC->nData+2 ); + pC->pData = sqlite3Malloc( pC->nData+2 ); if( !pC->pData ) goto no_mem; memcpy(pC->pData, pData->z, pC->nData); pC->pData[pC->nData] = 0; pC->pData[pC->nData+1] = 0; } @@ -4138,11 +4138,11 @@ char *z; /* Text of the error report */ Mem *pnErr; /* Register keeping track of errors remaining */ nRoot = pOp->p2; assert( nRoot>0 ); - aRoot = sqlite3_malloc( sizeof(int)*(nRoot+1) ); + aRoot = sqlite3Malloc( sizeof(int)*(nRoot+1) ); if( aRoot==0 ) goto no_mem; assert( pOp->p3>0 && pOp->p3<=p->nMem ); pnErr = &p->aMem[pOp->p3]; assert( (pnErr->flags & MEM_Int)!=0 ); assert( (pnErr->flags & (MEM_Str|MEM_Blob))==0 ); Index: src/vdbeaux.c ================================================================== --- src/vdbeaux.c +++ src/vdbeaux.c @@ -12,11 +12,11 @@ ** This file contains code used for creating, destroying, and populating ** a VDBE (or an "sqlite3_stmt" as it is known to the outside world.) Prior ** to version 2.8.7, all this code was combined into the vdbe.c source file. ** But that file was getting too big so this subroutines were split out. ** -** $Id: vdbeaux.c,v 1.386 2008/06/06 15:04:37 drh Exp $ +** $Id: vdbeaux.c,v 1.387 2008/06/15 02:51:48 drh Exp $ */ #include "sqliteInt.h" #include #include "vdbeInt.h" @@ -545,11 +545,11 @@ KeyInfo *pKeyInfo; int nField, nByte; nField = ((KeyInfo*)zP4)->nField; nByte = sizeof(*pKeyInfo) + (nField-1)*sizeof(pKeyInfo->aColl[0]) + nField; - pKeyInfo = sqlite3_malloc( nByte ); + pKeyInfo = sqlite3Malloc( nByte ); pOp->p4.pKeyInfo = pKeyInfo; if( pKeyInfo ){ memcpy(pKeyInfo, zP4, nByte); /* In the current implementation, P4_KEYINFO is only ever used on ** KeyInfo structures that have no aSortOrder component. Elements Index: src/vdbefifo.c ================================================================== --- src/vdbefifo.c +++ src/vdbefifo.c @@ -10,11 +10,11 @@ ** ************************************************************************* ** This file implements a FIFO queue of rowids used for processing ** UPDATE and DELETE statements. ** -** $Id: vdbefifo.c,v 1.6 2008/05/16 04:51:55 danielk1977 Exp $ +** $Id: vdbefifo.c,v 1.7 2008/06/15 02:51:48 drh Exp $ */ #include "sqliteInt.h" #include "vdbeInt.h" /* @@ -36,11 +36,11 @@ static FifoPage *allocateFifoPage(int nEntry){ FifoPage *pPage; if( nEntry>FIFOSIZE_MAX ){ nEntry = FIFOSIZE_MAX; } - pPage = sqlite3_malloc( sizeof(FifoPage) + sizeof(i64)*(nEntry-1) ); + pPage = sqlite3Malloc( sizeof(FifoPage) + sizeof(i64)*(nEntry-1) ); if( pPage ){ pPage->nSlot = nEntry; pPage->iWrite = 0; pPage->iRead = 0; pPage->pNext = 0; Index: src/where.c ================================================================== --- src/where.c +++ src/where.c @@ -14,11 +14,11 @@ ** generating the code that loops through a table looking for applicable ** rows. Indices are selected and used to speed the search when doing ** so is applicable. Because this module is responsible for selecting ** indices, you might also think of this module as the "query optimizer". ** -** $Id: where.c,v 1.308 2008/06/12 00:07:29 drh Exp $ +** $Id: where.c,v 1.309 2008/06/15 02:51:48 drh Exp $ */ #include "sqliteInt.h" /* ** The number of bits in a Bitmask. "BMS" means "BitMask Size". @@ -226,11 +226,11 @@ static int whereClauseInsert(WhereClause *pWC, Expr *p, int flags){ WhereTerm *pTerm; int idx; if( pWC->nTerm>=pWC->nSlot ){ WhereTerm *pOld = pWC->a; - pWC->a = sqlite3_malloc( sizeof(pWC->a[0])*pWC->nSlot*2 ); + pWC->a = sqlite3Malloc( sizeof(pWC->a[0])*pWC->nSlot*2 ); if( pWC->a==0 ){ pWC->pParse->db->mallocFailed = 1; if( flags & TERM_DYNAMIC ){ sqlite3ExprDelete(p); }