Index: main.mk ================================================================== --- main.mk +++ main.mk @@ -246,11 +246,11 @@ # all that automatic generation. # target_source: $(SRC) rm -rf tsrc mkdir tsrc - cp $(SRC) tsrc + cp $(SRC) $(TOP)/src/*.h tsrc rm tsrc/sqlite.h.in tsrc/parse.y # Rules to build the LEMON compiler generator # lemon: $(TOP)/tool/lemon.c $(TOP)/tool/lempar.c Index: src/btree.c ================================================================== --- src/btree.c +++ src/btree.c @@ -7,11 +7,11 @@ ** May you do good and not evil. ** May you find forgiveness for yourself and forgive others. ** May you share freely, never taking more than you give. ** ************************************************************************* -** $Id: btree.c,v 1.341 2007/03/19 17:44:27 danielk1977 Exp $ +** $Id: btree.c,v 1.342 2007/03/26 22:05:01 drh Exp $ ** ** This file implements a external (disk-based) database using BTrees. ** For a detailed discussion of BTrees, refer to ** ** Donald E. Knuth, THE ART OF COMPUTER PROGRAMMING, Volume 3: @@ -2267,11 +2267,11 @@ } return rc; } /* Forward declaration required by autoVacuumCommit(). */ -static int allocatePage(BtShared *, MemPage **, Pgno *, Pgno, u8); +static int allocateBtreePage(BtShared *, MemPage **, Pgno *, Pgno, u8); /* ** This routine is called prior to sqlite3PagerCommit when a transaction ** is commited for an auto-vacuum database. */ @@ -2357,18 +2357,18 @@ rc = getPage(pBt, iDbPage, &pDbMemPage, 0); if( rc!=SQLITE_OK ) goto autovacuum_out; /* Find the next page in the free-list that is not already at the end ** of the file. A page can be pulled off the free list using the - ** allocatePage() routine. + ** allocateBtreePage() routine. */ do{ if( pFreeMemPage ){ releasePage(pFreeMemPage); pFreeMemPage = 0; } - rc = allocatePage(pBt, &pFreeMemPage, &iFreePage, 0, 0); + rc = allocateBtreePage(pBt, &pFreeMemPage, &iFreePage, 0, 0); if( rc!=SQLITE_OK ){ releasePage(pDbMemPage); goto autovacuum_out; } assert( iFreePage<=origSize ); @@ -3565,11 +3565,11 @@ ** ** If the "exact" parameter is not 0, and the page-number nearby exists ** anywhere on the free-list, then it is guarenteed to be returned. This ** is only used by auto-vacuum databases when allocating a new table. */ -static int allocatePage( +static int allocateBtreePage( BtShared *pBt, MemPage **ppPage, Pgno *pPgno, Pgno nearby, u8 exact @@ -3972,11 +3972,11 @@ while( nPayload>0 ){ if( spaceLeft==0 ){ #ifndef SQLITE_OMIT_AUTOVACUUM Pgno pgnoPtrmap = pgnoOvfl; /* Overflow page pointer-map entry page */ #endif - rc = allocatePage(pBt, &pOvfl, &pgnoOvfl, pgnoOvfl, 0); + rc = allocateBtreePage(pBt, &pOvfl, &pgnoOvfl, pgnoOvfl, 0); #ifndef SQLITE_OMIT_AUTOVACUUM /* If the database supports auto-vacuum, and the second or subsequent ** overflow page is being allocated, add an entry to the pointer-map ** for that page now. The entry for the first overflow page will be ** added later, by the insertCell() routine. @@ -4304,11 +4304,11 @@ u8 parentCell[64]; /* Space for the new divider cell */ /* Allocate a new page. Insert the overflow cell from pPage ** into it. Then remove the overflow cell from pPage. */ - rc = allocatePage(pBt, &pNew, &pgnoNew, 0, 0); + rc = allocateBtreePage(pBt, &pNew, &pgnoNew, 0, 0); if( rc!=SQLITE_OK ){ return rc; } pCell = pPage->aOvfl[0].pCell; szCell = cellSizePtr(pPage, pCell); @@ -4748,11 +4748,11 @@ apOld[i] = 0; rc = sqlite3PagerWrite(pNew->pDbPage); if( rc ) goto balance_cleanup; }else{ assert( i>0 ); - rc = allocatePage(pBt, &pNew, &pgnoNew[i], pgnoNew[i-1], 0); + rc = allocateBtreePage(pBt, &pNew, &pgnoNew[i], pgnoNew[i-1], 0); if( rc ) goto balance_cleanup; apNew[i] = pNew; } nNew++; zeroPage(pNew, pageFlags); @@ -5069,11 +5069,11 @@ int brk; /* Offset to content of first cell in parent */ assert( pPage->pParent==0 ); assert( pPage->nOverflow>0 ); pBt = pPage->pBt; - rc = allocatePage(pBt, &pChild, &pgnoChild, pPage->pgno, 0); + rc = allocateBtreePage(pBt, &pChild, &pgnoChild, pPage->pgno, 0); if( rc ) return rc; assert( sqlite3PagerIswriteable(pChild->pDbPage) ); usableSize = pBt->usableSize; data = pPage->aData; hdr = pPage->hdrOffset; @@ -5405,11 +5405,11 @@ if( pBt->pCursor ){ return SQLITE_LOCKED; } #ifdef SQLITE_OMIT_AUTOVACUUM - rc = allocatePage(pBt, &pRoot, &pgnoRoot, 1, 0); + rc = allocateBtreePage(pBt, &pRoot, &pgnoRoot, 1, 0); if( rc ) return rc; #else if( pBt->autoVacuum ){ Pgno pgnoMove; /* Move a page here to make room for the root-page */ MemPage *pPageMove; /* The page to move to. */ @@ -5433,11 +5433,11 @@ /* Allocate a page. The page that currently resides at pgnoRoot will ** be moved to the allocated page (unless the allocated page happens ** to reside at pgnoRoot). */ - rc = allocatePage(pBt, &pPageMove, &pgnoMove, pgnoRoot, 1); + rc = allocateBtreePage(pBt, &pPageMove, &pgnoMove, pgnoRoot, 1); if( rc!=SQLITE_OK ){ return rc; } if( pgnoMove!=pgnoRoot ){ @@ -5490,11 +5490,11 @@ releasePage(pRoot); return rc; } }else{ - rc = allocatePage(pBt, &pRoot, &pgnoRoot, 1, 0); + rc = allocateBtreePage(pBt, &pRoot, &pgnoRoot, 1, 0); if( rc ) return rc; } #endif assert( sqlite3PagerIswriteable(pRoot->pDbPage) ); zeroPage(pRoot, flags | PTF_LEAF); Index: src/build.c ================================================================== --- src/build.c +++ src/build.c @@ -20,11 +20,11 @@ ** creating ID lists ** BEGIN TRANSACTION ** COMMIT ** ROLLBACK ** -** $Id: build.c,v 1.415 2007/03/17 10:26:59 danielk1977 Exp $ +** $Id: build.c,v 1.416 2007/03/26 22:05:01 drh Exp $ */ #include "sqliteInt.h" #include /* @@ -80,11 +80,11 @@ return; } } nBytes = sizeof(TableLock) * (pParse->nTableLock+1); - sqliteReallocOrFree((void **)&pParse->aTableLock, nBytes); + sqliteReallocOrFree(&pParse->aTableLock, nBytes); if( pParse->aTableLock ){ p = &pParse->aTableLock[pParse->nTableLock++]; p->iDb = iDb; p->iTab = iTab; p->isWriteLock = isWriteLock; @@ -2802,25 +2802,26 @@ ** and returns its index. If malloc fails a negative number is returned. ** ** szEntry is the sizeof of a single array entry. initSize is the ** number of array entries allocated on the initial allocation. */ -int sqlite3ArrayAllocate(void **ppArray, int szEntry, int initSize){ +int sqlite3ArrayAllocate(void *ppArray, int szEntry, int initSize){ char *p; - int *an = (int*)&ppArray[1]; + void **pp = (void**)ppArray; + int *an = (int*)&pp[1]; if( an[0]>=an[1] ){ void *pNew; int newSize; newSize = an[1]*2 + initSize; - pNew = sqliteRealloc(*ppArray, newSize*szEntry); + pNew = sqliteRealloc(*pp, newSize*szEntry); if( pNew==0 ){ return -1; } an[1] = newSize; - *ppArray = pNew; + *pp = pNew; } - p = *ppArray; + p = *pp; memset(&p[an[0]*szEntry], 0, szEntry); return an[0]++; } /* @@ -2834,11 +2835,11 @@ if( pList==0 ){ pList = sqliteMalloc( sizeof(IdList) ); if( pList==0 ) return 0; pList->nAlloc = 0; } - i = sqlite3ArrayAllocate((void**)&pList->a, sizeof(pList->a[0]), 5); + i = sqlite3ArrayAllocate(&pList->a, sizeof(pList->a[0]), 5); if( i<0 ){ sqlite3IdListDelete(pList); return 0; } pList->a[i].zName = sqlite3NameFromToken(pToken); Index: src/expr.c ================================================================== --- src/expr.c +++ src/expr.c @@ -10,11 +10,11 @@ ** ************************************************************************* ** This file contains routines used for analyzing expressions and ** for generating VDBE code that evaluates expressions in SQLite. ** -** $Id: expr.c,v 1.281 2007/03/12 23:48:53 drh Exp $ +** $Id: expr.c,v 1.282 2007/03/26 22:05:01 drh Exp $ */ #include "sqliteInt.h" #include /* @@ -402,11 +402,11 @@ } if( i>=pParse->nVarExpr ){ pExpr->iTable = ++pParse->nVar; if( pParse->nVarExpr>=pParse->nVarExprAlloc-1 ){ pParse->nVarExprAlloc += pParse->nVarExprAlloc + 10; - sqliteReallocOrFree((void**)&pParse->apVarExpr, + sqliteReallocOrFree(&pParse->apVarExpr, pParse->nVarExprAlloc*sizeof(pParse->apVarExpr[0]) ); } if( !sqlite3MallocFailed() ){ assert( pParse->apVarExpr!=0 ); pParse->apVarExpr[pParse->nVarExpr++] = pExpr; @@ -2235,11 +2235,11 @@ ** Add a new element to the pAggInfo->aCol[] array. Return the index of ** the new element. Return a negative number if malloc fails. */ static int addAggInfoColumn(AggInfo *pInfo){ int i; - i = sqlite3ArrayAllocate((void**)&pInfo->aCol, sizeof(pInfo->aCol[0]), 3); + i = sqlite3ArrayAllocate(&pInfo->aCol, sizeof(pInfo->aCol[0]), 3); if( i<0 ){ return -1; } return i; } @@ -2248,11 +2248,11 @@ ** Add a new element to the pAggInfo->aFunc[] array. Return the index of ** the new element. Return a negative number if malloc fails. */ static int addAggInfoFunc(AggInfo *pInfo){ int i; - i = sqlite3ArrayAllocate((void**)&pInfo->aFunc, sizeof(pInfo->aFunc[0]), 2); + i = sqlite3ArrayAllocate(&pInfo->aFunc, sizeof(pInfo->aFunc[0]), 2); if( i<0 ){ return -1; } return i; } Index: src/os_common.h ================================================================== --- src/os_common.h +++ src/os_common.h @@ -38,27 +38,28 @@ int sqlite3_os_trace = 0; #ifdef SQLITE_DEBUG static int last_page = 0; #define SEEK(X) last_page=(X) -#define TRACE1(X) if( sqlite3_os_trace ) sqlite3DebugPrintf(X) -#define TRACE2(X,Y) if( sqlite3_os_trace ) sqlite3DebugPrintf(X,Y) -#define TRACE3(X,Y,Z) if( sqlite3_os_trace ) sqlite3DebugPrintf(X,Y,Z) -#define TRACE4(X,Y,Z,A) if( sqlite3_os_trace ) sqlite3DebugPrintf(X,Y,Z,A) -#define TRACE5(X,Y,Z,A,B) if( sqlite3_os_trace ) sqlite3DebugPrintf(X,Y,Z,A,B) -#define TRACE6(X,Y,Z,A,B,C) if(sqlite3_os_trace) sqlite3DebugPrintf(X,Y,Z,A,B,C) -#define TRACE7(X,Y,Z,A,B,C,D) \ +#define OSTRACE1(X) if( sqlite3_os_trace ) sqlite3DebugPrintf(X) +#define OSTRACE2(X,Y) if( sqlite3_os_trace ) sqlite3DebugPrintf(X,Y) +#define OSTRACE3(X,Y,Z) if( sqlite3_os_trace ) sqlite3DebugPrintf(X,Y,Z) +#define OSTRACE4(X,Y,Z,A) if( sqlite3_os_trace ) sqlite3DebugPrintf(X,Y,Z,A) +#define OSTRACE5(X,Y,Z,A,B) if( sqlite3_os_trace ) sqlite3DebugPrintf(X,Y,Z,A,B) +#define OSTRACE6(X,Y,Z,A,B,C) \ + if(sqlite3_os_trace) sqlite3DebugPrintf(X,Y,Z,A,B,C) +#define OSTRACE7(X,Y,Z,A,B,C,D) \ if(sqlite3_os_trace) sqlite3DebugPrintf(X,Y,Z,A,B,C,D) #else #define SEEK(X) -#define TRACE1(X) -#define TRACE2(X,Y) -#define TRACE3(X,Y,Z) -#define TRACE4(X,Y,Z,A) -#define TRACE5(X,Y,Z,A,B) -#define TRACE6(X,Y,Z,A,B,C) -#define TRACE7(X,Y,Z,A,B,C,D) +#define OSTRACE1(X) +#define OSTRACE2(X,Y) +#define OSTRACE3(X,Y,Z) +#define OSTRACE4(X,Y,Z,A) +#define OSTRACE5(X,Y,Z,A,B) +#define OSTRACE6(X,Y,Z,A,B,C) +#define OSTRACE7(X,Y,Z,A,B,C,D) #endif /* ** Macros for performance tracing. Normally turned off. Only works ** on i486 hardware. @@ -195,6 +196,5 @@ ** The default size of a disk sector */ #ifndef PAGER_SECTOR_SIZE # define PAGER_SECTOR_SIZE 512 #endif - Index: src/os_os2.c ================================================================== --- src/os_os2.c +++ src/os_os2.c @@ -60,11 +60,11 @@ */ int sqlite3Os2Delete( const char *zFilename ){ APIRET rc = NO_ERROR; rc = DosDelete( (PSZ)zFilename ); - TRACE2( "DELETE \"%s\"\n", zFilename ); + OSTRACE2( "DELETE \"%s\"\n", zFilename ); return rc == NO_ERROR ? SQLITE_OK : SQLITE_IOERR; } /* ** Return TRUE if the named file exists. @@ -125,11 +125,11 @@ f.h = hf; f.locktype = NO_LOCK; f.delOnClose = 0; f.pathToDel = NULL; OpenCounter(+1); - TRACE3( "OPEN R/W %d \"%s\"\n", hf, zFilename ); + OSTRACE3( "OPEN R/W %d \"%s\"\n", hf, zFilename ); return allocateOs2File( &f, pld ); } /* @@ -165,11 +165,11 @@ f.locktype = NO_LOCK; f.delOnClose = delFlag ? 1 : 0; f.pathToDel = delFlag ? sqlite3OsFullPathname( zFilename ) : NULL; OpenCounter( +1 ); if( delFlag ) DosForceDelete( sqlite3OsFullPathname( zFilename ) ); - TRACE3( "OPEN EX %d \"%s\"\n", hf, sqlite3OsFullPathname ( zFilename ) ); + OSTRACE3( "OPEN EX %d \"%s\"\n", hf, sqlite3OsFullPathname ( zFilename ) ); return allocateOs2File( &f, pld ); } /* ** Attempt to open a new file for read-only access. @@ -195,11 +195,11 @@ f.h = hf; f.locktype = NO_LOCK; f.delOnClose = 0; f.pathToDel = NULL; OpenCounter( +1 ); - TRACE3( "OPEN RO %d \"%s\"\n", hf, zFilename ); + OSTRACE3( "OPEN RO %d \"%s\"\n", hf, zFilename ); return allocateOs2File( &f, pld ); } /* ** Attempt to open a file descriptor for the directory that contains a @@ -259,11 +259,11 @@ zBuf[j] = (char)zChars[ ((unsigned char)zBuf[j])%(sizeof(zChars)-1) ]; } zBuf[j] = 0; if( !sqlite3OsFileExists( zBuf ) ) break; } - TRACE2( "TEMP FILENAME: %s\n", zBuf ); + OSTRACE2( "TEMP FILENAME: %s\n", zBuf ); return SQLITE_OK; } /* ** Close a file. @@ -270,11 +270,11 @@ */ int os2Close( OsFile **pld ){ os2File *pFile; APIRET rc = NO_ERROR; if( pld && (pFile = (os2File*)*pld) != 0 ){ - TRACE2( "CLOSE %d\n", pFile->h ); + OSTRACE2( "CLOSE %d\n", pFile->h ); rc = DosClose( pFile->h ); pFile->locktype = NO_LOCK; if( pFile->delOnClose != 0 ){ rc = DosForceDelete( pFile->pathToDel ); } @@ -292,11 +292,11 @@ */ int os2Read( OsFile *id, void *pBuf, int amt ){ ULONG got; assert( id!=0 ); SimulateIOError( return SQLITE_IOERR ); - TRACE3( "READ %d lock=%d\n", ((os2File*)id)->h, ((os2File*)id)->locktype ); + OSTRACE3( "READ %d lock=%d\n", ((os2File*)id)->h, ((os2File*)id)->locktype ); DosRead( ((os2File*)id)->h, pBuf, amt, &got ); if (got == (ULONG)amt) return SQLITE_OK; else if (got < 0) return SQLITE_IOERR_READ; @@ -314,11 +314,11 @@ APIRET rc = NO_ERROR; ULONG wrote; assert( id!=0 ); SimulateIOError( return SQLITE_IOERR ); SimulateDiskfullError( return SQLITE_FULL ); - TRACE3( "WRITE %d lock=%d\n", ((os2File*)id)->h, ((os2File*)id)->locktype ); + OSTRACE3( "WRITE %d lock=%d\n", ((os2File*)id)->h, ((os2File*)id)->locktype ); while( amt > 0 && (rc = DosWrite( ((os2File*)id)->h, (PVOID)pBuf, amt, &wrote )) && wrote > 0 ){ amt -= wrote; pBuf = &((char*)pBuf)[wrote]; } @@ -332,20 +332,20 @@ int os2Seek( OsFile *id, i64 offset ){ APIRET rc = NO_ERROR; ULONG filePointer = 0L; assert( id!=0 ); rc = DosSetFilePtr( ((os2File*)id)->h, offset, FILE_BEGIN, &filePointer ); - TRACE3( "SEEK %d %lld\n", ((os2File*)id)->h, offset ); + OSTRACE3( "SEEK %d %lld\n", ((os2File*)id)->h, offset ); return rc == NO_ERROR ? SQLITE_OK : SQLITE_IOERR; } /* ** Make sure all writes to a particular file are committed to disk. */ int os2Sync( OsFile *id, int dataOnly ){ assert( id!=0 ); - TRACE3( "SYNC %d lock=%d\n", ((os2File*)id)->h, ((os2File*)id)->locktype ); + OSTRACE3( "SYNC %d lock=%d\n", ((os2File*)id)->h, ((os2File*)id)->locktype ); return DosResetBuffer( ((os2File*)id)->h ) == NO_ERROR ? SQLITE_OK : SQLITE_IOERR; } /* ** Sync the directory zDirname. This is a no-op on operating systems other @@ -361,11 +361,11 @@ */ int os2Truncate( OsFile *id, i64 nByte ){ APIRET rc = NO_ERROR; ULONG upperBits = nByte>>32; assert( id!=0 ); - TRACE3( "TRUNCATE %d %lld\n", ((os2File*)id)->h, nByte ); + OSTRACE3( "TRUNCATE %d %lld\n", ((os2File*)id)->h, nByte ); SimulateIOError( return SQLITE_IOERR ); rc = DosSetFilePtr( ((os2File*)id)->h, nByte, FILE_BEGIN, &upperBits ); if( rc != NO_ERROR ){ return SQLITE_IOERR; } @@ -476,11 +476,11 @@ UnlockArea; os2File *pFile = (os2File*)id; memset(&LockArea, 0, sizeof(LockArea)); memset(&UnlockArea, 0, sizeof(UnlockArea)); assert( pFile!=0 ); - TRACE4( "LOCK %d %d was %d\n", pFile->h, locktype, pFile->locktype ); + OSTRACE4( "LOCK %d %d was %d\n", pFile->h, locktype, pFile->locktype ); /* If there is already a lock of this type or more restrictive on the ** OsFile, do nothing. Don't use the end_lock: exit path, as ** sqlite3OsEnterMutex() hasn't been called yet. */ @@ -511,11 +511,11 @@ while( cnt-->0 && (res = DosSetFileLocks( pFile->h, &UnlockArea, &LockArea, 2000L, 1L) )!=NO_ERROR ){ /* Try 3 times to get the pending lock. The pending lock might be ** held by another reader process who will release it momentarily. */ - TRACE2( "could not get a PENDING lock. cnt=%d\n", cnt ); + OSTRACE2( "could not get a PENDING lock. cnt=%d\n", cnt ); DosSleep(1); } gotPendingLock = res; } @@ -553,20 +553,20 @@ /* Acquire an EXCLUSIVE lock */ if( locktype==EXCLUSIVE_LOCK && res ){ assert( pFile->locktype>=SHARED_LOCK ); res = unlockReadLock(pFile); - TRACE2( "unreadlock = %d\n", res ); + OSTRACE2( "unreadlock = %d\n", res ); LockArea.lOffset = SHARED_FIRST; LockArea.lRange = SHARED_SIZE; UnlockArea.lOffset = 0L; UnlockArea.lRange = 0L; res = DosSetFileLocks( pFile->h, &UnlockArea, &LockArea, 2000L, 1L ); if( res == NO_ERROR ){ newLocktype = EXCLUSIVE_LOCK; }else{ - TRACE2( "error-code = %d\n", res ); + OSTRACE2( "error-code = %d\n", res ); } } /* If we are holding a PENDING lock that ought to be released, then ** release it now. @@ -583,11 +583,11 @@ ** return the appropriate result code. */ if( res == NO_ERROR ){ rc = SQLITE_OK; }else{ - TRACE4( "LOCK FAILED %d trying for %d but got %d\n", pFile->h, + OSTRACE4( "LOCK FAILED %d trying for %d but got %d\n", pFile->h, locktype, newLocktype ); rc = SQLITE_BUSY; } pFile->locktype = newLocktype; return rc; @@ -602,11 +602,11 @@ APIRET rc = NO_ERROR; os2File *pFile = (os2File*)id; assert( pFile!=0 ); if( pFile->locktype>=RESERVED_LOCK ){ rc = 1; - TRACE3( "TEST WR-LOCK %d %d (local)\n", pFile->h, rc ); + OSTRACE3( "TEST WR-LOCK %d %d (local)\n", pFile->h, rc ); }else{ FILELOCK LockArea, UnlockArea; memset(&LockArea, 0, sizeof(LockArea)); memset(&UnlockArea, 0, sizeof(UnlockArea)); @@ -620,11 +620,11 @@ LockArea.lRange = 0L; UnlockArea.lOffset = RESERVED_BYTE; UnlockArea.lRange = 1L; rc = DosSetFileLocks( pFile->h, &UnlockArea, &LockArea, 2000L, 1L ); } - TRACE3( "TEST WR-LOCK %d %d (remote)\n", pFile->h, rc ); + OSTRACE3( "TEST WR-LOCK %d %d (remote)\n", pFile->h, rc ); } return rc; } /* @@ -646,11 +646,11 @@ UnlockArea; memset(&LockArea, 0, sizeof(LockArea)); memset(&UnlockArea, 0, sizeof(UnlockArea)); assert( pFile!=0 ); assert( locktype<=SHARED_LOCK ); - TRACE4( "UNLOCK %d to %d was %d\n", pFile->h, locktype, pFile->locktype ); + OSTRACE4( "UNLOCK %d to %d was %d\n", pFile->h, locktype, pFile->locktype ); type = pFile->locktype; if( type>=EXCLUSIVE_LOCK ){ LockArea.lOffset = 0L; LockArea.lRange = 0L; UnlockArea.lOffset = SHARED_FIRST; Index: src/os_unix.c ================================================================== --- src/os_unix.c +++ src/os_unix.c @@ -751,23 +751,24 @@ return SQLITE_OK; } hSelf = pthread_self(); if( pthread_equal(pFile->tid, hSelf) ){ /* We are still in the same thread */ - TRACE1("No-transfer, same thread\n"); + OSTRACE1("No-transfer, same thread\n"); return SQLITE_OK; } if( pFile->locktype!=NO_LOCK ){ /* We cannot change ownership while we are holding a lock! */ return SQLITE_MISUSE; } - TRACE4("Transfer ownership of %d from %d to %d\n", pFile->h,pFile->tid,hSelf); + OSTRACE4("Transfer ownership of %d from %d to %d\n", + pFile->h, pFile->tid, hSelf); pFile->tid = hSelf; if (pFile->pLock != NULL) { releaseLockInfo(pFile->pLock); rc = findLockInfo(pFile->h, &pFile->pLock, 0); - TRACE5("LOCK %d is now %s(%s,%d)\n", pFile->h, + OSTRACE5("LOCK %d is now %s(%s,%d)\n", pFile->h, locktypeName(pFile->locktype), locktypeName(pFile->pLock->locktype), pFile->pLock->cnt); return rc; } else { return SQLITE_OK; @@ -923,11 +924,11 @@ assert( pFile->dirfd<0 ); pFile->dirfd = open(zDirname, O_RDONLY|O_BINARY, 0); if( pFile->dirfd<0 ){ return SQLITE_CANTOPEN; } - TRACE3("OPENDIR %-3d %s\n", pFile->dirfd, zDirname); + OSTRACE3("OPENDIR %-3d %s\n", pFile->dirfd, zDirname); return SQLITE_OK; } /* ** If the following global variable points to a string which is the @@ -1012,11 +1013,11 @@ return -1; } got = read(id->h, pBuf, cnt); #endif TIMER_END; - TRACE5("READ %-3d %5d %7lld %d\n", id->h, got, id->offset, TIMER_ELAPSED); + OSTRACE5("READ %-3d %5d %7lld %d\n", id->h, got, id->offset, TIMER_ELAPSED); if( got>0 ){ id->offset += got; } return got; } @@ -1059,11 +1060,11 @@ return -1; } got = write(id->h, pBuf, cnt); #endif TIMER_END; - TRACE5("WRITE %-3d %5d %7lld %d\n", id->h, got, id->offset, TIMER_ELAPSED); + OSTRACE5("WRITE %-3d %5d %7lld %d\n", id->h, got, id->offset, TIMER_ELAPSED); if( got>0 ){ id->offset += got; } return got; } @@ -1209,18 +1210,18 @@ */ static int unixSync(OsFile *id, int dataOnly){ int rc; unixFile *pFile = (unixFile*)id; assert( pFile ); - TRACE2("SYNC %-3d\n", pFile->h); + OSTRACE2("SYNC %-3d\n", pFile->h); rc = full_fsync(pFile->h, pFile->fullSync, dataOnly); SimulateIOError( rc=1 ); if( rc ){ return SQLITE_IOERR_FSYNC; } if( pFile->dirfd>=0 ){ - TRACE4("DIRSYNC %-3d (have_fullfsync=%d fullsync=%d)\n", pFile->dirfd, + OSTRACE4("DIRSYNC %-3d (have_fullfsync=%d fullsync=%d)\n", pFile->dirfd, HAVE_FULLFSYNC, pFile->fullSync); #ifndef SQLITE_DISABLE_DIRSYNC /* The directory sync is only attempted if full_fsync is ** turned off or unavailable. If a full_fsync occurred above, ** then the directory sync is superfluous. @@ -1254,11 +1255,11 @@ return SQLITE_OK; #else int fd; int r; fd = open(zDirname, O_RDONLY|O_BINARY, 0); - TRACE3("DIRSYNC %-3d (%s)\n", fd, zDirname); + OSTRACE3("DIRSYNC %-3d (%s)\n", fd, zDirname); if( fd<0 ){ return SQLITE_CANTOPEN; } r = fsync(fd); close(fd); @@ -1333,11 +1334,11 @@ r = 1; } } sqlite3OsLeaveMutex(); - TRACE3("TEST WR-LOCK %d %d\n", pFile->h, r); + OSTRACE3("TEST WR-LOCK %d %d\n", pFile->h, r); return r; } /* @@ -1408,20 +1409,20 @@ struct lockInfo *pLock = pFile->pLock; struct flock lock; int s; assert( pFile ); - TRACE7("LOCK %d %s was %s(%s,%d) pid=%d\n", pFile->h, + OSTRACE7("LOCK %d %s was %s(%s,%d) pid=%d\n", pFile->h, locktypeName(locktype), locktypeName(pFile->locktype), locktypeName(pLock->locktype), pLock->cnt , getpid()); /* If there is already a lock of this type or more restrictive on the ** OsFile, do nothing. Don't use the end_lock: exit path, as ** sqlite3OsEnterMutex() hasn't been called yet. */ if( pFile->locktype>=locktype ){ - TRACE3("LOCK %d %s ok (already held)\n", pFile->h, + OSTRACE3("LOCK %d %s ok (already held)\n", pFile->h, locktypeName(locktype)); return SQLITE_OK; } /* Make sure the locking sequence is correct @@ -1552,11 +1553,11 @@ pLock->locktype = PENDING_LOCK; } end_lock: sqlite3OsLeaveMutex(); - TRACE4("LOCK %d %s %s\n", pFile->h, locktypeName(locktype), + OSTRACE4("LOCK %d %s %s\n", pFile->h, locktypeName(locktype), rc==SQLITE_OK ? "ok" : "failed"); return rc; } /* @@ -1571,11 +1572,11 @@ struct flock lock; int rc = SQLITE_OK; unixFile *pFile = (unixFile*)id; assert( pFile ); - TRACE7("UNLOCK %d %d was %d(%d,%d) pid=%d\n", pFile->h, locktype, + OSTRACE7("UNLOCK %d %d was %d(%d,%d) pid=%d\n", pFile->h, locktype, pFile->locktype, pFile->pLock->locktype, pFile->pLock->cnt, getpid()); assert( locktype<=SHARED_LOCK ); if( pFile->locktype<=locktype ){ return SQLITE_OK; @@ -1684,11 +1685,11 @@ releaseLockInfo(id->pLock); releaseOpenCnt(id->pOpen); sqlite3OsLeaveMutex(); id->isOpen = 0; - TRACE2("CLOSE %-3d\n", id->h); + OSTRACE2("CLOSE %-3d\n", id->h); OpenCounter(-1); sqlite3ThreadSafeFree(id); *pId = 0; return SQLITE_OK; } @@ -1731,15 +1732,15 @@ pb.unLockFlag = setLockFlag ? 0 : 1; pb.startEndFlag = 0; pb.offset = offset; pb.length = length; pb.fd = fd; - TRACE5("AFPLOCK setting lock %s for %d in range %llx:%llx\n", + OSTRACE5("AFPLOCK setting lock %s for %d in range %llx:%llx\n", (setLockFlag?"ON":"OFF"), fd, offset, length); err = fsctl(path, afpfsByteRangeLock2FSCTL, &pb, 0); if ( err==-1 ) { - TRACE4("AFPLOCK failed to fsctl() '%s' %d %s\n", path, errno, + OSTRACE4("AFPLOCK failed to fsctl() '%s' %d %s\n", path, errno, strerror(errno)); return 1; // error } else { return 0; } @@ -1775,11 +1776,11 @@ /* if we succeeded in taking the reserved lock, unlock it to restore ** the original state */ _AFPFSSetLock(context->filePath, pFile->h, RESERVED_BYTE, 1, 0); } } - TRACE3("TEST WR-LOCK %d %d\n", pFile->h, r); + OSTRACE3("TEST WR-LOCK %d %d\n", pFile->h, r); return r; } /* AFP-style locking following the behavior of unixLock, see the unixLock @@ -1790,18 +1791,18 @@ unixFile *pFile = (unixFile*)id; afpLockingContext *context = (afpLockingContext *) pFile->lockingContext; int gotPendingLock = 0; assert( pFile ); - TRACE5("LOCK %d %s was %s pid=%d\n", pFile->h, + OSTRACE5("LOCK %d %s was %s pid=%d\n", pFile->h, locktypeName(locktype), locktypeName(pFile->locktype), getpid()); /* If there is already a lock of this type or more restrictive on the ** OsFile, do nothing. Don't use the afp_end_lock: exit path, as ** sqlite3OsEnterMutex() hasn't been called yet. */ if( pFile->locktype>=locktype ){ - TRACE3("LOCK %d %s ok (already held)\n", pFile->h, + OSTRACE3("LOCK %d %s ok (already held)\n", pFile->h, locktypeName(locktype)); return SQLITE_OK; } /* Make sure the locking sequence is correct @@ -1904,11 +1905,11 @@ pFile->locktype = PENDING_LOCK; } afp_end_lock: sqlite3OsLeaveMutex(); - TRACE4("LOCK %d %s %s\n", pFile->h, locktypeName(locktype), + OSTRACE4("LOCK %d %s %s\n", pFile->h, locktypeName(locktype), rc==SQLITE_OK ? "ok" : "failed"); return rc; } /* @@ -1923,11 +1924,11 @@ int rc = SQLITE_OK; unixFile *pFile = (unixFile*)id; afpLockingContext *context = (afpLockingContext *) pFile->lockingContext; assert( pFile ); - TRACE5("UNLOCK %d %d was %d pid=%d\n", pFile->h, locktype, + OSTRACE5("UNLOCK %d %d was %d pid=%d\n", pFile->h, locktype, pFile->locktype, getpid()); assert( locktype<=SHARED_LOCK ); if( pFile->locktype<=locktype ){ return SQLITE_OK; @@ -2000,11 +2001,11 @@ if( id->dirfd>=0 ) close(id->dirfd); id->dirfd = -1; close(id->h); id->isOpen = 0; - TRACE2("CLOSE %-3d\n", id->h); + OSTRACE2("CLOSE %-3d\n", id->h); OpenCounter(-1); sqlite3ThreadSafeFree(id); *pId = 0; return SQLITE_OK; } @@ -2096,11 +2097,11 @@ sqlite3OsEnterMutex(); close(id->h); sqlite3OsLeaveMutex(); id->isOpen = 0; - TRACE2("CLOSE %-3d\n", id->h); + OSTRACE2("CLOSE %-3d\n", id->h); OpenCounter(-1); sqlite3ThreadSafeFree(id); *pId = 0; return SQLITE_OK; } @@ -2215,11 +2216,11 @@ close(id->h); sqlite3OsLeaveMutex(); id->isOpen = 0; - TRACE2("CLOSE %-3d\n", id->h); + OSTRACE2("CLOSE %-3d\n", id->h); OpenCounter(-1); sqlite3ThreadSafeFree(id); *pId = 0; return SQLITE_OK; } @@ -2257,11 +2258,11 @@ close(id->h); sqlite3OsLeaveMutex(); id->isOpen = 0; - TRACE2("CLOSE %-3d\n", id->h); + OSTRACE2("CLOSE %-3d\n", id->h); OpenCounter(-1); sqlite3ThreadSafeFree(id); *pId = 0; return SQLITE_OK; } @@ -2586,11 +2587,11 @@ } if( rc ){ close(h); return SQLITE_NOMEM; } - TRACE3("OPEN %-3d %s\n", h, zFilename); + OSTRACE3("OPEN %-3d %s\n", h, zFilename); f.dirfd = -1; f.fullSync = 0; f.locktype = 0; f.offset = 0; f.h = h; Index: src/os_win.c ================================================================== --- src/os_win.c +++ src/os_win.c @@ -610,11 +610,11 @@ }while( rc==0 && GetFileAttributesA(zConverted)!=0xffffffff && cnt++ < MX_DELETION_ATTEMPTS && (Sleep(100), 1) ); #endif } sqliteFree(zConverted); - TRACE2("DELETE \"%s\"\n", zFilename); + OSTRACE2("DELETE \"%s\"\n", zFilename); return rc!=0 ? SQLITE_OK : SQLITE_IOERR; } /* ** Return TRUE if the named file exists. @@ -736,11 +736,11 @@ f.h = h; #if OS_WINCE f.zDeleteOnClose = 0; #endif - TRACE3("OPEN R/W %d \"%s\"\n", h, zFilename); + OSTRACE3("OPEN R/W %d \"%s\"\n", h, zFilename); return allocateWinFile(&f, pId); } /* @@ -817,11 +817,11 @@ sqliteFree(zConverted); if( h==INVALID_HANDLE_VALUE ){ return SQLITE_CANTOPEN; } f.h = h; - TRACE3("OPEN EX %d \"%s\"\n", h, zFilename); + OSTRACE3("OPEN EX %d \"%s\"\n", h, zFilename); return allocateWinFile(&f, pId); } /* ** Attempt to open a new file for read-only access. @@ -868,11 +868,11 @@ f.h = h; #if OS_WINCE f.zDeleteOnClose = 0; f.hMutex = NULL; #endif - TRACE3("OPEN RO %d \"%s\"\n", h, zFilename); + OSTRACE3("OPEN RO %d \"%s\"\n", h, zFilename); return allocateWinFile(&f, pId); } /* ** Attempt to open a file descriptor for the directory that contains a @@ -953,11 +953,11 @@ zBuf[j] = (char)zChars[ ((unsigned char)zBuf[j])%(sizeof(zChars)-1) ]; } zBuf[j] = 0; if( !sqlite3OsFileExists(zBuf) ) break; } - TRACE2("TEMP FILENAME: %s\n", zBuf); + OSTRACE2("TEMP FILENAME: %s\n", zBuf); return SQLITE_OK; } /* ** Close a file. @@ -973,11 +973,11 @@ static int winClose(OsFile **pId){ winFile *pFile; int rc = 1; if( pId && (pFile = (winFile*)*pId)!=0 ){ int rc, cnt = 0; - TRACE2("CLOSE %d\n", pFile->h); + OSTRACE2("CLOSE %d\n", pFile->h); do{ rc = CloseHandle(pFile->h); }while( rc==0 && cnt++ < MX_CLOSE_ATTEMPT && (Sleep(100), 1) ); #if OS_WINCE winceDestroyLock(pFile); @@ -1000,11 +1000,11 @@ */ static int winRead(OsFile *id, void *pBuf, int amt){ DWORD got; assert( id!=0 ); SimulateIOError(return SQLITE_IOERR_READ); - TRACE3("READ %d lock=%d\n", ((winFile*)id)->h, ((winFile*)id)->locktype); + OSTRACE3("READ %d lock=%d\n", ((winFile*)id)->h, ((winFile*)id)->locktype); if( !ReadFile(((winFile*)id)->h, pBuf, amt, &got, 0) ){ return SQLITE_IOERR_READ; } if( got==(DWORD)amt ){ return SQLITE_OK; @@ -1022,11 +1022,11 @@ int rc = 0; DWORD wrote; assert( id!=0 ); SimulateIOError(return SQLITE_IOERR_READ); SimulateDiskfullError(return SQLITE_FULL); - TRACE3("WRITE %d lock=%d\n", ((winFile*)id)->h, ((winFile*)id)->locktype); + OSTRACE3("WRITE %d lock=%d\n", ((winFile*)id)->h, ((winFile*)id)->locktype); assert( amt>0 ); while( amt>0 && (rc = WriteFile(((winFile*)id)->h, pBuf, amt, &wrote, 0))!=0 && wrote>0 ){ amt -= wrote; pBuf = &((char*)pBuf)[wrote]; @@ -1055,11 +1055,11 @@ #ifdef SQLITE_TEST if( offset ) SimulateDiskfullError(return SQLITE_FULL); #endif SEEK(offset/1024 + 1); rc = SetFilePointer(((winFile*)id)->h, lowerBits, &upperBits, FILE_BEGIN); - TRACE3("SEEK %d %lld\n", ((winFile*)id)->h, offset); + OSTRACE3("SEEK %d %lld\n", ((winFile*)id)->h, offset); if( rc==INVALID_SET_FILE_POINTER && GetLastError()!=NO_ERROR ){ return SQLITE_FULL; } return SQLITE_OK; } @@ -1067,11 +1067,11 @@ /* ** Make sure all writes to a particular file are committed to disk. */ static int winSync(OsFile *id, int dataOnly){ assert( id!=0 ); - TRACE3("SYNC %d lock=%d\n", ((winFile*)id)->h, ((winFile*)id)->locktype); + OSTRACE3("SYNC %d lock=%d\n", ((winFile*)id)->h, ((winFile*)id)->locktype); if( FlushFileBuffers(((winFile*)id)->h) ){ return SQLITE_OK; }else{ return SQLITE_IOERR; } @@ -1090,11 +1090,11 @@ ** Truncate an open file to a specified size */ static int winTruncate(OsFile *id, i64 nByte){ LONG upperBits = nByte>>32; assert( id!=0 ); - TRACE3("TRUNCATE %d %lld\n", ((winFile*)id)->h, nByte); + OSTRACE3("TRUNCATE %d %lld\n", ((winFile*)id)->h, nByte); SimulateIOError(return SQLITE_IOERR_TRUNCATE); SetFilePointer(((winFile*)id)->h, nByte, &upperBits, FILE_BEGIN); SetEndOfFile(((winFile*)id)->h); return SQLITE_OK; } @@ -1218,11 +1218,11 @@ int newLocktype; /* Set id->locktype to this value before exiting */ int gotPendingLock = 0;/* True if we acquired a PENDING lock this time */ winFile *pFile = (winFile*)id; assert( pFile!=0 ); - TRACE5("LOCK %d %d was %d(%d)\n", + OSTRACE5("LOCK %d %d was %d(%d)\n", pFile->h, locktype, pFile->locktype, pFile->sharedLockByte); /* If there is already a lock of this type or more restrictive on the ** OsFile, do nothing. Don't use the end_lock: exit path, as ** sqlite3OsEnterMutex() hasn't been called yet. @@ -1248,11 +1248,11 @@ int cnt = 3; while( cnt-->0 && (res = LockFile(pFile->h, PENDING_BYTE, 0, 1, 0))==0 ){ /* Try 3 times to get the pending lock. The pending lock might be ** held by another reader process who will release it momentarily. */ - TRACE2("could not get a PENDING lock. cnt=%d\n", cnt); + OSTRACE2("could not get a PENDING lock. cnt=%d\n", cnt); Sleep(1); } gotPendingLock = res; } @@ -1286,16 +1286,16 @@ /* Acquire an EXCLUSIVE lock */ if( locktype==EXCLUSIVE_LOCK && res ){ assert( pFile->locktype>=SHARED_LOCK ); res = unlockReadLock(pFile); - TRACE2("unreadlock = %d\n", res); + OSTRACE2("unreadlock = %d\n", res); res = LockFile(pFile->h, SHARED_FIRST, 0, SHARED_SIZE, 0); if( res ){ newLocktype = EXCLUSIVE_LOCK; }else{ - TRACE2("error-code = %d\n", GetLastError()); + OSTRACE2("error-code = %d\n", GetLastError()); } } /* If we are holding a PENDING lock that ought to be released, then ** release it now. @@ -1308,11 +1308,11 @@ ** return the appropriate result code. */ if( res ){ rc = SQLITE_OK; }else{ - TRACE4("LOCK FAILED %d trying for %d but got %d\n", pFile->h, + OSTRACE4("LOCK FAILED %d trying for %d but got %d\n", pFile->h, locktype, newLocktype); rc = SQLITE_BUSY; } pFile->locktype = newLocktype; return rc; @@ -1327,18 +1327,18 @@ int rc; winFile *pFile = (winFile*)id; assert( pFile!=0 ); if( pFile->locktype>=RESERVED_LOCK ){ rc = 1; - TRACE3("TEST WR-LOCK %d %d (local)\n", pFile->h, rc); + OSTRACE3("TEST WR-LOCK %d %d (local)\n", pFile->h, rc); }else{ rc = LockFile(pFile->h, RESERVED_BYTE, 0, 1, 0); if( rc ){ UnlockFile(pFile->h, RESERVED_BYTE, 0, 1, 0); } rc = !rc; - TRACE3("TEST WR-LOCK %d %d (remote)\n", pFile->h, rc); + OSTRACE3("TEST WR-LOCK %d %d (remote)\n", pFile->h, rc); } return rc; } /* @@ -1356,11 +1356,11 @@ int type; int rc = SQLITE_OK; winFile *pFile = (winFile*)id; assert( pFile!=0 ); assert( locktype<=SHARED_LOCK ); - TRACE5("UNLOCK %d to %d was %d(%d)\n", pFile->h, locktype, + OSTRACE5("UNLOCK %d to %d was %d(%d)\n", pFile->h, locktype, pFile->locktype, pFile->sharedLockByte); type = pFile->locktype; if( type>=EXCLUSIVE_LOCK ){ UnlockFile(pFile->h, SHARED_FIRST, 0, SHARED_SIZE, 0); if( locktype==SHARED_LOCK && !getReadLock(pFile) ){ Index: src/pager.c ================================================================== --- src/pager.c +++ src/pager.c @@ -16,11 +16,11 @@ ** is separate from the database file. The pager also implements file ** locking to prevent two processes from writing the same database ** file simultaneously, or one process from reading the database while ** another is writing. ** -** @(#) $Id: pager.c,v 1.299 2007/03/26 15:46:01 danielk1977 Exp $ +** @(#) $Id: pager.c,v 1.300 2007/03/26 22:05:02 drh Exp $ */ #ifndef SQLITE_OMIT_DISKIO #include "sqliteInt.h" #include "os.h" #include "pager.h" @@ -30,25 +30,25 @@ /* ** Macros for troubleshooting. Normally turned off */ #if 0 #define sqlite3DebugPrintf printf -#define TRACE1(X) sqlite3DebugPrintf(X) -#define TRACE2(X,Y) sqlite3DebugPrintf(X,Y) -#define TRACE3(X,Y,Z) sqlite3DebugPrintf(X,Y,Z) -#define TRACE4(X,Y,Z,W) sqlite3DebugPrintf(X,Y,Z,W) -#define TRACE5(X,Y,Z,W,V) sqlite3DebugPrintf(X,Y,Z,W,V) +#define PAGERTRACE1(X) sqlite3DebugPrintf(X) +#define PAGERTRACE2(X,Y) sqlite3DebugPrintf(X,Y) +#define PAGERTRACE3(X,Y,Z) sqlite3DebugPrintf(X,Y,Z) +#define PAGERTRACE4(X,Y,Z,W) sqlite3DebugPrintf(X,Y,Z,W) +#define PAGERTRACE5(X,Y,Z,W,V) sqlite3DebugPrintf(X,Y,Z,W,V) #else -#define TRACE1(X) -#define TRACE2(X,Y) -#define TRACE3(X,Y,Z) -#define TRACE4(X,Y,Z,W) -#define TRACE5(X,Y,Z,W,V) +#define PAGERTRACE1(X) +#define PAGERTRACE2(X,Y) +#define PAGERTRACE3(X,Y,Z) +#define PAGERTRACE4(X,Y,Z,W) +#define PAGERTRACE5(X,Y,Z,W,V) #endif /* -** The following two macros are used within the TRACEX() macros above +** The following two macros are used within the PAGERTRACEX() macros above ** to print out file-descriptors. ** ** PAGERID() takes a pointer to a Pager struct as it's argument. The ** associated file-descriptor is returned. FILEHANDLEID() takes an OsFile ** struct as it's argument. @@ -1080,11 +1080,11 @@ ** page content is in the main journal either because the page is not in ** cache or else it is marked as needSync==0. */ pPg = pager_lookup(pPager, pgno); assert( pPager->state>=PAGER_EXCLUSIVE || pPg!=0 ); - TRACE3("PLAYBACK %d page %d\n", PAGERID(pPager), pgno); + PAGERTRACE3("PLAYBACK %d page %d\n", PAGERID(pPager), pgno); if( pPager->state>=PAGER_EXCLUSIVE && (pPg==0 || pPg->needSync==0) ){ rc = sqlite3OsSeek(pPager->fd, (pgno-1)*(i64)pPager->pageSize); if( rc==SQLITE_OK ){ rc = sqlite3OsWrite(pPager->fd, aData, pPager->pageSize); } @@ -1224,11 +1224,11 @@ if( (int)pPg->pgno <= pPager->origDbSize ){ rc = sqlite3OsSeek(pPager->fd, pPager->pageSize*(i64)(pPg->pgno-1)); if( rc==SQLITE_OK ){ rc = sqlite3OsRead(pPager->fd, zBuf, pPager->pageSize); } - TRACE3("REFETCH %d page %d\n", PAGERID(pPager), pPg->pgno); + PAGERTRACE3("REFETCH %d page %d\n", PAGERID(pPager), pPg->pgno); if( rc ) break; CODEC1(pPager, zBuf, pPg->pgno, 2); }else{ memset(zBuf, 0, pPager->pageSize); } @@ -1732,11 +1732,11 @@ sqliteFree(zFullPathname); sqliteFree(pPager); return ((rc==SQLITE_OK)?SQLITE_NOMEM:rc); } - TRACE3("OPEN %d %s\n", FILEHANDLEID(fd), zFullPathname); + PAGERTRACE3("OPEN %d %s\n", FILEHANDLEID(fd), zFullPathname); IOTRACE(("OPEN %p %s\n", pPager, zFullPathname)) pPager->zFilename = (char*)&pPager[1]; pPager->zDirectory = &pPager->zFilename[nameLen+1]; pPager->zJournal = &pPager->zDirectory[nameLen+1]; strcpy(pPager->zFilename, zFullPathname); @@ -1826,11 +1826,11 @@ int sqlite3PagerSetPagesize(Pager *pPager, int pageSize){ assert( pageSize>=512 && pageSize<=SQLITE_MAX_PAGE_SIZE ); if( !pPager->memDb && pPager->nRef==0 ){ pager_reset(pPager); pPager->pageSize = pageSize; - sqlite3ReallocOrFree((void **)&pPager->pTmpSpace, pageSize); + sqlite3ReallocOrFree(&pPager->pTmpSpace, pageSize); } return pPager->pageSize; } /* @@ -2137,11 +2137,11 @@ pPager->errCode = 0; pPager->exclusiveMode = 0; pager_reset(pPager); pagerUnlockAndRollback(pPager); enable_simulated_io_errors(); - TRACE2("CLOSE %d\n", PAGERID(pPager)); + PAGERTRACE2("CLOSE %d\n", PAGERID(pPager)); IOTRACE(("CLOSE %p\n", pPager)) assert( pPager->errCode || (pPager->journalOpen==0 && pPager->stmtOpen==0) ); if( pPager->journalOpen ){ sqlite3OsClose(&pPager->jfd); } @@ -2283,11 +2283,11 @@ ** full-synchronous mode, sync the journal first. This ensures that ** all data has really hit the disk before nRec is updated to mark ** it as a candidate for rollback. */ if( pPager->fullSync ){ - TRACE2("SYNC journal of %d\n", PAGERID(pPager)); + PAGERTRACE2("SYNC journal of %d\n", PAGERID(pPager)); IOTRACE(("JSYNC %p\n", pPager)) rc = sqlite3OsSync(pPager->jfd, 0); if( rc!=0 ) return rc; } rc = sqlite3OsSeek(pPager->jfd, @@ -2299,11 +2299,11 @@ if( rc ) return rc; rc = sqlite3OsSeek(pPager->jfd, pPager->journalOff); if( rc ) return rc; } - TRACE2("SYNC journal of %d\n", PAGERID(pPager)); + PAGERTRACE2("SYNC journal of %d\n", PAGERID(pPager)); IOTRACE(("JSYNC %d\n", pPager)) rc = sqlite3OsSync(pPager->jfd, pPager->full_fsync); if( rc!=0 ) return rc; pPager->journalStarted = 1; } @@ -2438,18 +2438,18 @@ ** make the file smaller (presumably by auto-vacuum code). Do not write ** any such pages to the file. */ if( pList->pgno<=pPager->dbSize ){ char *pData = CODEC2(pPager, PGHDR_TO_DATA(pList), pList->pgno, 6); - TRACE3("STORE %d page %d\n", PAGERID(pPager), pList->pgno); + PAGERTRACE3("STORE %d page %d\n", PAGERID(pPager), pList->pgno); IOTRACE(("PGOUT %p %d\n", pPager, pList->pgno)) rc = sqlite3OsWrite(pPager->fd, pData, pPager->pageSize); TEST_INCR(pPager->nWrite); } #ifndef NDEBUG else{ - TRACE3("NOSTORE %d page %d\n", PAGERID(pPager), pList->pgno); + PAGERTRACE3("NOSTORE %d page %d\n", PAGERID(pPager), pList->pgno); } #endif if( rc ) return rc; pList->dirty = 0; #ifdef SQLITE_CHECK_PAGES @@ -2905,11 +2905,11 @@ if( rc==SQLITE_OK ){ rc = sqlite3OsRead(pPager->fd, PGHDR_TO_DATA(pPg), pPager->pageSize); } IOTRACE(("PGIN %p %d\n", pPager, pgno)) - TRACE3("FETCH %d page %d\n", PAGERID(pPager), pPg->pgno); + PAGERTRACE3("FETCH %d page %d\n", PAGERID(pPager), pPg->pgno); CODEC1(pPager, PGHDR_TO_DATA(pPg), pPg->pgno, 3); if( rc!=SQLITE_OK && rc!=SQLITE_IOERR_SHORT_READ ){ pPg->pgno = 0; sqlite3PagerUnref(pPg); return rc; @@ -3140,11 +3140,11 @@ } if( rc!=SQLITE_OK ){ return rc; } pPager->dirtyCache = 0; - TRACE2("TRANSACTION %d\n", PAGERID(pPager)); + PAGERTRACE2("TRANSACTION %d\n", PAGERID(pPager)); if( pPager->useJournal && !pPager->tempFile ){ rc = pager_open_journal(pPager); } } }else if( pPager->journalOpen && pPager->journalOff==0 ){ @@ -3274,11 +3274,11 @@ if( !pPg->inJournal && (pPager->useJournal || MEMDB) ){ if( (int)pPg->pgno <= pPager->origDbSize ){ int szPg; if( MEMDB ){ PgHistory *pHist = PGHDR_TO_HIST(pPg, pPager); - TRACE3("JOURNAL %d page %d\n", PAGERID(pPager), pPg->pgno); + PAGERTRACE3("JOURNAL %d page %d\n", PAGERID(pPager), pPg->pgno); assert( pHist->pOrig==0 ); pHist->pOrig = sqliteMallocRaw( pPager->pageSize ); if( pHist->pOrig ){ memcpy(pHist->pOrig, PGHDR_TO_DATA(pPg), pPager->pageSize); } @@ -3299,11 +3299,11 @@ put32bits(pData2, pPg->pgno); rc = sqlite3OsWrite(pPager->jfd, pData2, szPg); IOTRACE(("JOUT %p %d %lld %d\n", pPager, pPg->pgno, pPager->journalOff, szPg)) pPager->journalOff += szPg; - TRACE4("JOURNAL %d page %d needSync=%d\n", + PAGERTRACE4("JOURNAL %d page %d needSync=%d\n", PAGERID(pPager), pPg->pgno, pPg->needSync); *(u32*)pEnd = saved; /* An error has occured writing to the journal file. The ** transaction will be rolled back by the layer above. @@ -3321,11 +3321,11 @@ page_add_to_stmt_list(pPg); } } }else{ pPg->needSync = !pPager->journalStarted && !pPager->noSync; - TRACE4("APPEND %d page %d needSync=%d\n", + PAGERTRACE4("APPEND %d page %d needSync=%d\n", PAGERID(pPager), pPg->pgno, pPg->needSync); } if( pPg->needSync ){ pPager->needSync = 1; } @@ -3344,16 +3344,16 @@ assert( pHist->pStmt==0 ); pHist->pStmt = sqliteMallocRaw( pPager->pageSize ); if( pHist->pStmt ){ memcpy(pHist->pStmt, PGHDR_TO_DATA(pPg), pPager->pageSize); } - TRACE3("STMT-JOURNAL %d page %d\n", PAGERID(pPager), pPg->pgno); + PAGERTRACE3("STMT-JOURNAL %d page %d\n", PAGERID(pPager), pPg->pgno); }else{ char *pData2 = CODEC2(pPager, pData, pPg->pgno, 7)-4; put32bits(pData2, pPg->pgno); rc = sqlite3OsWrite(pPager->stfd, pData2, pPager->pageSize+4); - TRACE3("STMT-JOURNAL %d page %d\n", PAGERID(pPager), pPg->pgno); + PAGERTRACE3("STMT-JOURNAL %d page %d\n", PAGERID(pPager), pPg->pgno); if( rc!=SQLITE_OK ){ return rc; } pPager->stmtNRec++; assert( pPager->aInStmt!=0 ); @@ -3520,11 +3520,11 @@ ** size. If you do not write this page and the size of the file ** on the disk ends up being too small, that can lead to database ** corruption during the next transaction. */ }else{ - TRACE3("DONT_WRITE page %d of %d\n", pgno, PAGERID(pPager)); + PAGERTRACE3("DONT_WRITE page %d of %d\n", pgno, PAGERID(pPager)); IOTRACE(("CLEAN %p %d\n", pPager, pgno)) makeClean(pPg); #ifdef SQLITE_CHECK_PAGES pPg->pageHash = pager_pagehash(pPg); #endif @@ -3550,11 +3550,11 @@ pPg->inJournal = 1; if( pPager->stmtInUse ){ pPager->aInStmt[pPg->pgno/8] |= 1<<(pPg->pgno&7); page_add_to_stmt_list(pPg); } - TRACE3("DONT_ROLLBACK page %d of %d\n", pPg->pgno, PAGERID(pPager)); + PAGERTRACE3("DONT_ROLLBACK page %d of %d\n", pPg->pgno, PAGERID(pPager)); IOTRACE(("GARBAGE %p %d\n", pPager, pPg->pgno)) } if( pPager->stmtInUse && !pPg->inStmt && (int)pPg->pgno<=pPager->stmtSize ){ assert( pPg->inJournal || (int)pPg->pgno>pPager->origDbSize ); assert( pPager->aInStmt!=0 ); @@ -3579,11 +3579,11 @@ return pPager->errCode; } if( pPager->statedirty = 0; @@ -3633,11 +3633,11 @@ ** codes are returned for all these occasions. Otherwise, ** SQLITE_OK is returned. */ int sqlite3PagerRollback(Pager *pPager){ int rc; - TRACE2("ROLLBACK %d\n", PAGERID(pPager)); + PAGERTRACE2("ROLLBACK %d\n", PAGERID(pPager)); if( MEMDB ){ PgHdr *p; for(p=pPager->pAll; p; p=p->pNextAll){ PgHistory *pHist; assert( !p->alwaysRollback ); @@ -3648,13 +3648,13 @@ } pHist = PGHDR_TO_HIST(p, pPager); if( pHist->pOrig ){ memcpy(PGHDR_TO_DATA(p), pHist->pOrig, pPager->pageSize); - TRACE3("ROLLBACK-PAGE %d of %d\n", p->pgno, PAGERID(pPager)); + PAGERTRACE3("ROLLBACK-PAGE %d of %d\n", p->pgno, PAGERID(pPager)); }else{ - TRACE3("PAGE %d is clean on %d\n", p->pgno, PAGERID(pPager)); + PAGERTRACE3("PAGE %d is clean on %d\n", p->pgno, PAGERID(pPager)); } clearHistory(pHist); p->dirty = 0; p->inJournal = 0; p->inStmt = 0; @@ -3748,11 +3748,11 @@ int sqlite3PagerStmtBegin(Pager *pPager){ int rc; assert( !pPager->stmtInUse ); assert( pPager->state>=PAGER_SHARED ); assert( pPager->dbSize>=0 ); - TRACE2("STMT-BEGIN %d\n", PAGERID(pPager)); + PAGERTRACE2("STMT-BEGIN %d\n", PAGERID(pPager)); if( MEMDB ){ pPager->stmtInUse = 1; pPager->stmtSize = pPager->dbSize; return SQLITE_OK; } @@ -3796,11 +3796,11 @@ ** Commit a statement. */ int sqlite3PagerStmtCommit(Pager *pPager){ if( pPager->stmtInUse ){ PgHdr *pPg, *pNext; - TRACE2("STMT-COMMIT %d\n", PAGERID(pPager)); + PAGERTRACE2("STMT-COMMIT %d\n", PAGERID(pPager)); if( !MEMDB ){ sqlite3OsSeek(pPager->stfd, 0); /* sqlite3OsTruncate(pPager->stfd, 0); */ sqliteFree( pPager->aInStmt ); pPager->aInStmt = 0; @@ -3828,11 +3828,11 @@ ** Rollback a statement. */ int sqlite3PagerStmtRollback(Pager *pPager){ int rc; if( pPager->stmtInUse ){ - TRACE2("STMT-ROLLBACK %d\n", PAGERID(pPager)); + PAGERTRACE2("STMT-ROLLBACK %d\n", PAGERID(pPager)); if( MEMDB ){ PgHdr *pPg; for(pPg=pPager->pStmt; pPg; pPg=pPg->pNextStmt){ PgHistory *pHist = PGHDR_TO_HIST(pPg, pPager); if( pHist->pStmt ){ @@ -3945,11 +3945,11 @@ ** nTrunc pages (this is used by auto-vacuum databases). */ int sqlite3PagerSync(Pager *pPager, const char *zMaster, Pgno nTrunc){ int rc = SQLITE_OK; - TRACE4("DATABASE SYNC: File=%s zMaster=%s nTrunc=%d\n", + PAGERTRACE4("DATABASE SYNC: File=%s zMaster=%s nTrunc=%d\n", pPager->zFilename, zMaster, nTrunc); /* If this is an in-memory db, or no pages have been written to, or this ** function has already been called, it is a no-op. */ @@ -4041,11 +4041,11 @@ int h; Pgno needSyncPgno = 0; assert( pPg->nRef>0 ); - TRACE5("MOVE %d page %d (needSync=%d) moves to %d\n", + PAGERTRACE5("MOVE %d page %d (needSync=%d) moves to %d\n", PAGERID(pPager), pPg->pgno, pPg->needSync, pgno); IOTRACE(("MOVE %p %d %d\n", pPager, pPg->pgno, pgno)) if( pPg->needSync ){ needSyncPgno = pPg->pgno; Index: src/prepare.c ================================================================== --- src/prepare.c +++ src/prepare.c @@ -11,11 +11,11 @@ ************************************************************************* ** This file contains the implementation of the sqlite3_prepare() ** interface, and routines that contribute to loading the database schema ** from disk. ** -** $Id: prepare.c,v 1.44 2007/03/14 15:37:04 danielk1977 Exp $ +** $Id: prepare.c,v 1.45 2007/03/26 22:05:02 drh Exp $ */ #include "sqliteInt.h" #include "os.h" #include @@ -564,30 +564,30 @@ ** Return true if the statement was recompiled successfully. ** Return false if there is an error of some kind. */ int sqlite3Reprepare(Vdbe *p){ int rc; - Vdbe *pNew; + sqlite3_stmt *pNew; const char *zSql; sqlite3 *db; zSql = sqlite3VdbeGetSql(p); if( zSql==0 ){ return 0; } db = sqlite3VdbeDb(p); - rc = sqlite3Prepare(db, zSql, -1, 0, (sqlite3_stmt**)&pNew, 0); + rc = sqlite3Prepare(db, zSql, -1, 0, &pNew, 0); if( rc ){ assert( pNew==0 ); return 0; }else{ assert( pNew!=0 ); } - sqlite3VdbeSwap(pNew, p); - sqlite3_transfer_bindings((sqlite3_stmt*)pNew, (sqlite3_stmt*)p); - sqlite3VdbeResetStepResult(pNew); - sqlite3VdbeFinalize(pNew); + sqlite3VdbeSwap((Vdbe*)pNew, p); + sqlite3_transfer_bindings(pNew, (sqlite3_stmt*)p); + sqlite3VdbeResetStepResult((Vdbe*)pNew); + sqlite3VdbeFinalize((Vdbe*)pNew); return 1; } /* Index: src/sqliteInt.h ================================================================== --- src/sqliteInt.h +++ src/sqliteInt.h @@ -9,20 +9,17 @@ ** May you share freely, never taking more than you give. ** ************************************************************************* ** Internal interface definitions for SQLite. ** -** @(#) $Id: sqliteInt.h,v 1.543 2007/03/24 16:45:05 danielk1977 Exp $ +** @(#) $Id: sqliteInt.h,v 1.544 2007/03/26 22:05:02 drh Exp $ */ #ifndef _SQLITEINT_H_ #define _SQLITEINT_H_ -/* -** Extra interface definitions for those who need them -*/ -#ifdef SQLITE_EXTRA -# include "sqliteExtra.h" +#if defined(SQLITE_TCL) || defined(TCLSH) +# include #endif /* ** Many people are failing to set -DNDEBUG=1 when compiling SQLite. ** Setting NDEBUG makes the code smaller and run faster. So the following @@ -1568,11 +1565,11 @@ void sqlite3Free(void*); void *sqlite3Realloc(void*,int); char *sqlite3StrDup(const char*); char *sqlite3StrNDup(const char*, int); # define sqlite3CheckMemory(a,b) -void sqlite3ReallocOrFree(void**,int); +void sqlite3ReallocOrFree(void*,int); void sqlite3FreeX(void*); void *sqlite3MallocX(int); int sqlite3AllocSize(void *); char *sqlite3MPrintf(const char*, ...); @@ -1625,11 +1622,11 @@ #endif void sqlite3DropTable(Parse*, SrcList*, int, int); void sqlite3DeleteTable(sqlite3*, Table*); void sqlite3Insert(Parse*, SrcList*, ExprList*, Select*, IdList*, int); -int sqlite3ArrayAllocate(void**,int,int); +int sqlite3ArrayAllocate(void*,int,int); IdList *sqlite3IdListAppend(IdList*, Token*); int sqlite3IdListIndex(IdList*,const char*); SrcList *sqlite3SrcListAppend(SrcList*, Token*, Token*); SrcList *sqlite3SrcListAppendFromTerm(SrcList*, Token*, Token*, Token*, Select*, Expr*, IdList*); Index: src/test1.c ================================================================== --- src/test1.c +++ src/test1.c @@ -11,11 +11,11 @@ ************************************************************************* ** Code for testing all sorts of SQLite interfaces. This code ** is not included in the SQLite library. It is used for automated ** testing of the SQLite library. ** -** $Id: test1.c,v 1.229 2007/02/24 13:53:05 drh Exp $ +** $Id: test1.c,v 1.230 2007/03/26 22:05:02 drh Exp $ */ #include "sqliteInt.h" #include "tcl.h" #include "os.h" #include @@ -110,11 +110,11 @@ case SQLITE_NOTADB: zName = "SQLITE_NOTADB"; break; default: zName = "SQLITE_Unknown"; break; } return zName; } -#define errorName sqlite3TestErrorName +#define t1ErrorName sqlite3TestErrorName /* ** Convert an sqlite3_stmt* into an sqlite3*. This depends on the ** fact that the sqlite3* is the first field in the Vdbe structure. */ @@ -127,11 +127,11 @@ int sqlite3TestErrCode(Tcl_Interp *interp, sqlite3 *db, int rc){ if( rc!=SQLITE_MISUSE && rc!=SQLITE_OK && sqlite3_errcode(db)!=rc ){ char zBuf[200]; int r2 = sqlite3_errcode(db); sprintf(zBuf, "error code %s (%d) does not match sqlite3_errcode %s (%d)", - errorName(rc), rc, errorName(r2), r2); + t1ErrorName(rc), rc, t1ErrorName(r2), r2); Tcl_ResetResult(interp); Tcl_AppendResult(interp, zBuf, 0); return 1; } return 0; @@ -488,19 +488,23 @@ " FILENAME\"", 0); return TCL_ERROR; } if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR; rc = sqlite3_close(db); - Tcl_SetResult(interp, (char *)errorName(rc), TCL_STATIC); + Tcl_SetResult(interp, (char *)t1ErrorName(rc), TCL_STATIC); return TCL_OK; } /* ** Implementation of the x_coalesce() function. ** Return the first argument non-NULL argument. */ -static void ifnullFunc(sqlite3_context *context, int argc, sqlite3_value **argv){ +static void t1_ifnullFunc( + sqlite3_context *context, + int argc, + sqlite3_value **argv +){ int i; for(i=0; in++; } if( argc>0 ){ @@ -751,12 +759,12 @@ sqlite3_result_error16(context, &zUtf16ErrMsg[1-SQLITE_BIGENDIAN], -1); #endif } } } -static void countFinalize(sqlite3_context *context){ - CountCtx *p; +static void t1CountFinalize(sqlite3_context *context){ + t1CountCtx *p; p = sqlite3_aggregate_context(context, sizeof(*p)); if( p ){ if( p->n==42 ){ sqlite3_result_error(context, "x_count totals to 42", -1); }else{ @@ -792,14 +800,14 @@ " FILENAME\"", 0); return TCL_ERROR; } if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR; rc = sqlite3_create_function(db, "x_count", 0, SQLITE_UTF8, 0, 0, - countStep,countFinalize); + t1CountStep,t1CountFinalize); if( rc==SQLITE_OK ){ sqlite3_create_function(db, "x_count", 1, SQLITE_UTF8, 0, 0, - countStep,countFinalize); + t1CountStep,t1CountFinalize); } if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR; return TCL_OK; } @@ -1495,11 +1503,11 @@ if( pStmt ){ db = StmtToDb(pStmt); } rc = sqlite3_finalize(pStmt); - Tcl_SetResult(interp, (char *)errorName(rc), TCL_STATIC); + Tcl_SetResult(interp, (char *)t1ErrorName(rc), TCL_STATIC); if( db && sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR; return TCL_OK; } /* @@ -1526,11 +1534,11 @@ rc = sqlite3_reset(pStmt); if( pStmt && sqlite3TestErrCode(interp, StmtToDb(pStmt), rc) ){ return TCL_ERROR; } - Tcl_SetResult(interp, (char *)errorName(rc), TCL_STATIC); + Tcl_SetResult(interp, (char *)t1ErrorName(rc), TCL_STATIC); /* if( rc ){ return TCL_ERROR; } */ @@ -2050,11 +2058,11 @@ Tcl_WrongNumArgs(interp, 1, objv, ""); } zCode = Tcl_GetString(objv[1]); for(i=0; i<200; i++){ - if( 0==strcmp(errorName(i), zCode) ) break; + if( 0==strcmp(t1ErrorName(i), zCode) ) break; } Tcl_SetResult(interp, (char *)sqlite3ErrStr(i), 0); return TCL_OK; } @@ -2502,11 +2510,11 @@ if( (rc&0xff)==rc ){ zBuf[0] = 0; }else{ sprintf(zBuf,"+%d", rc>>8); } - Tcl_AppendResult(interp, (char *)errorName(rc), zBuf, 0); + Tcl_AppendResult(interp, (char *)t1ErrorName(rc), zBuf, 0); return TCL_OK; } /* ** Usage: test_errmsg DB @@ -2898,11 +2906,11 @@ if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; rc = sqlite3_step(pStmt); /* if( rc!=SQLITE_DONE && rc!=SQLITE_ROW ) return TCL_ERROR; */ - Tcl_SetResult(interp, (char *)errorName(rc), 0); + Tcl_SetResult(interp, (char *)t1ErrorName(rc), 0); return TCL_OK; } /* ** Usage: sqlite3_column_count STMT @@ -3135,11 +3143,11 @@ if( objc!=1 ){ Tcl_WrongNumArgs(interp, 1, objv, ""); return TCL_ERROR; } rc = sqlite3_global_recover(); - Tcl_SetResult(interp, (char *)errorName(rc), TCL_STATIC); + Tcl_SetResult(interp, (char *)t1ErrorName(rc), TCL_STATIC); #endif return TCL_OK; } /* @@ -3233,11 +3241,11 @@ return TCL_ERROR; } rc = sqlite3OsOpenReadWrite(Tcl_GetString(objv[1]), &pFile, &dummy); if( rc!=SQLITE_OK ){ - Tcl_SetResult(interp, (char *)errorName(rc), TCL_STATIC); + Tcl_SetResult(interp, (char *)t1ErrorName(rc), TCL_STATIC); return TCL_ERROR; } sqlite3TestMakePointerStr(interp, zBuf, pFile); Tcl_SetResult(interp, zBuf, 0); return TCL_ERROR; @@ -3264,11 +3272,11 @@ if( getFilePointer(interp, Tcl_GetString(objv[1]), &pFile) ){ return TCL_ERROR; } rc = sqlite3OsClose(&pFile); if( rc!=SQLITE_OK ){ - Tcl_SetResult(interp, (char *)errorName(rc), TCL_STATIC); + Tcl_SetResult(interp, (char *)t1ErrorName(rc), TCL_STATIC); return TCL_ERROR; } return TCL_OK; } @@ -3312,11 +3320,11 @@ " filehandle (SHARED|RESERVED|PENDING|EXCLUSIVE)", 0); return TCL_ERROR; } if( rc!=SQLITE_OK ){ - Tcl_SetResult(interp, (char *)errorName(rc), TCL_STATIC); + Tcl_SetResult(interp, (char *)t1ErrorName(rc), TCL_STATIC); return TCL_ERROR; } return TCL_OK; } @@ -3341,11 +3349,11 @@ if( getFilePointer(interp, Tcl_GetString(objv[1]), &pFile) ){ return TCL_ERROR; } rc = sqlite3OsUnlock(pFile, NO_LOCK); if( rc!=SQLITE_OK ){ - Tcl_SetResult(interp, (char *)errorName(rc), TCL_STATIC); + Tcl_SetResult(interp, (char *)t1ErrorName(rc), TCL_STATIC); return TCL_ERROR; } return TCL_OK; } @@ -3361,11 +3369,11 @@ char zFile[SQLITE_TEMPNAME_SIZE]; int rc; rc = sqlite3OsTempFileName(zFile); if( rc!=SQLITE_OK ){ - Tcl_SetResult(interp, (char *)errorName(rc), TCL_STATIC); + Tcl_SetResult(interp, (char *)t1ErrorName(rc), TCL_STATIC); return TCL_ERROR; } Tcl_AppendResult(interp, zFile, 0); return TCL_OK; } @@ -3490,11 +3498,11 @@ " DB function-name", 0); return TCL_ERROR; } if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR; rc = sqlite3_create_function(db, argv[2], -1, SQLITE_UTF8, 0, 0, 0, 0); - Tcl_SetResult(interp, (char *)errorName(rc), TCL_STATIC); + Tcl_SetResult(interp, (char *)t1ErrorName(rc), TCL_STATIC); return TCL_OK; } /* ** Usage: sqlite_delete_collation DB collation-name @@ -3516,11 +3524,11 @@ " DB function-name", 0); return TCL_ERROR; } if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR; rc = sqlite3_create_collation(db, argv[2], SQLITE_UTF8, 0, 0); - Tcl_SetResult(interp, (char *)errorName(rc), TCL_STATIC); + Tcl_SetResult(interp, (char *)t1ErrorName(rc), TCL_STATIC); return TCL_OK; } /* ** Usage: sqlite3_get_autocommit DB @@ -4218,11 +4226,11 @@ extern int sqlite3_os_trace; extern int sqlite3_where_trace; extern int sqlite3_sync_count, sqlite3_fullsync_count; extern int sqlite3_opentemp_count; extern int sqlite3_memUsed; - extern int sqlite3_malloc_id; + extern char *sqlite3_malloc_id; extern int sqlite3_memMax; extern int sqlite3_like_count; extern int sqlite3_tsd_count; extern int sqlite3_xferopt_count; #if OS_UNIX && defined(SQLITE_TEST) && defined(THREADSAFE) && THREADSAFE Index: src/test3.c ================================================================== --- src/test3.c +++ src/test3.c @@ -11,11 +11,11 @@ ************************************************************************* ** Code for testing the btree.c module in SQLite. This code ** is not included in the SQLite library. It is used for automated ** testing of the SQLite library. ** -** $Id: test3.c,v 1.71 2007/03/19 17:44:28 danielk1977 Exp $ +** $Id: test3.c,v 1.72 2007/03/26 22:05:02 drh Exp $ */ #include "sqliteInt.h" #include "pager.h" #include "btree.h" #include "tcl.h" @@ -1227,11 +1227,11 @@ } /* ** Copied from btree.c: */ -static u32 get4byte(unsigned char *p){ +static u32 t4Get4byte(unsigned char *p){ return (p[0]<<24) | (p[1]<<16) | (p[2]<<8) | p[3]; } /* ** btree_ovfl_info BTREE CURSOR @@ -1289,11 +1289,11 @@ Tcl_DStringFree(&str); Tcl_AppendResult(interp, "unable to get page ", zElem, 0); return TCL_ERROR; } pPage = sqlite3PagerGetData(pDbPage); - pgno = get4byte((unsigned char*)pPage); + pgno = t4Get4byte((unsigned char*)pPage); sqlite3PagerUnref(pDbPage); } Tcl_DStringResult(interp, &str); return SQLITE_OK; } Index: src/test_async.c ================================================================== --- src/test_async.c +++ src/test_async.c @@ -104,11 +104,11 @@ typedef struct AsyncWrite AsyncWrite; typedef struct AsyncFile AsyncFile; /* Enable for debugging */ static int sqlite3async_trace = 0; -# define TRACE(X) if( sqlite3async_trace ) asyncTrace X +# define ASYNC_TRACE(X) if( sqlite3async_trace ) asyncTrace X static void asyncTrace(const char *zFormat, ...){ char *z; va_list ap; va_start(ap, zFormat); z = sqlite3_vmprintf(zFormat, ap); @@ -362,11 +362,11 @@ async.pQueueLast->pNext = pWrite; }else{ async.pQueueFirst = pWrite; } async.pQueueLast = pWrite; - TRACE(("PUSH %p (%s %s %d)\n", pWrite, azOpcodeName[pWrite->op], + ASYNC_TRACE(("PUSH %p (%s %s %d)\n", pWrite, azOpcodeName[pWrite->op], pWrite->pFile ? pWrite->pFile->zName : "-", pWrite->iOffset)); if( pWrite->op==ASYNC_CLOSE ){ async.nFile--; if( async.nFile==0 ){ @@ -518,11 +518,11 @@ goto asyncread_out; } nRead = MIN(filesize - pFile->iOffset, amt); if( nRead>0 ){ rc = sqlite3OsRead(pBase, obuf, nRead); - TRACE(("READ %s %d bytes at %d\n", pFile->zName, nRead, pFile->iOffset)); + ASYNC_TRACE(("READ %s %d bytes at %d\n", pFile->zName, nRead, pFile->iOffset)); } } if( rc==SQLITE_OK ){ AsyncWrite *p; @@ -538,11 +538,11 @@ if( iBeginOut<0 ) iBeginOut = 0; nCopy = MIN(p->nByte-iBeginIn, amt-iBeginOut); if( nCopy>0 ){ memcpy(&((char *)obuf)[iBeginOut], &p->zBuf[iBeginIn], nCopy); - TRACE(("OVERREAD %d bytes at %d\n", nCopy, iBeginOut+iOffset)); + ASYNC_TRACE(("OVERREAD %d bytes at %d\n", nCopy, iBeginOut+iOffset)); } } } pFile->iOffset += (i64)amt; @@ -624,11 +624,11 @@ ** cannot see our internal hash table (obviously) and will thus not ** honor our locks. */ static int asyncLock(OsFile *id, int lockType){ AsyncFile *pFile = (AsyncFile*)id; - TRACE(("LOCK %d (%s)\n", lockType, pFile->zName)); + ASYNC_TRACE(("LOCK %d (%s)\n", lockType, pFile->zName)); pthread_mutex_lock(&async.lockMutex); sqlite3HashInsert(&async.aLock, pFile->zName, pFile->nName, (void*)lockType); pthread_mutex_unlock(&async.lockMutex); return SQLITE_OK; } @@ -644,11 +644,11 @@ AsyncFile *pFile = (AsyncFile*)id; int rc; pthread_mutex_lock(&async.lockMutex); rc = (int)sqlite3HashFind(&async.aLock, pFile->zName, pFile->nName); pthread_mutex_unlock(&async.lockMutex); - TRACE(("CHECK-LOCK %d (%s)\n", rc, pFile->zName)); + ASYNC_TRACE(("CHECK-LOCK %d (%s)\n", rc, pFile->zName)); return rc>SHARED_LOCK; } static int asyncSectorSize(OsFile *id){ /* TODO: This is tricky to implement, as this backend might not have @@ -824,11 +824,11 @@ }else if( p->op==ASYNC_OPENEXCLUSIVE && 0==strcmp(p->zBuf, z) ){ ret = 1; } } - TRACE(("EXISTS: %s = %d\n", z, ret)); + ASYNC_TRACE(("EXISTS: %s = %d\n", z, ret)); pthread_mutex_unlock(&async.queueMutex); return ret; } /* @@ -914,13 +914,13 @@ pthread_cond_broadcast(&async.emptySignal); if( async.writerHaltWhenIdle ){ pthread_mutex_unlock(&async.queueMutex); break; }else{ - TRACE(("IDLE\n")); + ASYNC_TRACE(("IDLE\n")); pthread_cond_wait(&async.queueSignal, &async.queueMutex); - TRACE(("WAKEUP\n")); + ASYNC_TRACE(("WAKEUP\n")); } } if( p==0 ) break; holdingMutex = 1; @@ -965,64 +965,64 @@ case ASYNC_NOOP: break; case ASYNC_WRITE: assert( pBase ); - TRACE(("WRITE %s %d bytes at %d\n", + ASYNC_TRACE(("WRITE %s %d bytes at %d\n", p->pFile->zName, p->nByte, p->iOffset)); rc = sqlite3OsSeek(pBase, p->iOffset); if( rc==SQLITE_OK ){ rc = sqlite3OsWrite(pBase, (const void *)(p->zBuf), p->nByte); } break; case ASYNC_SYNC: assert( pBase ); - TRACE(("SYNC %s\n", p->pFile->zName)); + ASYNC_TRACE(("SYNC %s\n", p->pFile->zName)); rc = sqlite3OsSync(pBase, p->nByte); break; case ASYNC_TRUNCATE: assert( pBase ); - TRACE(("TRUNCATE %s to %d bytes\n", p->pFile->zName, p->iOffset)); + ASYNC_TRACE(("TRUNCATE %s to %d bytes\n", p->pFile->zName, p->iOffset)); rc = sqlite3OsTruncate(pBase, p->iOffset); break; case ASYNC_CLOSE: - TRACE(("CLOSE %s\n", p->pFile->zName)); + ASYNC_TRACE(("CLOSE %s\n", p->pFile->zName)); sqlite3OsClose(&p->pFile->pBaseWrite); sqlite3OsClose(&p->pFile->pBaseRead); sqlite3OsFree(p->pFile); break; case ASYNC_OPENDIRECTORY: assert( pBase ); - TRACE(("OPENDIR %s\n", p->zBuf)); + ASYNC_TRACE(("OPENDIR %s\n", p->zBuf)); sqlite3OsOpenDirectory(pBase, p->zBuf); break; case ASYNC_SETFULLSYNC: assert( pBase ); - TRACE(("SETFULLSYNC %s %d\n", p->pFile->zName, p->nByte)); + ASYNC_TRACE(("SETFULLSYNC %s %d\n", p->pFile->zName, p->nByte)); sqlite3OsSetFullSync(pBase, p->nByte); break; case ASYNC_DELETE: - TRACE(("DELETE %s\n", p->zBuf)); + ASYNC_TRACE(("DELETE %s\n", p->zBuf)); rc = xOrigDelete(p->zBuf); break; case ASYNC_SYNCDIRECTORY: - TRACE(("SYNCDIR %s\n", p->zBuf)); + ASYNC_TRACE(("SYNCDIR %s\n", p->zBuf)); rc = xOrigSyncDirectory(p->zBuf); break; case ASYNC_OPENEXCLUSIVE: { AsyncFile *pFile = p->pFile; int delFlag = ((p->iOffset)?1:0); OsFile *pBase = 0; - TRACE(("OPEN %s delFlag=%d\n", p->zBuf, delFlag)); + ASYNC_TRACE(("OPEN %s delFlag=%d\n", p->zBuf, delFlag)); assert(pFile->pBaseRead==0 && pFile->pBaseWrite==0); rc = xOrigOpenExclusive(p->zBuf, &pBase, delFlag); assert( holdingMutex==0 ); pthread_mutex_lock(&async.queueMutex); holdingMutex = 1; @@ -1041,11 +1041,11 @@ */ if( !holdingMutex ){ pthread_mutex_lock(&async.queueMutex); holdingMutex = 1; } - /* TRACE(("UNLINK %p\n", p)); */ + /* ASYNC_TRACE(("UNLINK %p\n", p)); */ if( p==async.pQueueLast ){ async.pQueueLast = 0; } async.pQueueFirst = p->pNext; sqlite3OsFree(p); @@ -1234,18 +1234,18 @@ while( cnt-- && !pthread_mutex_trylock(&async.writerMutex) ){ pthread_mutex_unlock(&async.writerMutex); sched_yield(); } if( cnt>=0 ){ - TRACE(("WAIT\n")); + ASYNC_TRACE(("WAIT\n")); pthread_mutex_lock(&async.queueMutex); pthread_cond_broadcast(&async.queueSignal); pthread_mutex_unlock(&async.queueMutex); pthread_mutex_lock(&async.writerMutex); pthread_mutex_unlock(&async.writerMutex); }else{ - TRACE(("NO-WAIT\n")); + ASYNC_TRACE(("NO-WAIT\n")); } return TCL_OK; } Index: src/util.c ================================================================== --- src/util.c +++ src/util.c @@ -12,11 +12,11 @@ ** Utility functions used throughout sqlite. ** ** This file contains functions for allocating memory, comparing ** strings, and stuff like that. ** -** $Id: util.c,v 1.195 2007/03/19 17:44:28 danielk1977 Exp $ +** $Id: util.c,v 1.196 2007/03/26 22:05:02 drh Exp $ */ #include "sqliteInt.h" #include "os.h" #include #include @@ -659,16 +659,17 @@ if( p ){ memset(p, 0, n); } return p; } -void sqlite3ReallocOrFree(void **pp, int n){ - void *p = sqlite3Realloc(*pp, n); +void sqlite3ReallocOrFree(void *pp, int n){ + char **x = (char**)pp; + void *p = sqlite3Realloc(*x, n); if( !p ){ - sqlite3FreeX(*pp); + sqlite3FreeX(*x); } - *pp = p; + *x = p; } /* ** sqlite3ThreadSafeMalloc() and sqlite3ThreadSafeFree() are used in those ** rare scenarios where sqlite may allocate memory in one thread and free @@ -1382,15 +1383,15 @@ while( *z ){ v = (v<<4) + hexToInt(*z); z++; } if( sizeof(p)==sizeof(v) ){ - p = *(void**)&v; + memcpy(&p, &v, sizeof(p)); }else{ assert( sizeof(p)==sizeof(v2) ); v2 = (u32)v; - p = *(void**)&v2; + memcpy(&p, &v2, sizeof(p)); } return p; } #endif Index: src/vdbe.c ================================================================== --- src/vdbe.c +++ src/vdbe.c @@ -41,11 +41,11 @@ ** documentation, headers files, or other derived files. The formatting ** of the code in this file is, therefore, important. See other comments ** 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.591 2007/03/15 12:05:36 danielk1977 Exp $ +** $Id: vdbe.c,v 1.592 2007/03/26 22:05:02 drh Exp $ */ #include "sqliteInt.h" #include "os.h" #include #include "vdbeInt.h" @@ -4234,11 +4234,11 @@ assert( i>=0 ); /* FIX ME: This should be allocated as part of the vdbe at compile-time */ if( i>=p->contextStackDepth ){ p->contextStackDepth = i+1; - sqliteReallocOrFree((void**)&p->contextStack, sizeof(Context)*(i+1)); + sqliteReallocOrFree(&p->contextStack, sizeof(Context)*(i+1)); if( p->contextStack==0 ) goto no_mem; } pContext = &p->contextStack[i]; pContext->lastRowid = db->lastRowid; pContext->nChange = p->nChange; Index: src/vdbeInt.h ================================================================== --- src/vdbeInt.h +++ src/vdbeInt.h @@ -29,11 +29,11 @@ ** The makefile scans the vdbe.c source file and creates the following ** array of string constants which are the names of all VDBE opcodes. This ** array is defined in a separate source code file named opcode.c which is ** automatically generated by the makefile. */ -extern char *sqlite3OpcodeNames[]; +extern const char *const sqlite3OpcodeNames[]; /* ** SQL is translated into a sequence of instructions to be ** executed by a virtual machine. Each instruction is an instance ** of the following structure. @@ -123,11 +123,14 @@ ** in a Mem struct is returned by the MemType(Mem*) macro. The type is ** one of SQLITE_NULL, SQLITE_INTEGER, SQLITE_REAL, SQLITE_TEXT or ** SQLITE_BLOB. */ struct Mem { - i64 i; /* Integer value. Or FuncDef* when flags==MEM_Agg */ + union { + i64 i; /* Integer value. Or FuncDef* when flags==MEM_Agg */ + FuncDef *pDef; + }; double r; /* Real value */ char *z; /* String or BLOB value */ int n; /* Number of characters in string value, including '\0' */ u16 flags; /* Some combination of MEM_Null, MEM_Str, MEM_Dyn, etc. */ u8 type; /* One of MEM_Null, MEM_Str, etc. */ Index: src/vdbeapi.c ================================================================== --- src/vdbeapi.c +++ src/vdbeapi.c @@ -339,11 +339,11 @@ assert( pMem->flags==MEM_Null ); pMem->z = 0; }else{ pMem->flags = MEM_Agg; pMem->xDel = sqlite3FreeX; - *(FuncDef**)&pMem->i = p->pFunc; + pMem->pDef = p->pFunc; if( nByte<=NBFS ){ pMem->z = pMem->zShort; memset(pMem->z, 0, nByte); }else{ pMem->z = sqliteMalloc( nByte ); @@ -441,11 +441,11 @@ */ static Mem *columnMem(sqlite3_stmt *pStmt, int i){ Vdbe *pVm = (Vdbe *)pStmt; int vals = sqlite3_data_count(pStmt); if( i>=vals || i<0 ){ - static const Mem nullMem = {0, 0.0, "", 0, MEM_Null, MEM_Null }; + static const Mem nullMem = {{0,}, 0.0, "", 0, MEM_Null, MEM_Null }; sqlite3Error(pVm->db, SQLITE_RANGE, 0); return (Mem*)&nullMem; } return &pVm->pTos[(1-vals)+i]; } Index: src/vdbeaux.c ================================================================== --- src/vdbeaux.c +++ src/vdbeaux.c @@ -193,12 +193,11 @@ int i; i = p->nLabel++; assert( p->magic==VDBE_MAGIC_INIT ); if( i>=p->nLabelAlloc ){ p->nLabelAlloc = p->nLabelAlloc*2 + 10; - sqliteReallocOrFree((void**)&p->aLabel, - p->nLabelAlloc*sizeof(p->aLabel[0])); + sqliteReallocOrFree(&p->aLabel, p->nLabelAlloc*sizeof(p->aLabel[0])); } if( p->aLabel ){ p->aLabel[i] = -1; } return -1-i; @@ -721,11 +720,11 @@ pMem->type = SQLITE_INTEGER; pMem->i = i; /* Program counter */ pMem++; pMem->flags = MEM_Static|MEM_Str|MEM_Term; - pMem->z = sqlite3OpcodeNames[pOp->opcode]; /* Opcode */ + pMem->z = (char*)sqlite3OpcodeNames[pOp->opcode]; /* Opcode */ assert( pMem->z!=0 ); pMem->n = strlen(pMem->z); pMem->type = SQLITE_TEXT; pMem->enc = SQLITE_UTF8; pMem++; @@ -1783,13 +1782,14 @@ /* Integer and Real */ if( serial_type<=7 && serial_type>0 ){ u64 v; int i; if( serial_type==7 ){ - v = *(u64*)&pMem->r; + assert( sizeof(v)==sizeof(pMem->r) ); + memcpy(&v, &pMem->r, sizeof(v)); }else{ - v = *(u64*)&pMem->i; + v = pMem->i; } len = i = sqlite3VdbeSerialTypeLen(serial_type); while( i-- ){ buf[i] = (v&0xFF); v >>= 8; @@ -1859,21 +1859,24 @@ #if !defined(NDEBUG) && !defined(SQLITE_OMIT_FLOATING_POINT) /* Verify that integers and floating point values use the same ** byte order. The byte order differs on some (broken) architectures. */ static const u64 t1 = ((u64)0x3ff00000)<<32; - assert( 1.0==*(double*)&t1 ); + static const double r1 = 1.0; + assert( sizeof(r1)==sizeof(t1) && memcmp(&r1, &t1, sizeof(r1))==0 ); #endif x = (buf[0]<<24) | (buf[1]<<16) | (buf[2]<<8) | buf[3]; y = (buf[4]<<24) | (buf[5]<<16) | (buf[6]<<8) | buf[7]; x = (x<<32) | y; if( serial_type==6 ){ pMem->i = *(i64*)&x; pMem->flags = MEM_Int; }else{ - pMem->r = *(double*)&x; + assert( sizeof(x)==8 && sizeof(pMem->r)==8 ); + memcpy(&pMem->r, &x, sizeof(x)); + /* pMem->r = *(double*)&x; */ pMem->flags = MEM_Real; } return 8; } case 8: /* Integer 0 */ Index: src/vdbefifo.c ================================================================== --- src/vdbefifo.c +++ src/vdbefifo.c @@ -17,11 +17,11 @@ /* ** Allocate a new FifoPage and return a pointer to it. Return NULL if ** we run out of memory. Leave space on the page for nEntry entries. */ -static FifoPage *allocatePage(int nEntry){ +static FifoPage *allocateFifoPage(int nEntry){ FifoPage *pPage; if( nEntry>32767 ){ nEntry = 32767; } pPage = sqliteMallocRaw( sizeof(FifoPage) + sizeof(i64)*(nEntry-1) ); @@ -48,16 +48,16 @@ */ int sqlite3VdbeFifoPush(Fifo *pFifo, i64 val){ FifoPage *pPage; pPage = pFifo->pLast; if( pPage==0 ){ - pPage = pFifo->pLast = pFifo->pFirst = allocatePage(20); + pPage = pFifo->pLast = pFifo->pFirst = allocateFifoPage(20); if( pPage==0 ){ return SQLITE_NOMEM; } }else if( pPage->iWrite>=pPage->nSlot ){ - pPage->pNext = allocatePage(pFifo->nEntry); + pPage->pNext = allocateFifoPage(pFifo->nEntry); if( pPage->pNext==0 ){ return SQLITE_NOMEM; } pPage = pFifo->pLast = pPage->pNext; } Index: src/vdbemem.c ================================================================== --- src/vdbemem.c +++ src/vdbemem.c @@ -193,11 +193,11 @@ */ int sqlite3VdbeMemFinalize(Mem *pMem, FuncDef *pFunc){ int rc = SQLITE_OK; if( pFunc && pFunc->xFinalize ){ sqlite3_context ctx; - assert( (pMem->flags & MEM_Null)!=0 || pFunc==*(FuncDef**)&pMem->i ); + assert( (pMem->flags & MEM_Null)!=0 || pFunc==pMem->pDef ); ctx.s.flags = MEM_Null; ctx.s.z = pMem->zShort; ctx.pMem = pMem; ctx.pFunc = pFunc; ctx.isError = 0; @@ -223,11 +223,11 @@ */ void sqlite3VdbeMemRelease(Mem *p){ if( p->flags & (MEM_Dyn|MEM_Agg) ){ if( p->xDel ){ if( p->flags & MEM_Agg ){ - sqlite3VdbeMemFinalize(p, *(FuncDef**)&p->i); + sqlite3VdbeMemFinalize(p, p->pDef); assert( (p->flags & MEM_Agg)==0 ); sqlite3VdbeMemRelease(p); }else{ p->xDel((void *)p->z); } Index: src/where.c ================================================================== --- src/where.c +++ src/where.c @@ -14,11 +14,11 @@ ** generating the code that loops through a table looking for applicable ** rows. Indices are selected and used to speed the search when doing ** 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.239 2007/03/02 08:12:22 danielk1977 Exp $ +** $Id: where.c,v 1.240 2007/03/26 22:05:02 drh Exp $ */ #include "sqliteInt.h" /* ** The number of bits in a Bitmask. "BMS" means "BitMask Size". @@ -33,13 +33,13 @@ /* ** Trace output macros */ #if defined(SQLITE_TEST) || defined(SQLITE_DEBUG) int sqlite3_where_trace = 0; -# define TRACE(X) if(sqlite3_where_trace) sqlite3DebugPrintf X +# define WHERETRACE(X) if(sqlite3_where_trace) sqlite3DebugPrintf X #else -# define TRACE(X) +# define WHERETRACE(X) #endif /* Forward reference */ typedef struct WhereClause WhereClause; @@ -1207,11 +1207,11 @@ */ pIdxInfo = *ppIdxInfo; if( pIdxInfo==0 ){ WhereTerm *pTerm; int nTerm; - TRACE(("Recomputing index info for %s...\n", pTab->zName)); + WHERETRACE(("Recomputing index info for %s...\n", pTab->zName)); /* Count the number of possible WHERE clause constraints referring ** to this virtual table */ for(i=nTerm=0, pTerm=pWC->a; inTerm; i++, pTerm++){ if( pTerm->leftCursor != pSrc->iCursor ) continue; @@ -1340,11 +1340,11 @@ if( pIdxInfo->nOrderBy && !orderByUsable ){ *(int*)&pIdxInfo->nOrderBy = 0; } sqlite3SafetyOff(pParse->db); - TRACE(("xBestIndex for %s\n", pTab->zName)); + WHERETRACE(("xBestIndex for %s\n", pTab->zName)); TRACE_IDX_INPUTS(pIdxInfo); rc = pTab->pVtab->pModule->xBestIndex(pTab->pVtab, pIdxInfo); TRACE_IDX_OUTPUTS(pIdxInfo); if( rc!=SQLITE_OK ){ if( rc==SQLITE_NOMEM ){ @@ -1401,11 +1401,11 @@ int flags; /* Flags associated with pProbe */ int nEq; /* Number of == or IN constraints */ int eqTermMask; /* Mask of valid equality operators */ double cost; /* Cost of using pProbe */ - TRACE(("bestIndex: tbl=%s notReady=%x\n", pSrc->pTab->zName, notReady)); + WHERETRACE(("bestIndex: tbl=%s notReady=%x\n", pSrc->pTab->zName, notReady)); lowestCost = SQLITE_BIG_DBL; pProbe = pSrc->pTab->pIndex; /* If the table has no indices and there are no terms in the where ** clause that refer to the ROWID, then we will never be able to do @@ -1432,11 +1432,11 @@ if( pTerm->eOperator & WO_EQ ){ /* Rowid== is always the best pick. Look no further. Because only ** a single row is generated, output is always in sorted order */ *pFlags = WHERE_ROWID_EQ | WHERE_UNIQUE; *pnEq = 1; - TRACE(("... best is rowid\n")); + WHERETRACE(("... best is rowid\n")); return 0.0; }else if( (pExpr = pTerm->pExpr)->pList!=0 ){ /* Rowid IN (LIST): cost is NlogN where N is the number of list ** elements. */ lowestCost = pExpr->pList->nExpr; @@ -1445,18 +1445,18 @@ /* Rowid IN (SELECT): cost is NlogN where N is the number of rows ** in the result of the inner select. We have no way to estimate ** that value so make a wild guess. */ lowestCost = 200; } - TRACE(("... rowid IN cost: %.9g\n", lowestCost)); + WHERETRACE(("... rowid IN cost: %.9g\n", lowestCost)); } /* Estimate the cost of a table scan. If we do not know how many ** entries are in the table, use 1 million as a guess. */ cost = pProbe ? pProbe->aiRowEst[0] : 1000000; - TRACE(("... table scan base cost: %.9g\n", cost)); + WHERETRACE(("... table scan base cost: %.9g\n", cost)); flags = WHERE_ROWID_RANGE; /* Check for constraints on a range of rowids in a table scan. */ pTerm = findTerm(pWC, iCur, -1, notReady, WO_LT|WO_LE|WO_GT|WO_GE, 0); @@ -1467,11 +1467,11 @@ } if( findTerm(pWC, iCur, -1, notReady, WO_GT|WO_GE, 0) ){ flags |= WHERE_BTM_LIMIT; cost /= 3; /* Guess that rowid>EXPR eliminates two-thirds of rows */ } - TRACE(("... rowid range reduces cost to %.9g\n", cost)); + WHERETRACE(("... rowid range reduces cost to %.9g\n", cost)); }else{ flags = 0; } /* If the table scan does not satisfy the ORDER BY clause, increase @@ -1482,11 +1482,11 @@ if( rev ){ flags |= WHERE_REVERSE; } }else{ cost += cost*estLog(cost); - TRACE(("... sorting increases cost to %.9g\n", cost)); + WHERETRACE(("... sorting increases cost to %.9g\n", cost)); } } if( costpNext){ int i; /* Loop counter */ double inMultiplier = 1; - TRACE(("... index %s:\n", pProbe->zName)); + WHERETRACE(("... index %s:\n", pProbe->zName)); /* Count the number of columns in the index that are satisfied ** by x=EXPR constraints or x IN (...) constraints. */ flags = 0; @@ -1534,11 +1534,11 @@ nEq = i; if( pProbe->onError!=OE_None && (flags & WHERE_COLUMN_IN)==0 && nEq==pProbe->nColumn ){ flags |= WHERE_UNIQUE; } - TRACE(("...... nEq=%d inMult=%.9g cost=%.9g\n", nEq, inMultiplier, cost)); + WHERETRACE(("...... nEq=%d inMult=%.9g cost=%.9g\n", nEq, inMultiplier, cost)); /* Look for range constraints */ if( nEqnColumn ){ int j = pProbe->aiColumn[nEq]; @@ -1551,11 +1551,11 @@ } if( findTerm(pWC, iCur, j, notReady, WO_GT|WO_GE, pProbe) ){ flags |= WHERE_BTM_LIMIT; cost /= 3; } - TRACE(("...... range reduces cost to %.9g\n", cost)); + WHERETRACE(("...... range reduces cost to %.9g\n", cost)); } } /* Add the additional cost of sorting if that is a factor. */ @@ -1569,11 +1569,11 @@ if( rev ){ flags |= WHERE_REVERSE; } }else{ cost += cost*estLog(cost); - TRACE(("...... orderby increases cost to %.9g\n", cost)); + WHERETRACE(("...... orderby increases cost to %.9g\n", cost)); } } /* Check to see if we can get away with using just the index without ** ever reading the table. If that is the case, then halve the @@ -1589,11 +1589,11 @@ } } if( m==0 ){ flags |= WHERE_IDX_ONLY; cost /= 2; - TRACE(("...... idx-only reduces cost to %.9g\n", cost)); + WHERETRACE(("...... idx-only reduces cost to %.9g\n", cost)); } } /* If this index has achieved the lowest cost so far, then use it. */ @@ -1607,11 +1607,11 @@ } /* Report the best result */ *ppIndex = bestIdx; - TRACE(("best index is %s, cost=%.9g, flags=%x, nEq=%d\n", + WHERETRACE(("best index is %s, cost=%.9g, flags=%x, nEq=%d\n", bestIdx ? bestIdx->zName : "(none)", lowestCost, bestFlags, bestNEq)); *pFlags = bestFlags | eqTermMask; *pnEq = bestNEq; return lowestCost; } @@ -1705,12 +1705,12 @@ sqlite3CodeSubselect(pParse, pX); iTab = pX->iTable; sqlite3VdbeAddOp(v, OP_Rewind, iTab, 0); VdbeComment((v, "# %.*s", pX->span.n, pX->span.z)); pLevel->nIn++; - sqliteReallocOrFree((void**)&pLevel->aInLoop, - sizeof(pLevel->aInLoop[0])*2*pLevel->nIn); + sqliteReallocOrFree(&pLevel->aInLoop, + sizeof(pLevel->aInLoop[0])*2*pLevel->nIn); aIn = pLevel->aInLoop; if( aIn ){ aIn += pLevel->nIn*2 - 2; aIn[0] = iTab; aIn[1] = sqlite3VdbeAddOp(v, OP_Column, iTab, 0); @@ -2001,11 +2001,11 @@ */ notReady = ~(Bitmask)0; pTabItem = pTabList->a; pLevel = pWInfo->a; andFlags = ~0; - TRACE(("*** Optimizer Start ***\n")); + WHERETRACE(("*** Optimizer Start ***\n")); for(i=iFrom=0, pLevel=pWInfo->a; inSrc; i++, pLevel++){ Index *pIdx; /* Index for FROM table at pTabItem */ int flags; /* Flags asssociated with pIdx */ int nEq; /* Number of == or IN constraints */ double cost; /* The cost for pIdx */ @@ -2069,11 +2069,11 @@ bestJ = j; pLevel->pBestIdx = pIndex; } if( doNotReorder ) break; } - TRACE(("*** Optimizer choose table %d for loop %d\n", bestJ, + WHERETRACE(("*** Optimizer choose table %d for loop %d\n", bestJ, pLevel-pWInfo->a)); if( (bestFlags & WHERE_ORDERBY)!=0 ){ *ppOrderBy = 0; } andFlags &= bestFlags; @@ -2088,11 +2088,11 @@ pLevel->iIdxCur = -1; } notReady &= ~getMask(&maskSet, pTabList->a[bestJ].iCursor); pLevel->iFrom = bestJ; } - TRACE(("*** Optimizer Finished ***\n")); + WHERETRACE(("*** Optimizer Finished ***\n")); /* If the total query only selects a single row, then the ORDER BY ** clause is irrelevant. */ if( (andFlags & WHERE_UNIQUE)!=0 && ppOrderBy ){