This commit is contained in:
Hongze Cheng 2022-02-21 09:11:34 +00:00
parent 7184778c28
commit a581d9b356
6 changed files with 441 additions and 370 deletions

View File

@ -391,7 +391,7 @@ static int setSharedCacheTableLock(Btree *p, Pgno iTable, u8 eLock){
if( !pLock ){
pLock = (BtLock *)sqlite3MallocZero(sizeof(BtLock));
if( !pLock ){
return SQLITE_NOMEM_BKPT;
return SQLITE_NOMEM;
}
pLock->iTable = iTable;
pLock->pBtree = p;
@ -606,7 +606,7 @@ static int btreeSetHasContent(BtShared *pBt, Pgno pgno){
assert( pgno<=pBt->nPage );
pBt->pHasContent = sqlite3BitvecCreate(pBt->nPage);
if( !pBt->pHasContent ){
rc = SQLITE_NOMEM_BKPT;
rc = SQLITE_NOMEM;
}
}
if( rc==SQLITE_OK && pgno<=sqlite3BitvecSize(pBt->pHasContent) ){
@ -691,7 +691,7 @@ static int saveCursorKey(BtCursor *pCur){
sqlite3_free(pKey);
}
}else{
rc = SQLITE_NOMEM_BKPT;
rc = SQLITE_NOMEM;
}
}
assert( !pCur->curIntKey || !pCur->pKey );
@ -823,7 +823,7 @@ static int btreeMoveto(
KeyInfo *pKeyInfo = pCur->pKeyInfo;
assert( nKey==(i64)(int)nKey );
pIdxKey = sqlite3VdbeAllocUnpackedRecord(pKeyInfo);
if( pIdxKey==0 ) return SQLITE_NOMEM_BKPT;
if( pIdxKey==0 ) return SQLITE_NOMEM;
sqlite3VdbeRecordUnpack(pKeyInfo, (int)nKey, pKey, pIdxKey);
if( pIdxKey->nField==0 || pIdxKey->nField>pKeyInfo->nAllField ){
rc = SQLITE_CORRUPT_BKPT;
@ -2404,7 +2404,7 @@ int sqlite3BtreeOpen(
}
p = sqlite3MallocZero(sizeof(Btree));
if( !p ){
return SQLITE_NOMEM_BKPT;
return SQLITE_NOMEM;
}
p->inTrans = TRANS_NONE;
p->db = db;
@ -2428,7 +2428,7 @@ int sqlite3BtreeOpen(
p->sharable = 1;
if( !zFullPathname ){
sqlite3_free(p);
return SQLITE_NOMEM_BKPT;
return SQLITE_NOMEM;
}
if( isMemdb ){
memcpy(zFullPathname, zFilename, nFilename);
@ -2500,7 +2500,7 @@ int sqlite3BtreeOpen(
pBt = sqlite3MallocZero( sizeof(*pBt) );
if( pBt==0 ){
rc = SQLITE_NOMEM_BKPT;
rc = SQLITE_NOMEM;
goto btree_open_out;
}
rc = sqlite3PagerOpen(pVfs, &pBt->pPager, zFilename,
@ -2571,7 +2571,7 @@ int sqlite3BtreeOpen(
if( SQLITE_THREADSAFE && sqlite3GlobalConfig.bCoreMutex ){
pBt->mutex = sqlite3MutexAlloc(SQLITE_MUTEX_FAST);
if( pBt->mutex==0 ){
rc = SQLITE_NOMEM_BKPT;
rc = SQLITE_NOMEM;
goto btree_open_out;
}
}
@ -4459,7 +4459,7 @@ static int btreeCursor(
if( wrFlag ){
allocateTempSpace(pBt);
if( pBt->pTmpSpace==0 ) return SQLITE_NOMEM_BKPT;
if( pBt->pTmpSpace==0 ) return SQLITE_NOMEM;
}
if( iTable<=1 ){
if( iTable<1 ){
@ -4919,7 +4919,7 @@ static int accessPayload(
pCur->aOverflow, nOvfl*2*sizeof(Pgno)
);
if( aNew==0 ){
return SQLITE_NOMEM_BKPT;
return SQLITE_NOMEM;
}else{
pCur->aOverflow = aNew;
}
@ -5746,7 +5746,7 @@ int sqlite3BtreeIndexMoveto(
}
pCellKey = sqlite3Malloc( nCell+nOverrun );
if( pCellKey==0 ){
rc = SQLITE_NOMEM_BKPT;
rc = SQLITE_NOMEM;
goto moveto_index_finish;
}
pCur->ix = (u16)idx;
@ -7721,7 +7721,7 @@ static int balance_nonroot(
assert( pParent->nOverflow==0 || pParent->aiOvfl[0]==iParentIdx );
if( !aOvflSpace ){
return SQLITE_NOMEM_BKPT;
return SQLITE_NOMEM;
}
assert( pParent->nFree>=0 );
@ -7827,7 +7827,7 @@ static int balance_nonroot(
assert( szScratch<=7*(int)pBt->pageSize );
b.apCell = sqlite3StackAllocRaw(0, szScratch );
if( b.apCell==0 ){
rc = SQLITE_NOMEM_BKPT;
rc = SQLITE_NOMEM;
goto balance_cleanup;
}
b.szCell = (u16*)&b.apCell[nMaxCells];

View File

@ -2499,7 +2499,7 @@ static int pager_delsuper(Pager *pPager, const char *zSuper){
*/
pSuper = (sqlite3_file *)sqlite3MallocZero(pVfs->szOsFile * 2);
if( !pSuper ){
rc = SQLITE_NOMEM_BKPT;
rc = SQLITE_NOMEM;
pJournal = 0;
}else{
const int flags = (SQLITE_OPEN_READONLY|SQLITE_OPEN_SUPER_JOURNAL);
@ -2518,7 +2518,7 @@ static int pager_delsuper(Pager *pPager, const char *zSuper){
nSuperPtr = pVfs->mxPathname+1;
zFree = sqlite3Malloc(4 + nSuperJournal + nSuperPtr + 2);
if( !zFree ){
rc = SQLITE_NOMEM_BKPT;
rc = SQLITE_NOMEM;
goto delsuper_out;
}
zFree[0] = zFree[1] = zFree[2] = zFree[3] = 0;
@ -3358,7 +3358,7 @@ static int pagerPlaybackSavepoint(Pager *pPager, PagerSavepoint *pSavepoint){
if( pSavepoint ){
pDone = sqlite3BitvecCreate(pSavepoint->nOrig);
if( !pDone ){
return SQLITE_NOMEM_BKPT;
return SQLITE_NOMEM;
}
}
@ -3725,7 +3725,7 @@ int sqlite3PagerSetPagesize(Pager *pPager, u32 *pPageSize, int nReserve){
* cell header parser will never run off the end of the allocation */
pNew = (char *)sqlite3PageMalloc(pageSize+8);
if( !pNew ){
rc = SQLITE_NOMEM_BKPT;
rc = SQLITE_NOMEM;
}else{
memset(pNew+pageSize, 0, 8);
}
@ -4009,7 +4009,7 @@ static int pagerAcquireMapPage(
*ppPage = p = (PgHdr *)sqlite3MallocZero(sizeof(PgHdr) + pPager->nExtra);
if( p==0 ){
sqlite3OsUnfetch(pPager->fd, (i64)(pgno-1) * pPager->pageSize, pData);
return SQLITE_NOMEM_BKPT;
return SQLITE_NOMEM;
}
p->pExtra = (void *)&p[1];
p->flags = PGHDR_MMAP;
@ -4695,7 +4695,7 @@ int sqlite3PagerOpen(
memDb = 1;
if( zFilename && zFilename[0] ){
zPathname = sqlite3DbStrDup(0, zFilename);
if( zPathname==0 ) return SQLITE_NOMEM_BKPT;
if( zPathname==0 ) return SQLITE_NOMEM;
nPathname = sqlite3Strlen30(zPathname);
zFilename = 0;
}
@ -4711,7 +4711,7 @@ int sqlite3PagerOpen(
nPathname = pVfs->mxPathname+1;
zPathname = sqlite3DbMallocRaw(0, nPathname*2);
if( zPathname==0 ){
return SQLITE_NOMEM_BKPT;
return SQLITE_NOMEM;
}
zPathname[0] = 0; /* Make sure initialized even if FullPathname() fails */
rc = sqlite3OsFullPathname(pVfs, zFilename, nPathname, zPathname);
@ -4810,7 +4810,7 @@ int sqlite3PagerOpen(
assert( EIGHT_BYTE_ALIGNMENT(SQLITE_INT_TO_PTR(journalFileSize)) );
if( !pPtr ){
sqlite3DbFree(0, zPathname);
return SQLITE_NOMEM_BKPT;
return SQLITE_NOMEM;
}
pPager = (Pager*)pPtr; pPtr += ROUND8(sizeof(*pPager));
pPager->pPCache = (PCache*)pPtr; pPtr += ROUND8(pcacheSize);
@ -5490,7 +5490,7 @@ static int getPageNormal(
rc = sqlite3PcacheFetchStress(pPager->pPCache, pgno, &pBase);
if( rc!=SQLITE_OK ) goto pager_acquire_err;
if( pBase==0 ){
rc = SQLITE_NOMEM_BKPT;
rc = SQLITE_NOMEM;
goto pager_acquire_err;
}
}
@ -5760,7 +5760,7 @@ static int pager_open_journal(Pager *pPager){
if( !pagerUseWal(pPager) && pPager->journalMode!=PAGER_JOURNALMODE_OFF ){
pPager->pInJournal = sqlite3BitvecCreate(pPager->dbSize);
if( pPager->pInJournal==0 ){
return SQLITE_NOMEM_BKPT;
return SQLITE_NOMEM;
}
/* Open the journal file if it is not already open. */
@ -6841,7 +6841,7 @@ static SQLITE_NOINLINE int pagerOpenSavepoint(Pager *pPager, int nSavepoint){
pPager->aSavepoint, sizeof(PagerSavepoint)*nSavepoint
);
if( !aNew ){
return SQLITE_NOMEM_BKPT;
return SQLITE_NOMEM;
}
memset(&aNew[nCurrent], 0, (nSavepoint-nCurrent) * sizeof(PagerSavepoint));
pPager->aSavepoint = aNew;
@ -6858,7 +6858,7 @@ static SQLITE_NOINLINE int pagerOpenSavepoint(Pager *pPager, int nSavepoint){
aNew[ii].pInSavepoint = sqlite3BitvecCreate(pPager->dbSize);
aNew[ii].bTruncateOnRelease = 1;
if( !aNew[ii].pInSavepoint ){
return SQLITE_NOMEM_BKPT;
return SQLITE_NOMEM;
}
if( pagerUseWal(pPager) ){
sqlite3WalSavepoint(pPager->pWal, aNew[ii].aWalData);

View File

@ -65,7 +65,10 @@ struct PCache {
#if defined(SQLITE_DEBUG) && 0
int sqlite3PcacheTrace = 2; /* 0: off 1: simple 2: cache dumps */
int sqlite3PcacheMxDump = 9999; /* Max cache entries for pcacheDump() */
# define pcacheTrace(X) if(sqlite3PcacheTrace){sqlite3DebugPrintf X;}
#define pcacheTrace(X) \
if (sqlite3PcacheTrace) { \
sqlite3DebugPrintf X; \
}
void pcacheDump(PCache *pCache) {
int N;
int i, j;
@ -95,52 +98,51 @@ struct PCache {
#define pcacheDump(X)
#endif
/*
** Check invariants on a PgHdr entry. Return true if everything is OK.
** Return false if any invariant is violated.
**
** This routine is for use inside of assert() statements only. For
** example:
**
** assert( sqlite3PcachePageSanity(pPg) );
*/
#ifdef SQLITE_DEBUG
int sqlite3PcachePageSanity(PgHdr *pPg){
PCache *pCache;
assert( pPg!=0 );
assert( pPg->pgno>0 || pPg->pPager==0 ); /* Page number is 1 or more */
pCache = pPg->pCache;
assert( pCache!=0 ); /* Every page has an associated PCache */
if( pPg->flags & PGHDR_CLEAN ){
assert( (pPg->flags & PGHDR_DIRTY)==0 );/* Cannot be both CLEAN and DIRTY */
assert( pCache->pDirty!=pPg ); /* CLEAN pages not on dirty list */
assert( pCache->pDirtyTail!=pPg );
}
/* WRITEABLE pages must also be DIRTY */
if( pPg->flags & PGHDR_WRITEABLE ){
assert( pPg->flags & PGHDR_DIRTY ); /* WRITEABLE implies DIRTY */
}
/* NEED_SYNC can be set independently of WRITEABLE. This can happen,
** for example, when using the sqlite3PagerDontWrite() optimization:
** (1) Page X is journalled, and gets WRITEABLE and NEED_SEEK.
** (2) Page X moved to freelist, WRITEABLE is cleared
** (3) Page X reused, WRITEABLE is set again
** If NEED_SYNC had been cleared in step 2, then it would not be reset
** in step 3, and page might be written into the database without first
** syncing the rollback journal, which might cause corruption on a power
** loss.
**
** Another example is when the database page size is smaller than the
** disk sector size. When any page of a sector is journalled, all pages
** in that sector are marked NEED_SYNC even if they are still CLEAN, just
** in case they are later modified, since all pages in the same sector
** must be journalled and synced before any of those pages can be safely
** written.
*/
return 1;
}
#endif /* SQLITE_DEBUG */
// /*
// ** Check invariants on a PgHdr entry. Return true if everything is OK.
// ** Return false if any invariant is violated.
// **
// ** This routine is for use inside of assert() statements only. For
// ** example:
// **
// ** assert( sqlite3PcachePageSanity(pPg) );
// */
// #ifdef SQLITE_DEBUG
// int sqlite3PcachePageSanity(PgHdr *pPg) {
// PCache *pCache;
// assert(pPg != 0);
// assert(pPg->pgno > 0 || pPg->pPager == 0); /* Page number is 1 or more */
// pCache = pPg->pCache;
// assert(pCache != 0); /* Every page has an associated PCache */
// if (pPg->flags & PGHDR_CLEAN) {
// assert((pPg->flags & PGHDR_DIRTY) == 0); /* Cannot be both CLEAN and DIRTY */
// assert(pCache->pDirty != pPg); /* CLEAN pages not on dirty list */
// assert(pCache->pDirtyTail != pPg);
// }
// /* WRITEABLE pages must also be DIRTY */
// if (pPg->flags & PGHDR_WRITEABLE) {
// assert(pPg->flags & PGHDR_DIRTY); /* WRITEABLE implies DIRTY */
// }
// /* NEED_SYNC can be set independently of WRITEABLE. This can happen,
// ** for example, when using the sqlite3PagerDontWrite() optimization:
// ** (1) Page X is journalled, and gets WRITEABLE and NEED_SEEK.
// ** (2) Page X moved to freelist, WRITEABLE is cleared
// ** (3) Page X reused, WRITEABLE is set again
// ** If NEED_SYNC had been cleared in step 2, then it would not be reset
// ** in step 3, and page might be written into the database without first
// ** syncing the rollback journal, which might cause corruption on a power
// ** loss.
// **
// ** Another example is when the database page size is smaller than the
// ** disk sector size. When any page of a sector is journalled, all pages
// ** in that sector are marked NEED_SYNC even if they are still CLEAN, just
// ** in case they are later modified, since all pages in the same sector
// ** must be journalled and synced before any of those pages can be safely
// ** written.
// */
// return 1;
// }
// #endif /* SQLITE_DEBUG */
/********************************** Linked List Management ********************/
@ -158,9 +160,7 @@ int sqlite3PcachePageSanity(PgHdr *pPg){
static void pcacheManageDirtyList(PgHdr *pPage, u8 addRemove) {
PCache *p = pPage->pCache;
pcacheTrace(("%p.DIRTYLIST.%s %d\n", p,
addRemove==1 ? "REMOVE" : addRemove==2 ? "ADD" : "FRONT",
pPage->pgno));
pcacheTrace(("%p.DIRTYLIST.%s %d\n", p, addRemove == 1 ? "REMOVE" : addRemove == 2 ? "ADD" : "FRONT", pPage->pgno));
if (addRemove & PCACHE_DIRTYLIST_REMOVE) {
assert(pPage->pDirtyNext || pPage == p->pDirtyTail);
assert(pPage->pDirtyPrev || pPage == p->pDirty);
@ -212,8 +212,7 @@ static void pcacheManageDirtyList(PgHdr *pPage, u8 addRemove){
** optimization, as if pSynced points to a page with the NEED_SYNC
** flag set sqlite3PcacheFetchStress() searches through all newer
** entries of the dirty-list for a page with NEED_SYNC clear anyway. */
if( !p->pSynced
&& 0==(pPage->flags&PGHDR_NEED_SYNC) /*OPTIMIZATION-IF-FALSE*/
if (!p->pSynced && 0 == (pPage->flags & PGHDR_NEED_SYNC) /*OPTIMIZATION-IF-FALSE*/
) {
p->pSynced = pPage;
}
@ -259,9 +258,7 @@ static int numberOfCachePages(PCache *p){
** Initialize and shutdown the page cache subsystem. Neither of these
** functions are threadsafe.
*/
int sqlite3PcacheInitialize(void){
return pcache2.xInit(pcache2.pArg);
}
int sqlite3PcacheInitialize(void) { return pcache2.xInit(pcache2.pArg); }
void sqlite3PcacheShutdown(void) {
if (pcache2.xShutdown) {
/* IMPLEMENTATION-OF: R-26000-56589 The xShutdown() method may be NULL. */
@ -286,8 +283,7 @@ int sqlite3PcacheSize(void){ return sizeof(PCache); }
** to this module, the extra space really ends up being the MemPage
** structure in the pager.
*/
int sqlite3PcacheOpen(
int szPage, /* Size of every page */
int sqlite3PcacheOpen(int szPage, /* Size of every page */
int szExtra, /* Extra space associated with each page */
int bPurgeable, /* True if pages are on backing store */
int (*xStress)(void *, PgHdr *), /* Call to try to make pages clean */
@ -316,11 +312,8 @@ int sqlite3PcacheSetPageSize(PCache *pCache, int szPage){
assert(pCache->nRefSum == 0 && pCache->pDirty == 0);
if (pCache->szPage) {
sqlite3_pcache *pNew;
pNew = pcache2.xCreate(
szPage, pCache->szExtra + ROUND8(sizeof(PgHdr)),
pCache->bPurgeable
);
if( pNew==0 ) return SQLITE_NOMEM_BKPT;
pNew = pcache2.xCreate(szPage, pCache->szExtra + ROUND8(sizeof(PgHdr)), pCache->bPurgeable);
if (pNew == 0) return SQLITE_NOMEM;
pcache2.xCachesize(pNew, numberOfCachePages(pCache));
if (pCache->pCache) {
pcache2.xDestroy(pCache->pCache);
@ -356,8 +349,7 @@ int sqlite3PcacheSetPageSize(PCache *pCache, int szPage){
** the stack on entry and pop them back off on exit, which saves a
** lot of pushing and popping.
*/
sqlite3_pcache_page *sqlite3PcacheFetch(
PCache *pCache, /* Obtain the page from this cache */
sqlite3_pcache_page *sqlite3PcacheFetch(PCache *pCache, /* Obtain the page from this cache */
Pgno pgno, /* Page number to obtain */
int createFlag /* If true, create page if it does not exist already */
) {
@ -381,8 +373,7 @@ sqlite3_pcache_page *sqlite3PcacheFetch(
assert(createFlag == 0 || pCache->eCreate == eCreate);
assert(createFlag == 0 || eCreate == 1 + (!pCache->bPurgeable || !pCache->pDirty));
pRes = pcache2.xFetch(pCache->pCache, pgno, eCreate);
pcacheTrace(("%p.FETCH %d%s (result: %p)\n",pCache,pgno,
createFlag?" create":"",pRes));
pcacheTrace(("%p.FETCH %d%s (result: %p)\n", pCache, pgno, createFlag ? " create" : "", pRes));
return pRes;
}
@ -397,8 +388,7 @@ sqlite3_pcache_page *sqlite3PcacheFetch(
**
** This routine should be invoked only after sqlite3PcacheFetch() fails.
*/
int sqlite3PcacheFetchStress(
PCache *pCache, /* Obtain the page from this cache */
int sqlite3PcacheFetchStress(PCache * pCache, /* Obtain the page from this cache */
Pgno pgno, /* Page number to obtain */
sqlite3_pcache_page **ppPage /* Write result here */
) {
@ -415,22 +405,18 @@ int sqlite3PcacheFetchStress(
** flag is currently referenced, then the following may leave pSynced
** set incorrectly (pointing to other than the LRU page with NEED_SYNC
** cleared). This is Ok, as pSynced is just an optimization. */
for(pPg=pCache->pSynced;
pPg && (pPg->nRef || (pPg->flags&PGHDR_NEED_SYNC));
pPg=pPg->pDirtyPrev
);
for (pPg = pCache->pSynced; pPg && (pPg->nRef || (pPg->flags & PGHDR_NEED_SYNC)); pPg = pPg->pDirtyPrev)
;
pCache->pSynced = pPg;
if (!pPg) {
for(pPg=pCache->pDirtyTail; pPg && pPg->nRef; pPg=pPg->pDirtyPrev);
for (pPg = pCache->pDirtyTail; pPg && pPg->nRef; pPg = pPg->pDirtyPrev)
;
}
if (pPg) {
int rc;
#ifdef SQLITE_LOG_CACHE_SPILL
sqlite3_log(SQLITE_FULL,
"spill page %d making room for %d - cache used: %d/%d",
pPg->pgno, pgno,
pcache2.xPagecount(pCache->pCache),
numberOfCachePages(pCache));
sqlite3_log(SQLITE_FULL, "spill page %d making room for %d - cache used: %d/%d", pPg->pgno, pgno,
pcache2.xPagecount(pCache->pCache), numberOfCachePages(pCache));
#endif
pcacheTrace(("%p.SPILL %d\n", pCache, pPg->pgno));
rc = pCache->xStress(pCache->pStress, pPg);
@ -441,7 +427,7 @@ int sqlite3PcacheFetchStress(
}
}
*ppPage = pcache2.xFetch(pCache->pCache, pgno, 2);
return *ppPage==0 ? SQLITE_NOMEM_BKPT : 0;
return *ppPage == 0 ? SQLITE_NOMEM : 0;
}
/*
@ -453,8 +439,7 @@ int sqlite3PcacheFetchStress(
** requires extra stack manipulation that can be avoided in the common
** case.
*/
static SQLITE_NOINLINE PgHdr *pcacheFetchFinishWithInit(
PCache *pCache, /* Obtain the page from this cache */
static PgHdr *pcacheFetchFinishWithInit(PCache * pCache, /* Obtain the page from this cache */
Pgno pgno, /* Page number obtained */
sqlite3_pcache_page *pPage /* Page obtained by prior PcacheFetch() call */
) {
@ -479,8 +464,7 @@ static SQLITE_NOINLINE PgHdr *pcacheFetchFinishWithInit(
** must be called after sqlite3PcacheFetch() in order to get a usable
** result.
*/
PgHdr *sqlite3PcacheFetchFinish(
PCache *pCache, /* Obtain the page from this cache */
PgHdr *sqlite3PcacheFetchFinish(PCache * pCache, /* Obtain the page from this cache */
Pgno pgno, /* Page number obtained */
sqlite3_pcache_page *pPage /* Page obtained by prior PcacheFetch() call */
) {
@ -494,7 +478,7 @@ PgHdr *sqlite3PcacheFetchFinish(
}
pCache->nRefSum++;
pPgHdr->nRef++;
assert( sqlite3PcachePageSanity(pPgHdr) );
// assert(sqlite3PcachePageSanity(pPgHdr));
return pPgHdr;
}
@ -502,7 +486,7 @@ PgHdr *sqlite3PcacheFetchFinish(
** Decrement the reference count on a page. If the page is clean and the
** reference count drops to 0, then it is made eligible for recycling.
*/
void SQLITE_NOINLINE sqlite3PcacheRelease(PgHdr *p){
void sqlite3PcacheRelease(PgHdr *p) {
assert(p->nRef > 0);
p->pCache->nRefSum--;
if ((--p->nRef) == 0) {
@ -519,7 +503,7 @@ void SQLITE_NOINLINE sqlite3PcacheRelease(PgHdr *p){
*/
void sqlite3PcacheRef(PgHdr *p) {
assert(p->nRef > 0);
assert( sqlite3PcachePageSanity(p) );
// assert(sqlite3PcachePageSanity(p));
p->nRef++;
p->pCache->nRefSum++;
}
@ -531,7 +515,7 @@ void sqlite3PcacheRef(PgHdr *p){
*/
void sqlite3PcacheDrop(PgHdr *p) {
assert(p->nRef == 1);
assert( sqlite3PcachePageSanity(p) );
// assert(sqlite3PcachePageSanity(p));
if (p->flags & PGHDR_DIRTY) {
pcacheManageDirtyList(p, PCACHE_DIRTYLIST_REMOVE);
}
@ -545,7 +529,7 @@ void sqlite3PcacheDrop(PgHdr *p){
*/
void sqlite3PcacheMakeDirty(PgHdr *p) {
assert(p->nRef > 0);
assert( sqlite3PcachePageSanity(p) );
// assert(sqlite3PcachePageSanity(p));
if (p->flags & (PGHDR_CLEAN | PGHDR_DONT_WRITE)) { /*OPTIMIZATION-IF-FALSE*/
p->flags &= ~PGHDR_DONT_WRITE;
if (p->flags & PGHDR_CLEAN) {
@ -554,7 +538,7 @@ void sqlite3PcacheMakeDirty(PgHdr *p){
assert((p->flags & (PGHDR_DIRTY | PGHDR_CLEAN)) == PGHDR_DIRTY);
pcacheManageDirtyList(p, PCACHE_DIRTYLIST_ADD);
}
assert( sqlite3PcachePageSanity(p) );
// assert(sqlite3PcachePageSanity(p));
}
}
@ -563,14 +547,14 @@ void sqlite3PcacheMakeDirty(PgHdr *p){
** make it so.
*/
void sqlite3PcacheMakeClean(PgHdr *p) {
assert( sqlite3PcachePageSanity(p) );
// assert(sqlite3PcachePageSanity(p));
assert((p->flags & PGHDR_DIRTY) != 0);
assert((p->flags & PGHDR_CLEAN) == 0);
pcacheManageDirtyList(p, PCACHE_DIRTYLIST_REMOVE);
p->flags &= ~(PGHDR_DIRTY | PGHDR_NEED_SYNC | PGHDR_WRITEABLE);
p->flags |= PGHDR_CLEAN;
pcacheTrace(("%p.CLEAN %d\n", p->pCache, p->pgno));
assert( sqlite3PcachePageSanity(p) );
// assert(sqlite3PcachePageSanity(p));
if (p->nRef == 0) {
pcacheUnpin(p);
}
@ -617,7 +601,7 @@ void sqlite3PcacheMove(PgHdr *p, Pgno newPgno){
PCache *pCache = p->pCache;
assert(p->nRef > 0);
assert(newPgno > 0);
assert( sqlite3PcachePageSanity(p) );
// assert(sqlite3PcachePageSanity(p));
pcacheTrace(("%p.MOVE %d -> %d\n", pCache, p->pgno, newPgno));
pcache2.xRekey(pCache->pCache, p->pPage, p->pgno, newPgno);
p->pgno = newPgno;
@ -677,9 +661,7 @@ void sqlite3PcacheClose(PCache *pCache){
/*
** Discard the contents of the cache.
*/
void sqlite3PcacheClear(PCache *pCache){
sqlite3PcacheTruncate(pCache, 0);
}
void sqlite3PcacheClear(PCache *pCache) { sqlite3PcacheTruncate(pCache, 0); }
/*
** Merge two lists of pages connected by pDirty and in pgno order.
@ -771,16 +753,12 @@ PgHdr *sqlite3PcacheDirtyList(PCache *pCache){
** This is not the total number of pages referenced, but the sum of the
** reference count for all pages.
*/
int sqlite3PcacheRefCount(PCache *pCache){
return pCache->nRefSum;
}
int sqlite3PcacheRefCount(PCache *pCache) { return pCache->nRefSum; }
/*
** Return the number of references to the page supplied as an argument.
*/
int sqlite3PcachePageRefcount(PgHdr *p){
return p->nRef;
}
int sqlite3PcachePageRefcount(PgHdr *p) { return p->nRef; }
/*
** Return the total number of pages in the cache.
@ -794,9 +772,7 @@ int sqlite3PcachePagecount(PCache *pCache){
/*
** Get the suggested cache-size value.
*/
int sqlite3PcacheGetCachesize(PCache *pCache){
return numberOfCachePages(pCache);
}
int sqlite3PcacheGetCachesize(PCache *pCache) { return numberOfCachePages(pCache); }
#endif
/*
@ -805,8 +781,7 @@ int sqlite3PcacheGetCachesize(PCache *pCache){
void sqlite3PcacheSetCachesize(PCache *pCache, int mxPage) {
assert(pCache->pCache != 0);
pCache->szCache = mxPage;
pcache2.xCachesize(pCache->pCache,
numberOfCachePages(pCache));
pcache2.xCachesize(pCache->pCache, numberOfCachePages(pCache));
}
/*
@ -858,9 +833,7 @@ int sqlite3PCachePercentDirty(PCache *pCache){
/*
** Return true if there are one or more dirty pages in the cache. Else false.
*/
int sqlite3PCacheIsDirty(PCache *pCache){
return (pCache->pDirty!=0);
}
int sqlite3PCacheIsDirty(PCache *pCache) { return (pCache->pDirty != 0); }
#endif
#if defined(SQLITE_CHECK_PAGES) || defined(SQLITE_DEBUG)

View File

@ -642,7 +642,7 @@ static SQLITE_NOINLINE int walIndexPageRealloc(
apNew = (volatile u32 **)sqlite3Realloc((void *)pWal->apWiData, nByte);
if( !apNew ){
*ppPage = 0;
return SQLITE_NOMEM_BKPT;
return SQLITE_NOMEM;
}
memset((void*)&apNew[pWal->nWiData], 0,
sizeof(u32*)*(iPage+1-pWal->nWiData));
@ -654,7 +654,7 @@ static SQLITE_NOINLINE int walIndexPageRealloc(
assert( pWal->apWiData[iPage]==0 );
if( pWal->exclusiveMode==WAL_HEAPMEMORY_MODE ){
pWal->apWiData[iPage] = (u32 volatile *)sqlite3MallocZero(WALINDEX_PGSZ);
if( !pWal->apWiData[iPage] ) rc = SQLITE_NOMEM_BKPT;
if( !pWal->apWiData[iPage] ) rc = SQLITE_NOMEM;
}else{
rc = sqlite3OsShmMap(pWal->pDbFd, iPage, WALINDEX_PGSZ,
pWal->writeLock, (void volatile **)&pWal->apWiData[iPage]
@ -1310,7 +1310,7 @@ static int walIndexRecover(Wal *pWal){
szFrame = szPage + WAL_FRAME_HDRSIZE;
aFrame = (u8 *)sqlite3_malloc64(szFrame + WALINDEX_PGSZ);
if( !aFrame ){
rc = SQLITE_NOMEM_BKPT;
rc = SQLITE_NOMEM;
goto recovery_error;
}
aData = &aFrame[WAL_FRAME_HDRSIZE];
@ -1534,7 +1534,7 @@ int sqlite3WalOpen(
*ppWal = 0;
pRet = (Wal*)sqlite3MallocZero(sizeof(Wal) + pVfs->szOsFile);
if( !pRet ){
return SQLITE_NOMEM_BKPT;
return SQLITE_NOMEM;
}
pRet->pVfs = pVfs;
@ -1799,7 +1799,7 @@ static int walIteratorInit(Wal *pWal, u32 nBackfill, WalIterator **pp){
+ iLast*sizeof(ht_slot);
p = (WalIterator *)sqlite3_malloc64(nByte);
if( !p ){
return SQLITE_NOMEM_BKPT;
return SQLITE_NOMEM;
}
memset(p, 0, nByte);
p->nSegment = nSegment;
@ -1811,7 +1811,7 @@ static int walIteratorInit(Wal *pWal, u32 nBackfill, WalIterator **pp){
sizeof(ht_slot) * (iLast>HASHTABLE_NPAGE?HASHTABLE_NPAGE:iLast)
);
if( !aTmp ){
rc = SQLITE_NOMEM_BKPT;
rc = SQLITE_NOMEM;
}
for(i=walFramePage(nBackfill+1); rc==SQLITE_OK && i<nSegment; i++){
@ -2129,7 +2129,7 @@ static int walCheckpoint(
i64 iOffset;
assert( walFramePgno(pWal, iFrame)==iDbpage );
if( AtomicLoad(&db->u1.isInterrupted) ){
rc = db->mallocFailed ? SQLITE_NOMEM_BKPT : SQLITE_INTERRUPT;
rc = db->mallocFailed ? SQLITE_NOMEM : SQLITE_INTERRUPT;
break;
}
if( iFrame<=nBackfill || iFrame>mxSafeFrame || iDbpage>mxPage ){
@ -2606,7 +2606,7 @@ static int walBeginShmUnreliable(Wal *pWal, int *pChanged){
szFrame = pWal->hdr.szPage + WAL_FRAME_HDRSIZE;
aFrame = (u8 *)sqlite3_malloc64(szFrame);
if( aFrame==0 ){
rc = SQLITE_NOMEM_BKPT;
rc = SQLITE_NOMEM;
goto begin_unreliable_shm_out;
}
aData = &aFrame[WAL_FRAME_HDRSIZE];
@ -3559,7 +3559,7 @@ static int walRewriteChecksums(Wal *pWal, u32 iLast){
i64 iCksumOff;
aBuf = sqlite3_malloc(szPage + WAL_FRAME_HDRSIZE);
if( aBuf==0 ) return SQLITE_NOMEM_BKPT;
if( aBuf==0 ) return SQLITE_NOMEM;
/* Find the checksum values to use as input for the recalculating the
** first checksum. If the first frame is frame 1 (implying that the current
@ -4059,7 +4059,7 @@ int sqlite3WalSnapshotGet(Wal *pWal, sqlite3_snapshot **ppSnapshot){
}
pRet = (WalIndexHdr*)sqlite3_malloc(sizeof(WalIndexHdr));
if( pRet==0 ){
rc = SQLITE_NOMEM_BKPT;
rc = SQLITE_NOMEM;
}else{
memcpy(pRet, &pWal->hdr, sizeof(WalIndexHdr));
*ppSnapshot = (sqlite3_snapshot*)pRet;

View File

@ -0,0 +1,95 @@
/*
** 2001-09-15
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** 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.
**
*************************************************************************
** This header file defines the interface that the SQLite library
** presents to client programs. If a C-function, structure, datatype,
** or constant definition does not appear in this file, then it is
** not a published API of SQLite, is subject to change without
** notice, and should not be referenced by programs that use SQLite.
**
** Some of the definitions that are in this file are marked as
** "experimental". Experimental interfaces are normally new
** features recently added to SQLite. We do not anticipate changes
** to experimental interfaces but reserve the right to make minor changes
** if experience from use "in the wild" suggest such changes are prudent.
**
** The official C-language API documentation for SQLite is derived
** from comments in this file. This file is the authoritative source
** on how SQLite interfaces are supposed to operate.
**
** 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.
*/
#ifndef SQLITE3_H
#define SQLITE3_H
#include <stdarg.h> /* Needed for the definition of va_list */
/*
** Make sure we can call this stuff from C++.
*/
#ifdef __cplusplus
extern "C" {
#endif
/*
** CAPI3REF: Result Codes
** KEYWORDS: {result code definitions}
**
** Many SQLite functions return an integer result code from the set shown
** here in order to indicate success or failure.
**
** New error codes may be added in future versions of SQLite.
**
** See also: [extended result code definitions]
*/
#define SQLITE_OK 0 /* Successful result */
/* beginning-of-error-codes */
#define SQLITE_ERROR 1 /* Generic error */
#define SQLITE_INTERNAL 2 /* Internal logic error in SQLite */
#define SQLITE_PERM 3 /* Access permission denied */
#define SQLITE_ABORT 4 /* Callback routine requested an abort */
#define SQLITE_BUSY 5 /* The database file is locked */
#define SQLITE_LOCKED 6 /* A table in the database is locked */
#define SQLITE_NOMEM 7 /* A malloc() failed */
#define SQLITE_READONLY 8 /* Attempt to write a readonly database */
#define SQLITE_INTERRUPT 9 /* Operation terminated by sqlite3_interrupt()*/
#define SQLITE_IOERR 10 /* Some kind of disk I/O error occurred */
#define SQLITE_CORRUPT 11 /* The database disk image is malformed */
#define SQLITE_NOTFOUND 12 /* Unknown opcode in sqlite3_file_control() */
#define SQLITE_FULL 13 /* Insertion failed because database is full */
#define SQLITE_CANTOPEN 14 /* Unable to open the database file */
#define SQLITE_PROTOCOL 15 /* Database lock protocol error */
#define SQLITE_EMPTY 16 /* Internal use only */
#define SQLITE_SCHEMA 17 /* The database schema changed */
#define SQLITE_TOOBIG 18 /* String or BLOB exceeds size limit */
#define SQLITE_CONSTRAINT 19 /* Abort due to constraint violation */
#define SQLITE_MISMATCH 20 /* Data type mismatch */
#define SQLITE_MISUSE 21 /* Library used incorrectly */
#define SQLITE_NOLFS 22 /* Uses OS features not supported on host */
#define SQLITE_AUTH 23 /* Authorization denied */
#define SQLITE_FORMAT 24 /* Not used */
#define SQLITE_RANGE 25 /* 2nd parameter to sqlite3_bind out of range */
#define SQLITE_NOTADB 26 /* File opened that is not a database file */
#define SQLITE_NOTICE 27 /* Notifications from sqlite3_log() */
#define SQLITE_WARNING 28 /* Warnings from sqlite3_log() */
#define SQLITE_ROW 100 /* sqlite3_step() has another row ready */
#define SQLITE_DONE 101 /* sqlite3_step() has finished executing */
/* end-of-error-codes */
#ifdef __cplusplus
} /* end of the 'extern "C"' block */
#endif
#endif /* _FTS5_H */
/******** End of fts5.h *********/

View File

@ -15,12 +15,15 @@
#include <assert.h>
#include <pthread.h>
#include <stddef.h>
#include <stdint.h>
#include <string.h>
#ifndef SQLITEINT_H
#define SQLITEINT_H
#include "sqlite3.h"
typedef int8_t i8;
typedef int16_t i16;
typedef int32_t i32;