diff --git a/ext/fts3/fts3_icu.c b/ext/fts3/fts3_icu.c index e2d040ca2a..85390d3b06 100644 --- a/ext/fts3/fts3_icu.c +++ b/ext/fts3/fts3_icu.c @@ -11,7 +11,7 @@ ************************************************************************* ** This file implements a tokenizer for fts3 based on the ICU library. ** -** $Id: fts3_icu.c,v 1.2 2007/10/24 21:52:37 shess Exp $ +** $Id: fts3_icu.c,v 1.3 2008/09/01 18:34:20 danielk1977 Exp $ */ #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) @@ -112,7 +112,9 @@ static int icuOpen( *ppCursor = 0; - if( -1 == nInput ) nInput = strlen(nInput); + if( nInput<0 ){ + nInput = strlen(zInput); + } nChar = nInput+1; pCsr = (IcuCursor *)sqlite3_malloc( sizeof(IcuCursor) + /* IcuCursor */ diff --git a/main.mk b/main.mk index ec8b0ed49a..55cc7beaa4 100644 --- a/main.mk +++ b/main.mk @@ -224,6 +224,7 @@ TESTSRC = \ $(TOP)/src/test_server.c \ $(TOP)/src/test_tclvar.c \ $(TOP)/src/test_thread.c \ + $(TOP)/src/test_wsd.c \ #TESTSRC += $(TOP)/ext/fts2/fts2_tokenizer.c #TESTSRC += $(TOP)/ext/fts3/fts3_tokenizer.c diff --git a/manifest b/manifest index 0f9732d7dd..0df92af317 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Remove\san\sunused\sfunction\sdeclaration\sfrom\sa\sheader\sfile.\s\sTicket\s#3349.\s(CVS\s5651) -D 2008-09-01T17:23:29 +C Begin\sadding\ssupport\sfor\sthe\sSQLITE_OMIT_WSD\smacro.\sSome\s(many)\sWSD\svariables\sstill\sneed\swrappers\sadded\sto\sthem.\s(CVS\s5652) +D 2008-09-01T18:34:20 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0 F Makefile.in 689e14735f862a5553bceef206d8c13e29504e44 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 @@ -55,7 +55,7 @@ F ext/fts3/fts3.c fa37048c369491ba6fb74e1732f24a8a8daaef65 F ext/fts3/fts3.h 3a10a0af180d502cecc50df77b1b22df142817fe F ext/fts3/fts3_hash.c 83e7bb4042106b32811681dd2859b4577a7a6b35 F ext/fts3/fts3_hash.h 004b759e1602ff16dfa02fea3ca1c77336ad6798 -F ext/fts3/fts3_icu.c e676f8f0c472cfbb3194febf0eadc1cea6ff0d0c +F ext/fts3/fts3_icu.c ac494aed69835008185299315403044664bda295 F ext/fts3/fts3_porter.c 3063da945fb0a935781c135f7575f39166173eca F ext/fts3/fts3_tokenizer.c fcc8fdb5c161df7d61c77285ec2991da131f0181 F ext/fts3/fts3_tokenizer.h 7eb79de4f991a77f43c517e209e5fae95dfa7369 @@ -77,7 +77,7 @@ F ext/rtree/rtree_util.tcl ee0a0311eb12175319d78bfb37302320496cee6e F ext/rtree/viewrtree.tcl 09526398dae87a5a87c5aac2b3854dbaf8376869 F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 F ltmain.sh 09fe5815427dc7d0abb188bbcdf0e34896577210 -F main.mk 5ce1477b7fdc00f5c981f06e5708255dc217902c +F main.mk 256259ff346a85fa98ad67848faae2b3ed817d57 F mkdll.sh 79d1ed6ae221c10589dd969f130f8a3cccfffbb7 F mkextu.sh 416f9b7089d80e5590a29692c9d9280a10dbad9f F mkextw.sh 4123480947681d9b434a5e7b1ee08135abe409ac @@ -97,18 +97,18 @@ F src/attach.c db3f4a60538733c1e4dcb9d0217a6e0d6ccd615b F src/auth.c c8b2ab5c8bad4bd90ed7c294694f48269162c627 F src/bitvec.c 95c86bd18d8fedf0533f5af196192546e10a7e7d F src/btmutex.c 709cad2cdca0afd013f0f612363810e53f59ec53 -F src/btree.c 9b98b0d2e2273998b13a74856d5c62971b35449c +F src/btree.c deb7e145e4e287763e317ff36a805826f5ed2e56 F src/btree.h 6371c5e599fab391a150c96afbc10062b276d107 F src/btreeInt.h ab18c7b4980314e9e4b402e5dcde09f3c2545576 F src/build.c 160c71acca8f643f436ed6c1ee2f684c88df4dfe -F src/callback.c 27e55dfafc66e97dd8e7343a1d7bb295f3afd736 +F src/callback.c cfc8d4f95fd831e25532d0fee2af5306283f4835 F src/complete.c cb14e06dbe79dee031031f0d9e686ff306afe07c -F src/date.c 2373f20a91bec70e20e0e715520c8010d26ebb52 +F src/date.c 6609557446f2d6788e64e18c09e03fdaf4dd55cc F src/delete.c 434dd6f9d19475b35f2f57041d4bbba9f64da5ac F src/expr.c 6413795aa13ceb05994e6b2b453a77df3b892e7b F src/fault.c 3638519d1e0b82bccfafcb9f5ff491918b28f8e1 -F src/func.c f2e0b55f13e678a5c5ff94f0f225ed0a995acba7 -F src/global.c 239d03b6dbae6c985deb2ffb54ab919debb9f8d7 +F src/func.c 964a610bd68d79764f9e435615d723146f94f0e0 +F src/global.c 9ced7c26127f04fb4baaebed1f5bf6d7063b089f F src/hash.c eb64e48f3781100e5934f759fbe72a63a8fe78cb F src/hash.h 031cd9f915aff27e12262cb9eb570ac1b8326b53 F src/hwtime.h 4a1d45f4cae1f402ea19686acf24acf4f0cb53cb @@ -116,15 +116,15 @@ F src/insert.c 110cca7845ed5a66c08fdd413b02e706ae34455f F src/journal.c cffd2cd214e58c0e99c3ff632b3bee6c7cbb260e F src/legacy.c aac57bd984e666059011ea01ec4383892a253be3 F src/loadext.c eb1fe4f44d7c8ff53fc0c6a4388ab79fbd34cd64 -F src/main.c f372968372bdf4275333327fd04737f667e0f3af -F src/malloc.c 6bd94746cca2ad3afc0020b934848378f27df244 -F src/mem1.c 3a7fe31d8290baa3bb203af72f7dfd6323966bcd -F src/mem2.c 7256327b96927020824e06ffb3443b99a28da047 -F src/mem3.c c73e935d0b900abc51d5fa45f880937b062f4a9f +F src/main.c 47ce9da041a5aa9a1adadd92be795bde887e2dc9 +F src/malloc.c 2ffd62fb4a299cf3945e50a4c53d27ec1813f8b1 +F src/mem1.c 5a529ff121c55ab067be14de00f86f6dcc4f4fb9 +F src/mem2.c f87e681d0d1ed8436870d089332ed0d27d885b5c +F src/mem3.c afb0ace2be6a9134713f399711bacf7d3cdc60c6 F src/mem4.c 6703adb1717b26d9d70a1c2586b4b7b7ffee7909 -F src/mem5.c 0b0ba1c2a02d86eb812dea6debacee841e3856f7 -F src/mem6.c a3932c3d2f6382f077d7c94cf6a6e15e0a8cbd07 -F src/mutex.c a485a0eac8ee2cd95f66e565b4c6696c18db968f +F src/mem5.c 7a8e54fd3ca801c2a3cf9060175c008c55715d8b +F src/mem6.c 637d1e65bfcebb68844981cc80f9da4483428539 +F src/mutex.c 81174f600553c25832e9a8705b609f16c73a4c01 F src/mutex.h e52ffa1dfc6a6077e8b1823d2c2b7dfcbcf85594 F src/mutex_os2.c 9c5637aa4c307c552566d0f0b3bd206245b54a97 F src/mutex_unix.c 29049a61755cccddb2ee53904e6906bb7674223c @@ -138,7 +138,7 @@ F src/os_win.c aefe9ee26430678a19a058a874e4e2bd91398142 F src/pager.c 032d11049af4ec49bdbaa3584e7ce9887098b66a F src/pager.h c45380ca9d0933ea5bc4ecb3a43958b6d2ec5a9c F src/parse.y d0f76d2cb8d6883d5600dc20beb961a6022b94b8 -F src/pcache.c e1cb0e77d2a299cfa4aa95d2e3307cc6900d2007 +F src/pcache.c 200de27e85b123840a30a11f5055544e06845569 F src/pcache.h 53730c33310cdf7a5c94e8333c853d59a3b30226 F src/pragma.c f5b271b090af7fcedd308d7c5807a5503f7a853d F src/prepare.c c197041e0c4770672cda75e6bfe10242f885e510 @@ -147,9 +147,9 @@ F src/random.c 5c754319d38abdd6acd74601ee0105504adc508a F src/resolve.c a6abf83125bce0c80ba04acc27c3565155ad305c F src/select.c eec7c5f28a0c75fdd8500630435af176bba73219 F src/shell.c d83b578a8ccdd3e0e7fef4388a0887ce9f810967 -F src/sqlite.h.in c0e84a2d6e9f3263599174ff7261ba6daf730b4f +F src/sqlite.h.in 0031454ccb163b191daab7f7151d9d68af8b26c9 F src/sqlite3ext.h 1e3887c9bd3ae66cb599e922824b04cd0d0f2c3e -F src/sqliteInt.h 2243b0eadb5dd32de8f0a38571afedb711fa2cc5 +F src/sqliteInt.h 3ea61550f587eb4432373bcf145cd754da342ddc F src/sqliteLimit.h f435e728c6b620ef7312814d660a81f9356eb5c8 F src/status.c 8caa772cd9310bc297280f7cf0ede4d69ed5b801 F src/table.c 22744786199c9195720c15a7a42cb97b2e2728d8 @@ -180,6 +180,7 @@ F src/test_schema.c 4b4bf7bb329326458c491b0e6facd4c8c4c5b479 F src/test_server.c f0a403b5f699c09bd2b1236b6f69830fd6221f6b F src/test_tclvar.c 9e42fa59d3d2f064b7ab8628e7ab2dc8a9fe93d4 F src/test_thread.c d74fc445e0dba0e00806117eb449b307c0b146bf +F src/test_wsd.c 9eadce9ae2910d738018649d5de26a65b5881ce6 F src/tokenize.c aaa5fa6a4536a9dd7c855a3f66f32508f1612138 F src/trigger.c 649940b5bf5838a33721fb72372e7c9d1faf56a9 F src/update.c f2cf6f00d542956bd49ba4b9815c2900d9225bf2 @@ -629,7 +630,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81 F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 1dbced29de5f59ba2ebf877edcadf171540374d1 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e -P d04d70336727a0db959c672e6c22cdaa0505dce5 -R 04f6f8f1d929ad05f0d2d67cc6fb131a -U drh -Z 14bd2f399c6134eded42b5797d53425f +P 7a577428b22918c232815e7998a623dbc47a8d41 +R b45f7764c971fd9d217268e94c98eacf +U danielk1977 +Z a30ccc5ce0944839576c9352eb85797d diff --git a/manifest.uuid b/manifest.uuid index 5dbffe5386..69370d0946 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -7a577428b22918c232815e7998a623dbc47a8d41 \ No newline at end of file +573d92abb9adb1c321ebc2fcadcf14374213b093 \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index e4eff21810..c62312974a 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.504 2008/08/27 15:16:34 danielk1977 Exp $ +** $Id: btree.c,v 1.505 2008/09/01 18:34:20 danielk1977 Exp $ ** ** This file implements a external (disk-based) database using BTrees. ** See the header comment on "btreeInt.h" for additional information. @@ -1340,7 +1340,7 @@ int sqlite3BtreeOpen( sqlite3_mutex *mutexShared; pBt->nRef = 1; mutexShared = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); - if( SQLITE_THREADSAFE && sqlite3Config.bCoreMutex ){ + if( SQLITE_THREADSAFE && sqlite3GlobalConfig.bCoreMutex ){ pBt->mutex = sqlite3MutexAlloc(SQLITE_MUTEX_FAST); if( pBt->mutex==0 ){ rc = SQLITE_NOMEM; diff --git a/src/callback.c b/src/callback.c index 336f9a5591..e891f3321d 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.29 2008/08/21 20:21:35 drh Exp $ +** $Id: callback.c,v 1.30 2008/09/01 18:34:20 danielk1977 Exp $ */ #include "sqliteInt.h" @@ -357,7 +357,8 @@ FuncDef *sqlite3FindFunction( ** function to use. */ if( !createFlag && !pBest ){ - p = functionSearch(&sqlite3GlobalFunctions, h, zName, nName); + FuncDefHash *pHash = &GLOBAL(FuncDefHash, sqlite3GlobalFunctions); + p = functionSearch(pHash, h, zName, nName); while( p ){ int score = matchQuality(p, nArg, enc); if( score>bestScore ){ diff --git a/src/date.c b/src/date.c index 68f33d7b22..53fe4a1e1b 100644 --- a/src/date.c +++ b/src/date.c @@ -16,7 +16,7 @@ ** sqlite3RegisterDateTimeFunctions() found at the bottom of the file. ** All other code has file scope. ** -** $Id: date.c,v 1.88 2008/08/21 20:21:35 drh Exp $ +** $Id: date.c,v 1.89 2008/09/01 18:34:20 danielk1977 Exp $ ** ** SQLite processes all times and dates as Julian Day numbers. The ** dates and times are stored as the number of days since noon @@ -1053,7 +1053,7 @@ static void currentTimeFunc( ** external linkage. */ void sqlite3RegisterDateTimeFunctions(void){ - static FuncDef aDateTimeFuncs[] = { + static SQLITE_WSD FuncDef aDateTimeFuncs[] = { #ifndef SQLITE_OMIT_DATETIME_FUNCS FUNCTION(julianday, -1, 0, 0, juliandayFunc ), FUNCTION(date, -1, 0, 0, dateFunc ), @@ -1070,8 +1070,10 @@ void sqlite3RegisterDateTimeFunctions(void){ #endif }; int i; + FuncDefHash *pHash = &GLOBAL(FuncDefHash, sqlite3GlobalFunctions); + FuncDef *aFunc = &GLOBAL(FuncDef, aDateTimeFuncs); for(i=0; i @@ -1375,7 +1375,8 @@ static FuncDef aBuiltinFunc[] = { void sqlite3RegisterGlobalFunctions(void){ int i; for(i=0; i @@ -85,16 +85,23 @@ char *sqlite3_temp_directory = 0; ** without blocking. */ int sqlite3_initialize(void){ - static int inProgress = 0; /* Prevent recursion */ - sqlite3_mutex *pMaster; /* The main static mutex */ - int rc; /* Result code */ + SQLITE_WSD static int inProgress = 0; /* Prevent recursion */ + sqlite3_mutex *pMaster; /* The main static mutex */ + int rc; /* Result code */ + +#ifdef SQLITE_OMIT_WSD + rc = sqlite3_wsd_init(1024, 256); + if( rc!=SQLITE_OK ){ + return rc; + } +#endif /* If SQLite is already completely initialized, then this call ** to sqlite3_initialize() should be a no-op. But the initialization ** must be complete. So isInit must not be set until the very end ** of this routine. */ - if( sqlite3Config.isInit ) return SQLITE_OK; + if( sqlite3GlobalConfig.isInit ) return SQLITE_OK; /* Make sure the mutex subsystem is initialized. If unable to ** initialize the mutex subsystem, return early with the error. @@ -115,18 +122,18 @@ int sqlite3_initialize(void){ */ pMaster = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); sqlite3_mutex_enter(pMaster); - if( !sqlite3Config.isMallocInit ){ + if( !sqlite3GlobalConfig.isMallocInit ){ rc = sqlite3MallocInit(); } if( rc==SQLITE_OK ){ - sqlite3Config.isMallocInit = 1; - if( !sqlite3Config.pInitMutex ){ - sqlite3Config.pInitMutex = sqlite3MutexAlloc(SQLITE_MUTEX_RECURSIVE); - if( sqlite3Config.bCoreMutex && !sqlite3Config.pInitMutex ){ + sqlite3GlobalConfig.isMallocInit = 1; + if( !sqlite3GlobalConfig.pInitMutex ){ + sqlite3GlobalConfig.pInitMutex = sqlite3MutexAlloc(SQLITE_MUTEX_RECURSIVE); + if( sqlite3GlobalConfig.bCoreMutex && !sqlite3GlobalConfig.pInitMutex ){ rc = SQLITE_NOMEM; } } - sqlite3Config.nRefInitMutex++; + sqlite3GlobalConfig.nRefInitMutex++; } sqlite3_mutex_leave(pMaster); @@ -144,31 +151,32 @@ int sqlite3_initialize(void){ ** sqlite3_os_init() when it invokes sqlite3_vfs_register(), but other ** recursive calls might also be possible. */ - sqlite3_mutex_enter(sqlite3Config.pInitMutex); - if( sqlite3Config.isInit==0 && inProgress==0 ){ - inProgress = 1; - memset(&sqlite3GlobalFunctions, 0, sizeof(sqlite3GlobalFunctions)); + sqlite3_mutex_enter(sqlite3GlobalConfig.pInitMutex); + if( sqlite3GlobalConfig.isInit==0 && GLOBAL(int, inProgress)==0 ){ + FuncDefHash *pHash = &GLOBAL(FuncDefHash, sqlite3GlobalFunctions); + GLOBAL(int, inProgress) = 1; + memset(pHash, 0, sizeof(sqlite3GlobalFunctions)); sqlite3RegisterGlobalFunctions(); rc = sqlite3_os_init(); if( rc==SQLITE_OK ){ rc = sqlite3PcacheInitialize(); - sqlite3PCacheBufferSetup(sqlite3Config.pPage, sqlite3Config.szPage, - sqlite3Config.nPage); + sqlite3PCacheBufferSetup(sqlite3GlobalConfig.pPage, sqlite3GlobalConfig.szPage, + sqlite3GlobalConfig.nPage); } - inProgress = 0; - sqlite3Config.isInit = (rc==SQLITE_OK ? 1 : 0); + GLOBAL(int, inProgress) = 0; + sqlite3GlobalConfig.isInit = (rc==SQLITE_OK ? 1 : 0); } - sqlite3_mutex_leave(sqlite3Config.pInitMutex); + sqlite3_mutex_leave(sqlite3GlobalConfig.pInitMutex); /* Go back under the static mutex and clean up the recursive ** mutex to prevent a resource leak. */ sqlite3_mutex_enter(pMaster); - sqlite3Config.nRefInitMutex--; - if( sqlite3Config.nRefInitMutex<=0 ){ - assert( sqlite3Config.nRefInitMutex==0 ); - sqlite3_mutex_free(sqlite3Config.pInitMutex); - sqlite3Config.pInitMutex = 0; + sqlite3GlobalConfig.nRefInitMutex--; + if( sqlite3GlobalConfig.nRefInitMutex<=0 ){ + assert( sqlite3GlobalConfig.nRefInitMutex==0 ); + sqlite3_mutex_free(sqlite3GlobalConfig.pInitMutex); + sqlite3GlobalConfig.pInitMutex = 0; } sqlite3_mutex_leave(pMaster); @@ -199,18 +207,18 @@ int sqlite3_initialize(void){ ** routine is not threadsafe. Not by a long shot. */ int sqlite3_shutdown(void){ - sqlite3Config.isMallocInit = 0; + sqlite3GlobalConfig.isMallocInit = 0; sqlite3PcacheShutdown(); - if( sqlite3Config.isInit ){ + if( sqlite3GlobalConfig.isInit ){ sqlite3_os_end(); } - if( sqlite3Config.m.xShutdown ){ + if( sqlite3GlobalConfig.m.xShutdown ){ sqlite3MallocEnd(); } - if( sqlite3Config.mutex.xMutexEnd ){ + if( sqlite3GlobalConfig.mutex.xMutexEnd ){ sqlite3MutexEnd(); } - sqlite3Config.isInit = 0; + sqlite3GlobalConfig.isInit = 0; return SQLITE_OK; } @@ -229,84 +237,84 @@ int sqlite3_config(int op, ...){ /* sqlite3_config() shall return SQLITE_MISUSE if it is invoked while ** the SQLite library is in use. */ - if( sqlite3Config.isInit ) return SQLITE_MISUSE; + if( sqlite3GlobalConfig.isInit ) return SQLITE_MISUSE; va_start(ap, op); switch( op ){ case SQLITE_CONFIG_SINGLETHREAD: { /* Disable all mutexing */ - sqlite3Config.bCoreMutex = 0; - sqlite3Config.bFullMutex = 0; + sqlite3GlobalConfig.bCoreMutex = 0; + sqlite3GlobalConfig.bFullMutex = 0; break; } case SQLITE_CONFIG_MULTITHREAD: { /* Disable mutexing of database connections */ /* Enable mutexing of core data structures */ - sqlite3Config.bCoreMutex = 1; - sqlite3Config.bFullMutex = 0; + sqlite3GlobalConfig.bCoreMutex = 1; + sqlite3GlobalConfig.bFullMutex = 0; break; } case SQLITE_CONFIG_SERIALIZED: { /* Enable all mutexing */ - sqlite3Config.bCoreMutex = 1; - sqlite3Config.bFullMutex = 1; + sqlite3GlobalConfig.bCoreMutex = 1; + sqlite3GlobalConfig.bFullMutex = 1; break; } case SQLITE_CONFIG_MALLOC: { /* Specify an alternative malloc implementation */ - sqlite3Config.m = *va_arg(ap, sqlite3_mem_methods*); + sqlite3GlobalConfig.m = *va_arg(ap, sqlite3_mem_methods*); break; } case SQLITE_CONFIG_GETMALLOC: { /* Retrieve the current malloc() implementation */ - if( sqlite3Config.m.xMalloc==0 ) sqlite3MemSetDefault(); - *va_arg(ap, sqlite3_mem_methods*) = sqlite3Config.m; + if( sqlite3GlobalConfig.m.xMalloc==0 ) sqlite3MemSetDefault(); + *va_arg(ap, sqlite3_mem_methods*) = sqlite3GlobalConfig.m; break; } case SQLITE_CONFIG_MUTEX: { /* Specify an alternative mutex implementation */ - sqlite3Config.mutex = *va_arg(ap, sqlite3_mutex_methods*); + sqlite3GlobalConfig.mutex = *va_arg(ap, sqlite3_mutex_methods*); break; } case SQLITE_CONFIG_GETMUTEX: { /* Retrieve the current mutex implementation */ - *va_arg(ap, sqlite3_mutex_methods*) = sqlite3Config.mutex; + *va_arg(ap, sqlite3_mutex_methods*) = sqlite3GlobalConfig.mutex; break; } case SQLITE_CONFIG_MEMSTATUS: { /* Enable or disable the malloc status collection */ - sqlite3Config.bMemstat = va_arg(ap, int); + sqlite3GlobalConfig.bMemstat = va_arg(ap, int); break; } case SQLITE_CONFIG_SCRATCH: { /* Designate a buffer for scratch memory space */ - sqlite3Config.pScratch = va_arg(ap, void*); - sqlite3Config.szScratch = va_arg(ap, int); - sqlite3Config.nScratch = va_arg(ap, int); + sqlite3GlobalConfig.pScratch = va_arg(ap, void*); + sqlite3GlobalConfig.szScratch = va_arg(ap, int); + sqlite3GlobalConfig.nScratch = va_arg(ap, int); break; } case SQLITE_CONFIG_PAGECACHE: { /* Designate a buffer for scratch memory space */ - sqlite3Config.pPage = va_arg(ap, void*); - sqlite3Config.szPage = va_arg(ap, int); - sqlite3Config.nPage = va_arg(ap, int); + sqlite3GlobalConfig.pPage = va_arg(ap, void*); + sqlite3GlobalConfig.szPage = va_arg(ap, int); + sqlite3GlobalConfig.nPage = va_arg(ap, int); break; } #if defined(SQLITE_ENABLE_MEMSYS3) || defined(SQLITE_ENABLE_MEMSYS5) case SQLITE_CONFIG_HEAP: { /* Designate a buffer for heap memory space */ - sqlite3Config.pHeap = va_arg(ap, void*); - sqlite3Config.nHeap = va_arg(ap, int); - sqlite3Config.mnReq = va_arg(ap, int); + sqlite3GlobalConfig.pHeap = va_arg(ap, void*); + sqlite3GlobalConfig.nHeap = va_arg(ap, int); + sqlite3GlobalConfig.mnReq = va_arg(ap, int); - if( sqlite3Config.pHeap==0 ){ + if( sqlite3GlobalConfig.pHeap==0 ){ /* If the heap pointer is NULL, then restore the malloc implementation ** back to NULL pointers too. This will cause the malloc to go ** back to its default implementation when sqlite3_initialize() is ** run. */ - memset(&sqlite3Config.m, 0, sizeof(sqlite3Config.m)); + memset(&sqlite3GlobalConfig.m, 0, sizeof(sqlite3GlobalConfig.m)); }else{ /* The heap pointer is not NULL, then install one of the ** mem5.c/mem3.c methods. If neither ENABLE_MEMSYS3 nor @@ -314,10 +322,10 @@ int sqlite3_config(int op, ...){ ** the default case and return an error. */ #ifdef SQLITE_ENABLE_MEMSYS3 - sqlite3Config.m = *sqlite3MemGetMemsys3(); + sqlite3GlobalConfig.m = *sqlite3MemGetMemsys3(); #endif #ifdef SQLITE_ENABLE_MEMSYS5 - sqlite3Config.m = *sqlite3MemGetMemsys5(); + sqlite3GlobalConfig.m = *sqlite3MemGetMemsys5(); #endif } break; @@ -326,15 +334,15 @@ int sqlite3_config(int op, ...){ #if defined(SQLITE_ENABLE_MEMSYS6) case SQLITE_CONFIG_CHUNKALLOC: { - sqlite3Config.nSmall = va_arg(ap, int); - sqlite3Config.m = *sqlite3MemGetMemsys6(); + sqlite3GlobalConfig.nSmall = va_arg(ap, int); + sqlite3GlobalConfig.m = *sqlite3MemGetMemsys6(); break; } #endif case SQLITE_CONFIG_LOOKASIDE: { - sqlite3Config.szLookaside = va_arg(ap, int); - sqlite3Config.nLookaside = va_arg(ap, int); + sqlite3GlobalConfig.szLookaside = va_arg(ap, int); + sqlite3GlobalConfig.nLookaside = va_arg(ap, int); break; } @@ -1445,7 +1453,7 @@ static int openDatabase( /* Allocate the sqlite data structure */ db = sqlite3MallocZero( sizeof(sqlite3) ); if( db==0 ) goto opendb_out; - if( sqlite3Config.bFullMutex && isThreadsafe ){ + if( sqlite3GlobalConfig.bFullMutex && isThreadsafe ){ db->mutex = sqlite3MutexAlloc(SQLITE_MUTEX_RECURSIVE); if( db->mutex==0 ){ sqlite3_free(db); @@ -1598,11 +1606,11 @@ static int openDatabase( #endif /* Enable the lookaside-malloc subsystem */ - setupLookaside(db, 0, sqlite3Config.szLookaside, sqlite3Config.nLookaside); + setupLookaside(db, 0, sqlite3GlobalConfig.szLookaside, sqlite3GlobalConfig.nLookaside); opendb_out: if( db ){ - assert( db->mutex!=0 || isThreadsafe==0 || sqlite3Config.bFullMutex==0 ); + assert( db->mutex!=0 || isThreadsafe==0 || sqlite3GlobalConfig.bFullMutex==0 ); sqlite3_mutex_leave(db->mutex); } rc = sqlite3_errcode(db); diff --git a/src/malloc.c b/src/malloc.c index ca15631a55..5a318b113a 100644 --- a/src/malloc.c +++ b/src/malloc.c @@ -12,7 +12,7 @@ ** ** Memory allocation functions used throughout sqlite. ** -** $Id: malloc.c,v 1.37 2008/08/29 17:56:13 danielk1977 Exp $ +** $Id: malloc.c,v 1.38 2008/09/01 18:34:20 danielk1977 Exp $ */ #include "sqliteInt.h" #include @@ -92,8 +92,8 @@ static struct { int alarmBusy; /* - ** Pointers to the end of sqlite3Config.pScratch and - ** sqlite3Config.pPage to a block of memory that records + ** Pointers to the end of sqlite3GlobalConfig.pScratch and + ** sqlite3GlobalConfig.pPage to a block of memory that records ** which pages are available. */ u32 *aScratchFree; @@ -108,49 +108,49 @@ static struct { ** Initialize the memory allocation subsystem. */ int sqlite3MallocInit(void){ - if( sqlite3Config.m.xMalloc==0 ){ + if( sqlite3GlobalConfig.m.xMalloc==0 ){ sqlite3MemSetDefault(); } memset(&mem0, 0, sizeof(mem0)); - if( sqlite3Config.bCoreMutex ){ + if( sqlite3GlobalConfig.bCoreMutex ){ mem0.mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MEM); } - if( sqlite3Config.pScratch && sqlite3Config.szScratch>=100 - && sqlite3Config.nScratch>=0 ){ + if( sqlite3GlobalConfig.pScratch && sqlite3GlobalConfig.szScratch>=100 + && sqlite3GlobalConfig.nScratch>=0 ){ int i; - sqlite3Config.szScratch -= 4; - mem0.aScratchFree = (u32*)&((char*)sqlite3Config.pScratch) - [sqlite3Config.szScratch*sqlite3Config.nScratch]; - for(i=0; i=512 - && sqlite3Config.nPage>=1 ){ + if( sqlite3GlobalConfig.pPage && sqlite3GlobalConfig.szPage>=512 + && sqlite3GlobalConfig.nPage>=1 ){ int i; int overhead; - int sz = sqlite3Config.szPage; - int n = sqlite3Config.nPage; + int sz = sqlite3GlobalConfig.szPage; + int n = sqlite3GlobalConfig.nPage; overhead = (4*n + sz - 1)/sz; - sqlite3Config.nPage -= overhead; - mem0.aPageFree = (u32*)&((char*)sqlite3Config.pPage) - [sqlite3Config.szPage*sqlite3Config.nPage]; - for(i=0; i=(void*)mem0.aScratchFree ){ - if( sqlite3Config.bMemstat ){ + if( sqlite3GlobalConfig.bMemstat ){ int iSize = sqlite3MallocSize(p); sqlite3_mutex_enter(mem0.mutex); sqlite3StatusAdd(SQLITE_STATUS_SCRATCH_OVERFLOW, -iSize); sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, -iSize); - sqlite3Config.m.xFree(p); + sqlite3GlobalConfig.m.xFree(p); sqlite3_mutex_leave(mem0.mutex); }else{ - sqlite3Config.m.xFree(p); + sqlite3GlobalConfig.m.xFree(p); } }else{ int i; - i = (u8 *)p - (u8 *)sqlite3Config.pScratch; - i /= sqlite3Config.szScratch; - assert( i>=0 && i=0 && i=512 && n<=32768 ); - if( sqlite3Config.szPage=(void*)mem0.aPageFree ){ /* In this case, the page allocation was obtained from a regular ** call to sqlite3_mem_methods.xMalloc() (a page-cache-memory ** "overflow"). Free the block with sqlite3_mem_methods.xFree(). */ - if( sqlite3Config.bMemstat ){ + if( sqlite3GlobalConfig.bMemstat ){ int iSize = sqlite3MallocSize(p); sqlite3_mutex_enter(mem0.mutex); sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_OVERFLOW, -iSize); sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, -iSize); - sqlite3Config.m.xFree(p); + sqlite3GlobalConfig.m.xFree(p); sqlite3_mutex_leave(mem0.mutex); }else{ - sqlite3Config.m.xFree(p); + sqlite3GlobalConfig.m.xFree(p); } }else{ - /* The page allocation was allocated from the sqlite3Config.pPage + /* The page allocation was allocated from the sqlite3GlobalConfig.pPage ** buffer. In this case all that is add the index of the page in - ** the sqlite3Config.pPage array to the set of free indexes stored + ** the sqlite3GlobalConfig.pPage array to the set of free indexes stored ** in the mem0.aPageFree[] array. */ int i; - i = (u8 *)p - (u8 *)sqlite3Config.pPage; - i /= sqlite3Config.szPage; - assert( i>=0 && i=0 && ilookaside.sz; }else{ - return sqlite3Config.m.xSize(p); + return sqlite3GlobalConfig.m.xSize(p); } } @@ -495,13 +495,13 @@ int sqlite3DbMallocSize(sqlite3 *db, void *p){ */ void sqlite3_free(void *p){ if( p==0 ) return; - if( sqlite3Config.bMemstat ){ + if( sqlite3GlobalConfig.bMemstat ){ sqlite3_mutex_enter(mem0.mutex); sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, -sqlite3MallocSize(p)); - sqlite3Config.m.xFree(p); + sqlite3GlobalConfig.m.xFree(p); sqlite3_mutex_leave(mem0.mutex); }else{ - sqlite3Config.m.xFree(p); + sqlite3GlobalConfig.m.xFree(p); } } @@ -534,10 +534,10 @@ void *sqlite3Realloc(void *pOld, int nBytes){ return 0; } nOld = sqlite3MallocSize(pOld); - if( sqlite3Config.bMemstat ){ + if( sqlite3GlobalConfig.bMemstat ){ sqlite3_mutex_enter(mem0.mutex); sqlite3StatusSet(SQLITE_STATUS_MALLOC_SIZE, nBytes); - nNew = sqlite3Config.m.xRoundup(nBytes); + nNew = sqlite3GlobalConfig.m.xRoundup(nBytes); if( nOld==nNew ){ pNew = pOld; }else{ @@ -545,10 +545,10 @@ void *sqlite3Realloc(void *pOld, int nBytes){ mem0.alarmThreshold ){ sqlite3MallocAlarm(nNew-nOld); } - pNew = sqlite3Config.m.xRealloc(pOld, nNew); + pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew); if( pNew==0 && mem0.alarmCallback ){ sqlite3MallocAlarm(nBytes); - pNew = sqlite3Config.m.xRealloc(pOld, nNew); + pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew); } if( pNew ){ nNew = sqlite3MallocSize(pNew); @@ -557,7 +557,7 @@ void *sqlite3Realloc(void *pOld, int nBytes){ } sqlite3_mutex_leave(mem0.mutex); }else{ - pNew = sqlite3Config.m.xRealloc(pOld, nBytes); + pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nBytes); } return pNew; } diff --git a/src/mem1.c b/src/mem1.c index 1a3a68eb04..5f8dcea775 100644 --- a/src/mem1.c +++ b/src/mem1.c @@ -17,7 +17,7 @@ ** This file contains implementations of the low-level memory allocation ** routines specified in the sqlite3_mem_methods object. ** -** $Id: mem1.c,v 1.25 2008/07/25 08:49:00 danielk1977 Exp $ +** $Id: mem1.c,v 1.26 2008/09/01 18:34:20 danielk1977 Exp $ */ #include "sqliteInt.h" @@ -138,7 +138,7 @@ const sqlite3_mem_methods *sqlite3MemGetDefault(void){ ** This routine is the only routine in this file with external linkage. ** ** Populate the low-level memory allocation function pointers in -** sqlite3Config.m with pointers to the routines in this file. +** sqlite3GlobalConfig.m with pointers to the routines in this file. */ void sqlite3MemSetDefault(void){ sqlite3_config(SQLITE_CONFIG_MALLOC, sqlite3MemGetDefault()); diff --git a/src/mem2.c b/src/mem2.c index 6a24bb85dd..80fd387bd3 100644 --- a/src/mem2.c +++ b/src/mem2.c @@ -19,7 +19,7 @@ ** This file contains implementations of the low-level memory allocation ** routines specified in the sqlite3_mem_methods object. ** -** $Id: mem2.c,v 1.38 2008/08/12 15:04:59 danielk1977 Exp $ +** $Id: mem2.c,v 1.39 2008/09/01 18:34:20 danielk1977 Exp $ */ #include "sqliteInt.h" @@ -185,7 +185,7 @@ static int sqlite3MemSize(void *p){ ** Initialize the memory allocation subsystem. */ static int sqlite3MemInit(void *NotUsed){ - if( !sqlite3Config.bMemstat ){ + if( !sqlite3GlobalConfig.bMemstat ){ /* If memory status is enabled, then the malloc.c wrapper will already ** hold the STATIC_MEM mutex when the routines here are invoked. */ mem.mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MEM); @@ -270,7 +270,7 @@ static void sqlite3MemFree(void *pPrior){ struct MemBlockHdr *pHdr; void **pBt; char *z; - assert( sqlite3Config.bMemstat || mem.mutex!=0 ); + assert( sqlite3GlobalConfig.bMemstat || mem.mutex!=0 ); pHdr = sqlite3MemsysGetHeader(pPrior); pBt = (void**)pHdr; pBt -= pHdr->nBacktraceSlots; @@ -340,7 +340,7 @@ const sqlite3_mem_methods *sqlite3MemGetDefault(void){ /* ** Populate the low-level memory allocation function pointers in -** sqlite3Config.m with pointers to the routines in this file. +** sqlite3GlobalConfig.m with pointers to the routines in this file. */ void sqlite3MemSetDefault(void){ sqlite3_config(SQLITE_CONFIG_MALLOC, sqlite3MemGetDefault()); diff --git a/src/mem3.c b/src/mem3.c index 46a58982a3..08f6e6e2ad 100644 --- a/src/mem3.c +++ b/src/mem3.c @@ -23,7 +23,7 @@ ** This version of the memory allocation subsystem is included ** in the build only if SQLITE_ENABLE_MEMSYS3 is defined. ** -** $Id: mem3.c,v 1.20 2008/07/18 18:56:17 drh Exp $ +** $Id: mem3.c,v 1.21 2008/09/01 18:34:20 danielk1977 Exp $ */ #include "sqliteInt.h" @@ -217,10 +217,10 @@ static void memsys3Link(u32 i){ /* ** If the STATIC_MEM mutex is not already held, obtain it now. The mutex ** will already be held (obtained by code in malloc.c) if -** sqlite3Config.bMemStat is true. +** sqlite3GlobalConfig.bMemStat is true. */ static void memsys3Enter(void){ - if( sqlite3Config.bMemstat==0 && mem3.mutex==0 ){ + if( sqlite3GlobalConfig.bMemstat==0 && mem3.mutex==0 ){ mem3.mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MEM); } sqlite3_mutex_enter(mem3.mutex); @@ -550,14 +550,14 @@ void *memsys3Realloc(void *pPrior, int nBytes){ ** Initialize this module. */ static int memsys3Init(void *NotUsed){ - if( !sqlite3Config.pHeap ){ + if( !sqlite3GlobalConfig.pHeap ){ return SQLITE_ERROR; } /* Store a pointer to the memory block in global structure mem3. */ assert( sizeof(Mem3Block)==8 ); - mem3.aPool = (Mem3Block *)sqlite3Config.pHeap; - mem3.nPool = (sqlite3Config.nHeap / sizeof(Mem3Block)) - 2; + mem3.aPool = (Mem3Block *)sqlite3GlobalConfig.pHeap; + mem3.nPool = (sqlite3GlobalConfig.nHeap / sizeof(Mem3Block)) - 2; /* Initialize the master block. */ mem3.szMaster = mem3.nPool; @@ -659,7 +659,7 @@ void sqlite3Memsys3Dump(const char *zFilename){ ** linkage. ** ** Populate the low-level memory allocation function pointers in -** sqlite3Config.m with pointers to the routines in this file. The +** sqlite3GlobalConfig.m with pointers to the routines in this file. The ** arguments specify the block of memory to manage. ** ** This routine is only called by sqlite3_config(), and therefore diff --git a/src/mem5.c b/src/mem5.c index 7ce28a342c..9ee0adb28a 100644 --- a/src/mem5.c +++ b/src/mem5.c @@ -23,7 +23,7 @@ ** This version of the memory allocation subsystem is included ** in the build only if SQLITE_ENABLE_MEMSYS5 is defined. ** -** $Id: mem5.c,v 1.11 2008/07/16 12:25:32 drh Exp $ +** $Id: mem5.c,v 1.12 2008/09/01 18:34:20 danielk1977 Exp $ */ #include "sqliteInt.h" @@ -181,10 +181,10 @@ static void memsys5Link(int i, int iLogsize){ /* ** If the STATIC_MEM mutex is not already held, obtain it now. The mutex ** will already be held (obtained by code in malloc.c) if -** sqlite3Config.bMemStat is true. +** sqlite3GlobalConfig.bMemStat is true. */ static void memsys5Enter(void){ - if( sqlite3Config.bMemstat==0 && mem5.mutex==0 ){ + if( sqlite3GlobalConfig.bMemstat==0 && mem5.mutex==0 ){ mem5.mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MEM); } sqlite3_mutex_enter(mem5.mutex); @@ -406,8 +406,8 @@ static int memsys5Log(int iValue){ */ static int memsys5Init(void *NotUsed){ int ii; - int nByte = sqlite3Config.nHeap; - u8 *zByte = (u8 *)sqlite3Config.pHeap; + int nByte = sqlite3GlobalConfig.nHeap; + u8 *zByte = (u8 *)sqlite3GlobalConfig.pHeap; int nMinLog; /* Log of minimum allocation size in bytes*/ int iOffset; @@ -415,7 +415,7 @@ static int memsys5Init(void *NotUsed){ return SQLITE_ERROR; } - nMinLog = memsys5Log(sqlite3Config.mnReq); + nMinLog = memsys5Log(sqlite3GlobalConfig.mnReq); mem5.nAtom = (1<mem5.nAtom ){ mem5.nAtom = mem5.nAtom << 1; diff --git a/src/mem6.c b/src/mem6.c index 95723ad39c..27ba307d85 100644 --- a/src/mem6.c +++ b/src/mem6.c @@ -32,7 +32,7 @@ ** fragmentation. On some systems, heap fragmentation can cause a ** significant real-time slowdown. ** -** $Id: mem6.c,v 1.7 2008/07/28 19:34:53 drh Exp $ +** $Id: mem6.c,v 1.8 2008/09/01 18:34:20 danielk1977 Exp $ */ #ifdef SQLITE_ENABLE_MEMSYS6 @@ -456,10 +456,10 @@ static int memsys6Roundup(int n){ } static int memsys6Init(void *pCtx){ - u8 bMemstat = sqlite3Config.bMemstat; + u8 bMemstat = sqlite3GlobalConfig.bMemstat; mem6.nMinAlloc = (1 << LOG2_MINALLOC); mem6.pChunk = 0; - mem6.nThreshold = sqlite3Config.nSmall; + mem6.nThreshold = sqlite3GlobalConfig.nSmall; if( mem6.nThreshold<=0 ){ mem6.nThreshold = SMALL_MALLOC_DEFAULT_THRESHOLD; } diff --git a/src/mutex.c b/src/mutex.c index 43e1965eb0..79ff86ece3 100644 --- a/src/mutex.c +++ b/src/mutex.c @@ -19,7 +19,7 @@ ** implementation is suitable for testing. ** debugging purposes ** -** $Id: mutex.c,v 1.27 2008/06/19 08:51:24 danielk1977 Exp $ +** $Id: mutex.c,v 1.28 2008/09/01 18:34:20 danielk1977 Exp $ */ #include "sqliteInt.h" @@ -29,17 +29,17 @@ */ int sqlite3MutexInit(void){ int rc = SQLITE_OK; - if( sqlite3Config.bCoreMutex ){ - if( !sqlite3Config.mutex.xMutexAlloc ){ + if( sqlite3GlobalConfig.bCoreMutex ){ + if( !sqlite3GlobalConfig.mutex.xMutexAlloc ){ /* If the xMutexAlloc method has not been set, then the user did not ** install a mutex implementation via sqlite3_config() prior to ** sqlite3_initialize() being called. This block copies pointers to - ** the default implementation into the sqlite3Config structure. + ** the default implementation into the sqlite3GlobalConfig structure. ** ** The danger is that although sqlite3_config() is not a threadsafe ** API, sqlite3_initialize() is, and so multiple threads may be ** attempting to run this function simultaneously. To guard write - ** access to the sqlite3Config structure, the 'MASTER' static mutex + ** access to the sqlite3GlobalConfig structure, the 'MASTER' static mutex ** is obtained before modifying it. */ sqlite3_mutex_methods *p = sqlite3DefaultMutex(); @@ -50,16 +50,16 @@ int sqlite3MutexInit(void){ pMaster = p->xMutexAlloc(SQLITE_MUTEX_STATIC_MASTER); assert(pMaster); p->xMutexEnter(pMaster); - assert( sqlite3Config.mutex.xMutexAlloc==0 - || sqlite3Config.mutex.xMutexAlloc==p->xMutexAlloc + assert( sqlite3GlobalConfig.mutex.xMutexAlloc==0 + || sqlite3GlobalConfig.mutex.xMutexAlloc==p->xMutexAlloc ); - if( !sqlite3Config.mutex.xMutexAlloc ){ - sqlite3Config.mutex = *p; + if( !sqlite3GlobalConfig.mutex.xMutexAlloc ){ + sqlite3GlobalConfig.mutex = *p; } p->xMutexLeave(pMaster); } }else{ - rc = sqlite3Config.mutex.xMutexInit(); + rc = sqlite3GlobalConfig.mutex.xMutexInit(); } } @@ -72,7 +72,7 @@ int sqlite3MutexInit(void){ */ int sqlite3MutexEnd(void){ int rc = SQLITE_OK; - rc = sqlite3Config.mutex.xMutexEnd(); + rc = sqlite3GlobalConfig.mutex.xMutexEnd(); return rc; } @@ -83,14 +83,14 @@ sqlite3_mutex *sqlite3_mutex_alloc(int id){ #ifndef SQLITE_OMIT_AUTOINIT if( sqlite3_initialize() ) return 0; #endif - return sqlite3Config.mutex.xMutexAlloc(id); + return sqlite3GlobalConfig.mutex.xMutexAlloc(id); } sqlite3_mutex *sqlite3MutexAlloc(int id){ - if( !sqlite3Config.bCoreMutex ){ + if( !sqlite3GlobalConfig.bCoreMutex ){ return 0; } - return sqlite3Config.mutex.xMutexAlloc(id); + return sqlite3GlobalConfig.mutex.xMutexAlloc(id); } /* @@ -98,7 +98,7 @@ sqlite3_mutex *sqlite3MutexAlloc(int id){ */ void sqlite3_mutex_free(sqlite3_mutex *p){ if( p ){ - sqlite3Config.mutex.xMutexFree(p); + sqlite3GlobalConfig.mutex.xMutexFree(p); } } @@ -108,7 +108,7 @@ void sqlite3_mutex_free(sqlite3_mutex *p){ */ void sqlite3_mutex_enter(sqlite3_mutex *p){ if( p ){ - sqlite3Config.mutex.xMutexEnter(p); + sqlite3GlobalConfig.mutex.xMutexEnter(p); } } @@ -119,7 +119,7 @@ void sqlite3_mutex_enter(sqlite3_mutex *p){ int sqlite3_mutex_try(sqlite3_mutex *p){ int rc = SQLITE_OK; if( p ){ - return sqlite3Config.mutex.xMutexTry(p); + return sqlite3GlobalConfig.mutex.xMutexTry(p); } return rc; } @@ -132,7 +132,7 @@ int sqlite3_mutex_try(sqlite3_mutex *p){ */ void sqlite3_mutex_leave(sqlite3_mutex *p){ if( p ){ - sqlite3Config.mutex.xMutexLeave(p); + sqlite3GlobalConfig.mutex.xMutexLeave(p); } } @@ -142,10 +142,10 @@ void sqlite3_mutex_leave(sqlite3_mutex *p){ ** intended for use inside assert() statements. */ int sqlite3_mutex_held(sqlite3_mutex *p){ - return p==0 || sqlite3Config.mutex.xMutexHeld(p); + return p==0 || sqlite3GlobalConfig.mutex.xMutexHeld(p); } int sqlite3_mutex_notheld(sqlite3_mutex *p){ - return p==0 || sqlite3Config.mutex.xMutexNotheld(p); + return p==0 || sqlite3GlobalConfig.mutex.xMutexNotheld(p); } #endif diff --git a/src/pcache.c b/src/pcache.c index 552f6c772d..3a9bd493e2 100644 --- a/src/pcache.c +++ b/src/pcache.c @@ -11,7 +11,7 @@ ************************************************************************* ** This file implements that page cache. ** -** @(#) $Id: pcache.c,v 1.24 2008/08/29 09:10:03 danielk1977 Exp $ +** @(#) $Id: pcache.c,v 1.25 2008/09/01 18:34:20 danielk1977 Exp $ */ #include "sqliteInt.h" @@ -606,7 +606,7 @@ static int pcacheRecycleOrAlloc(PCache *pCache, PgHdr **ppPage){ int sqlite3PcacheInitialize(void){ assert( pcache.isInit==0 ); memset(&pcache, 0, sizeof(pcache)); - if( sqlite3Config.bCoreMutex ){ + if( sqlite3GlobalConfig.bCoreMutex ){ /* No need to check the return value of sqlite3_mutex_alloc(). ** Allocating a static mutex cannot fail. */ diff --git a/src/sqlite.h.in b/src/sqlite.h.in index e51908b721..0a38fed5f1 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -30,7 +30,7 @@ ** the version number) and changes its name to "sqlite3.h" as ** part of the build process. ** -** @(#) $Id: sqlite.h.in,v 1.394 2008/08/25 21:23:02 drh Exp $ +** @(#) $Id: sqlite.h.in,v 1.395 2008/09/01 18:34:20 danielk1977 Exp $ */ #ifndef _SQLITE3_H_ #define _SQLITE3_H_ @@ -6197,6 +6197,10 @@ SQLITE_EXPERIMENTAL int sqlite3_status(int op, int *pCurrent, int *pHighwater, i */ SQLITE_EXPERIMENTAL int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg); + +int sqlite3_wsd_init(int N, int J); +void *sqlite3_wsd_find(void *K, int L); + /* ** CAPI3REF: Status Parameters {H17250} ** EXPERIMENTAL diff --git a/src/sqliteInt.h b/src/sqliteInt.h index b581303f94..51cdc324d9 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -11,7 +11,7 @@ ************************************************************************* ** Internal interface definitions for SQLite. ** -** @(#) $Id: sqliteInt.h,v 1.765 2008/09/01 15:52:11 drh Exp $ +** @(#) $Id: sqliteInt.h,v 1.766 2008/09/01 18:34:20 danielk1977 Exp $ */ #ifndef _SQLITEINT_H_ #define _SQLITEINT_H_ @@ -441,6 +441,16 @@ struct BusyHandler { */ #define SQLITE_DYNAMIC ((sqlite3_destructor_type)sqlite3DbFree) +#ifdef SQLITE_OMIT_WSD + #define SQLITE_WSD const + #define GLOBAL(t,v) (*(t*)sqlite3_wsd_find((void*)&(v), sizeof(v))) + #define sqlite3GlobalConfig GLOBAL(struct Sqlite3Config, sqlite3Config) +#else + #define SQLITE_WSD + #define GLOBAL(t,v) v + #define sqlite3GlobalConfig sqlite3Config +#endif + /* ** Forward references to structures */ @@ -2317,8 +2327,8 @@ int sqlite3ValueFromExpr(sqlite3 *, Expr *, u8, u8, sqlite3_value **); void sqlite3ValueApplyAffinity(sqlite3_value *, u8, u8); #ifndef SQLITE_AMALGAMATION extern const unsigned char sqlite3UpperToLower[]; -extern struct Sqlite3Config sqlite3Config; -extern FuncDefHash sqlite3GlobalFunctions; +extern SQLITE_WSD struct Sqlite3Config sqlite3Config; +extern SQLITE_WSD FuncDefHash sqlite3GlobalFunctions; #endif void sqlite3RootPageMoved(Db*, int, int); void sqlite3Reindex(Parse*, Token*, Token*); diff --git a/src/test_wsd.c b/src/test_wsd.c new file mode 100644 index 0000000000..a704da2fe1 --- /dev/null +++ b/src/test_wsd.c @@ -0,0 +1,87 @@ +/* +** 2008 September 1 +** +** The author disclaims copyright to this source code. In place of +** a legal notice, here is a blessing: +** +** 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. +** +************************************************************************* +** +** The code in this file contains sample implementations of the +** sqlite3_wsd_init() and sqlite3_wsd_find() functions required if the +** SQLITE_OMIT_WSD symbol is defined at build time. +** +** $Id: test_wsd.c,v 1.1 2008/09/01 18:34:20 danielk1977 Exp $ +*/ + +#if defined(SQLITE_OMIT_WSD) && defined(SQLITE_TEST) + +#include "sqliteInt.h" + +#define PLS_HASHSIZE 43 + +typedef struct ProcessLocalStorage ProcessLocalStorage; +typedef struct ProcessLocalVar ProcessLocalVar; + +struct ProcessLocalStorage { + ProcessLocalVar *aData[PLS_HASHSIZE]; + int nFree; + u8 *pFree; +}; + +struct ProcessLocalVar { + void *pKey; + ProcessLocalVar *pNext; +}; + +static ProcessLocalStorage *pGlobal = 0; + +int sqlite3_wsd_init(int N, int J){ + if( !pGlobal ){ + int nMalloc = N + sizeof(ProcessLocalStorage) + J*sizeof(ProcessLocalVar); + pGlobal = (ProcessLocalStorage *)malloc(nMalloc); + if( pGlobal ){ + memset(pGlobal, 0, sizeof(ProcessLocalStorage)); + pGlobal->nFree = nMalloc - sizeof(ProcessLocalStorage); + pGlobal->pFree = (u8 *)&pGlobal[1]; + } + } + + return pGlobal ? SQLITE_OK : SQLITE_NOMEM; +} + +void *sqlite3_wsd_find(void *K, int L){ + int i; + int iHash = 0; + ProcessLocalVar *pVar; + + /* Calculate a hash of K */ + for(i=0; iaData[iHash]; pVar && pVar->pKey!=K; pVar=pVar->pNext); + + /* If no entry for K was found, create and populate a new one. */ + if( !pVar ){ + int nByte = (sizeof(ProcessLocalVar) + L + 7)&~7; + assert( pGlobal->nFree>=nByte ); + pVar = (ProcessLocalVar *)pGlobal->pFree; + pVar->pKey = K; + pVar->pNext = pGlobal->aData[iHash]; + pGlobal->aData[iHash] = pVar; + pGlobal->nFree -= nByte; + pGlobal->pFree += nByte; + memcpy(&pVar[1], K, L); + } + + return (void *)&pVar[1]; +} + +#endif +