From: drh Date: Tue, 14 May 2013 23:12:06 +0000 (+0000) Subject: Fix an assert() in unlockBtreeIfUnused() so that it checks for the existance X-Git-Tag: version-3.7.17~17^2~4^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=85ec3b63d896bb0227c6f2363c3f944de0eb2d9f;p=thirdparty%2Fsqlite.git Fix an assert() in unlockBtreeIfUnused() so that it checks for the existance of an untripped cursor, not for the existance of any cursor at all. FossilOrigin-Name: a6f851d0fe01d8c8d44a2fe0b716ff7a5194c63b --- diff --git a/manifest b/manifest index 008ee4a3df..0764d64e6e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Candidate\sfixes\sfor\sproblems\srevealed\sby\snotify2.test.\sNotify2.test\sis\sstill\sfailing\sat\sthis\spoint. -D 2013-05-13T18:23:15.893 +C Fix\san\sassert()\sin\sunlockBtreeIfUnused()\sso\sthat\sit\schecks\sfor\sthe\sexistance\nof\san\suntripped\scursor,\snot\sfor\sthe\sexistance\sof\sany\scursor\sat\sall. +D 2013-05-14T23:12:06.185 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in ce81671efd6223d19d4c8c6b88ac2c4134427111 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -137,7 +137,7 @@ F src/auth.c 523da7fb4979469955d822ff9298352d6b31de34 F src/backup.c b266767351ae2d847716c56fcb2a1fea7c761c03 F src/bitvec.c 19a4ba637bd85f8f63fc8c9bae5ade9fb05ec1cb F src/btmutex.c 976f45a12e37293e32cae0281b15a21d48a8aaa7 -F src/btree.c 480a6d255cc4f066029daf23dd54acf152cd0e13 +F src/btree.c 34ea83e16ece6d666214c7d0c3a39ce92fe292fd F src/btree.h 6fa8a3ff2483d0bb64a9f0105a8cedeac9e00cca F src/btreeInt.h eecc84f02375b2bb7a44abbcbbe3747dde73edb2 F src/build.c 083da8466fd7e481cb8bd5264398f537507f6176 @@ -646,7 +646,7 @@ F test/misc4.test 9c078510fbfff05a9869a0b6d8b86a623ad2c4f6 F test/misc5.test 528468b26d03303b1f047146e5eefc941b9069f5 F test/misc6.test 953cc693924d88e6117aeba16f46f0bf5abede91 F test/misc7.test dd82ec9250b89178b96cd28b2aca70639d21e5b3 -F test/misuse.test ba4fb5d1a6101d1c171ea38b3c613d0661c83054 +F test/misuse.test 9e580d30f94968ebb57878de3503608dc9f0f226 F test/mmap1.test 8696aa1b0bd88961c2f16af2a3f7a69d701cea50 F test/mmap2.test a5ba639f90b5fc487400a49e158e14e465943e98 F test/multiplex.test e08cc7177bd6d85990ee1d71100bb6c684c02256 @@ -1063,10 +1063,7 @@ F tool/vdbe-compress.tcl f12c884766bd14277f4fcedcae07078011717381 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac -P cf5c3642247fdd34d87f0368594cd7b8f081636a -R 9334ad7d318214aee7b701f9959b5d6e -T *branch * shared-cache-fixes -T *sym-shared-cache-fixes * -T -sym-trunk * -U dan -Z 816ab4789f48f56b3bf310736184e47d +P ea0428f9b6e63066e7444a2ba2f8c12a2e3ab7e4 +R 2410ec7fd380116c79746c720dac4cd6 +U drh +Z 5ded41815869fd9a599b4926f7c8b138 diff --git a/manifest.uuid b/manifest.uuid index 133cb8b794..fc052d359f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ea0428f9b6e63066e7444a2ba2f8c12a2e3ab7e4 \ No newline at end of file +a6f851d0fe01d8c8d44a2fe0b716ff7a5194c63b \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index 616d403681..297b0a7f8e 100644 --- a/src/btree.c +++ b/src/btree.c @@ -2517,6 +2517,29 @@ page1_init_failed: return rc; } +#ifndef NDEBUG +/* +** Return the number of cursors open on pBt. This is for use +** in assert() expressions, so it is only compiled if NDEBUG is not +** defined. +** +** Only write cursors are counted if wrOnly is true. If wrOnly is +** false then all cursors are counted. +** +** For the purposes of this routine, a cursor is any cursor that +** is capable of reading or writing to the databse. Cursors that +** have been tripped into the CURSOR_FAULT state are not counted. +*/ +static int countValidCursors(BtShared *pBt, int wrOnly){ + BtCursor *pCur; + int r = 0; + for(pCur=pBt->pCursor; pCur; pCur=pCur->pNext){ + if( (wrOnly==0 || pCur->wrFlag) && pCur->eState!=CURSOR_FAULT ) r++; + } + return r; +} +#endif + /* ** If there are no outstanding cursors and we are not in the middle ** of a transaction but there is a read lock on the database, then @@ -2527,7 +2550,7 @@ page1_init_failed: */ static void unlockBtreeIfUnused(BtShared *pBt){ assert( sqlite3_mutex_held(pBt->mutex) ); - assert( pBt->pCursor==0 || pBt->inTransaction>TRANS_NONE ); + assert( countValidCursors(pBt,0)==0 || pBt->inTransaction>TRANS_NONE ); if( pBt->inTransaction==TRANS_NONE && pBt->pPage1!=0 ){ assert( pBt->pPage1->aData ); assert( sqlite3PagerRefcount(pBt->pPager)==1 ); @@ -3351,27 +3374,6 @@ int sqlite3BtreeCommit(Btree *p){ return rc; } -#ifndef NDEBUG -/* -** Return the number of write-cursors open on this handle. This is for use -** in assert() expressions, so it is only compiled if NDEBUG is not -** defined. -** -** For the purposes of this routine, a write-cursor is any cursor that -** is capable of writing to the databse. That means the cursor was -** originally opened for writing and the cursor has not be disabled -** by having its state changed to CURSOR_FAULT. -*/ -static int countWriteCursors(BtShared *pBt){ - BtCursor *pCur; - int r = 0; - for(pCur=pBt->pCursor; pCur; pCur=pCur->pNext){ - if( pCur->wrFlag && pCur->eState!=CURSOR_FAULT ) r++; - } - return r; -} -#endif - /* ** This routine sets the state to CURSOR_FAULT and the error ** code to errCode for every cursor on BtShared that pBtree @@ -3451,7 +3453,7 @@ int sqlite3BtreeRollback(Btree *p, int tripCode){ pBt->nPage = nPage; releasePage(pPage1); } - assert( countWriteCursors(pBt)==0 ); + assert( countValidCursors(pBt, 1)==0 ); pBt->inTransaction = TRANS_READ; } diff --git a/test/misuse.test b/test/misuse.test index 71ee0118c8..84ead1c669 100644 --- a/test/misuse.test +++ b/test/misuse.test @@ -170,7 +170,7 @@ do_test misuse-4.3 { } } msg] lappend v $msg $r -} {0 {} SQLITE_BUSY} +} {1 {callback requested query abort} SQLITE_BUSY} do_test misuse-4.4 { # Flush the TCL statement cache here, otherwise the sqlite3_close() will # fail because there are still un-finalized() VDBEs.