diff options
-rw-r--r-- | manifest | 66 | ||||
-rw-r--r-- | manifest.uuid | 2 | ||||
-rw-r--r-- | src/alter.c | 8 | ||||
-rw-r--r-- | src/analyze.c | 4 | ||||
-rw-r--r-- | src/attach.c | 6 | ||||
-rw-r--r-- | src/btree.c | 38 | ||||
-rw-r--r-- | src/build.c | 35 | ||||
-rw-r--r-- | src/callback.c | 4 | ||||
-rw-r--r-- | src/delete.c | 4 | ||||
-rw-r--r-- | src/expr.c | 12 | ||||
-rw-r--r-- | src/insert.c | 8 | ||||
-rw-r--r-- | src/legacy.c | 4 | ||||
-rw-r--r-- | src/main.c | 14 | ||||
-rw-r--r-- | src/os_unix.c | 8 | ||||
-rw-r--r-- | src/pager.c | 12 | ||||
-rw-r--r-- | src/prepare.c | 32 | ||||
-rw-r--r-- | src/select.c | 12 | ||||
-rw-r--r-- | src/sqliteInt.h | 32 | ||||
-rw-r--r-- | src/test1.c | 14 | ||||
-rw-r--r-- | src/tokenize.c | 6 | ||||
-rw-r--r-- | src/trigger.c | 8 | ||||
-rw-r--r-- | src/update.c | 4 | ||||
-rw-r--r-- | src/util.c | 54 | ||||
-rw-r--r-- | src/vacuum.c | 10 | ||||
-rw-r--r-- | src/vdbe.c | 12 | ||||
-rw-r--r-- | src/vdbeapi.c | 4 | ||||
-rw-r--r-- | src/vdbeaux.c | 14 | ||||
-rw-r--r-- | src/vdbemem.c | 2 | ||||
-rw-r--r-- | src/where.c | 8 | ||||
-rw-r--r-- | test/shared.test | 74 |
30 files changed, 296 insertions, 215 deletions
@@ -1,5 +1,5 @@ -C Minor\schanges\sso\sthat\sOMIT_SHARED_CACHE\sworks.\s(CVS\s2892) -D 2006-01-09T05:36:27 +C Rename\sDbSchema\sto\s"Schema"\sand\sSqliteTsd\sto\s"ThreadData".\s(CVS\s2893) +D 2006-01-09T06:29:48 F Makefile.in c79fbdaa264c6afcd435f2fb492551de5a8cf80d F Makefile.linux-gcc aee18d8a05546dcf1888bd4547e442008a49a092 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028 @@ -30,68 +30,68 @@ F sqlite.pc.in 30552343140c53304c2a658c080fbe810cd09ca2 F sqlite3.1 6be1ad09113570e1fc8dcaff84c9b0b337db5ffc F sqlite3.def c413e514217736884254739a105c8c942fdf0c2f F sqlite3.pc.in 985b9bf34192a549d7d370e0f0b6b34a4f61369a -F src/alter.c e9deb3f4fd7c663a0d1f235d541bc5ea1f2cfa8b -F src/analyze.c fd2fe03b10dd5058747083362e56dec5bd9c4e5c -F src/attach.c 4a04ffcd17357a7848aa17c12c955d109f533bd0 +F src/alter.c d0dd079b9ef0d551ff4a4ce09ee270c07b307bbb +F src/analyze.c ed87abad3f6f60e1bd5308ed6ff6e0fa396db52b +F src/attach.c 833e38b4fa6966de05fcf875c94cd521478a2811 F src/auth.c cdec356a5cd8b217c346f816c5912221537fe87f -F src/btree.c 5c2d7f7482049006fd03b6661e6187fecaefa7cb +F src/btree.c fc3f7f936b4f58c05ce95d710c1c15bb86cd522a F src/btree.h 5663c4f43e8521546ccebc8fc95acb013b8f3184 -F src/build.c 8f0b1da79b7a5845fde0f831b065b42077ac124f -F src/callback.c 62066afd516f220575e81b1a1239ab92a2eae252 +F src/build.c e40a4caaba4afab3fc7f0866ca8766e8146dd62c +F src/callback.c 79cfbac59139b525e3a195ee27b8be1ca06fbd38 F src/complete.c df1681cef40dec33a286006981845f87b194e7a4 F src/date.c a927bdbb51296ac398d2f667086a7072c099e5ab -F src/delete.c 32ba37cced50d26ed996d67dc7d19195e081bbb7 +F src/delete.c 66199ba71a0f753033073b080baebb349157c960 F src/experimental.c 50c1e3b34f752f4ac10c36f287db095c2b61766d -F src/expr.c ed2a272c7afd63232ca04881159ce2366266e35d +F src/expr.c 3bf54eca0b0d34bd097750c622d4490a08e78a2b F src/func.c 5e4204b2ebe89de5228d78eef9352a0ed253f4c0 F src/hash.c 8747cf51d12de46512880dfcf1b68b4e24072863 F src/hash.h 1b0c445e1c89ff2aaad9b4605ba61375af001e84 -F src/insert.c 59f8c1f95c3d27e07f4b4a962bef54a34655786c -F src/legacy.c 59757d857ab95fcbb0ac27692d3201e35f093dd7 -F src/main.c 8c2d64f1460200d79d7de4605a9489c0506be5fe +F src/insert.c 16610475976dc9b25d231338e283dd4b4362a430 +F src/legacy.c f651ccd3700f99fa05766ac53506bf9a0694761b +F src/main.c 2e6d9482919371c9d0c522fd87273b6261473b29 F src/md5.c c5fdfa5c2593eaee2e32a5ce6c6927c986eaf217 F src/os.c 1d1a61cdf150e9f9520a3bc787c8465148ea2e78 F src/os.h 8710c0068f3386a73a37f8ad242b92c7580464df F src/os_common.h 78bcc34dded9b625b3c16d072b7e5b76d075a674 F src/os_test.c 49833426101f99aee4bb5f6a44b7c4b2029fda1c F src/os_test.h 903c93554c23d88f34f667f1979e4a1cee792af3 -F src/os_unix.c ba70f76230c9cd95c08f27ec40710838ea15a785 +F src/os_unix.c c5d1a3fe88ad93b5f6a29f1b5b889f2a756aaec0 F src/os_unix.h 5768d56d28240d3fe4537fac08cc85e4fb52279e F src/os_win.c 9cedcb13d6bcd4ab5f50907a99112f45cd335893 F src/os_win.h 41a946bea10f61c158ce8645e7646b29d44f122b -F src/pager.c f06b85eb1e43bb2e6a7a5108ac8346576b4b78fa +F src/pager.c f838695a6c0c8d0051ce7491036fd675052aa6f6 F src/pager.h e0acb095b3ad0bca48f2ab00c87346665643f64f F src/parse.y 83df51fea35f68f7e07384d75dce83d1ed30434c F src/pragma.c 7358baf8e2be14a0f3d71e7afae41e430d76b054 -F src/prepare.c fef89dc92703d345251142af966b60e44a66cfc5 +F src/prepare.c e0812d49ef30e07cabb8f77df943e557e6bf927a F src/printf.c f47a2f4b5387cd2ebb12e9117a1a5d6bd9a2b812 F src/random.c d40f8d356cecbd351ccfab6eaedd7ec1b54f5261 -F src/select.c 72b7b83fbf17b9b4c087135fede6c1367391f2af +F src/select.c d97a43973d82a2e1e24be43ca5543c08b93e9e8d F src/shell.c 66b073375efbdee19045e7e0cd38b85f9aff71da F src/sqlite.h.in ba3a29daa6a16e054191ccb384a981964e882a1d -F src/sqliteInt.h 40c3511c05df83c7c1c244d0432baa9497feee4d +F src/sqliteInt.h 9fed92df9ab1cccbe649c28e6d24685a1f3373a4 F src/table.c 486dcfce532685b53b5a2b5da8bba0ded6fb2316 F src/tclsqlite.c 42151e6c78502277be77b88c00535d53ce89b917 -F src/test1.c 53c6c0f86e280e739a9adfb56ba7d8b6e26cc16f +F src/test1.c 25e687fcc3c962958c5aa5114a74592cc5b7e6ba F src/test2.c ca74a1d8aeb7d9606e8f6b762c5daf85c1a3f92b F src/test3.c 9742aa146eb750cab81c1d5605286c3a0eb88054 F src/test4.c a8fd681e139e1c61f22a77d07fc3a99cb28fff3f F src/test5.c 7162f8526affb771c4ed256826eee7bb9eca265f F src/test6.c 74d91b487c68154156eded457925d96aa2a3fdbb -F src/tokenize.c 10c32e980e3d8db98cfe32e3485a458fda5b3117 -F src/trigger.c d8e0fe913fcd3819649faf2863cd881ff60ffc2e -F src/update.c 29ba0385c8639803cd8e6e616e99096a0bc10443 +F src/tokenize.c 196486012c871cdcad6cc84a820cc988603f1b9d +F src/trigger.c c515afa5fe964e9854c54dc66dde179a90d0cfe3 +F src/update.c 9a3761250c2ac9e6871f4e9c37560b224ba0067e F src/utf.c b7bffac4260177ae7f83c01d025fe0f5ed70ce71 -F src/util.c 8a3ef3c1b345cdadcee33ce4537c63bb0fda0ed8 -F src/vacuum.c a7301804d4f849da0ce9d869219c71c6d621c34e -F src/vdbe.c 1aee0e9d410e1f633e8c1fb247731af3566fc98c +F src/util.c 9af2eab4203627982e433102be55b58dd38f8a38 +F src/vacuum.c f5a068096b22fad438bf1f1cf69ccb7f9e8cc7fb +F src/vdbe.c ce31105fc91e1ea346e2383cd536149cc66c34bd F src/vdbe.h 8729a4ee16ff9aeab2af9667df3cf300ff978e13 F src/vdbeInt.h 5451cf71f229e366ac543607c0a17f36e5737ea9 -F src/vdbeapi.c 7335569b1bad946ba53892384b4b1534e877b1ee -F src/vdbeaux.c cb57a0b6aef5ff002b42baf366c85e389509b2d7 +F src/vdbeapi.c 2e22bd0c845fc380f112aacfc6c5af29be73152e +F src/vdbeaux.c e4b8f492e41e3b8ecee8f66045e897dae92d1356 F src/vdbefifo.c 9efb94c8c3f4c979ebd0028219483f88e57584f5 -F src/vdbemem.c deba8d6e3727643924b210a8c531a496c2b8d386 -F src/where.c de22a3a84c595ca1ad206dd19818f65f950e79f8 +F src/vdbemem.c d712dfd80d58011db688fa8234c1821262a57cae +F src/where.c 18a7a16a5b050b2df6f8b03945313ec0f46dc30c F tclinstaller.tcl 046e3624671962dc50f0481d7c25b38ef803eb42 F test/all.test 90cf64bb655e3d474b0dda04e63ece03e36b0ce2 F test/alter.test b94b640063e725d062b2997bd2810ac39195c718 @@ -220,7 +220,7 @@ F test/select4.test c239f516aa31f42f2ef7c6d7cd01105f08f934ca F test/select5.test 07a90ab3c7e3f0a241a9cdea1d997b2c8a89ff0b F test/select6.test f459a19bdac0501c4d3eb1a4df4b7a76f1bb8ad4 F test/select7.test 1bf795b948c133a15a2a5e99d3270e652ec58ce6 -F test/shared.test a19b3db0d10dcb965ab73b04830f94149f6eb85b +F test/shared.test f37afcdc0f4d521fbf1b6d573e7aae1950e71848 F test/sort.test 0e4456e729e5a92a625907c63dcdedfbe72c5dc5 F test/subquery.test e6de53332c0301b3cfa34edc3f3cd5fa1e859efd F test/subselect.test 2d13fb7f450db3595adcdd24079a0dd1d2d6abc2 @@ -335,7 +335,7 @@ F www/tclsqlite.tcl bb0d1357328a42b1993d78573e587c6dcbc964b9 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0 F www/version3.tcl a99cf5f6d8bd4d5537584a2b342f0fb9fa601d8b F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513 -P 94c87b70161d4d44fbf1602fc2baae22dca08759 -R a0a8036ba73e85a05dbaa2966904d0a4 +P cc963f8cfc6c704c645c627bffb8df21dfebffc6 +R 7000da8baf46b4c1ff76e715121c7c17 U danielk1977 -Z 10b9ce228823f887832ae0fa03cba38b +Z c505bc6b6a245c795a8be1eda400ccd9 diff --git a/manifest.uuid b/manifest.uuid index a8dfdada0..239463625 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -cc963f8cfc6c704c645c627bffb8df21dfebffc6
\ No newline at end of file +82b81f69c78cb3f54634d9aea4f6a838474dc5e5
\ No newline at end of file diff --git a/src/alter.c b/src/alter.c index d99001161..c9fa9deed 100644 --- a/src/alter.c +++ b/src/alter.c @@ -12,7 +12,7 @@ ** This file contains C code routines that used to generate VDBE code ** that implements the ALTER TABLE command. ** -** $Id: alter.c,v 1.14 2006/01/05 11:34:33 danielk1977 Exp $ +** $Id: alter.c,v 1.15 2006/01/09 06:29:48 danielk1977 Exp $ */ #include "sqliteInt.h" #include <ctype.h> @@ -177,7 +177,7 @@ static char *whereTempTriggers(Parse *pParse, Table *pTab){ Trigger *pTrig; char *zWhere = 0; char *tmp = 0; - const DbSchema *pTempSchema = pParse->db->aDb[1].pSchema; /* Temp db schema */ + const Schema *pTempSchema = pParse->db->aDb[1].pSchema; /* Temp db schema */ /* If the table is not located in the temp-db (in which case NULL is ** returned, loop through the tables list of triggers. For each trigger @@ -267,7 +267,7 @@ void sqlite3AlterRenameTable( char *zWhere = 0; /* Where clause to locate temp triggers */ #endif - if( sqlite3Tsd()->mallocFailed ) goto exit_rename_table; + if( sqlite3ThreadData()->mallocFailed ) goto exit_rename_table; assert( pSrc->nSrc==1 ); pTab = sqlite3LocateTable(pParse, pSrc->a[0].zName, pSrc->a[0].zDatabase); @@ -501,7 +501,7 @@ void sqlite3AlterBeginAddColumn(Parse *pParse, SrcList *pSrc){ /* Look up the table being altered. */ assert( pParse->pNewTable==0 ); - if( sqlite3Tsd()->mallocFailed ) goto exit_begin_add_column; + if( sqlite3ThreadData()->mallocFailed ) goto exit_begin_add_column; pTab = sqlite3LocateTable(pParse, pSrc->a[0].zName, pSrc->a[0].zDatabase); if( !pTab ) goto exit_begin_add_column; diff --git a/src/analyze.c b/src/analyze.c index acd812b27..ba07b7bd2 100644 --- a/src/analyze.c +++ b/src/analyze.c @@ -11,7 +11,7 @@ ************************************************************************* ** This file contains code associated with the ANALYZE command. ** -** @(#) $Id: analyze.c,v 1.14 2006/01/08 18:10:18 drh Exp $ +** @(#) $Id: analyze.c,v 1.15 2006/01/09 06:29:48 danielk1977 Exp $ */ #ifndef SQLITE_OMIT_ANALYZE #include "sqliteInt.h" @@ -228,7 +228,7 @@ static void loadAnalysis(Parse *pParse, int iDb){ */ static void analyzeDatabase(Parse *pParse, int iDb){ sqlite3 *db = pParse->db; - DbSchema *pSchema = db->aDb[iDb].pSchema; /* Schema of database iDb */ + Schema *pSchema = db->aDb[iDb].pSchema; /* Schema of database iDb */ HashElem *k; int iStatCur; int iMem; diff --git a/src/attach.c b/src/attach.c index b63260c34..57e0a98f8 100644 --- a/src/attach.c +++ b/src/attach.c @@ -11,7 +11,7 @@ ************************************************************************* ** This file contains code used to implement the ATTACH and DETACH commands. ** -** $Id: attach.c,v 1.40 2006/01/06 21:52:50 drh Exp $ +** $Id: attach.c,v 1.41 2006/01/09 06:29:48 danielk1977 Exp $ */ #include "sqliteInt.h" @@ -267,7 +267,7 @@ static void codeAttach( sqlite3* db = pParse->db; #ifndef SQLITE_OMIT_AUTHORIZATION - assert( sqlite3Tsd()->mallocFailed || pAuthArg ); + assert( sqlite3ThreadData()->mallocFailed || pAuthArg ); if( pAuthArg ){ char *zAuthArg = sqlite3NameFromToken(&pAuthArg->span); if( !zAuthArg ){ @@ -298,7 +298,7 @@ static void codeAttach( sqlite3ExprCode(pParse, pDbname); sqlite3ExprCode(pParse, pKey); - assert(v || sqlite3Tsd()->mallocFailed); + assert(v || sqlite3ThreadData()->mallocFailed); if( v ){ sqlite3VdbeAddOp(v, OP_Function, 0, nFunc); pFunc = sqlite3FindFunction(db, zFunc, strlen(zFunc), nFunc, SQLITE_UTF8,0); diff --git a/src/btree.c b/src/btree.c index 9b206a3b9..3ab5f5c00 100644 --- a/src/btree.c +++ b/src/btree.c @@ -9,7 +9,7 @@ ** May you share freely, never taking more than you give. ** ************************************************************************* -** $Id: btree.c,v 1.286 2006/01/09 05:36:27 danielk1977 Exp $ +** $Id: btree.c,v 1.287 2006/01/09 06:29:48 danielk1977 Exp $ ** ** This file implements a external (disk-based) database using BTrees. ** For a detailed discussion of BTrees, refer to @@ -345,13 +345,13 @@ struct BtShared { int minLeaf; /* Minimum local payload in a LEAFDATA table */ BusyHandler *pBusyHandler; /* Callback for when there is lock contention */ u8 inTransaction; /* Transaction state */ - BtShared *pNext; /* Next in SqliteTsd.pBtree linked list */ int nRef; /* Number of references to this structure */ int nTransaction; /* Number of open transactions (read + write) */ void *pSchema; /* Pointer to space allocated by sqlite3BtreeSchema() */ void (*xFreeSchema)(void*); /* Destructor for BtShared.pSchema */ #ifndef SQLITE_OMIT_SHARED_CACHE BtLock *pLock; /* List of locks held on this shared-btree struct */ + BtShared *pNext; /* Next in ThreadData.pBtree linked list */ #endif }; @@ -557,7 +557,7 @@ static int saveCursorPosition(BtCursor *pCur){ */ static int saveAllCursors(BtShared *pBt, Pgno iRoot, BtCursor *pExcept){ BtCursor *p; - if( sqlite3Tsd()->useSharedData ){ + if( sqlite3ThreadData()->useSharedData ){ for(p=pBt->pCursor; p; p=p->pNext){ if( p!=pExcept && p->pgnoRoot==iRoot && p->eState==CURSOR_VALID ){ int rc = saveCursorPosition(p); @@ -584,7 +584,7 @@ static int saveAllCursors(BtShared *pBt, Pgno iRoot, BtCursor *pExcept){ static int restoreCursorPosition(BtCursor *pCur, int doSeek){ int rc = SQLITE_OK; if( pCur->eState==CURSOR_REQUIRESEEK ){ - assert( sqlite3Tsd()->useSharedData ); + assert( sqlite3ThreadData()->useSharedData ); if( doSeek ){ rc = sqlite3BtreeMoveto(pCur, pCur->pKey, pCur->nKey, &pCur->skip); }else{ @@ -610,7 +610,7 @@ static int queryTableLock(Btree *p, Pgno iTab, u8 eLock){ BtLock *pIter; /* This is a no-op if the shared-cache is not enabled */ - if( 0==sqlite3Tsd()->useSharedData ){ + if( 0==sqlite3ThreadData()->useSharedData ){ return SQLITE_OK; } @@ -658,7 +658,7 @@ static int lockTable(Btree *p, Pgno iTable, u8 eLock){ BtLock *pIter; /* This is a no-op if the shared-cache is not enabled */ - if( 0==sqlite3Tsd()->useSharedData ){ + if( 0==sqlite3ThreadData()->useSharedData ){ return SQLITE_OK; } @@ -723,7 +723,7 @@ static void unlockAllTables(Btree *p){ ** locks in the BtShared.pLock list, making this procedure a no-op. Assert ** that this is the case. */ - assert( sqlite3Tsd()->useSharedData || 0==*ppIter ); + assert( sqlite3ThreadData()->useSharedData || 0==*ppIter ); while( *ppIter ){ BtLock *pLock = *ppIter; @@ -1547,7 +1547,7 @@ int sqlite3BtreeOpen( int nReserve; unsigned char zDbHeader[100]; #ifndef SQLITE_OMIT_SHARED_CACHE - SqliteTsd *pTsd = sqlite3Tsd(); + ThreadData *pTsd = sqlite3ThreadData(); #endif /* Set the variable isMemdb to true for an in-memory database, or @@ -1658,7 +1658,7 @@ int sqlite3BtreeOpen( sqlite3pager_set_pagesize(pBt->pPager, pBt->pageSize); #ifndef SQLITE_OMIT_SHARED_CACHE - /* Add the new btree to the linked list starting at SqliteTsd.pBtree */ + /* Add the new btree to the linked list starting at ThreadData.pBtree */ if( pTsd->useSharedData && zFilename && !isMemdb ){ pBt->pNext = pTsd->pBtree; pTsd->pBtree = pBt; @@ -1677,7 +1677,7 @@ int sqlite3BtreeClose(Btree *p){ BtCursor *pCur; #ifndef SQLITE_OMIT_SHARED_CACHE - SqliteTsd *pTsd = sqlite3Tsd(); + ThreadData *pTsd = sqlite3ThreadData(); #endif /* Drop any table-locks */ @@ -2305,11 +2305,11 @@ static int allocatePage(BtShared *, MemPage **, Pgno *, Pgno, u8); */ static int autoVacuumCommit(BtShared *pBt, Pgno *nTrunc){ Pager *pPager = pBt->pPager; - Pgno nFreeList; /* Number of pages remaining on the free-list. */ - int nPtrMap; /* Number of pointer-map pages deallocated */ - Pgno origSize; /* Pages in the database file */ - Pgno finSize; /* Pages in the database file after truncation */ - int rc; /* Return code */ + Pgno nFreeList; /* Number of pages remaining on the free-list. */ + int nPtrMap; /* Number of pointer-map pages deallocated */ + Pgno origSize; /* Pages in the database file */ + Pgno finSize; /* Pages in the database file after truncation */ + int rc; /* Return code */ u8 eType; int pgsz = pBt->pageSize; /* Page size for this database */ Pgno iDbPage; /* The database page to move */ @@ -2392,6 +2392,12 @@ static int autoVacuumCommit(BtShared *pBt, Pgno *nTrunc){ releasePage(pFreeMemPage); pFreeMemPage = 0; + /* Relocate the page into the body of the file. Note that although the + ** page has moved within the database file, the pDbMemPage pointer + ** remains valid. This means that this function can run without + ** invalidating cursors open on the btree. This is important in + ** shared-cache mode. + */ rc = relocatePage(pBt, pDbMemPage, eType, iPtrPage, iFreePage); releasePage(pDbMemPage); if( rc!=SQLITE_OK ) goto autovacuum_out; @@ -6498,7 +6504,7 @@ int sqlite3BtreeLockTable(Btree *p, int iTab, u8 isWriteLock){ ** Enable the shared pager and schema features. */ int sqlite3_enable_shared_cache(int enable){ - SqliteTsd *pTsd = sqlite3Tsd(); + ThreadData *pTsd = sqlite3ThreadData(); if( pTsd->pPager ){ return SQLITE_MISUSE; } diff --git a/src/build.c b/src/build.c index 907746584..5b3594f2f 100644 --- a/src/build.c +++ b/src/build.c @@ -22,7 +22,7 @@ ** COMMIT ** ROLLBACK ** -** $Id: build.c,v 1.370 2006/01/09 05:36:27 danielk1977 Exp $ +** $Id: build.c,v 1.371 2006/01/09 06:29:48 danielk1977 Exp $ */ #include "sqliteInt.h" #include <ctype.h> @@ -66,7 +66,7 @@ void sqlite3TableLock( int i; int nBytes; TableLock *p; - SqliteTsd *pTsd = sqlite3Tsd(); + ThreadData *pTsd = sqlite3ThreadData(); if( 0==pTsd->useSharedData ){ return; @@ -98,7 +98,7 @@ void sqlite3TableLock( static void codeTableLocks(Parse *pParse){ int i; Vdbe *pVdbe; - assert( sqlite3Tsd()->useSharedData || pParse->nTableLock==0 ); + assert( sqlite3ThreadData()->useSharedData || pParse->nTableLock==0 ); if( 0==(pVdbe = sqlite3GetVdbe(pParse)) ){ return; @@ -131,7 +131,7 @@ void sqlite3FinishCoding(Parse *pParse){ sqlite3 *db; Vdbe *v; - if( sqlite3Tsd()->mallocFailed ) return; + if( sqlite3ThreadData()->mallocFailed ) return; if( pParse->nested ) return; if( !pParse->pVdbe ){ if( pParse->rc==SQLITE_OK && pParse->nErr ){ @@ -314,7 +314,7 @@ Index *sqlite3FindIndex(sqlite3 *db, const char *zName, const char *zDb){ assert( (db->flags & SQLITE_Initialized) || db->init.busy ); for(i=OMIT_TEMPDB; i<db->nDb; i++){ int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */ - DbSchema *pSchema = db->aDb[j].pSchema; + Schema *pSchema = db->aDb[j].pSchema; if( zDb && sqlite3StrICmp(zDb, db->aDb[j].zName) ) continue; assert( pSchema || (j==1 && !db->aDb[1].pBt) ); if( pSchema ){ @@ -1379,7 +1379,8 @@ void sqlite3EndTable( sqlite3 *db = pParse->db; int iDb; - if( (pEnd==0 && pSelect==0) || pParse->nErr || sqlite3Tsd()->mallocFailed ) { + if( (pEnd==0 && pSelect==0) || + pParse->nErr || sqlite3ThreadData()->mallocFailed ) { return; } p = pParse->pNewTable; @@ -1542,7 +1543,7 @@ void sqlite3EndTable( if( db->init.busy && pParse->nErr==0 ){ Table *pOld; FKey *pFKey; - DbSchema *pSchema = p->pSchema; + Schema *pSchema = p->pSchema; pOld = sqlite3HashInsert(&pSchema->tblHash, p->zName, strlen(p->zName)+1,p); if( pOld ){ assert( p==pOld ); /* Malloc must have failed inside HashInsert() */ @@ -1616,7 +1617,7 @@ void sqlite3CreateView( */ p->pSelect = sqlite3SelectDup(pSelect); sqlite3SelectDelete(pSelect); - if( sqlite3Tsd()->mallocFailed ){ + if( sqlite3ThreadData()->mallocFailed ){ return; } if( !pParse->db->init.busy ){ @@ -1857,7 +1858,7 @@ void sqlite3DropTable(Parse *pParse, SrcList *pName, int isView, int noErr){ sqlite3 *db = pParse->db; int iDb; - if( pParse->nErr || sqlite3Tsd()->mallocFailed ) goto exit_drop_table; + if( pParse->nErr || sqlite3ThreadData()->mallocFailed ) goto exit_drop_table; assert( pName->nSrc==1 ); pTab = sqlite3LocateTable(pParse, pName->a[0].zName, pName->a[0].zDatabase); @@ -2220,7 +2221,9 @@ void sqlite3CreateIndex( Token *pName = 0; /* Unqualified name of the index to create */ struct ExprList_item *pListItem; /* For looping over pList */ - if( pParse->nErr || sqlite3Tsd()->mallocFailed ) goto exit_create_index; + if( pParse->nErr || sqlite3ThreadData()->mallocFailed ){ + goto exit_create_index; + } /* ** Find the table that is to be indexed. Return early if not found. @@ -2354,7 +2357,7 @@ void sqlite3CreateIndex( nName = strlen(zName); pIndex = sqliteMalloc( sizeof(Index) + nName + 2 + sizeof(int) + (sizeof(int)*2 + sizeof(CollSeq*) + 1)*pList->nExpr ); - if( sqlite3Tsd()->mallocFailed ) goto exit_create_index; + if( sqlite3ThreadData()->mallocFailed ) goto exit_create_index; pIndex->aiColumn = (int*)&pIndex->keyInfo.aColl[pList->nExpr]; pIndex->aiRowEst = (unsigned*)&pIndex->aiColumn[pList->nExpr]; pIndex->zName = (char*)&pIndex->aiRowEst[pList->nExpr+1]; @@ -2633,7 +2636,7 @@ void sqlite3DropIndex(Parse *pParse, SrcList *pName, int ifExists){ sqlite3 *db = pParse->db; int iDb; - if( pParse->nErr || sqlite3Tsd()->mallocFailed ){ + if( pParse->nErr || sqlite3ThreadData()->mallocFailed ){ goto exit_drop_index; } assert( pName->nSrc==1 ); @@ -2842,7 +2845,7 @@ SrcList *sqlite3SrcListAppend(SrcList *pList, Token *pTable, Token *pDatabase){ void sqlite3SrcListAssignCursors(Parse *pParse, SrcList *pList){ int i; struct SrcList_item *pItem; - assert(pList || sqlite3Tsd()->mallocFailed); + assert(pList || sqlite3ThreadData()->mallocFailed); if( pList ){ for(i=0, pItem=pList->a; i<pList->nSrc; i++, pItem++){ if( pItem->iCursor>=0 ) break; @@ -2891,7 +2894,7 @@ void sqlite3BeginTransaction(Parse *pParse, int type){ int i; if( pParse==0 || (db=pParse->db)==0 || db->aDb[0].pBt==0 ) return; - if( pParse->nErr || sqlite3Tsd()->mallocFailed ) return; + if( pParse->nErr || sqlite3ThreadData()->mallocFailed ) return; if( sqlite3AuthCheck(pParse, SQLITE_TRANSACTION, "BEGIN", 0, 0) ) return; v = sqlite3GetVdbe(pParse); @@ -2912,7 +2915,7 @@ void sqlite3CommitTransaction(Parse *pParse){ Vdbe *v; if( pParse==0 || (db=pParse->db)==0 || db->aDb[0].pBt==0 ) return; - if( pParse->nErr || sqlite3Tsd()->mallocFailed ) return; + if( pParse->nErr || sqlite3ThreadData()->mallocFailed ) return; if( sqlite3AuthCheck(pParse, SQLITE_TRANSACTION, "COMMIT", 0, 0) ) return; v = sqlite3GetVdbe(pParse); @@ -2929,7 +2932,7 @@ void sqlite3RollbackTransaction(Parse *pParse){ Vdbe *v; if( pParse==0 || (db=pParse->db)==0 || db->aDb[0].pBt==0 ) return; - if( pParse->nErr || sqlite3Tsd()->mallocFailed ) return; + if( pParse->nErr || sqlite3ThreadData()->mallocFailed ) return; if( sqlite3AuthCheck(pParse, SQLITE_TRANSACTION, "ROLLBACK", 0, 0) ) return; v = sqlite3GetVdbe(pParse); diff --git a/src/callback.c b/src/callback.c index 4995ec36b..d753a4d20 100644 --- a/src/callback.c +++ b/src/callback.c @@ -13,7 +13,7 @@ ** This file contains functions used to access the internal hash tables ** of user defined functions and collation sequences. ** -** $Id: callback.c,v 1.7 2005/12/14 22:51:17 drh Exp $ +** $Id: callback.c,v 1.8 2006/01/09 06:29:48 danielk1977 Exp $ */ #include "sqliteInt.h" @@ -177,7 +177,7 @@ static CollSeq *findCollSeqEntry( ** return the pColl pointer to be deleted (because it wasn't added ** to the hash table). */ - assert( !pDel || (sqlite3Tsd()->mallocFailed && pDel==pColl) ); + assert( !pDel || (sqlite3ThreadData()->mallocFailed && pDel==pColl) ); sqliteFree(pDel); } } diff --git a/src/delete.c b/src/delete.c index 9c5cf5175..fd5065d54 100644 --- a/src/delete.c +++ b/src/delete.c @@ -12,7 +12,7 @@ ** This file contains C code routines that are called by the parser ** in order to generate code for DELETE FROM statements. ** -** $Id: delete.c,v 1.115 2006/01/07 13:21:04 danielk1977 Exp $ +** $Id: delete.c,v 1.116 2006/01/09 06:29:48 danielk1977 Exp $ */ #include "sqliteInt.h" @@ -108,7 +108,7 @@ void sqlite3DeleteFrom( #endif sContext.pParse = 0; - if( pParse->nErr || sqlite3Tsd()->mallocFailed ){ + if( pParse->nErr || sqlite3ThreadData()->mallocFailed ){ goto delete_from_cleanup; } db = pParse->db; diff --git a/src/expr.c b/src/expr.c index 2846017db..6c78582ba 100644 --- a/src/expr.c +++ b/src/expr.c @@ -12,7 +12,7 @@ ** This file contains routines used for analyzing expressions and ** for generating VDBE code that evaluates expressions in SQLite. ** -** $Id: expr.c,v 1.244 2006/01/05 11:34:34 danielk1977 Exp $ +** $Id: expr.c,v 1.245 2006/01/09 06:29:48 danielk1977 Exp $ */ #include "sqliteInt.h" #include <ctype.h> @@ -263,7 +263,7 @@ Expr *sqlite3ExprAnd(Expr *pLeft, Expr *pRight){ void sqlite3ExprSpan(Expr *pExpr, Token *pLeft, Token *pRight){ assert( pRight!=0 ); assert( pLeft!=0 ); - if( !sqlite3Tsd()->mallocFailed && pRight->z && pLeft->z ){ + if( !sqlite3ThreadData()->mallocFailed && pRight->z && pLeft->z ){ assert( pLeft->dyn==0 || pLeft->z[pLeft->n]==0 ); if( pLeft->dyn==0 && pRight->dyn==0 ){ pExpr->span.z = pLeft->z; @@ -358,7 +358,7 @@ void sqlite3ExprAssignVarNumber(Parse *pParse, Expr *pExpr){ sqlite3ReallocOrFree((void**)&pParse->apVarExpr, pParse->nVarExprAlloc*sizeof(pParse->apVarExpr[0]) ); } - if( !sqlite3Tsd()->mallocFailed ){ + if( !sqlite3ThreadData()->mallocFailed ){ assert( pParse->apVarExpr!=0 ); pParse->apVarExpr[pParse->nVarExpr++] = pExpr; } @@ -462,7 +462,7 @@ ExprList *sqlite3ExprListDup(ExprList *p){ sqlite3TokenCopy(&pNewExpr->span, &pOldExpr->span); } assert( pNewExpr==0 || pNewExpr->span.z!=0 - || pOldExpr->span.z==0 || sqlite3Tsd()->mallocFailed ); + || pOldExpr->span.z==0 || sqlite3ThreadData()->mallocFailed ); pItem->zName = sqliteStrDup(pOldItem->zName); pItem->sortOrder = pOldItem->sortOrder; pItem->isAgg = pOldItem->isAgg; @@ -831,7 +831,7 @@ static int lookupName( zDb = sqlite3NameFromToken(pDbToken); zTab = sqlite3NameFromToken(pTableToken); zCol = sqlite3NameFromToken(pColumnToken); - if( sqlite3Tsd()->mallocFailed ){ + if( sqlite3ThreadData()->mallocFailed ){ goto lookupname_end; } @@ -1306,7 +1306,7 @@ void sqlite3CodeSubselect(Parse *pParse, Expr *pExpr){ int mem = pParse->nMem++; sqlite3VdbeAddOp(v, OP_MemLoad, mem, 0); testAddr = sqlite3VdbeAddOp(v, OP_If, 0, 0); - assert( testAddr>0 || sqlite3Tsd()->mallocFailed ); + assert( testAddr>0 || sqlite3ThreadData()->mallocFailed ); sqlite3VdbeAddOp(v, OP_MemInt, 1, mem); } diff --git a/src/insert.c b/src/insert.c index 3de2c4250..b1191eb7d 100644 --- a/src/insert.c +++ b/src/insert.c @@ -12,7 +12,7 @@ ** This file contains C code routines that are called by the parser ** to handle INSERT statements in SQLite. ** -** $Id: insert.c,v 1.154 2006/01/08 18:10:18 drh Exp $ +** $Id: insert.c,v 1.155 2006/01/09 06:29:48 danielk1977 Exp $ */ #include "sqliteInt.h" @@ -104,7 +104,7 @@ void sqlite3TableAffinityStr(Vdbe *v, Table *pTab){ ** ** No checking is done for sub-selects that are part of expressions. */ -static int selectReadsTable(Select *p, DbSchema *pSchema, int iTab){ +static int selectReadsTable(Select *p, Schema *pSchema, int iTab){ int i; struct SrcList_item *pItem; if( p->pSrc==0 ) return 0; @@ -225,7 +225,7 @@ void sqlite3Insert( int counterRowid; /* Memory cell holding rowid of autoinc counter */ #endif - if( pParse->nErr || sqlite3Tsd()->mallocFailed ) goto insert_cleanup; + if( pParse->nErr || sqlite3ThreadData()->mallocFailed ) goto insert_cleanup; db = pParse->db; /* Locate the table into which we will be inserting new information. @@ -338,7 +338,7 @@ void sqlite3Insert( /* Resolve the expressions in the SELECT statement and execute it. */ rc = sqlite3Select(pParse, pSelect, SRT_Subroutine, iInsertBlock,0,0,0,0); - if( rc || pParse->nErr || sqlite3Tsd()->mallocFailed ) goto insert_cleanup; + if( rc || pParse->nErr || sqlite3ThreadData()->mallocFailed ) goto insert_cleanup; iCleanup = sqlite3VdbeMakeLabel(v); sqlite3VdbeAddOp(v, OP_Goto, 0, iCleanup); diff --git a/src/legacy.c b/src/legacy.c index 40fa8f5b0..2d928aeac 100644 --- a/src/legacy.c +++ b/src/legacy.c @@ -14,7 +14,7 @@ ** other files are for internal use by SQLite and should not be ** accessed by users of the library. ** -** $Id: legacy.c,v 1.9 2005/12/12 06:53:04 danielk1977 Exp $ +** $Id: legacy.c,v 1.10 2006/01/09 06:29:49 danielk1977 Exp $ */ #include "sqliteInt.h" @@ -121,7 +121,7 @@ exec_out: if( pStmt ) sqlite3_finalize(pStmt); if( azCols ) sqliteFree(azCols); - if( sqlite3Tsd()->mallocFailed ){ + if( sqlite3ThreadData()->mallocFailed ){ rc = SQLITE_NOMEM; sqlite3MallocClearFailed(); } diff --git a/src/main.c b/src/main.c index d31439b92..236b103ff 100644 --- a/src/main.c +++ b/src/main.c @@ -14,7 +14,7 @@ ** other files are for internal use by SQLite and should not be ** accessed by users of the library. ** -** $Id: main.c,v 1.318 2006/01/06 21:52:50 drh Exp $ +** $Id: main.c,v 1.319 2006/01/09 06:29:49 danielk1977 Exp $ */ #include "sqliteInt.h" #include "os.h" @@ -634,7 +634,7 @@ int sqlite3BtreeFactory( */ const char *sqlite3_errmsg(sqlite3 *db){ const char *z; - if( sqlite3Tsd()->mallocFailed ){ + if( sqlite3ThreadData()->mallocFailed ){ return sqlite3ErrStr(SQLITE_NOMEM); } if( sqlite3SafetyCheck(db) || db->errCode==SQLITE_MISUSE ){ @@ -673,7 +673,7 @@ const void *sqlite3_errmsg16(sqlite3 *db){ }; const void *z; - if( sqlite3Tsd()->mallocFailed ){ + if( sqlite3ThreadData()->mallocFailed ){ return (void *)(&outOfMemBe[SQLITE_UTF16NATIVE==SQLITE_UTF16LE?1:0]); } if( sqlite3SafetyCheck(db) || db->errCode==SQLITE_MISUSE ){ @@ -694,7 +694,7 @@ const void *sqlite3_errmsg16(sqlite3 *db){ ** passed to this function, we assume a malloc() failed during sqlite3_open(). */ int sqlite3_errcode(sqlite3 *db){ - if( !db || sqlite3Tsd()->mallocFailed ){ + if( !db || sqlite3ThreadData()->mallocFailed ){ return SQLITE_NOMEM; } if( sqlite3SafetyCheck(db) ){ @@ -716,7 +716,7 @@ static int openDatabase( int rc; CollSeq *pColl; - assert( !sqlite3Tsd()->mallocFailed ); + assert( !sqlite3ThreadData()->mallocFailed ); /* Allocate the sqlite data structure */ db = sqliteMalloc( sizeof(sqlite3) ); @@ -751,7 +751,7 @@ static int openDatabase( /* sqlite3_create_collation() is an external API. So the mallocFailed flag ** will have been cleared before returning. So set it explicitly here. */ - sqlite3Tsd()->mallocFailed = 1; + sqlite3ThreadData()->mallocFailed = 1; db->magic = SQLITE_MAGIC_CLOSED; goto opendb_out; } @@ -840,7 +840,7 @@ int sqlite3_open16( rc = sqlite3_exec(*ppDb, "PRAGMA encoding = 'UTF-16'", 0, 0, 0); } }else{ - assert( sqlite3Tsd()->mallocFailed ); + assert( sqlite3ThreadData()->mallocFailed ); sqlite3MallocClearFailed(); } sqlite3ValueFree(pVal); diff --git a/src/os_unix.c b/src/os_unix.c index 71125fa61..34da78dd6 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -502,7 +502,7 @@ static int findLockInfo( struct stat statbuf; struct lockInfo *pLock; struct openCnt *pOpen; - SqliteTsd *pTsd = sqlite3Tsd(); + ThreadData *pTsd = sqlite3ThreadData(); rc = fstat(fd, &statbuf); if( rc!=0 ) return 1; @@ -1407,7 +1407,7 @@ static int unixUnlock(OsFile *id, int locktype){ ** Close a file. */ static int unixClose(OsFile **pId){ - SqliteTsd *pTsd = sqlite3Tsd(); + ThreadData *pTsd = sqlite3ThreadData(); unixFile *id = (unixFile*)*pId; if( !id ) return SQLITE_OK; if( CHECK_THREADID(id) ) return SQLITE_MISUSE; @@ -1646,9 +1646,9 @@ int sqlite3UnixInMutex(){ /* ** This function is called automatically when a thread exists to delete -** the threads SqliteTsd structure. +** the threads ThreadData structure. ** -** Because the SqliteTsd structure is required by higher level routines +** Because the ThreadData structure is required by higher level routines ** such as sqliteMalloc() we use OsFree() and OsMalloc() directly to ** allocate the thread specific data. */ diff --git a/src/pager.c b/src/pager.c index e41833ce8..6b266c1e0 100644 --- a/src/pager.c +++ b/src/pager.c @@ -18,7 +18,7 @@ ** file simultaneously, or one process from reading the database while ** another is writing. ** -** @(#) $Id: pager.c,v 1.231 2006/01/06 14:32:20 drh Exp $ +** @(#) $Id: pager.c,v 1.232 2006/01/09 06:29:49 danielk1977 Exp $ */ #ifndef SQLITE_OMIT_DISKIO #include "sqliteInt.h" @@ -1623,14 +1623,14 @@ int sqlite3pager_open( int useJournal = (flags & PAGER_OMIT_JOURNAL)==0; int noReadlock = (flags & PAGER_NO_READLOCK)!=0; char zTemp[SQLITE_TEMPNAME_SIZE]; - SqliteTsd *pTsd = sqlite3Tsd(); + ThreadData *pTsd = sqlite3ThreadData(); /* If malloc() has already failed return SQLITE_NOMEM. Before even ** testing for this, set *ppPager to NULL so the caller knows the pager ** structure was never allocated. */ *ppPager = 0; - if( sqlite3Tsd()->mallocFailed ){ + if( sqlite3ThreadData()->mallocFailed ){ return SQLITE_NOMEM; } memset(&fd, 0, sizeof(fd)); @@ -2027,7 +2027,7 @@ int sqlite3pager_truncate(Pager *pPager, Pgno nPage){ int sqlite3pager_close(Pager *pPager){ PgHdr *pPg, *pNext; #ifndef SQLITE_OMIT_MEMORY_MANAGEMENT - SqliteTsd *pTsd = sqlite3Tsd(); + ThreadData *pTsd = sqlite3ThreadData(); #endif switch( pPager->state ){ @@ -2088,7 +2088,7 @@ int sqlite3pager_close(Pager *pPager){ #ifndef SQLITE_OMIT_MEMORY_MANAGEMENT /* Remove the pager from the linked list of pagers starting at - ** SqliteTsd.pPager. + ** ThreadData.pPager. */ if( pPager==pTsd->pPager ){ pTsd->pPager = pPager->pNext; @@ -2455,7 +2455,7 @@ static int pager_recycle(Pager *pPager, int syncOk, PgHdr **ppPg){ */ #ifndef SQLITE_OMIT_MEMORY_MANAGEMENT int sqlite3pager_release_memory(int nReq){ - SqliteTsd *pTsd = sqlite3Tsd(); + ThreadData *pTsd = sqlite3ThreadData(); Pager *p; int nReleased = 0; int i; diff --git a/src/prepare.c b/src/prepare.c index 4b86e7663..0b24596d2 100644 --- a/src/prepare.c +++ b/src/prepare.c @@ -13,7 +13,7 @@ ** interface, and routines that contribute to loading the database schema ** from disk. ** -** $Id: prepare.c,v 1.15 2006/01/06 21:52:50 drh Exp $ +** $Id: prepare.c,v 1.16 2006/01/09 06:29:49 danielk1977 Exp $ */ #include "sqliteInt.h" #include "os.h" @@ -24,7 +24,7 @@ ** that the database is corrupt. */ static void corruptSchema(InitData *pData, const char *zExtra){ - if( !sqlite3Tsd()->mallocFailed ){ + if( !sqlite3ThreadData()->mallocFailed ){ sqlite3SetString(pData->pzErrMsg, "malformed database schema", zExtra!=0 && zExtra[0]!=0 ? " - " : (char*)0, zExtra, (char*)0); } @@ -49,7 +49,7 @@ int sqlite3InitCallback(void *pInit, int argc, char **argv, char **azColName){ sqlite3 *db = pData->db; int iDb; - if( sqlite3Tsd()->mallocFailed ){ + if( sqlite3ThreadData()->mallocFailed ){ return SQLITE_NOMEM; } @@ -76,7 +76,7 @@ int sqlite3InitCallback(void *pInit, int argc, char **argv, char **azColName){ db->init.iDb = 0; if( SQLITE_OK!=rc ){ if( rc==SQLITE_NOMEM ){ - sqlite3Tsd()->mallocFailed = 1; + sqlite3ThreadData()->mallocFailed = 1; }else{ corruptSchema(pData, zErr); } @@ -156,7 +156,7 @@ static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){ assert( iDb>=0 && iDb<db->nDb ); if( 0==db->aDb[iDb].pSchema ){ - DbSchema *pS = sqlite3BtreeSchema(db->aDb[iDb].pBt, sizeof(DbSchema), + Schema *pS = sqlite3BtreeSchema(db->aDb[iDb].pBt, sizeof(Schema), sqlite3SchemaFree); db->aDb[iDb].pSchema = pS; if( !pS ){ @@ -313,7 +313,7 @@ static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){ #endif sqlite3BtreeCloseCursor(curMain); } - if( sqlite3Tsd()->mallocFailed ){ + if( sqlite3ThreadData()->mallocFailed ){ sqlite3SetString(pzErrMsg, "out of memory", (char*)0); rc = SQLITE_NOMEM; sqlite3ResetInternalSchema(db, 0); @@ -425,7 +425,7 @@ static int schemaIsValid(sqlite3 *db){ /* ** Free all resources held by the schema structure. The void* argument points -** at a DbSchema struct. This function does not call sqliteFree() on the +** at a Schema struct. This function does not call sqliteFree() on the ** pointer itself, it just cleans up subsiduary resources (i.e. the contents ** of the schema hash tables). */ @@ -433,7 +433,7 @@ void sqlite3SchemaFree(void *p){ Hash temp1; Hash temp2; HashElem *pElem; - DbSchema *pSchema = (DbSchema *)p; + Schema *pSchema = (Schema *)p; temp1 = pSchema->tblHash; temp2 = pSchema->trigHash; @@ -454,12 +454,12 @@ void sqlite3SchemaFree(void *p){ pSchema->flags &= ~DB_SchemaLoaded; } -DbSchema *sqlite3SchemaGet(Btree *pBt){ - DbSchema * p; +Schema *sqlite3SchemaGet(Btree *pBt){ + Schema * p; if( pBt ){ - p = (DbSchema *)sqlite3BtreeSchema(pBt,sizeof(DbSchema),sqlite3SchemaFree); + p = (Schema *)sqlite3BtreeSchema(pBt,sizeof(Schema),sqlite3SchemaFree); }else{ - p = (DbSchema *)sqliteMalloc(sizeof(DbSchema)); + p = (Schema *)sqliteMalloc(sizeof(Schema)); } if( p && 0==p->file_format ){ sqlite3HashInit(&p->tblHash, SQLITE_HASH_STRING, 0); @@ -470,7 +470,7 @@ DbSchema *sqlite3SchemaGet(Btree *pBt){ return p; } -int sqlite3SchemaToIndex(sqlite3 *db, DbSchema *pSchema){ +int sqlite3SchemaToIndex(sqlite3 *db, Schema *pSchema){ int i = -1000000; /* If pSchema is NULL, then return -1000000. This happens when code in @@ -509,7 +509,7 @@ int sqlite3_prepare( int rc = SQLITE_OK; int i; - assert( !sqlite3Tsd()->mallocFailed ); + assert( !sqlite3ThreadData()->mallocFailed ); assert( ppStmt ); *ppStmt = 0; @@ -534,7 +534,7 @@ int sqlite3_prepare( sParse.db = db; sqlite3RunParser(&sParse, zSql, &zErrMsg); - if( sqlite3Tsd()->mallocFailed ){ + if( sqlite3ThreadData()->mallocFailed ){ sParse.rc = SQLITE_NOMEM; } if( sParse.rc==SQLITE_DONE ) sParse.rc = SQLITE_OK; @@ -584,7 +584,7 @@ int sqlite3_prepare( /* We must check for malloc failure last of all, in case malloc() failed ** inside of the sqlite3Error() call above or something. */ - if( sqlite3Tsd()->mallocFailed ){ + if( sqlite3ThreadData()->mallocFailed ){ rc = SQLITE_NOMEM; sqlite3Error(db, rc, 0); } diff --git a/src/select.c b/src/select.c index 6b7091204..1f42d6423 100644 --- a/src/select.c +++ b/src/select.c @@ -12,7 +12,7 @@ ** This file contains C code routines that are called by the parser ** to handle SELECT statements in SQLite. ** -** $Id: select.c,v 1.289 2006/01/09 00:09:02 drh Exp $ +** $Id: select.c,v 1.290 2006/01/09 06:29:49 danielk1977 Exp $ */ #include "sqliteInt.h" @@ -872,7 +872,7 @@ static void generateColumnNames( #endif assert( v!=0 ); - if( pParse->colNamesSet || v==0 || sqlite3Tsd()->mallocFailed ) return; + if( pParse->colNamesSet || v==0 || sqlite3ThreadData()->mallocFailed ) return; pParse->colNamesSet = 1; fullNames = (db->flags & SQLITE_FullColNames)!=0; shortNames = (db->flags & SQLITE_ShortColNames)!=0; @@ -1000,7 +1000,7 @@ Table *sqlite3ResultSetOfSelect(Parse *pParse, char *zTabName, Select *pSelect){ zName = sqlite3MPrintf("column%d", i+1); } sqlite3Dequote(zName); - if( sqlite3Tsd()->mallocFailed ){ + if( sqlite3ThreadData()->mallocFailed ){ sqliteFree(zName); sqlite3DeleteTable(0, pTab); return 0; @@ -1072,7 +1072,7 @@ static int prepSelectStmt(Parse *pParse, Select *p){ Table *pTab; struct SrcList_item *pFrom; - if( p==0 || p->pSrc==0 || sqlite3Tsd()->mallocFailed ) return 1; + if( p==0 || p->pSrc==0 || sqlite3ThreadData()->mallocFailed ) return 1; pTabList = p->pSrc; pEList = p->pEList; @@ -2684,7 +2684,7 @@ int sqlite3Select( AggInfo sAggInfo; /* Information used by aggregate queries */ int iEnd; /* Address of the end of the query */ - if( sqlite3Tsd()->mallocFailed || pParse->nErr || p==0 ) return 1; + if( sqlite3ThreadData()->mallocFailed || pParse->nErr || p==0 ) return 1; if( sqlite3AuthCheck(pParse, SQLITE_SELECT, 0, 0, 0) ) return 1; memset(&sAggInfo, 0, sizeof(sAggInfo)); @@ -2938,7 +2938,7 @@ int sqlite3Select( goto select_end; } } - if( sqlite3Tsd()->mallocFailed ) goto select_end; + if( sqlite3ThreadData()->mallocFailed ) goto select_end; /* Processing for aggregates with GROUP BY is very different and ** much more complex tha aggregates without a GROUP BY. diff --git a/src/sqliteInt.h b/src/sqliteInt.h index e2c618ee1..20af08b31 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -11,7 +11,7 @@ ************************************************************************* ** Internal interface definitions for SQLite. ** -** @(#) $Id: sqliteInt.h,v 1.453 2006/01/07 13:21:04 danielk1977 Exp $ +** @(#) $Id: sqliteInt.h,v 1.454 2006/01/09 06:29:49 danielk1977 Exp $ */ #ifndef _SQLITEINT_H_ #define _SQLITEINT_H_ @@ -262,7 +262,7 @@ extern int sqlite3_nFree; /* Number of sqliteFree() calls */ extern int sqlite3_iMallocFail; /* Fail sqliteMalloc() after this many calls */ extern int sqlite3_iMallocReset; /* Set iMallocFail to this when it reaches 0 */ #define ENTER_MALLOC (\ - sqlite3Tsd()->zFile = __FILE__, sqlite3Tsd()->iLine = __LINE__ \ + sqlite3ThreadData()->zFile = __FILE__, sqlite3ThreadData()->iLine = __LINE__ \ ) #define sqliteMalloc(x) (ENTER_MALLOC, sqlite3Malloc(x)) #define sqliteMallocRaw(x) (ENTER_MALLOC, sqlite3MallocRaw(x)) @@ -288,7 +288,7 @@ extern int sqlite3_iMallocReset; /* Set iMallocFail to this when it reaches 0 */ /* ** An instance of this structure is allocated for each thread that uses SQLite. */ -struct SqliteTsd { +struct ThreadData { u8 isInit; /* True if structure has been initialised */ u8 mallocFailed; /* True after a malloc() has failed */ u8 disableReleaseMemory; /* True to make sqlite3_release_memory() a no-op */ @@ -305,7 +305,7 @@ struct SqliteTsd { #endif #ifdef SQLITE_MEMDEBUG - i64 nMaxAlloc; /* High water mark of SqliteTsd.nAlloc */ + i64 nMaxAlloc; /* High water mark of ThreadData.nAlloc */ int mallocAllowed; /* assert() in sqlite3Malloc() if not set */ int isFail; /* True if all malloc() calls should fail */ const char *zFile; /* Filename to associate debugging info with */ @@ -346,7 +346,7 @@ typedef struct AuthContext AuthContext; typedef struct CollSeq CollSeq; typedef struct Column Column; typedef struct Db Db; -typedef struct DbSchema DbSchema; +typedef struct Schema Schema; typedef struct Expr Expr; typedef struct ExprList ExprList; typedef struct FKey FKey; @@ -359,7 +359,7 @@ typedef struct NameContext NameContext; typedef struct Parse Parse; typedef struct Select Select; typedef struct SrcList SrcList; -typedef struct SqliteTsd SqliteTsd; +typedef struct ThreadData ThreadData; typedef struct Table Table; typedef struct TableLock TableLock; typedef struct Token Token; @@ -384,13 +384,13 @@ struct Db { int cache_size; /* Number of pages to use in the cache */ void *pAux; /* Auxiliary data. Usually NULL */ void (*xFreeAux)(void*); /* Routine to free pAux */ - DbSchema *pSchema; /* Pointer to database schema (possibly shared) */ + Schema *pSchema; /* Pointer to database schema (possibly shared) */ }; /* ** An instance of the following structure stores a database schema. */ -struct DbSchema { +struct Schema { int schema_cookie; /* Database schema version number for this file */ Hash tblHash; /* All tables indexed by name */ Hash idxHash; /* All (named) indices indexed by name */ @@ -707,7 +707,7 @@ struct Table { #ifndef SQLITE_OMIT_ALTERTABLE int addColOffset; /* Offset in CREATE TABLE statement to add a new column */ #endif - DbSchema *pSchema; + Schema *pSchema; }; /* @@ -846,7 +846,7 @@ struct Index { // u8 iDb; /* Index in sqlite.aDb[] of where this index is stored */ char *zColAff; /* String defining the affinity of each column */ Index *pNext; /* The next index associated with the same table */ - DbSchema *pSchema; + Schema *pSchema; KeyInfo keyInfo; /* Info on how to order keys. MUST BE LAST */ }; @@ -972,7 +972,7 @@ struct Expr { Select *pSelect; /* When the expression is a sub-select. Also the ** right side of "<expr> IN (<select>)" */ Table *pTab; /* Table for OP_Column expressions. */ - DbSchema *pSchema; + Schema *pSchema; }; /* @@ -1317,8 +1317,8 @@ struct Trigger { the <column-list> is stored here */ int foreach; /* One of TK_ROW or TK_STATEMENT */ Token nameToken; /* Token containing zName. Use during parsing only */ - DbSchema *pSchema; /* Schema containing the trigger */ - DbSchema *pTabSchema; /* Schema containing the table */ + Schema *pSchema; /* Schema containing the trigger */ + Schema *pTabSchema; /* Schema containing the table */ TriggerStep *step_list; /* Link list of trigger program steps */ Trigger *pNext; /* Next trigger associated with the table */ }; @@ -1728,12 +1728,12 @@ void sqlite3AnalysisLoad(sqlite3*,int iDB); void sqlite3DefaultRowEst(Index*); void sqlite3RegisterLikeFunctions(sqlite3*, int); int sqlite3IsLikeFunction(sqlite3*,Expr*,int*,char*); -SqliteTsd *sqlite3Tsd(); +ThreadData *sqlite3ThreadData(); void sqlite3AttachFunctions(sqlite3 *); void sqlite3MinimumFileFormat(Parse*, int, int); void sqlite3SchemaFree(void *); -DbSchema *sqlite3SchemaGet(Btree *); -int sqlite3SchemaToIndex(sqlite3 *db, DbSchema *); +Schema *sqlite3SchemaGet(Btree *); +int sqlite3SchemaToIndex(sqlite3 *db, Schema *); #ifndef SQLITE_OMIT_SHARED_CACHE void sqlite3TableLock(Parse *, int, int, u8, const char *); diff --git a/src/test1.c b/src/test1.c index c86d3e622..a58d71113 100644 --- a/src/test1.c +++ b/src/test1.c @@ -13,7 +13,7 @@ ** is not included in the SQLite library. It is used for automated ** testing of the SQLite library. ** -** $Id: test1.c,v 1.183 2006/01/07 16:06:07 drh Exp $ +** $Id: test1.c,v 1.184 2006/01/09 06:29:49 danielk1977 Exp $ */ #include "sqliteInt.h" #include "tcl.h" @@ -829,7 +829,7 @@ static int sqlite3_mprintf_hexdouble( ** first failure will continue to fail on every call. If REPEAT-INTERVAL is ** 2 then every other malloc will fail. And so forth. ** -** Turn off this mechanism and reset the sqlite3Tsd()->mallocFailed variable is N==0. +** Turn off this mechanism and reset the sqlite3ThreadData()->mallocFailed variable is N==0. */ #ifdef SQLITE_MEMDEBUG static int sqlite_malloc_fail( @@ -911,12 +911,12 @@ static int sqlite_malloc_outstanding( if( objc==2 ){ const char *zArg = Tcl_GetString(objv[1]); if( 0==strcmp(zArg, "-bytes") ){ - Tcl_SetObjResult(interp, Tcl_NewIntObj(sqlite3Tsd()->nAlloc)); + Tcl_SetObjResult(interp, Tcl_NewIntObj(sqlite3ThreadData()->nAlloc)); #ifndef SQLITE_OMIT_MEMORY_MANAGEMENT }else if( 0==strcmp(zArg, "-maxbytes") ){ - Tcl_SetObjResult(interp, Tcl_NewWideIntObj(sqlite3Tsd()->nMaxAlloc)); + Tcl_SetObjResult(interp, Tcl_NewWideIntObj(sqlite3ThreadData()->nMaxAlloc)); }else if( 0==strcmp(zArg, "-clearmaxbytes") ){ - sqlite3Tsd()->nMaxAlloc = sqlite3Tsd()->nAlloc; + sqlite3ThreadData()->nMaxAlloc = sqlite3ThreadData()->nAlloc; #endif }else{ Tcl_AppendResult(interp, "bad option \"", zArg, @@ -945,7 +945,7 @@ static int test_enable_shared_cache( ){ int rc; int enable; - SqliteTsd *pTsd = sqlite3Tsd(); + ThreadData *pTsd = sqlite3ThreadData(); Tcl_SetObjResult(interp, Tcl_NewBooleanObj(pTsd->useSharedData)); if( objc!=2 ){ @@ -2988,7 +2988,7 @@ static int test_soft_heap_limit( Tcl_WrongNumArgs(interp, 1, objv, "?N?"); return TCL_ERROR; } - amt = sqlite3Tsd()->nSoftHeapLimit; + amt = sqlite3ThreadData()->nSoftHeapLimit; if( objc==2 ){ int N; if( Tcl_GetIntFromObj(interp, objv[1], &N) ) return TCL_ERROR; diff --git a/src/tokenize.c b/src/tokenize.c index 6ea3b6878..5645317ba 100644 --- a/src/tokenize.c +++ b/src/tokenize.c @@ -15,7 +15,7 @@ ** individual tokens and sends those tokens one-by-one over to the ** parser for analysis. ** -** $Id: tokenize.c,v 1.111 2006/01/07 13:21:04 danielk1977 Exp $ +** $Id: tokenize.c,v 1.112 2006/01/09 06:29:49 danielk1977 Exp $ */ #include "sqliteInt.h" #include "os.h" @@ -358,7 +358,7 @@ int sqlite3RunParser(Parse *pParse, const char *zSql, char **pzErrMsg){ assert( pParse->nVarExprAlloc==0 ); assert( pParse->apVarExpr==0 ); pParse->zTail = pParse->zSql = zSql; - while( sqlite3Tsd()->mallocFailed==0 && zSql[i]!=0 ){ + while( sqlite3ThreadData()->mallocFailed==0 && zSql[i]!=0 ){ assert( i>=0 ); pParse->sLastToken.z = (u8*)&zSql[i]; assert( pParse->sLastToken.dyn==0 ); @@ -406,7 +406,7 @@ abort_parse: sqlite3Parser(pEngine, 0, pParse->sLastToken, pParse); } sqlite3ParserFree(pEngine, sqlite3FreeX); - if( sqlite3Tsd()->mallocFailed ){ + if( sqlite3ThreadData()->mallocFailed ){ pParse->rc = SQLITE_NOMEM; } if( pParse->rc!=SQLITE_OK && pParse->rc!=SQLITE_DONE && pParse->zErrMsg==0 ){ diff --git a/src/trigger.c b/src/trigger.c index b88839335..ec1c4c67a 100644 --- a/src/trigger.c +++ b/src/trigger.c @@ -81,14 +81,14 @@ void sqlite3BeginTrigger( ** If sqlite3SrcListLookup() returns 0, indicating the table does not ** exist, the error is caught by the block below. */ - if( !pTableName || sqlite3Tsd()->mallocFailed ) goto trigger_cleanup; + if( !pTableName || sqlite3ThreadData()->mallocFailed ) goto trigger_cleanup; pTab = sqlite3SrcListLookup(pParse, pTableName); if( pName2->n==0 && pTab && pTab->pSchema==db->aDb[1].pSchema ){ iDb = 1; } /* Ensure the table name matches database name and that the table exists */ - if( sqlite3Tsd()->mallocFailed ) goto trigger_cleanup; + if( sqlite3ThreadData()->mallocFailed ) goto trigger_cleanup; assert( pTableName->nSrc==1 ); if( sqlite3FixInit(&sFix, pParse, iDb, "trigger", pName) && sqlite3FixSrcList(&sFix, pTableName) ){ @@ -255,7 +255,7 @@ void sqlite3FinishTrigger( pDel = sqlite3HashInsert(&db->aDb[iDb].pSchema->trigHash, pTrig->name, strlen(pTrig->name)+1, pTrig); if( pDel ){ - assert( sqlite3Tsd()->mallocFailed && pDel==pTrig ); + assert( sqlite3ThreadData()->mallocFailed && pDel==pTrig ); goto triggerfinish_cleanup; } n = strlen(pTrig->table) + 1; @@ -439,7 +439,7 @@ void sqlite3DropTrigger(Parse *pParse, SrcList *pName){ int nName; sqlite3 *db = pParse->db; - if( sqlite3Tsd()->mallocFailed ) goto drop_trigger_cleanup; + if( sqlite3ThreadData()->mallocFailed ) goto drop_trigger_cleanup; if( SQLITE_OK!=sqlite3ReadSchema(pParse) ){ goto drop_trigger_cleanup; } diff --git a/src/update.c b/src/update.c index 0a47d1da5..ff10b95e8 100644 --- a/src/update.c +++ b/src/update.c @@ -12,7 +12,7 @@ ** This file contains C code routines that are called by the parser ** to handle UPDATE statements. ** -** $Id: update.c,v 1.116 2006/01/07 13:21:04 danielk1977 Exp $ +** $Id: update.c,v 1.117 2006/01/09 06:29:49 danielk1977 Exp $ */ #include "sqliteInt.h" @@ -100,7 +100,7 @@ void sqlite3Update( int oldIdx = -1; /* index of trigger "old" temp table */ sContext.pParse = 0; - if( pParse->nErr || sqlite3Tsd()->mallocFailed ) goto update_cleanup; + if( pParse->nErr || sqlite3ThreadData()->mallocFailed ) goto update_cleanup; db = pParse->db; assert( pTabList->nSrc==1 ); diff --git a/src/util.c b/src/util.c index ebdcfb597..f5e4c69a8 100644 --- a/src/util.c +++ b/src/util.c @@ -14,7 +14,7 @@ ** This file contains functions for allocating memory, comparing ** strings, and stuff like that. ** -** $Id: util.c,v 1.162 2006/01/06 21:52:50 drh Exp $ +** $Id: util.c,v 1.163 2006/01/09 06:29:49 danielk1977 Exp $ */ #include "sqliteInt.h" #include "os.h" @@ -72,7 +72,7 @@ ** value indicates no limit. */ void sqlite3_soft_heap_limit(sqlite_int64 n){ - sqlite3Tsd()->nSoftHeapLimit = n; + sqlite3ThreadData()->nSoftHeapLimit = n; } /* @@ -198,7 +198,7 @@ int sqlite3_iMallocReset = -1; /* When iMallocFail reaches 0, set to this */ ** the failure should be simulated. Return false to proceed as normal. */ static int failMalloc(){ - SqliteTsd *pTsd = sqlite3Tsd(); + ThreadData *pTsd = sqlite3ThreadData(); if( pTsd->isFail ){ return 1; } @@ -266,11 +266,11 @@ static void applyGuards(u32 *p) /* Line number */ z = &((char *)z)[TESTALLOC_NGUARD*sizeof(u32)]; /* Guard words */ z = &zAlloc[TESTALLOC_OFFSET_LINENUMBER(p)]; - memcpy(z, &sqlite3Tsd()->iLine, sizeof(u32)); + memcpy(z, &sqlite3ThreadData()->iLine, sizeof(u32)); /* File name */ z = &zAlloc[TESTALLOC_OFFSET_FILENAME(p)]; - strncpy(z, sqlite3Tsd()->zFile, TESTALLOC_FILESIZE); + strncpy(z, sqlite3ThreadData()->zFile, TESTALLOC_FILESIZE); z[TESTALLOC_FILESIZE - 1] = '\0'; /* User string */ @@ -306,7 +306,7 @@ static void *getOsPointer(void *p) ** of allocations. */ static void linkAlloc(void *p){ - SqliteTsd *pTsd = sqlite3Tsd(); + ThreadData *pTsd = sqlite3ThreadData(); void **pp = (void **)p; pp[0] = 0; pp[1] = pTsd->pFirst; @@ -322,7 +322,7 @@ static void linkAlloc(void *p){ */ static void unlinkAlloc(void *p) { - SqliteTsd *pTsd = sqlite3Tsd(); + ThreadData *pTsd = sqlite3ThreadData(); void **pp = (void **)p; if( p==pTsd->pFirst ){ assert(!pp[0]); @@ -355,7 +355,7 @@ static void relinkAlloc(void *p) if( pp[0] ){ ((void **)(pp[0]))[1] = p; }else{ - SqliteTsd *pTsd = sqlite3Tsd(); + ThreadData *pTsd = sqlite3ThreadData(); pTsd->pFirst = p; } if( pp[1] ){ @@ -387,7 +387,7 @@ static void relinkAlloc(void *p) #include <tcl.h> int sqlite3OutstandingMallocs(Tcl_Interp *interp){ void *p; - SqliteTsd *pTsd = sqlite3Tsd(); + ThreadData *pTsd = sqlite3ThreadData(); Tcl_Obj *pRes = Tcl_NewObj(); Tcl_IncrRefCount(pRes); @@ -435,7 +435,7 @@ int sqlite3OutstandingMallocs(Tcl_Interp *interp){ */ static void * OSMALLOC(int n){ #ifndef SQLITE_OMIT_MEMORY_MANAGEMENT - SqliteTsd *pTsd = sqlite3Tsd(); + ThreadData *pTsd = sqlite3ThreadData(); pTsd->nMaxAlloc = MAX(pTsd->nMaxAlloc, pTsd->nAlloc); #endif if( !failMalloc() ){ @@ -467,7 +467,7 @@ void OSFREE(void *pFree){ */ void * OSREALLOC(void *pRealloc, int n){ #ifndef SQLITE_OMIT_MEMORY_MANAGEMENT - SqliteTsd *pTsd = sqlite3Tsd(); + ThreadData *pTsd = sqlite3ThreadData(); pTsd->nMaxAlloc = MAX(pTsd->nMaxAlloc, pTsd->nAlloc); #endif if( !failMalloc() ){ @@ -482,7 +482,7 @@ void * OSREALLOC(void *pRealloc, int n){ } void OSMALLOC_FAILED(){ - sqlite3Tsd()->isFail = 0; + sqlite3ThreadData()->isFail = 0; } int OSSIZEOF(void *p){ @@ -522,7 +522,7 @@ int OSSIZEOF(void *p){ */ #ifndef SQLITE_OMIT_MEMORY_MANAGEMENT static void handleSoftLimit(int n){ - SqliteTsd *pTsd = sqlite3Tsd(); + ThreadData *pTsd = sqlite3ThreadData(); pTsd->nAlloc += (i64)n; if( n>0 && pTsd->nSoftHeapLimit>0 ){ while( pTsd->nAlloc>pTsd->nSoftHeapLimit && sqlite3_release_memory(n) ); @@ -538,7 +538,7 @@ static void handleSoftLimit(int n){ ** by calling sqlite3_release_memory(). */ void *sqlite3MallocRaw(int n){ - SqliteTsd *pTsd = sqlite3Tsd(); + ThreadData *pTsd = sqlite3ThreadData(); void *p = 0; if( n>0 && !pTsd->mallocFailed ){ handleSoftLimit(n); @@ -546,11 +546,11 @@ void *sqlite3MallocRaw(int n){ if( !p ){ /* If the allocation failed, call handleSoftLimit() again, this time ** with the additive inverse of the argument passed to - ** handleSoftLimit() above. This is so the SqliteTsd.nAlloc variable is + ** handleSoftLimit() above. This is so the ThreadData.nAlloc variable is ** still correct after a malloc() failure. */ handleSoftLimit(n * -1); - sqlite3Tsd()->mallocFailed = 1; + sqlite3ThreadData()->mallocFailed = 1; OSMALLOC_FAILED(); } } @@ -563,7 +563,7 @@ void *sqlite3MallocRaw(int n){ ** attempt to free memory by calling sqlite3_release_memory(). */ void *sqlite3Realloc(void *p, int n){ - SqliteTsd *pTsd = sqlite3Tsd(); + ThreadData *pTsd = sqlite3ThreadData(); if( pTsd->mallocFailed ){ return 0; } @@ -577,7 +577,7 @@ void *sqlite3Realloc(void *p, int n){ if( !np ){ /* If the allocation failed, call handleSoftLimit() again, this time ** with the additive inverse of the argument passed to - ** handleSoftLimit() above. This is so the SqliteTsd.nAlloc variable is + ** handleSoftLimit() above. This is so the ThreadData.nAlloc variable is ** still correct after a malloc() failure. */ handleSoftLimit(OSSIZEOF(p) - n); @@ -648,7 +648,7 @@ int sqlite3AllocSize(void *p){ ** functions call sqlite3MallocRaw() directly instead of sqliteMalloc(). This ** is because when memory debugging is turned on, these two functions are ** called via macros that record the current file and line number in the -** SqliteTsd structure. +** ThreadData structure. */ char *sqlite3StrDup(const char *z){ char *zNew; @@ -1302,10 +1302,10 @@ void *sqlite3TextToPtr(const char *z){ #endif /* -** Return a pointer to the SqliteTsd associated with the calling thread. +** Return a pointer to the ThreadData associated with the calling thread. */ -SqliteTsd *sqlite3Tsd(){ - SqliteTsd *pTsd = sqlite3OsThreadSpecificData(sizeof(SqliteTsd)); +ThreadData *sqlite3ThreadData(){ + ThreadData *pTsd = sqlite3OsThreadSpecificData(sizeof(ThreadData)); if( pTsd && !pTsd->isInit ){ pTsd->nSoftHeapLimit = -1; #ifndef NDEBUG @@ -1321,7 +1321,7 @@ SqliteTsd *sqlite3Tsd(){ ** entry points that may have called sqliteMalloc(). */ void sqlite3MallocClearFailed(){ - sqlite3Tsd()->mallocFailed = 0; + sqlite3ThreadData()->mallocFailed = 0; } @@ -1331,8 +1331,8 @@ void sqlite3MallocClearFailed(){ ** cause an assert to fail if sqliteMalloc() or sqliteRealloc() is called. */ void sqlite3MallocDisallow(){ - assert(sqlite3Tsd()->mallocAllowed); - sqlite3Tsd()->mallocAllowed = 0; + assert(sqlite3ThreadData()->mallocAllowed); + sqlite3ThreadData()->mallocAllowed = 0; } /* @@ -1340,7 +1340,7 @@ void sqlite3MallocDisallow(){ ** by sqlite3MallocDisallow(). */ void sqlite3MallocAllow(){ - assert(!sqlite3Tsd()->mallocAllowed); - sqlite3Tsd()->mallocAllowed = 1; + assert(!sqlite3ThreadData()->mallocAllowed); + sqlite3ThreadData()->mallocAllowed = 1; } #endif diff --git a/src/vacuum.c b/src/vacuum.c index 5af673a48..2d7f7652c 100644 --- a/src/vacuum.c +++ b/src/vacuum.c @@ -14,7 +14,7 @@ ** Most of the code in this file may be omitted by defining the ** SQLITE_OMIT_VACUUM macro. ** -** $Id: vacuum.c,v 1.54 2006/01/06 14:32:20 drh Exp $ +** $Id: vacuum.c,v 1.55 2006/01/09 06:29:49 danielk1977 Exp $ */ #include "sqliteInt.h" #include "vdbeInt.h" @@ -311,8 +311,8 @@ end_of_vacuum: db->autoCommit = 1; if( pDetach ){ - int mf = sqlite3Tsd()->mallocFailed; - sqlite3Tsd()->mallocFailed = 0; + int mf = sqlite3ThreadData()->mallocFailed; + sqlite3ThreadData()->mallocFailed = 0; sqlite3MallocDisallow(); ((Vdbe *)pDetach)->expired = 0; sqlite3_step(pDetach); @@ -321,7 +321,7 @@ end_of_vacuum: rc = rc2; } sqlite3MallocAllow(); - sqlite3Tsd()->mallocFailed = mf; + sqlite3ThreadData()->mallocFailed = mf; } /* If one of the execSql() calls above returned SQLITE_NOMEM, then the @@ -329,7 +329,7 @@ end_of_vacuum: ** Fix this so the flag and return code match. */ if( rc==SQLITE_NOMEM ){ - sqlite3Tsd()->mallocFailed = 1; + sqlite3ThreadData()->mallocFailed = 1; } if( zTemp ){ diff --git a/src/vdbe.c b/src/vdbe.c index 53cf82f77..8de4b1308 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -43,7 +43,7 @@ ** 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.518 2006/01/08 18:10:18 drh Exp $ +** $Id: vdbe.c,v 1.519 2006/01/09 06:29:49 danielk1977 Exp $ */ #include "sqliteInt.h" #include "os.h" @@ -412,7 +412,7 @@ int sqlite3VdbeExec( for(pc=p->pc; rc==SQLITE_OK; pc++){ assert( pc>=0 && pc<p->nOp ); assert( pTos<=&p->aStack[pc] ); - if( sqlite3Tsd()->mallocFailed ) goto no_mem; + if( sqlite3ThreadData()->mallocFailed ) goto no_mem; #ifdef VDBE_PROFILE origPc = pc; start = hwtime(); @@ -1167,7 +1167,7 @@ case OP_Function: { if( sqlite3SafetyOff(db) ) goto abort_due_to_misuse; (*ctx.pFunc->xFunc)(&ctx, n, apVal); if( sqlite3SafetyOn(db) ) goto abort_due_to_misuse; - if( sqlite3Tsd()->mallocFailed ) goto no_mem; + if( sqlite3ThreadData()->mallocFailed ) goto no_mem; popStack(&pTos, n); /* If any auxilary data functions have been called by this user function, @@ -4019,13 +4019,13 @@ case OP_ParseSchema: { /* no-push */ sqlite3SafetyOff(db); assert( db->init.busy==0 ); db->init.busy = 1; - assert(0==sqlite3Tsd()->mallocFailed); + assert(0==sqlite3ThreadData()->mallocFailed); rc = sqlite3_exec(db, zSql, sqlite3InitCallback, &initData, 0); sqliteFree(zSql); db->init.busy = 0; sqlite3SafetyOn(db); if( rc==SQLITE_NOMEM ){ - sqlite3Tsd()->mallocFailed = 1; + sqlite3ThreadData()->mallocFailed = 1; goto no_mem; } break; @@ -4615,7 +4615,7 @@ abort_due_to_misuse: */ abort_due_to_error: if( p->zErrMsg==0 ){ - if( sqlite3Tsd()->mallocFailed ) rc = SQLITE_NOMEM; + if( sqlite3ThreadData()->mallocFailed ) rc = SQLITE_NOMEM; sqlite3SetString(&p->zErrMsg, sqlite3ErrStr(rc), (char*)0); } goto vdbe_halt; diff --git a/src/vdbeapi.c b/src/vdbeapi.c index 9537ac669..c18067dfa 100644 --- a/src/vdbeapi.c +++ b/src/vdbeapi.c @@ -156,7 +156,7 @@ int sqlite3_step(sqlite3_stmt *pStmt){ sqlite3 *db; int rc; - assert(!sqlite3Tsd()->mallocFailed); + assert(!sqlite3ThreadData()->mallocFailed); if( p==0 || p->magic!=VDBE_MAGIC_RUN ){ return SQLITE_MISUSE; @@ -404,7 +404,7 @@ static void columnMallocFailure(sqlite3_stmt *pStmt) ** SQLITE_NOMEM. The next call to _step() (if any) will return SQLITE_ERROR ** and _finalize() will return NOMEM. */ - if( sqlite3Tsd()->mallocFailed ){ + if( sqlite3ThreadData()->mallocFailed ){ ((Vdbe *)pStmt)->rc = SQLITE_NOMEM; sqlite3MallocClearFailed(); } diff --git a/src/vdbeaux.c b/src/vdbeaux.c index a1302dc98..3080af59e 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -102,7 +102,7 @@ int sqlite3VdbeAddOp(Vdbe *p, int op, int p1, int p2){ p->nOp++; assert( p->magic==VDBE_MAGIC_INIT ); resizeOpArray(p, i+1); - if( sqlite3Tsd()->mallocFailed ){ + if( sqlite3ThreadData()->mallocFailed ){ return 0; } pOp = &p->aOp[i]; @@ -301,7 +301,7 @@ int sqlite3VdbeAddOpList(Vdbe *p, int nOp, VdbeOpList const *aOp){ int addr; assert( p->magic==VDBE_MAGIC_INIT ); resizeOpArray(p, p->nOp + nOp); - if( sqlite3Tsd()->mallocFailed ){ + if( sqlite3ThreadData()->mallocFailed ){ return 0; } addr = p->nOp; @@ -415,7 +415,7 @@ static void freeP3(int p3type, void *p3){ void sqlite3VdbeChangeP3(Vdbe *p, int addr, const char *zP3, int n){ Op *pOp; assert( p->magic==VDBE_MAGIC_INIT ); - if( p==0 || p->aOp==0 || sqlite3Tsd()->mallocFailed ){ + if( p==0 || p->aOp==0 || sqlite3ThreadData()->mallocFailed ){ if (n != P3_KEYINFO) { freeP3(n, (void*)*(char**)&zP3); } @@ -472,7 +472,7 @@ void sqlite3VdbeChangeP3(Vdbe *p, int addr, const char *zP3, int n){ void sqlite3VdbeComment(Vdbe *p, const char *zFormat, ...){ va_list ap; assert( p->nOp>0 ); - assert( p->aOp==0 || p->aOp[p->nOp-1].p3==0 || sqlite3Tsd()->mallocFailed ); + assert( p->aOp==0 || p->aOp[p->nOp-1].p3==0 || sqlite3ThreadData()->mallocFailed ); va_start(ap, zFormat); sqlite3VdbeChangeP3(p, -1, sqlite3VMPrintf(zFormat, ap), P3_DYNAMIC); va_end(ap); @@ -738,7 +738,7 @@ void sqlite3VdbeMakeReady( + nMem*sizeof(Mem) /* aMem */ + nCursor*sizeof(Cursor*) /* apCsr */ ); - if( !sqlite3Tsd()->mallocFailed ){ + if( !sqlite3ThreadData()->mallocFailed ){ p->aMem = &p->aStack[nStack]; p->nMem = nMem; p->aVar = &p->aMem[nMem]; @@ -890,7 +890,7 @@ int sqlite3VdbeSetColName(Vdbe *p, int idx, const char *zName, int N){ int rc; Mem *pColName; assert( idx<(2*p->nResColumn) ); - if( sqlite3Tsd()->mallocFailed ) return SQLITE_NOMEM; + if( sqlite3ThreadData()->mallocFailed ) return SQLITE_NOMEM; assert( p->aColName!=0 ); pColName = &(p->aColName[idx]); if( N==P3_DYNAMIC || N==P3_STATIC ){ @@ -1153,7 +1153,7 @@ int sqlite3VdbeHalt(Vdbe *p){ int i; int (*xFunc)(Btree *pBt) = 0; /* Function to call on each btree backend */ - if( sqlite3Tsd()->mallocFailed ){ + if( sqlite3ThreadData()->mallocFailed ){ p->rc = SQLITE_NOMEM; } diff --git a/src/vdbemem.c b/src/vdbemem.c index 7d9f8d2a8..e7b5b0d63 100644 --- a/src/vdbemem.c +++ b/src/vdbemem.c @@ -756,7 +756,7 @@ const void *sqlite3ValueText(sqlite3_value* pVal, u8 enc){ }else if( !(pVal->flags&MEM_Blob) ){ sqlite3VdbeMemStringify(pVal, enc); } - assert(pVal->enc==enc || sqlite3Tsd()->mallocFailed); + assert(pVal->enc==enc || sqlite3ThreadData()->mallocFailed); return (const void *)(pVal->enc==enc ? (pVal->z) : 0); } diff --git a/src/where.c b/src/where.c index 587080bf9..104a7892e 100644 --- a/src/where.c +++ b/src/where.c @@ -16,7 +16,7 @@ ** 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.191 2006/01/07 13:21:04 danielk1977 Exp $ +** $Id: where.c,v 1.192 2006/01/09 06:29:49 danielk1977 Exp $ */ #include "sqliteInt.h" @@ -567,7 +567,7 @@ static void exprAnalyze( int nPattern; int isComplete; - if( sqlite3Tsd()->mallocFailed ) return; + if( sqlite3ThreadData()->mallocFailed ) return; prereqLeft = exprTableUsage(pMaskSet, pExpr->pLeft); if( pExpr->op==TK_IN ){ assert( pExpr->pRight==0 ); @@ -1437,7 +1437,7 @@ WhereInfo *sqlite3WhereBegin( ** return value. */ pWInfo = sqliteMalloc( sizeof(WhereInfo) + pTabList->nSrc*sizeof(WhereLevel)); - if( sqlite3Tsd()->mallocFailed ){ + if( sqlite3ThreadData()->mallocFailed ){ goto whereBeginNoMem; } pWInfo->pParse = pParse; @@ -1461,7 +1461,7 @@ WhereInfo *sqlite3WhereBegin( createMask(&maskSet, pTabList->a[i].iCursor); } exprAnalyzeAll(pTabList, &maskSet, &wc); - if( sqlite3Tsd()->mallocFailed ){ + if( sqlite3ThreadData()->mallocFailed ){ goto whereBeginNoMem; } diff --git a/test/shared.test b/test/shared.test index 6929e50a0..f41290385 100644 --- a/test/shared.test +++ b/test/shared.test @@ -11,7 +11,7 @@ # This file implements regression tests for SQLite library. The # focus of this file is testing the SELECT statement. # -# $Id: shared.test,v 1.6 2006/01/07 13:21:04 danielk1977 Exp $ +# $Id: shared.test,v 1.7 2006/01/09 06:29:49 danielk1977 Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl @@ -35,6 +35,7 @@ set ::enable_shared_cache [sqlite3_enable_shared_cache 1] # shared-5.*: Test that creating/dropping schema items works when databases # are attached in different orders to different handles. # shared-6.*: Locking, UNION ALL queries and sub-queries. +# shared-6.*: Autovacuum and shared-cache. # do_test shared-1.1 { @@ -464,6 +465,77 @@ do_test shared-6.1.3 { catch {db1 close} catch {db2 close} +foreach f [list test.db test2.db] { + file delete -force $f ${f}-journal +} + +#-------------------------------------------------------------------------- +# Tests shared-7.* test auto-vacuum does not invalidate cursors from +# other shared-cache users when it reorganizes the database on +# COMMIT. +# +do_test shared-7.1 { + sqlite3 db test.db + sqlite3 db2 test.db + execsql { + PRAGMA auto_vacuum = 1; + BEGIN; + CREATE TABLE t1(a PRIMARY KEY, b); + CREATE TABLE t2(a PRIMARY KEY, b); + } + for {set i 0} {$i < 100} {incr i} { + set a [string repeat "$i " 20] + set b [string repeat "$i " 20] + db eval { + INSERT INTO t1 VALUES($a, $b); + } + lappend ::contents [list [expr $i+1] $a $b] + } + execsql { + INSERT INTO t2 SELECT * FROM t1; + COMMIT; + } + execsql { + PRAGMA auto_vacuum; + } +} {1} +do_test shared-7.2 { + proc lockrow {db tbl oids body} { + set ret [list] + db eval "SELECT oid AS i, a, b FROM $tbl ORDER BY a" { + if {$i==[lindex $oids 0]} { + set noids [lrange $oids 1 end] + if {[llength $noids]==0} { + set subret [eval $body] + } else { + set subret [lockrow $db $tbl $noids $body] + } + } + lappend ret [list $i $a $b] + } + return [linsert $subret 0 $ret] + } + proc locktblrows {db tbl body} { + set oids [db eval "SELECT oid FROM $tbl"] + lockrow $db $tbl $oids $body + } + + set scans [locktblrows db t2 { + execsql { + DELETE FROM t1; + } db2 + }] + set error 0 + foreach s $scans { + if {[lsort -integer -index 0 $s]!=$::contents} { + set error 1 + } + } + set error +} {0} + +catch {db close} +catch {db2 close} finish_test sqlite3_enable_shared_cache $::enable_shared_cache |