Rename DbSchema to "Schema" and SqliteTsd to "ThreadData". (CVS 2893)

FossilOrigin-Name: 82b81f69c78cb3f54634d9aea4f6a838474dc5e5
diff --git a/src/alter.c b/src/alter.c
index d990011..c9fa9de 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 @@
   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 @@
   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 @@
 
   /* 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 acd812b..ba07b7b 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 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 b63260c..57e0a98 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 @@
   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 @@
   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 9b206a3..3ab5f5c 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 @@
   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 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 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 @@
   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 @@
   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 @@
   ** 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 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 @@
   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 @@
   BtCursor *pCur;
 
 #ifndef SQLITE_OMIT_SHARED_CACHE
-  SqliteTsd *pTsd = sqlite3Tsd();
+  ThreadData *pTsd = sqlite3ThreadData();
 #endif
 
   /* Drop any table-locks */
@@ -2305,11 +2305,11 @@
 */
 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 @@
     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 @@
 ** 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 9077465..5b3594f 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 @@
   int i;
   int nBytes;
   TableLock *p;
-  SqliteTsd *pTsd = sqlite3Tsd();
+  ThreadData *pTsd = sqlite3ThreadData();
 
   if( 0==pTsd->useSharedData ){
     return;
@@ -98,7 +98,7 @@
 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 @@
   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 @@
   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 @@
   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 @@
   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 @@
   */
   p->pSelect = sqlite3SelectDup(pSelect);
   sqlite3SelectDelete(pSelect);
-  if( sqlite3Tsd()->mallocFailed ){
+  if( sqlite3ThreadData()->mallocFailed ){
     return;
   }
   if( !pParse->db->init.busy ){
@@ -1857,7 +1858,7 @@
   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 @@
   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 @@
   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 @@
   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 @@
 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 @@
   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 @@
   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 @@
   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 4995ec3..d753a4d 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 @@
       ** 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 9c5cf51..fd5065d 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 @@
 #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 2846017..6c78582 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 @@
 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 @@
         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 @@
       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 @@
   zDb = sqlite3NameFromToken(pDbToken);
   zTab = sqlite3NameFromToken(pTableToken);
   zCol = sqlite3NameFromToken(pColumnToken);
-  if( sqlite3Tsd()->mallocFailed ){
+  if( sqlite3ThreadData()->mallocFailed ){
     goto lookupname_end;
   }
 
@@ -1306,7 +1306,7 @@
     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 3de2c42..b1191eb 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 @@
 **
 ** 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 @@
   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 @@
 
     /* 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 40fa8f5..2d928ae 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 @@
   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 d31439b..236b103 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 @@
 */
 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 *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 @@
 ** 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 @@
   int rc;
   CollSeq *pColl;
 
-  assert( !sqlite3Tsd()->mallocFailed );
+  assert( !sqlite3ThreadData()->mallocFailed );
 
   /* Allocate the sqlite data structure */
   db = sqliteMalloc( sizeof(sqlite3) );
@@ -751,7 +751,7 @@
     /* 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 @@
       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 71125fa..34da78d 100644
--- a/src/os_unix.c
+++ b/src/os_unix.c
@@ -502,7 +502,7 @@
   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 @@
 ** 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 @@
 
 /*
 ** 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 e41833c..6b266c1 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 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_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 @@
 
 #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 @@
 */
 #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 4b86e76..0b24596 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 @@
   sqlite3 *db = pData->db;
   int iDb;
 
-  if( sqlite3Tsd()->mallocFailed ){
+  if( sqlite3ThreadData()->mallocFailed ){
     return SQLITE_NOMEM;
   }
 
@@ -76,7 +76,7 @@
     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 @@
   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 @@
 #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 @@
 
 /*
 ** 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 @@
   Hash temp1;
   Hash temp2;
   HashElem *pElem;
-  DbSchema *pSchema = (DbSchema *)p;
+  Schema *pSchema = (Schema *)p;
 
   temp1 = pSchema->tblHash;
   temp2 = pSchema->trigHash;
@@ -454,12 +454,12 @@
   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 @@
   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 rc = SQLITE_OK;
   int i;
 
-  assert( !sqlite3Tsd()->mallocFailed );
+  assert( !sqlite3ThreadData()->mallocFailed );
 
   assert( ppStmt );
   *ppStmt = 0;
@@ -534,7 +534,7 @@
   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 @@
   /* 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 6b70912..1f42d64 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 @@
 #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 @@
       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 @@
   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 @@
   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 @@
         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 e2c618e..20af08b 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_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 @@
 /*
 ** 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 @@
 #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 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 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 @@
   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 @@
 #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 @@
   // 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 @@
   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 @@
                              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 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 c86d3e6..a58d711 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 @@
 ** 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 @@
   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 @@
 ){
   int rc;
   int enable;
-  SqliteTsd *pTsd = sqlite3Tsd();
+  ThreadData *pTsd = sqlite3ThreadData();
   Tcl_SetObjResult(interp, Tcl_NewBooleanObj(pTsd->useSharedData));
 
   if( objc!=2 ){
@@ -2988,7 +2988,7 @@
     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 6ea3b68..5645317 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 @@
   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 @@
     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 b888393..ec1c4c6 100644
--- a/src/trigger.c
+++ b/src/trigger.c
@@ -81,14 +81,14 @@
   ** 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 @@
     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 @@
   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 0a47d1d..ff10b95 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 @@
   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 ebdcfb5..f5e4c69 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 @@
 ** 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 @@
   /* 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 @@
 ** 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 unlinkAlloc(void *p)
 {
-  SqliteTsd *pTsd = sqlite3Tsd();
+  ThreadData *pTsd = sqlite3ThreadData();
   void **pp = (void **)p;
   if( p==pTsd->pFirst ){
     assert(!pp[0]);
@@ -355,7 +355,7 @@
   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 @@
 #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 @@
 */
 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 * 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 OSMALLOC_FAILED(){
-  sqlite3Tsd()->isFail = 0;
+  sqlite3ThreadData()->isFail = 0;
 }
 
 int OSSIZEOF(void *p){
@@ -522,7 +522,7 @@
 */
 #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 @@
 ** 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 @@
     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 @@
 ** 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 @@
     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 @@
 ** 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 @@
 #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 @@
 ** entry points that may have called sqliteMalloc().
 */
 void sqlite3MallocClearFailed(){
-  sqlite3Tsd()->mallocFailed = 0;
+  sqlite3ThreadData()->mallocFailed = 0;
 }
 
 
@@ -1331,8 +1331,8 @@
 ** 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 @@
 ** 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 5af673a..2d7f765 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 @@
   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 @@
       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 @@
   ** 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 53cf82f..8de4b13 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 @@
   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 @@
   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 @@
   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_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 9537ac6..c18067d 100644
--- a/src/vdbeapi.c
+++ b/src/vdbeapi.c
@@ -156,7 +156,7 @@
   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 @@
   ** 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 a1302dc..3080af5 100644
--- a/src/vdbeaux.c
+++ b/src/vdbeaux.c
@@ -102,7 +102,7 @@
   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 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 @@
 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 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 @@
       + 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 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 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 7d9f8d2..e7b5b0d 100644
--- a/src/vdbemem.c
+++ b/src/vdbemem.c
@@ -756,7 +756,7 @@
   }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 587080b..104a789 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 @@
   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 @@
   ** 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 @@
     createMask(&maskSet, pTabList->a[i].iCursor);
   }
   exprAnalyzeAll(pTabList, &maskSet, &wc);
-  if( sqlite3Tsd()->mallocFailed ){
+  if( sqlite3ThreadData()->mallocFailed ){
     goto whereBeginNoMem;
   }