mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-07 02:42:48 +03:00
Add some assert() statements to verify, where possible, that BtShared.db is set correctly.
FossilOrigin-Name: 359277e0e5338f6d7743d58cf99e1c934a8460d5
This commit is contained in:
42
src/btree.c
42
src/btree.c
@@ -450,6 +450,10 @@ static void releasePage(MemPage *pPage); /* Forward reference */
|
||||
static int cursorHoldsMutex(BtCursor *p){
|
||||
return sqlite3_mutex_held(p->pBt->mutex);
|
||||
}
|
||||
static int cursorOwnsBtShared(BtCursor *p){
|
||||
assert( cursorHoldsMutex(p) );
|
||||
return (p->pBtree->db==p->pBt->db);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
@@ -786,7 +790,7 @@ static int btreeMoveto(
|
||||
static int btreeRestoreCursorPosition(BtCursor *pCur){
|
||||
int rc;
|
||||
int skipNext;
|
||||
assert( cursorHoldsMutex(pCur) );
|
||||
assert( cursorOwnsBtShared(pCur) );
|
||||
assert( pCur->eState>=CURSOR_REQUIRESEEK );
|
||||
if( pCur->eState==CURSOR_FAULT ){
|
||||
return pCur->skipNext;
|
||||
@@ -4286,7 +4290,7 @@ int sqlite3BtreeKeySize(BtCursor *pCur, i64 *pSize){
|
||||
** to return an integer result code for historical reasons.
|
||||
*/
|
||||
int sqlite3BtreeDataSize(BtCursor *pCur, u32 *pSize){
|
||||
assert( cursorHoldsMutex(pCur) );
|
||||
assert( cursorOwnsBtShared(pCur) );
|
||||
assert( pCur->eState==CURSOR_VALID );
|
||||
assert( pCur->iPage>=0 );
|
||||
assert( pCur->iPage<BTCURSOR_MAX_DEPTH );
|
||||
@@ -4666,7 +4670,7 @@ int sqlite3BtreeData(BtCursor *pCur, u32 offset, u32 amt, void *pBuf){
|
||||
}
|
||||
#endif
|
||||
|
||||
assert( cursorHoldsMutex(pCur) );
|
||||
assert( cursorOwnsBtShared(pCur) );
|
||||
rc = restoreCursorPosition(pCur);
|
||||
if( rc==SQLITE_OK ){
|
||||
assert( pCur->eState==CURSOR_VALID );
|
||||
@@ -4704,7 +4708,7 @@ static const void *fetchPayload(
|
||||
assert( pCur!=0 && pCur->iPage>=0 && pCur->apPage[pCur->iPage]);
|
||||
assert( pCur->eState==CURSOR_VALID );
|
||||
assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
|
||||
assert( cursorHoldsMutex(pCur) );
|
||||
assert( cursorOwnsBtShared(pCur) );
|
||||
assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell );
|
||||
assert( pCur->info.nSize>0 );
|
||||
assert( pCur->info.pPayload>pCur->apPage[pCur->iPage]->aData || CORRUPT_DB );
|
||||
@@ -4750,7 +4754,7 @@ const void *sqlite3BtreeDataFetch(BtCursor *pCur, u32 *pAmt){
|
||||
static int moveToChild(BtCursor *pCur, u32 newPgno){
|
||||
BtShared *pBt = pCur->pBt;
|
||||
|
||||
assert( cursorHoldsMutex(pCur) );
|
||||
assert( cursorOwnsBtShared(pCur) );
|
||||
assert( pCur->eState==CURSOR_VALID );
|
||||
assert( pCur->iPage<BTCURSOR_MAX_DEPTH );
|
||||
assert( pCur->iPage>=0 );
|
||||
@@ -4796,7 +4800,7 @@ static void assertParentIndex(MemPage *pParent, int iIdx, Pgno iChild){
|
||||
** the largest cell index.
|
||||
*/
|
||||
static void moveToParent(BtCursor *pCur){
|
||||
assert( cursorHoldsMutex(pCur) );
|
||||
assert( cursorOwnsBtShared(pCur) );
|
||||
assert( pCur->eState==CURSOR_VALID );
|
||||
assert( pCur->iPage>0 );
|
||||
assert( pCur->apPage[pCur->iPage] );
|
||||
@@ -4836,7 +4840,7 @@ static int moveToRoot(BtCursor *pCur){
|
||||
MemPage *pRoot;
|
||||
int rc = SQLITE_OK;
|
||||
|
||||
assert( cursorHoldsMutex(pCur) );
|
||||
assert( cursorOwnsBtShared(pCur) );
|
||||
assert( CURSOR_INVALID < CURSOR_REQUIRESEEK );
|
||||
assert( CURSOR_VALID < CURSOR_REQUIRESEEK );
|
||||
assert( CURSOR_FAULT > CURSOR_REQUIRESEEK );
|
||||
@@ -4915,7 +4919,7 @@ static int moveToLeftmost(BtCursor *pCur){
|
||||
int rc = SQLITE_OK;
|
||||
MemPage *pPage;
|
||||
|
||||
assert( cursorHoldsMutex(pCur) );
|
||||
assert( cursorOwnsBtShared(pCur) );
|
||||
assert( pCur->eState==CURSOR_VALID );
|
||||
while( rc==SQLITE_OK && !(pPage = pCur->apPage[pCur->iPage])->leaf ){
|
||||
assert( pCur->aiIdx[pCur->iPage]<pPage->nCell );
|
||||
@@ -4940,7 +4944,7 @@ static int moveToRightmost(BtCursor *pCur){
|
||||
int rc = SQLITE_OK;
|
||||
MemPage *pPage = 0;
|
||||
|
||||
assert( cursorHoldsMutex(pCur) );
|
||||
assert( cursorOwnsBtShared(pCur) );
|
||||
assert( pCur->eState==CURSOR_VALID );
|
||||
while( !(pPage = pCur->apPage[pCur->iPage])->leaf ){
|
||||
pgno = get4byte(&pPage->aData[pPage->hdrOffset+8]);
|
||||
@@ -4961,7 +4965,7 @@ static int moveToRightmost(BtCursor *pCur){
|
||||
int sqlite3BtreeFirst(BtCursor *pCur, int *pRes){
|
||||
int rc;
|
||||
|
||||
assert( cursorHoldsMutex(pCur) );
|
||||
assert( cursorOwnsBtShared(pCur) );
|
||||
assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
|
||||
rc = moveToRoot(pCur);
|
||||
if( rc==SQLITE_OK ){
|
||||
@@ -4984,7 +4988,7 @@ int sqlite3BtreeFirst(BtCursor *pCur, int *pRes){
|
||||
int sqlite3BtreeLast(BtCursor *pCur, int *pRes){
|
||||
int rc;
|
||||
|
||||
assert( cursorHoldsMutex(pCur) );
|
||||
assert( cursorOwnsBtShared(pCur) );
|
||||
assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
|
||||
|
||||
/* If the cursor already points to the last entry, this is a no-op. */
|
||||
@@ -5062,7 +5066,7 @@ int sqlite3BtreeMovetoUnpacked(
|
||||
int rc;
|
||||
RecordCompare xRecordCompare;
|
||||
|
||||
assert( cursorHoldsMutex(pCur) );
|
||||
assert( cursorOwnsBtShared(pCur) );
|
||||
assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
|
||||
assert( pRes );
|
||||
assert( (pIdxKey==0)==(pCur->pKeyInfo==0) );
|
||||
@@ -5310,7 +5314,7 @@ static SQLITE_NOINLINE int btreeNext(BtCursor *pCur, int *pRes){
|
||||
int idx;
|
||||
MemPage *pPage;
|
||||
|
||||
assert( cursorHoldsMutex(pCur) );
|
||||
assert( cursorOwnsBtShared(pCur) );
|
||||
assert( pCur->skipNext==0 || pCur->eState!=CURSOR_VALID );
|
||||
assert( *pRes==0 );
|
||||
if( pCur->eState!=CURSOR_VALID ){
|
||||
@@ -5374,7 +5378,7 @@ static SQLITE_NOINLINE int btreeNext(BtCursor *pCur, int *pRes){
|
||||
}
|
||||
int sqlite3BtreeNext(BtCursor *pCur, int *pRes){
|
||||
MemPage *pPage;
|
||||
assert( cursorHoldsMutex(pCur) );
|
||||
assert( cursorOwnsBtShared(pCur) );
|
||||
assert( pRes!=0 );
|
||||
assert( *pRes==0 || *pRes==1 );
|
||||
assert( pCur->skipNext==0 || pCur->eState!=CURSOR_VALID );
|
||||
@@ -5419,7 +5423,7 @@ static SQLITE_NOINLINE int btreePrevious(BtCursor *pCur, int *pRes){
|
||||
int rc;
|
||||
MemPage *pPage;
|
||||
|
||||
assert( cursorHoldsMutex(pCur) );
|
||||
assert( cursorOwnsBtShared(pCur) );
|
||||
assert( pRes!=0 );
|
||||
assert( *pRes==0 );
|
||||
assert( pCur->skipNext==0 || pCur->eState!=CURSOR_VALID );
|
||||
@@ -5475,7 +5479,7 @@ static SQLITE_NOINLINE int btreePrevious(BtCursor *pCur, int *pRes){
|
||||
return rc;
|
||||
}
|
||||
int sqlite3BtreePrevious(BtCursor *pCur, int *pRes){
|
||||
assert( cursorHoldsMutex(pCur) );
|
||||
assert( cursorOwnsBtShared(pCur) );
|
||||
assert( pRes!=0 );
|
||||
assert( *pRes==0 || *pRes==1 );
|
||||
assert( pCur->skipNext==0 || pCur->eState!=CURSOR_VALID );
|
||||
@@ -7955,7 +7959,7 @@ int sqlite3BtreeInsert(
|
||||
return pCur->skipNext;
|
||||
}
|
||||
|
||||
assert( cursorHoldsMutex(pCur) );
|
||||
assert( cursorOwnsBtShared(pCur) );
|
||||
assert( (pCur->curFlags & BTCF_WriteFlag)!=0
|
||||
&& pBt->inTransaction==TRANS_WRITE
|
||||
&& (pBt->btsFlags & BTS_READ_ONLY)==0 );
|
||||
@@ -8102,7 +8106,7 @@ int sqlite3BtreeDelete(BtCursor *pCur, int bPreserve){
|
||||
u16 szCell; /* Size of the cell being deleted */
|
||||
int bSkipnext = 0; /* Leaf cursor in SKIPNEXT state */
|
||||
|
||||
assert( cursorHoldsMutex(pCur) );
|
||||
assert( cursorOwnsBtShared(pCur) );
|
||||
assert( pBt->inTransaction==TRANS_WRITE );
|
||||
assert( (pBt->btsFlags & BTS_READ_ONLY)==0 );
|
||||
assert( pCur->curFlags & BTCF_WriteFlag );
|
||||
@@ -9564,7 +9568,7 @@ int sqlite3BtreeLockTable(Btree *p, int iTab, u8 isWriteLock){
|
||||
*/
|
||||
int sqlite3BtreePutData(BtCursor *pCsr, u32 offset, u32 amt, void *z){
|
||||
int rc;
|
||||
assert( cursorHoldsMutex(pCsr) );
|
||||
assert( cursorOwnsBtShared(pCsr) );
|
||||
assert( sqlite3_mutex_held(pCsr->pBtree->db->mutex) );
|
||||
assert( pCsr->curFlags & BTCF_Incrblob );
|
||||
|
||||
|
Reference in New Issue
Block a user