1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-08 14:02:16 +03:00

Begin adding support for the SQLITE_OMIT_WSD macro. Some (many) WSD variables still need wrappers added to them. (CVS 5652)

FossilOrigin-Name: 573d92abb9adb1c321ebc2fcadcf14374213b093
This commit is contained in:
danielk1977
2008-09-01 18:34:20 +00:00
parent cb275be4b1
commit 075c23af26
21 changed files with 339 additions and 222 deletions

View File

@@ -11,7 +11,7 @@
************************************************************************* *************************************************************************
** This file implements a tokenizer for fts3 based on the ICU library. ** 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) #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3)
@@ -112,7 +112,9 @@ static int icuOpen(
*ppCursor = 0; *ppCursor = 0;
if( -1 == nInput ) nInput = strlen(nInput); if( nInput<0 ){
nInput = strlen(zInput);
}
nChar = nInput+1; nChar = nInput+1;
pCsr = (IcuCursor *)sqlite3_malloc( pCsr = (IcuCursor *)sqlite3_malloc(
sizeof(IcuCursor) + /* IcuCursor */ sizeof(IcuCursor) + /* IcuCursor */

View File

@@ -224,6 +224,7 @@ TESTSRC = \
$(TOP)/src/test_server.c \ $(TOP)/src/test_server.c \
$(TOP)/src/test_tclvar.c \ $(TOP)/src/test_tclvar.c \
$(TOP)/src/test_thread.c \ $(TOP)/src/test_thread.c \
$(TOP)/src/test_wsd.c \
#TESTSRC += $(TOP)/ext/fts2/fts2_tokenizer.c #TESTSRC += $(TOP)/ext/fts2/fts2_tokenizer.c
#TESTSRC += $(TOP)/ext/fts3/fts3_tokenizer.c #TESTSRC += $(TOP)/ext/fts3/fts3_tokenizer.c

View File

@@ -1,5 +1,5 @@
C Remove\san\sunused\sfunction\sdeclaration\sfrom\sa\sheader\sfile.\s\sTicket\s#3349.\s(CVS\s5651) 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-01T17:23:29 D 2008-09-01T18:34:20
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
F Makefile.in 689e14735f862a5553bceef206d8c13e29504e44 F Makefile.in 689e14735f862a5553bceef206d8c13e29504e44
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 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.h 3a10a0af180d502cecc50df77b1b22df142817fe
F ext/fts3/fts3_hash.c 83e7bb4042106b32811681dd2859b4577a7a6b35 F ext/fts3/fts3_hash.c 83e7bb4042106b32811681dd2859b4577a7a6b35
F ext/fts3/fts3_hash.h 004b759e1602ff16dfa02fea3ca1c77336ad6798 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_porter.c 3063da945fb0a935781c135f7575f39166173eca
F ext/fts3/fts3_tokenizer.c fcc8fdb5c161df7d61c77285ec2991da131f0181 F ext/fts3/fts3_tokenizer.c fcc8fdb5c161df7d61c77285ec2991da131f0181
F ext/fts3/fts3_tokenizer.h 7eb79de4f991a77f43c517e209e5fae95dfa7369 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 ext/rtree/viewrtree.tcl 09526398dae87a5a87c5aac2b3854dbaf8376869
F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895
F ltmain.sh 09fe5815427dc7d0abb188bbcdf0e34896577210 F ltmain.sh 09fe5815427dc7d0abb188bbcdf0e34896577210
F main.mk 5ce1477b7fdc00f5c981f06e5708255dc217902c F main.mk 256259ff346a85fa98ad67848faae2b3ed817d57
F mkdll.sh 79d1ed6ae221c10589dd969f130f8a3cccfffbb7 F mkdll.sh 79d1ed6ae221c10589dd969f130f8a3cccfffbb7
F mkextu.sh 416f9b7089d80e5590a29692c9d9280a10dbad9f F mkextu.sh 416f9b7089d80e5590a29692c9d9280a10dbad9f
F mkextw.sh 4123480947681d9b434a5e7b1ee08135abe409ac F mkextw.sh 4123480947681d9b434a5e7b1ee08135abe409ac
@@ -97,18 +97,18 @@ F src/attach.c db3f4a60538733c1e4dcb9d0217a6e0d6ccd615b
F src/auth.c c8b2ab5c8bad4bd90ed7c294694f48269162c627 F src/auth.c c8b2ab5c8bad4bd90ed7c294694f48269162c627
F src/bitvec.c 95c86bd18d8fedf0533f5af196192546e10a7e7d F src/bitvec.c 95c86bd18d8fedf0533f5af196192546e10a7e7d
F src/btmutex.c 709cad2cdca0afd013f0f612363810e53f59ec53 F src/btmutex.c 709cad2cdca0afd013f0f612363810e53f59ec53
F src/btree.c 9b98b0d2e2273998b13a74856d5c62971b35449c F src/btree.c deb7e145e4e287763e317ff36a805826f5ed2e56
F src/btree.h 6371c5e599fab391a150c96afbc10062b276d107 F src/btree.h 6371c5e599fab391a150c96afbc10062b276d107
F src/btreeInt.h ab18c7b4980314e9e4b402e5dcde09f3c2545576 F src/btreeInt.h ab18c7b4980314e9e4b402e5dcde09f3c2545576
F src/build.c 160c71acca8f643f436ed6c1ee2f684c88df4dfe F src/build.c 160c71acca8f643f436ed6c1ee2f684c88df4dfe
F src/callback.c 27e55dfafc66e97dd8e7343a1d7bb295f3afd736 F src/callback.c cfc8d4f95fd831e25532d0fee2af5306283f4835
F src/complete.c cb14e06dbe79dee031031f0d9e686ff306afe07c F src/complete.c cb14e06dbe79dee031031f0d9e686ff306afe07c
F src/date.c 2373f20a91bec70e20e0e715520c8010d26ebb52 F src/date.c 6609557446f2d6788e64e18c09e03fdaf4dd55cc
F src/delete.c 434dd6f9d19475b35f2f57041d4bbba9f64da5ac F src/delete.c 434dd6f9d19475b35f2f57041d4bbba9f64da5ac
F src/expr.c 6413795aa13ceb05994e6b2b453a77df3b892e7b F src/expr.c 6413795aa13ceb05994e6b2b453a77df3b892e7b
F src/fault.c 3638519d1e0b82bccfafcb9f5ff491918b28f8e1 F src/fault.c 3638519d1e0b82bccfafcb9f5ff491918b28f8e1
F src/func.c f2e0b55f13e678a5c5ff94f0f225ed0a995acba7 F src/func.c 964a610bd68d79764f9e435615d723146f94f0e0
F src/global.c 239d03b6dbae6c985deb2ffb54ab919debb9f8d7 F src/global.c 9ced7c26127f04fb4baaebed1f5bf6d7063b089f
F src/hash.c eb64e48f3781100e5934f759fbe72a63a8fe78cb F src/hash.c eb64e48f3781100e5934f759fbe72a63a8fe78cb
F src/hash.h 031cd9f915aff27e12262cb9eb570ac1b8326b53 F src/hash.h 031cd9f915aff27e12262cb9eb570ac1b8326b53
F src/hwtime.h 4a1d45f4cae1f402ea19686acf24acf4f0cb53cb F src/hwtime.h 4a1d45f4cae1f402ea19686acf24acf4f0cb53cb
@@ -116,15 +116,15 @@ F src/insert.c 110cca7845ed5a66c08fdd413b02e706ae34455f
F src/journal.c cffd2cd214e58c0e99c3ff632b3bee6c7cbb260e F src/journal.c cffd2cd214e58c0e99c3ff632b3bee6c7cbb260e
F src/legacy.c aac57bd984e666059011ea01ec4383892a253be3 F src/legacy.c aac57bd984e666059011ea01ec4383892a253be3
F src/loadext.c eb1fe4f44d7c8ff53fc0c6a4388ab79fbd34cd64 F src/loadext.c eb1fe4f44d7c8ff53fc0c6a4388ab79fbd34cd64
F src/main.c f372968372bdf4275333327fd04737f667e0f3af F src/main.c 47ce9da041a5aa9a1adadd92be795bde887e2dc9
F src/malloc.c 6bd94746cca2ad3afc0020b934848378f27df244 F src/malloc.c 2ffd62fb4a299cf3945e50a4c53d27ec1813f8b1
F src/mem1.c 3a7fe31d8290baa3bb203af72f7dfd6323966bcd F src/mem1.c 5a529ff121c55ab067be14de00f86f6dcc4f4fb9
F src/mem2.c 7256327b96927020824e06ffb3443b99a28da047 F src/mem2.c f87e681d0d1ed8436870d089332ed0d27d885b5c
F src/mem3.c c73e935d0b900abc51d5fa45f880937b062f4a9f F src/mem3.c afb0ace2be6a9134713f399711bacf7d3cdc60c6
F src/mem4.c 6703adb1717b26d9d70a1c2586b4b7b7ffee7909 F src/mem4.c 6703adb1717b26d9d70a1c2586b4b7b7ffee7909
F src/mem5.c 0b0ba1c2a02d86eb812dea6debacee841e3856f7 F src/mem5.c 7a8e54fd3ca801c2a3cf9060175c008c55715d8b
F src/mem6.c a3932c3d2f6382f077d7c94cf6a6e15e0a8cbd07 F src/mem6.c 637d1e65bfcebb68844981cc80f9da4483428539
F src/mutex.c a485a0eac8ee2cd95f66e565b4c6696c18db968f F src/mutex.c 81174f600553c25832e9a8705b609f16c73a4c01
F src/mutex.h e52ffa1dfc6a6077e8b1823d2c2b7dfcbcf85594 F src/mutex.h e52ffa1dfc6a6077e8b1823d2c2b7dfcbcf85594
F src/mutex_os2.c 9c5637aa4c307c552566d0f0b3bd206245b54a97 F src/mutex_os2.c 9c5637aa4c307c552566d0f0b3bd206245b54a97
F src/mutex_unix.c 29049a61755cccddb2ee53904e6906bb7674223c F src/mutex_unix.c 29049a61755cccddb2ee53904e6906bb7674223c
@@ -138,7 +138,7 @@ F src/os_win.c aefe9ee26430678a19a058a874e4e2bd91398142
F src/pager.c 032d11049af4ec49bdbaa3584e7ce9887098b66a F src/pager.c 032d11049af4ec49bdbaa3584e7ce9887098b66a
F src/pager.h c45380ca9d0933ea5bc4ecb3a43958b6d2ec5a9c F src/pager.h c45380ca9d0933ea5bc4ecb3a43958b6d2ec5a9c
F src/parse.y d0f76d2cb8d6883d5600dc20beb961a6022b94b8 F src/parse.y d0f76d2cb8d6883d5600dc20beb961a6022b94b8
F src/pcache.c e1cb0e77d2a299cfa4aa95d2e3307cc6900d2007 F src/pcache.c 200de27e85b123840a30a11f5055544e06845569
F src/pcache.h 53730c33310cdf7a5c94e8333c853d59a3b30226 F src/pcache.h 53730c33310cdf7a5c94e8333c853d59a3b30226
F src/pragma.c f5b271b090af7fcedd308d7c5807a5503f7a853d F src/pragma.c f5b271b090af7fcedd308d7c5807a5503f7a853d
F src/prepare.c c197041e0c4770672cda75e6bfe10242f885e510 F src/prepare.c c197041e0c4770672cda75e6bfe10242f885e510
@@ -147,9 +147,9 @@ F src/random.c 5c754319d38abdd6acd74601ee0105504adc508a
F src/resolve.c a6abf83125bce0c80ba04acc27c3565155ad305c F src/resolve.c a6abf83125bce0c80ba04acc27c3565155ad305c
F src/select.c eec7c5f28a0c75fdd8500630435af176bba73219 F src/select.c eec7c5f28a0c75fdd8500630435af176bba73219
F src/shell.c d83b578a8ccdd3e0e7fef4388a0887ce9f810967 F src/shell.c d83b578a8ccdd3e0e7fef4388a0887ce9f810967
F src/sqlite.h.in c0e84a2d6e9f3263599174ff7261ba6daf730b4f F src/sqlite.h.in 0031454ccb163b191daab7f7151d9d68af8b26c9
F src/sqlite3ext.h 1e3887c9bd3ae66cb599e922824b04cd0d0f2c3e F src/sqlite3ext.h 1e3887c9bd3ae66cb599e922824b04cd0d0f2c3e
F src/sqliteInt.h 2243b0eadb5dd32de8f0a38571afedb711fa2cc5 F src/sqliteInt.h 3ea61550f587eb4432373bcf145cd754da342ddc
F src/sqliteLimit.h f435e728c6b620ef7312814d660a81f9356eb5c8 F src/sqliteLimit.h f435e728c6b620ef7312814d660a81f9356eb5c8
F src/status.c 8caa772cd9310bc297280f7cf0ede4d69ed5b801 F src/status.c 8caa772cd9310bc297280f7cf0ede4d69ed5b801
F src/table.c 22744786199c9195720c15a7a42cb97b2e2728d8 F src/table.c 22744786199c9195720c15a7a42cb97b2e2728d8
@@ -180,6 +180,7 @@ F src/test_schema.c 4b4bf7bb329326458c491b0e6facd4c8c4c5b479
F src/test_server.c f0a403b5f699c09bd2b1236b6f69830fd6221f6b F src/test_server.c f0a403b5f699c09bd2b1236b6f69830fd6221f6b
F src/test_tclvar.c 9e42fa59d3d2f064b7ab8628e7ab2dc8a9fe93d4 F src/test_tclvar.c 9e42fa59d3d2f064b7ab8628e7ab2dc8a9fe93d4
F src/test_thread.c d74fc445e0dba0e00806117eb449b307c0b146bf F src/test_thread.c d74fc445e0dba0e00806117eb449b307c0b146bf
F src/test_wsd.c 9eadce9ae2910d738018649d5de26a65b5881ce6
F src/tokenize.c aaa5fa6a4536a9dd7c855a3f66f32508f1612138 F src/tokenize.c aaa5fa6a4536a9dd7c855a3f66f32508f1612138
F src/trigger.c 649940b5bf5838a33721fb72372e7c9d1faf56a9 F src/trigger.c 649940b5bf5838a33721fb72372e7c9d1faf56a9
F src/update.c f2cf6f00d542956bd49ba4b9815c2900d9225bf2 F src/update.c f2cf6f00d542956bd49ba4b9815c2900d9225bf2
@@ -629,7 +630,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81
F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
F tool/speedtest8.c 1dbced29de5f59ba2ebf877edcadf171540374d1 F tool/speedtest8.c 1dbced29de5f59ba2ebf877edcadf171540374d1
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
P d04d70336727a0db959c672e6c22cdaa0505dce5 P 7a577428b22918c232815e7998a623dbc47a8d41
R 04f6f8f1d929ad05f0d2d67cc6fb131a R b45f7764c971fd9d217268e94c98eacf
U drh U danielk1977
Z 14bd2f399c6134eded42b5797d53425f Z a30ccc5ce0944839576c9352eb85797d

View File

@@ -1 +1 @@
7a577428b22918c232815e7998a623dbc47a8d41 573d92abb9adb1c321ebc2fcadcf14374213b093

View File

@@ -9,7 +9,7 @@
** May you share freely, never taking more than you give. ** 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. ** This file implements a external (disk-based) database using BTrees.
** See the header comment on "btreeInt.h" for additional information. ** See the header comment on "btreeInt.h" for additional information.
@@ -1340,7 +1340,7 @@ int sqlite3BtreeOpen(
sqlite3_mutex *mutexShared; sqlite3_mutex *mutexShared;
pBt->nRef = 1; pBt->nRef = 1;
mutexShared = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); mutexShared = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
if( SQLITE_THREADSAFE && sqlite3Config.bCoreMutex ){ if( SQLITE_THREADSAFE && sqlite3GlobalConfig.bCoreMutex ){
pBt->mutex = sqlite3MutexAlloc(SQLITE_MUTEX_FAST); pBt->mutex = sqlite3MutexAlloc(SQLITE_MUTEX_FAST);
if( pBt->mutex==0 ){ if( pBt->mutex==0 ){
rc = SQLITE_NOMEM; rc = SQLITE_NOMEM;

View File

@@ -13,7 +13,7 @@
** This file contains functions used to access the internal hash tables ** This file contains functions used to access the internal hash tables
** of user defined functions and collation sequences. ** 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" #include "sqliteInt.h"
@@ -357,7 +357,8 @@ FuncDef *sqlite3FindFunction(
** function to use. ** function to use.
*/ */
if( !createFlag && !pBest ){ if( !createFlag && !pBest ){
p = functionSearch(&sqlite3GlobalFunctions, h, zName, nName); FuncDefHash *pHash = &GLOBAL(FuncDefHash, sqlite3GlobalFunctions);
p = functionSearch(pHash, h, zName, nName);
while( p ){ while( p ){
int score = matchQuality(p, nArg, enc); int score = matchQuality(p, nArg, enc);
if( score>bestScore ){ if( score>bestScore ){

View File

@@ -16,7 +16,7 @@
** sqlite3RegisterDateTimeFunctions() found at the bottom of the file. ** sqlite3RegisterDateTimeFunctions() found at the bottom of the file.
** All other code has file scope. ** 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 ** SQLite processes all times and dates as Julian Day numbers. The
** dates and times are stored as the number of days since noon ** dates and times are stored as the number of days since noon
@@ -1053,7 +1053,7 @@ static void currentTimeFunc(
** external linkage. ** external linkage.
*/ */
void sqlite3RegisterDateTimeFunctions(void){ void sqlite3RegisterDateTimeFunctions(void){
static FuncDef aDateTimeFuncs[] = { static SQLITE_WSD FuncDef aDateTimeFuncs[] = {
#ifndef SQLITE_OMIT_DATETIME_FUNCS #ifndef SQLITE_OMIT_DATETIME_FUNCS
FUNCTION(julianday, -1, 0, 0, juliandayFunc ), FUNCTION(julianday, -1, 0, 0, juliandayFunc ),
FUNCTION(date, -1, 0, 0, dateFunc ), FUNCTION(date, -1, 0, 0, dateFunc ),
@@ -1070,8 +1070,10 @@ void sqlite3RegisterDateTimeFunctions(void){
#endif #endif
}; };
int i; int i;
FuncDefHash *pHash = &GLOBAL(FuncDefHash, sqlite3GlobalFunctions);
FuncDef *aFunc = &GLOBAL(FuncDef, aDateTimeFuncs);
for(i=0; i<ArraySize(aDateTimeFuncs); i++){ for(i=0; i<ArraySize(aDateTimeFuncs); i++){
sqlite3FuncDefInsert(&sqlite3GlobalFunctions, &aDateTimeFuncs[i]); sqlite3FuncDefInsert(pHash, &aFunc[i]);
} }
} }

View File

@@ -16,7 +16,7 @@
** sqliteRegisterBuildinFunctions() found at the bottom of the file. ** sqliteRegisterBuildinFunctions() found at the bottom of the file.
** All other code has file scope. ** All other code has file scope.
** **
** $Id: func.c,v 1.199 2008/08/21 20:21:35 drh Exp $ ** $Id: func.c,v 1.200 2008/09/01 18:34:20 danielk1977 Exp $
*/ */
#include "sqliteInt.h" #include "sqliteInt.h"
#include <ctype.h> #include <ctype.h>
@@ -1375,7 +1375,8 @@ static FuncDef aBuiltinFunc[] = {
void sqlite3RegisterGlobalFunctions(void){ void sqlite3RegisterGlobalFunctions(void){
int i; int i;
for(i=0; i<ArraySize(aBuiltinFunc); i++){ for(i=0; i<ArraySize(aBuiltinFunc); i++){
sqlite3FuncDefInsert(&sqlite3GlobalFunctions, &aBuiltinFunc[i]); FuncDefHash *pHash = &GLOBAL(FuncDefHash, sqlite3GlobalFunctions);
sqlite3FuncDefInsert(pHash, &aBuiltinFunc[i]);
} }
sqlite3RegisterDateTimeFunctions(); sqlite3RegisterDateTimeFunctions();
} }

View File

@@ -12,7 +12,7 @@
** **
** This file contains definitions of global variables and contants. ** This file contains definitions of global variables and contants.
** **
** $Id: global.c,v 1.6 2008/08/21 20:21:35 drh Exp $ ** $Id: global.c,v 1.7 2008/09/01 18:34:20 danielk1977 Exp $
*/ */
#include "sqliteInt.h" #include "sqliteInt.h"
@@ -66,7 +66,7 @@ const unsigned char sqlite3UpperToLower[] = {
** The following singleton contains the global configuration for ** The following singleton contains the global configuration for
** the SQLite library. ** the SQLite library.
*/ */
struct Sqlite3Config sqlite3Config = { SQLITE_WSD struct Sqlite3Config sqlite3Config = {
1, /* bMemstat */ 1, /* bMemstat */
1, /* bCoreMutex */ 1, /* bCoreMutex */
1, /* bFullMutex */ 1, /* bFullMutex */
@@ -82,4 +82,4 @@ struct Sqlite3Config sqlite3Config = {
** database connections. After initialization, this table is ** database connections. After initialization, this table is
** read-only. ** read-only.
*/ */
FuncDefHash sqlite3GlobalFunctions; SQLITE_WSD FuncDefHash sqlite3GlobalFunctions;

View File

@@ -14,7 +14,7 @@
** other files are for internal use by SQLite and should not be ** other files are for internal use by SQLite and should not be
** accessed by users of the library. ** accessed by users of the library.
** **
** $Id: main.c,v 1.494 2008/08/27 19:01:58 danielk1977 Exp $ ** $Id: main.c,v 1.495 2008/09/01 18:34:20 danielk1977 Exp $
*/ */
#include "sqliteInt.h" #include "sqliteInt.h"
#include <ctype.h> #include <ctype.h>
@@ -85,16 +85,23 @@ char *sqlite3_temp_directory = 0;
** without blocking. ** without blocking.
*/ */
int sqlite3_initialize(void){ int sqlite3_initialize(void){
static int inProgress = 0; /* Prevent recursion */ SQLITE_WSD static int inProgress = 0; /* Prevent recursion */
sqlite3_mutex *pMaster; /* The main static mutex */ sqlite3_mutex *pMaster; /* The main static mutex */
int rc; /* Result code */ 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 /* If SQLite is already completely initialized, then this call
** to sqlite3_initialize() should be a no-op. But the initialization ** to sqlite3_initialize() should be a no-op. But the initialization
** must be complete. So isInit must not be set until the very end ** must be complete. So isInit must not be set until the very end
** of this routine. ** 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 /* Make sure the mutex subsystem is initialized. If unable to
** initialize the mutex subsystem, return early with the error. ** initialize the mutex subsystem, return early with the error.
@@ -115,18 +122,18 @@ int sqlite3_initialize(void){
*/ */
pMaster = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); pMaster = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
sqlite3_mutex_enter(pMaster); sqlite3_mutex_enter(pMaster);
if( !sqlite3Config.isMallocInit ){ if( !sqlite3GlobalConfig.isMallocInit ){
rc = sqlite3MallocInit(); rc = sqlite3MallocInit();
} }
if( rc==SQLITE_OK ){ if( rc==SQLITE_OK ){
sqlite3Config.isMallocInit = 1; sqlite3GlobalConfig.isMallocInit = 1;
if( !sqlite3Config.pInitMutex ){ if( !sqlite3GlobalConfig.pInitMutex ){
sqlite3Config.pInitMutex = sqlite3MutexAlloc(SQLITE_MUTEX_RECURSIVE); sqlite3GlobalConfig.pInitMutex = sqlite3MutexAlloc(SQLITE_MUTEX_RECURSIVE);
if( sqlite3Config.bCoreMutex && !sqlite3Config.pInitMutex ){ if( sqlite3GlobalConfig.bCoreMutex && !sqlite3GlobalConfig.pInitMutex ){
rc = SQLITE_NOMEM; rc = SQLITE_NOMEM;
} }
} }
sqlite3Config.nRefInitMutex++; sqlite3GlobalConfig.nRefInitMutex++;
} }
sqlite3_mutex_leave(pMaster); sqlite3_mutex_leave(pMaster);
@@ -144,31 +151,32 @@ int sqlite3_initialize(void){
** sqlite3_os_init() when it invokes sqlite3_vfs_register(), but other ** sqlite3_os_init() when it invokes sqlite3_vfs_register(), but other
** recursive calls might also be possible. ** recursive calls might also be possible.
*/ */
sqlite3_mutex_enter(sqlite3Config.pInitMutex); sqlite3_mutex_enter(sqlite3GlobalConfig.pInitMutex);
if( sqlite3Config.isInit==0 && inProgress==0 ){ if( sqlite3GlobalConfig.isInit==0 && GLOBAL(int, inProgress)==0 ){
inProgress = 1; FuncDefHash *pHash = &GLOBAL(FuncDefHash, sqlite3GlobalFunctions);
memset(&sqlite3GlobalFunctions, 0, sizeof(sqlite3GlobalFunctions)); GLOBAL(int, inProgress) = 1;
memset(pHash, 0, sizeof(sqlite3GlobalFunctions));
sqlite3RegisterGlobalFunctions(); sqlite3RegisterGlobalFunctions();
rc = sqlite3_os_init(); rc = sqlite3_os_init();
if( rc==SQLITE_OK ){ if( rc==SQLITE_OK ){
rc = sqlite3PcacheInitialize(); rc = sqlite3PcacheInitialize();
sqlite3PCacheBufferSetup(sqlite3Config.pPage, sqlite3Config.szPage, sqlite3PCacheBufferSetup(sqlite3GlobalConfig.pPage, sqlite3GlobalConfig.szPage,
sqlite3Config.nPage); sqlite3GlobalConfig.nPage);
} }
inProgress = 0; GLOBAL(int, inProgress) = 0;
sqlite3Config.isInit = (rc==SQLITE_OK ? 1 : 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 /* Go back under the static mutex and clean up the recursive
** mutex to prevent a resource leak. ** mutex to prevent a resource leak.
*/ */
sqlite3_mutex_enter(pMaster); sqlite3_mutex_enter(pMaster);
sqlite3Config.nRefInitMutex--; sqlite3GlobalConfig.nRefInitMutex--;
if( sqlite3Config.nRefInitMutex<=0 ){ if( sqlite3GlobalConfig.nRefInitMutex<=0 ){
assert( sqlite3Config.nRefInitMutex==0 ); assert( sqlite3GlobalConfig.nRefInitMutex==0 );
sqlite3_mutex_free(sqlite3Config.pInitMutex); sqlite3_mutex_free(sqlite3GlobalConfig.pInitMutex);
sqlite3Config.pInitMutex = 0; sqlite3GlobalConfig.pInitMutex = 0;
} }
sqlite3_mutex_leave(pMaster); sqlite3_mutex_leave(pMaster);
@@ -199,18 +207,18 @@ int sqlite3_initialize(void){
** routine is not threadsafe. Not by a long shot. ** routine is not threadsafe. Not by a long shot.
*/ */
int sqlite3_shutdown(void){ int sqlite3_shutdown(void){
sqlite3Config.isMallocInit = 0; sqlite3GlobalConfig.isMallocInit = 0;
sqlite3PcacheShutdown(); sqlite3PcacheShutdown();
if( sqlite3Config.isInit ){ if( sqlite3GlobalConfig.isInit ){
sqlite3_os_end(); sqlite3_os_end();
} }
if( sqlite3Config.m.xShutdown ){ if( sqlite3GlobalConfig.m.xShutdown ){
sqlite3MallocEnd(); sqlite3MallocEnd();
} }
if( sqlite3Config.mutex.xMutexEnd ){ if( sqlite3GlobalConfig.mutex.xMutexEnd ){
sqlite3MutexEnd(); sqlite3MutexEnd();
} }
sqlite3Config.isInit = 0; sqlite3GlobalConfig.isInit = 0;
return SQLITE_OK; return SQLITE_OK;
} }
@@ -229,84 +237,84 @@ int sqlite3_config(int op, ...){
/* sqlite3_config() shall return SQLITE_MISUSE if it is invoked while /* sqlite3_config() shall return SQLITE_MISUSE if it is invoked while
** the SQLite library is in use. */ ** the SQLite library is in use. */
if( sqlite3Config.isInit ) return SQLITE_MISUSE; if( sqlite3GlobalConfig.isInit ) return SQLITE_MISUSE;
va_start(ap, op); va_start(ap, op);
switch( op ){ switch( op ){
case SQLITE_CONFIG_SINGLETHREAD: { case SQLITE_CONFIG_SINGLETHREAD: {
/* Disable all mutexing */ /* Disable all mutexing */
sqlite3Config.bCoreMutex = 0; sqlite3GlobalConfig.bCoreMutex = 0;
sqlite3Config.bFullMutex = 0; sqlite3GlobalConfig.bFullMutex = 0;
break; break;
} }
case SQLITE_CONFIG_MULTITHREAD: { case SQLITE_CONFIG_MULTITHREAD: {
/* Disable mutexing of database connections */ /* Disable mutexing of database connections */
/* Enable mutexing of core data structures */ /* Enable mutexing of core data structures */
sqlite3Config.bCoreMutex = 1; sqlite3GlobalConfig.bCoreMutex = 1;
sqlite3Config.bFullMutex = 0; sqlite3GlobalConfig.bFullMutex = 0;
break; break;
} }
case SQLITE_CONFIG_SERIALIZED: { case SQLITE_CONFIG_SERIALIZED: {
/* Enable all mutexing */ /* Enable all mutexing */
sqlite3Config.bCoreMutex = 1; sqlite3GlobalConfig.bCoreMutex = 1;
sqlite3Config.bFullMutex = 1; sqlite3GlobalConfig.bFullMutex = 1;
break; break;
} }
case SQLITE_CONFIG_MALLOC: { case SQLITE_CONFIG_MALLOC: {
/* Specify an alternative malloc implementation */ /* Specify an alternative malloc implementation */
sqlite3Config.m = *va_arg(ap, sqlite3_mem_methods*); sqlite3GlobalConfig.m = *va_arg(ap, sqlite3_mem_methods*);
break; break;
} }
case SQLITE_CONFIG_GETMALLOC: { case SQLITE_CONFIG_GETMALLOC: {
/* Retrieve the current malloc() implementation */ /* Retrieve the current malloc() implementation */
if( sqlite3Config.m.xMalloc==0 ) sqlite3MemSetDefault(); if( sqlite3GlobalConfig.m.xMalloc==0 ) sqlite3MemSetDefault();
*va_arg(ap, sqlite3_mem_methods*) = sqlite3Config.m; *va_arg(ap, sqlite3_mem_methods*) = sqlite3GlobalConfig.m;
break; break;
} }
case SQLITE_CONFIG_MUTEX: { case SQLITE_CONFIG_MUTEX: {
/* Specify an alternative mutex implementation */ /* Specify an alternative mutex implementation */
sqlite3Config.mutex = *va_arg(ap, sqlite3_mutex_methods*); sqlite3GlobalConfig.mutex = *va_arg(ap, sqlite3_mutex_methods*);
break; break;
} }
case SQLITE_CONFIG_GETMUTEX: { case SQLITE_CONFIG_GETMUTEX: {
/* Retrieve the current mutex implementation */ /* Retrieve the current mutex implementation */
*va_arg(ap, sqlite3_mutex_methods*) = sqlite3Config.mutex; *va_arg(ap, sqlite3_mutex_methods*) = sqlite3GlobalConfig.mutex;
break; break;
} }
case SQLITE_CONFIG_MEMSTATUS: { case SQLITE_CONFIG_MEMSTATUS: {
/* Enable or disable the malloc status collection */ /* Enable or disable the malloc status collection */
sqlite3Config.bMemstat = va_arg(ap, int); sqlite3GlobalConfig.bMemstat = va_arg(ap, int);
break; break;
} }
case SQLITE_CONFIG_SCRATCH: { case SQLITE_CONFIG_SCRATCH: {
/* Designate a buffer for scratch memory space */ /* Designate a buffer for scratch memory space */
sqlite3Config.pScratch = va_arg(ap, void*); sqlite3GlobalConfig.pScratch = va_arg(ap, void*);
sqlite3Config.szScratch = va_arg(ap, int); sqlite3GlobalConfig.szScratch = va_arg(ap, int);
sqlite3Config.nScratch = va_arg(ap, int); sqlite3GlobalConfig.nScratch = va_arg(ap, int);
break; break;
} }
case SQLITE_CONFIG_PAGECACHE: { case SQLITE_CONFIG_PAGECACHE: {
/* Designate a buffer for scratch memory space */ /* Designate a buffer for scratch memory space */
sqlite3Config.pPage = va_arg(ap, void*); sqlite3GlobalConfig.pPage = va_arg(ap, void*);
sqlite3Config.szPage = va_arg(ap, int); sqlite3GlobalConfig.szPage = va_arg(ap, int);
sqlite3Config.nPage = va_arg(ap, int); sqlite3GlobalConfig.nPage = va_arg(ap, int);
break; break;
} }
#if defined(SQLITE_ENABLE_MEMSYS3) || defined(SQLITE_ENABLE_MEMSYS5) #if defined(SQLITE_ENABLE_MEMSYS3) || defined(SQLITE_ENABLE_MEMSYS5)
case SQLITE_CONFIG_HEAP: { case SQLITE_CONFIG_HEAP: {
/* Designate a buffer for heap memory space */ /* Designate a buffer for heap memory space */
sqlite3Config.pHeap = va_arg(ap, void*); sqlite3GlobalConfig.pHeap = va_arg(ap, void*);
sqlite3Config.nHeap = va_arg(ap, int); sqlite3GlobalConfig.nHeap = va_arg(ap, int);
sqlite3Config.mnReq = 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 /* 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 NULL pointers too. This will cause the malloc to go
** back to its default implementation when sqlite3_initialize() is ** back to its default implementation when sqlite3_initialize() is
** run. ** run.
*/ */
memset(&sqlite3Config.m, 0, sizeof(sqlite3Config.m)); memset(&sqlite3GlobalConfig.m, 0, sizeof(sqlite3GlobalConfig.m));
}else{ }else{
/* The heap pointer is not NULL, then install one of the /* The heap pointer is not NULL, then install one of the
** mem5.c/mem3.c methods. If neither ENABLE_MEMSYS3 nor ** 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. ** the default case and return an error.
*/ */
#ifdef SQLITE_ENABLE_MEMSYS3 #ifdef SQLITE_ENABLE_MEMSYS3
sqlite3Config.m = *sqlite3MemGetMemsys3(); sqlite3GlobalConfig.m = *sqlite3MemGetMemsys3();
#endif #endif
#ifdef SQLITE_ENABLE_MEMSYS5 #ifdef SQLITE_ENABLE_MEMSYS5
sqlite3Config.m = *sqlite3MemGetMemsys5(); sqlite3GlobalConfig.m = *sqlite3MemGetMemsys5();
#endif #endif
} }
break; break;
@@ -326,15 +334,15 @@ int sqlite3_config(int op, ...){
#if defined(SQLITE_ENABLE_MEMSYS6) #if defined(SQLITE_ENABLE_MEMSYS6)
case SQLITE_CONFIG_CHUNKALLOC: { case SQLITE_CONFIG_CHUNKALLOC: {
sqlite3Config.nSmall = va_arg(ap, int); sqlite3GlobalConfig.nSmall = va_arg(ap, int);
sqlite3Config.m = *sqlite3MemGetMemsys6(); sqlite3GlobalConfig.m = *sqlite3MemGetMemsys6();
break; break;
} }
#endif #endif
case SQLITE_CONFIG_LOOKASIDE: { case SQLITE_CONFIG_LOOKASIDE: {
sqlite3Config.szLookaside = va_arg(ap, int); sqlite3GlobalConfig.szLookaside = va_arg(ap, int);
sqlite3Config.nLookaside = va_arg(ap, int); sqlite3GlobalConfig.nLookaside = va_arg(ap, int);
break; break;
} }
@@ -1445,7 +1453,7 @@ static int openDatabase(
/* Allocate the sqlite data structure */ /* Allocate the sqlite data structure */
db = sqlite3MallocZero( sizeof(sqlite3) ); db = sqlite3MallocZero( sizeof(sqlite3) );
if( db==0 ) goto opendb_out; if( db==0 ) goto opendb_out;
if( sqlite3Config.bFullMutex && isThreadsafe ){ if( sqlite3GlobalConfig.bFullMutex && isThreadsafe ){
db->mutex = sqlite3MutexAlloc(SQLITE_MUTEX_RECURSIVE); db->mutex = sqlite3MutexAlloc(SQLITE_MUTEX_RECURSIVE);
if( db->mutex==0 ){ if( db->mutex==0 ){
sqlite3_free(db); sqlite3_free(db);
@@ -1598,11 +1606,11 @@ static int openDatabase(
#endif #endif
/* Enable the lookaside-malloc subsystem */ /* Enable the lookaside-malloc subsystem */
setupLookaside(db, 0, sqlite3Config.szLookaside, sqlite3Config.nLookaside); setupLookaside(db, 0, sqlite3GlobalConfig.szLookaside, sqlite3GlobalConfig.nLookaside);
opendb_out: opendb_out:
if( db ){ 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); sqlite3_mutex_leave(db->mutex);
} }
rc = sqlite3_errcode(db); rc = sqlite3_errcode(db);

View File

@@ -12,7 +12,7 @@
** **
** Memory allocation functions used throughout sqlite. ** 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 "sqliteInt.h"
#include <stdarg.h> #include <stdarg.h>
@@ -92,8 +92,8 @@ static struct {
int alarmBusy; int alarmBusy;
/* /*
** Pointers to the end of sqlite3Config.pScratch and ** Pointers to the end of sqlite3GlobalConfig.pScratch and
** sqlite3Config.pPage to a block of memory that records ** sqlite3GlobalConfig.pPage to a block of memory that records
** which pages are available. ** which pages are available.
*/ */
u32 *aScratchFree; u32 *aScratchFree;
@@ -108,49 +108,49 @@ static struct {
** Initialize the memory allocation subsystem. ** Initialize the memory allocation subsystem.
*/ */
int sqlite3MallocInit(void){ int sqlite3MallocInit(void){
if( sqlite3Config.m.xMalloc==0 ){ if( sqlite3GlobalConfig.m.xMalloc==0 ){
sqlite3MemSetDefault(); sqlite3MemSetDefault();
} }
memset(&mem0, 0, sizeof(mem0)); memset(&mem0, 0, sizeof(mem0));
if( sqlite3Config.bCoreMutex ){ if( sqlite3GlobalConfig.bCoreMutex ){
mem0.mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MEM); mem0.mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MEM);
} }
if( sqlite3Config.pScratch && sqlite3Config.szScratch>=100 if( sqlite3GlobalConfig.pScratch && sqlite3GlobalConfig.szScratch>=100
&& sqlite3Config.nScratch>=0 ){ && sqlite3GlobalConfig.nScratch>=0 ){
int i; int i;
sqlite3Config.szScratch -= 4; sqlite3GlobalConfig.szScratch -= 4;
mem0.aScratchFree = (u32*)&((char*)sqlite3Config.pScratch) mem0.aScratchFree = (u32*)&((char*)sqlite3GlobalConfig.pScratch)
[sqlite3Config.szScratch*sqlite3Config.nScratch]; [sqlite3GlobalConfig.szScratch*sqlite3GlobalConfig.nScratch];
for(i=0; i<sqlite3Config.nScratch; i++){ mem0.aScratchFree[i] = i; } for(i=0; i<sqlite3GlobalConfig.nScratch; i++){ mem0.aScratchFree[i] = i; }
mem0.nScratchFree = sqlite3Config.nScratch; mem0.nScratchFree = sqlite3GlobalConfig.nScratch;
}else{ }else{
sqlite3Config.pScratch = 0; sqlite3GlobalConfig.pScratch = 0;
sqlite3Config.szScratch = 0; sqlite3GlobalConfig.szScratch = 0;
} }
if( sqlite3Config.pPage && sqlite3Config.szPage>=512 if( sqlite3GlobalConfig.pPage && sqlite3GlobalConfig.szPage>=512
&& sqlite3Config.nPage>=1 ){ && sqlite3GlobalConfig.nPage>=1 ){
int i; int i;
int overhead; int overhead;
int sz = sqlite3Config.szPage; int sz = sqlite3GlobalConfig.szPage;
int n = sqlite3Config.nPage; int n = sqlite3GlobalConfig.nPage;
overhead = (4*n + sz - 1)/sz; overhead = (4*n + sz - 1)/sz;
sqlite3Config.nPage -= overhead; sqlite3GlobalConfig.nPage -= overhead;
mem0.aPageFree = (u32*)&((char*)sqlite3Config.pPage) mem0.aPageFree = (u32*)&((char*)sqlite3GlobalConfig.pPage)
[sqlite3Config.szPage*sqlite3Config.nPage]; [sqlite3GlobalConfig.szPage*sqlite3GlobalConfig.nPage];
for(i=0; i<sqlite3Config.nPage; i++){ mem0.aPageFree[i] = i; } for(i=0; i<sqlite3GlobalConfig.nPage; i++){ mem0.aPageFree[i] = i; }
mem0.nPageFree = sqlite3Config.nPage; mem0.nPageFree = sqlite3GlobalConfig.nPage;
}else{ }else{
sqlite3Config.pPage = 0; sqlite3GlobalConfig.pPage = 0;
sqlite3Config.szPage = 0; sqlite3GlobalConfig.szPage = 0;
} }
return sqlite3Config.m.xInit(sqlite3Config.m.pAppData); return sqlite3GlobalConfig.m.xInit(sqlite3GlobalConfig.m.pAppData);
} }
/* /*
** Deinitialize the memory allocation subsystem. ** Deinitialize the memory allocation subsystem.
*/ */
void sqlite3MallocEnd(void){ void sqlite3MallocEnd(void){
sqlite3Config.m.xShutdown(sqlite3Config.m.pAppData); sqlite3GlobalConfig.m.xShutdown(sqlite3GlobalConfig.m.pAppData);
memset(&mem0, 0, sizeof(mem0)); memset(&mem0, 0, sizeof(mem0));
} }
@@ -220,7 +220,7 @@ static int mallocWithAlarm(int n, void **pp){
int nFull; int nFull;
void *p; void *p;
assert( sqlite3_mutex_held(mem0.mutex) ); assert( sqlite3_mutex_held(mem0.mutex) );
nFull = sqlite3Config.m.xRoundup(n); nFull = sqlite3GlobalConfig.m.xRoundup(n);
sqlite3StatusSet(SQLITE_STATUS_MALLOC_SIZE, n); sqlite3StatusSet(SQLITE_STATUS_MALLOC_SIZE, n);
if( mem0.alarmCallback!=0 ){ if( mem0.alarmCallback!=0 ){
int nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED); int nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED);
@@ -228,10 +228,10 @@ static int mallocWithAlarm(int n, void **pp){
sqlite3MallocAlarm(nFull); sqlite3MallocAlarm(nFull);
} }
} }
p = sqlite3Config.m.xMalloc(nFull); p = sqlite3GlobalConfig.m.xMalloc(nFull);
if( p==0 && mem0.alarmCallback ){ if( p==0 && mem0.alarmCallback ){
sqlite3MallocAlarm(nFull); sqlite3MallocAlarm(nFull);
p = sqlite3Config.m.xMalloc(nFull); p = sqlite3GlobalConfig.m.xMalloc(nFull);
} }
if( p ){ if( p ){
nFull = sqlite3MallocSize(p); nFull = sqlite3MallocSize(p);
@@ -249,12 +249,12 @@ void *sqlite3Malloc(int n){
void *p; void *p;
if( n<=0 ){ if( n<=0 ){
p = 0; p = 0;
}else if( sqlite3Config.bMemstat ){ }else if( sqlite3GlobalConfig.bMemstat ){
sqlite3_mutex_enter(mem0.mutex); sqlite3_mutex_enter(mem0.mutex);
mallocWithAlarm(n, &p); mallocWithAlarm(n, &p);
sqlite3_mutex_leave(mem0.mutex); sqlite3_mutex_leave(mem0.mutex);
}else{ }else{
p = sqlite3Config.m.xMalloc(n); p = sqlite3GlobalConfig.m.xMalloc(n);
} }
return p; return p;
} }
@@ -302,7 +302,7 @@ void *sqlite3ScratchMalloc(int n){
assert( scratchAllocOut==0 ); assert( scratchAllocOut==0 );
#endif #endif
if( sqlite3Config.szScratch<n ){ if( sqlite3GlobalConfig.szScratch<n ){
goto scratch_overflow; goto scratch_overflow;
}else{ }else{
sqlite3_mutex_enter(mem0.mutex); sqlite3_mutex_enter(mem0.mutex);
@@ -312,11 +312,11 @@ void *sqlite3ScratchMalloc(int n){
}else{ }else{
int i; int i;
i = mem0.aScratchFree[--mem0.nScratchFree]; i = mem0.aScratchFree[--mem0.nScratchFree];
i *= sqlite3Config.szScratch; i *= sqlite3GlobalConfig.szScratch;
sqlite3StatusAdd(SQLITE_STATUS_SCRATCH_USED, 1); sqlite3StatusAdd(SQLITE_STATUS_SCRATCH_USED, 1);
sqlite3StatusSet(SQLITE_STATUS_SCRATCH_SIZE, n); sqlite3StatusSet(SQLITE_STATUS_SCRATCH_SIZE, n);
sqlite3_mutex_leave(mem0.mutex); sqlite3_mutex_leave(mem0.mutex);
p = (void*)&((char*)sqlite3Config.pScratch)[i]; p = (void*)&((char*)sqlite3GlobalConfig.pScratch)[i];
} }
} }
#if SQLITE_THREADSAFE==0 && !defined(NDEBUG) #if SQLITE_THREADSAFE==0 && !defined(NDEBUG)
@@ -326,14 +326,14 @@ void *sqlite3ScratchMalloc(int n){
return p; return p;
scratch_overflow: scratch_overflow:
if( sqlite3Config.bMemstat ){ if( sqlite3GlobalConfig.bMemstat ){
sqlite3_mutex_enter(mem0.mutex); sqlite3_mutex_enter(mem0.mutex);
sqlite3StatusSet(SQLITE_STATUS_SCRATCH_SIZE, n); sqlite3StatusSet(SQLITE_STATUS_SCRATCH_SIZE, n);
n = mallocWithAlarm(n, &p); n = mallocWithAlarm(n, &p);
if( p ) sqlite3StatusAdd(SQLITE_STATUS_SCRATCH_OVERFLOW, n); if( p ) sqlite3StatusAdd(SQLITE_STATUS_SCRATCH_OVERFLOW, n);
sqlite3_mutex_leave(mem0.mutex); sqlite3_mutex_leave(mem0.mutex);
}else{ }else{
p = sqlite3Config.m.xMalloc(n); p = sqlite3GlobalConfig.m.xMalloc(n);
} }
#if SQLITE_THREADSAFE==0 && !defined(NDEBUG) #if SQLITE_THREADSAFE==0 && !defined(NDEBUG)
scratchAllocOut = p!=0; scratchAllocOut = p!=0;
@@ -352,26 +352,26 @@ void sqlite3ScratchFree(void *p){
scratchAllocOut = 0; scratchAllocOut = 0;
#endif #endif
if( sqlite3Config.pScratch==0 if( sqlite3GlobalConfig.pScratch==0
|| p<sqlite3Config.pScratch || p<sqlite3GlobalConfig.pScratch
|| p>=(void*)mem0.aScratchFree ){ || p>=(void*)mem0.aScratchFree ){
if( sqlite3Config.bMemstat ){ if( sqlite3GlobalConfig.bMemstat ){
int iSize = sqlite3MallocSize(p); int iSize = sqlite3MallocSize(p);
sqlite3_mutex_enter(mem0.mutex); sqlite3_mutex_enter(mem0.mutex);
sqlite3StatusAdd(SQLITE_STATUS_SCRATCH_OVERFLOW, -iSize); sqlite3StatusAdd(SQLITE_STATUS_SCRATCH_OVERFLOW, -iSize);
sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, -iSize); sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, -iSize);
sqlite3Config.m.xFree(p); sqlite3GlobalConfig.m.xFree(p);
sqlite3_mutex_leave(mem0.mutex); sqlite3_mutex_leave(mem0.mutex);
}else{ }else{
sqlite3Config.m.xFree(p); sqlite3GlobalConfig.m.xFree(p);
} }
}else{ }else{
int i; int i;
i = (u8 *)p - (u8 *)sqlite3Config.pScratch; i = (u8 *)p - (u8 *)sqlite3GlobalConfig.pScratch;
i /= sqlite3Config.szScratch; i /= sqlite3GlobalConfig.szScratch;
assert( i>=0 && i<sqlite3Config.nScratch ); assert( i>=0 && i<sqlite3GlobalConfig.nScratch );
sqlite3_mutex_enter(mem0.mutex); sqlite3_mutex_enter(mem0.mutex);
assert( mem0.nScratchFree<sqlite3Config.nScratch ); assert( mem0.nScratchFree<sqlite3GlobalConfig.nScratch );
mem0.aScratchFree[mem0.nScratchFree++] = i; mem0.aScratchFree[mem0.nScratchFree++] = i;
sqlite3StatusAdd(SQLITE_STATUS_SCRATCH_USED, -1); sqlite3StatusAdd(SQLITE_STATUS_SCRATCH_USED, -1);
sqlite3_mutex_leave(mem0.mutex); sqlite3_mutex_leave(mem0.mutex);
@@ -392,7 +392,7 @@ void *sqlite3PageMalloc(int n){
assert( (n & (n-1))==0 ); assert( (n & (n-1))==0 );
assert( n>=512 && n<=32768 ); assert( n>=512 && n<=32768 );
if( sqlite3Config.szPage<n ){ if( sqlite3GlobalConfig.szPage<n ){
goto page_overflow; goto page_overflow;
}else{ }else{
sqlite3_mutex_enter(mem0.mutex); sqlite3_mutex_enter(mem0.mutex);
@@ -403,57 +403,57 @@ void *sqlite3PageMalloc(int n){
int i; int i;
i = mem0.aPageFree[--mem0.nPageFree]; i = mem0.aPageFree[--mem0.nPageFree];
sqlite3_mutex_leave(mem0.mutex); sqlite3_mutex_leave(mem0.mutex);
i *= sqlite3Config.szPage; i *= sqlite3GlobalConfig.szPage;
sqlite3StatusSet(SQLITE_STATUS_PAGECACHE_SIZE, n); sqlite3StatusSet(SQLITE_STATUS_PAGECACHE_SIZE, n);
sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_USED, 1); sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_USED, 1);
p = (void*)&((char*)sqlite3Config.pPage)[i]; p = (void*)&((char*)sqlite3GlobalConfig.pPage)[i];
} }
} }
return p; return p;
page_overflow: page_overflow:
if( sqlite3Config.bMemstat ){ if( sqlite3GlobalConfig.bMemstat ){
sqlite3_mutex_enter(mem0.mutex); sqlite3_mutex_enter(mem0.mutex);
sqlite3StatusSet(SQLITE_STATUS_PAGECACHE_SIZE, n); sqlite3StatusSet(SQLITE_STATUS_PAGECACHE_SIZE, n);
n = mallocWithAlarm(n, &p); n = mallocWithAlarm(n, &p);
if( p ) sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_OVERFLOW, n); if( p ) sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_OVERFLOW, n);
sqlite3_mutex_leave(mem0.mutex); sqlite3_mutex_leave(mem0.mutex);
}else{ }else{
p = sqlite3Config.m.xMalloc(n); p = sqlite3GlobalConfig.m.xMalloc(n);
} }
return p; return p;
} }
void sqlite3PageFree(void *p){ void sqlite3PageFree(void *p){
if( p ){ if( p ){
if( sqlite3Config.pPage==0 if( sqlite3GlobalConfig.pPage==0
|| p<sqlite3Config.pPage || p<sqlite3GlobalConfig.pPage
|| p>=(void*)mem0.aPageFree ){ || p>=(void*)mem0.aPageFree ){
/* In this case, the page allocation was obtained from a regular /* In this case, the page allocation was obtained from a regular
** call to sqlite3_mem_methods.xMalloc() (a page-cache-memory ** call to sqlite3_mem_methods.xMalloc() (a page-cache-memory
** "overflow"). Free the block with sqlite3_mem_methods.xFree(). ** "overflow"). Free the block with sqlite3_mem_methods.xFree().
*/ */
if( sqlite3Config.bMemstat ){ if( sqlite3GlobalConfig.bMemstat ){
int iSize = sqlite3MallocSize(p); int iSize = sqlite3MallocSize(p);
sqlite3_mutex_enter(mem0.mutex); sqlite3_mutex_enter(mem0.mutex);
sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_OVERFLOW, -iSize); sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_OVERFLOW, -iSize);
sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, -iSize); sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, -iSize);
sqlite3Config.m.xFree(p); sqlite3GlobalConfig.m.xFree(p);
sqlite3_mutex_leave(mem0.mutex); sqlite3_mutex_leave(mem0.mutex);
}else{ }else{
sqlite3Config.m.xFree(p); sqlite3GlobalConfig.m.xFree(p);
} }
}else{ }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 ** 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. ** in the mem0.aPageFree[] array.
*/ */
int i; int i;
i = (u8 *)p - (u8 *)sqlite3Config.pPage; i = (u8 *)p - (u8 *)sqlite3GlobalConfig.pPage;
i /= sqlite3Config.szPage; i /= sqlite3GlobalConfig.szPage;
assert( i>=0 && i<sqlite3Config.nPage ); assert( i>=0 && i<sqlite3GlobalConfig.nPage );
sqlite3_mutex_enter(mem0.mutex); sqlite3_mutex_enter(mem0.mutex);
assert( mem0.nPageFree<sqlite3Config.nPage ); assert( mem0.nPageFree<sqlite3GlobalConfig.nPage );
mem0.aPageFree[mem0.nPageFree++] = i; mem0.aPageFree[mem0.nPageFree++] = i;
sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_USED, -1); sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_USED, -1);
sqlite3_mutex_leave(mem0.mutex); sqlite3_mutex_leave(mem0.mutex);
@@ -480,13 +480,13 @@ static int isLookaside(sqlite3 *db, void *p){
** sqlite3Malloc() or sqlite3_malloc(). ** sqlite3Malloc() or sqlite3_malloc().
*/ */
int sqlite3MallocSize(void *p){ int sqlite3MallocSize(void *p){
return sqlite3Config.m.xSize(p); return sqlite3GlobalConfig.m.xSize(p);
} }
int sqlite3DbMallocSize(sqlite3 *db, void *p){ int sqlite3DbMallocSize(sqlite3 *db, void *p){
if( isLookaside(db, p) ){ if( isLookaside(db, p) ){
return db->lookaside.sz; return db->lookaside.sz;
}else{ }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){ void sqlite3_free(void *p){
if( p==0 ) return; if( p==0 ) return;
if( sqlite3Config.bMemstat ){ if( sqlite3GlobalConfig.bMemstat ){
sqlite3_mutex_enter(mem0.mutex); sqlite3_mutex_enter(mem0.mutex);
sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, -sqlite3MallocSize(p)); sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, -sqlite3MallocSize(p));
sqlite3Config.m.xFree(p); sqlite3GlobalConfig.m.xFree(p);
sqlite3_mutex_leave(mem0.mutex); sqlite3_mutex_leave(mem0.mutex);
}else{ }else{
sqlite3Config.m.xFree(p); sqlite3GlobalConfig.m.xFree(p);
} }
} }
@@ -534,10 +534,10 @@ void *sqlite3Realloc(void *pOld, int nBytes){
return 0; return 0;
} }
nOld = sqlite3MallocSize(pOld); nOld = sqlite3MallocSize(pOld);
if( sqlite3Config.bMemstat ){ if( sqlite3GlobalConfig.bMemstat ){
sqlite3_mutex_enter(mem0.mutex); sqlite3_mutex_enter(mem0.mutex);
sqlite3StatusSet(SQLITE_STATUS_MALLOC_SIZE, nBytes); sqlite3StatusSet(SQLITE_STATUS_MALLOC_SIZE, nBytes);
nNew = sqlite3Config.m.xRoundup(nBytes); nNew = sqlite3GlobalConfig.m.xRoundup(nBytes);
if( nOld==nNew ){ if( nOld==nNew ){
pNew = pOld; pNew = pOld;
}else{ }else{
@@ -545,10 +545,10 @@ void *sqlite3Realloc(void *pOld, int nBytes){
mem0.alarmThreshold ){ mem0.alarmThreshold ){
sqlite3MallocAlarm(nNew-nOld); sqlite3MallocAlarm(nNew-nOld);
} }
pNew = sqlite3Config.m.xRealloc(pOld, nNew); pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
if( pNew==0 && mem0.alarmCallback ){ if( pNew==0 && mem0.alarmCallback ){
sqlite3MallocAlarm(nBytes); sqlite3MallocAlarm(nBytes);
pNew = sqlite3Config.m.xRealloc(pOld, nNew); pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
} }
if( pNew ){ if( pNew ){
nNew = sqlite3MallocSize(pNew); nNew = sqlite3MallocSize(pNew);
@@ -557,7 +557,7 @@ void *sqlite3Realloc(void *pOld, int nBytes){
} }
sqlite3_mutex_leave(mem0.mutex); sqlite3_mutex_leave(mem0.mutex);
}else{ }else{
pNew = sqlite3Config.m.xRealloc(pOld, nBytes); pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nBytes);
} }
return pNew; return pNew;
} }

View File

@@ -17,7 +17,7 @@
** This file contains implementations of the low-level memory allocation ** This file contains implementations of the low-level memory allocation
** routines specified in the sqlite3_mem_methods object. ** 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" #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. ** This routine is the only routine in this file with external linkage.
** **
** Populate the low-level memory allocation function pointers in ** 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){ void sqlite3MemSetDefault(void){
sqlite3_config(SQLITE_CONFIG_MALLOC, sqlite3MemGetDefault()); sqlite3_config(SQLITE_CONFIG_MALLOC, sqlite3MemGetDefault());

View File

@@ -19,7 +19,7 @@
** This file contains implementations of the low-level memory allocation ** This file contains implementations of the low-level memory allocation
** routines specified in the sqlite3_mem_methods object. ** 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" #include "sqliteInt.h"
@@ -185,7 +185,7 @@ static int sqlite3MemSize(void *p){
** Initialize the memory allocation subsystem. ** Initialize the memory allocation subsystem.
*/ */
static int sqlite3MemInit(void *NotUsed){ static int sqlite3MemInit(void *NotUsed){
if( !sqlite3Config.bMemstat ){ if( !sqlite3GlobalConfig.bMemstat ){
/* If memory status is enabled, then the malloc.c wrapper will already /* If memory status is enabled, then the malloc.c wrapper will already
** hold the STATIC_MEM mutex when the routines here are invoked. */ ** hold the STATIC_MEM mutex when the routines here are invoked. */
mem.mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MEM); mem.mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MEM);
@@ -270,7 +270,7 @@ static void sqlite3MemFree(void *pPrior){
struct MemBlockHdr *pHdr; struct MemBlockHdr *pHdr;
void **pBt; void **pBt;
char *z; char *z;
assert( sqlite3Config.bMemstat || mem.mutex!=0 ); assert( sqlite3GlobalConfig.bMemstat || mem.mutex!=0 );
pHdr = sqlite3MemsysGetHeader(pPrior); pHdr = sqlite3MemsysGetHeader(pPrior);
pBt = (void**)pHdr; pBt = (void**)pHdr;
pBt -= pHdr->nBacktraceSlots; pBt -= pHdr->nBacktraceSlots;
@@ -340,7 +340,7 @@ const sqlite3_mem_methods *sqlite3MemGetDefault(void){
/* /*
** Populate the low-level memory allocation function pointers in ** 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){ void sqlite3MemSetDefault(void){
sqlite3_config(SQLITE_CONFIG_MALLOC, sqlite3MemGetDefault()); sqlite3_config(SQLITE_CONFIG_MALLOC, sqlite3MemGetDefault());

View File

@@ -23,7 +23,7 @@
** This version of the memory allocation subsystem is included ** This version of the memory allocation subsystem is included
** in the build only if SQLITE_ENABLE_MEMSYS3 is defined. ** 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" #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 ** 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 ** will already be held (obtained by code in malloc.c) if
** sqlite3Config.bMemStat is true. ** sqlite3GlobalConfig.bMemStat is true.
*/ */
static void memsys3Enter(void){ 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); mem3.mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MEM);
} }
sqlite3_mutex_enter(mem3.mutex); sqlite3_mutex_enter(mem3.mutex);
@@ -550,14 +550,14 @@ void *memsys3Realloc(void *pPrior, int nBytes){
** Initialize this module. ** Initialize this module.
*/ */
static int memsys3Init(void *NotUsed){ static int memsys3Init(void *NotUsed){
if( !sqlite3Config.pHeap ){ if( !sqlite3GlobalConfig.pHeap ){
return SQLITE_ERROR; return SQLITE_ERROR;
} }
/* Store a pointer to the memory block in global structure mem3. */ /* Store a pointer to the memory block in global structure mem3. */
assert( sizeof(Mem3Block)==8 ); assert( sizeof(Mem3Block)==8 );
mem3.aPool = (Mem3Block *)sqlite3Config.pHeap; mem3.aPool = (Mem3Block *)sqlite3GlobalConfig.pHeap;
mem3.nPool = (sqlite3Config.nHeap / sizeof(Mem3Block)) - 2; mem3.nPool = (sqlite3GlobalConfig.nHeap / sizeof(Mem3Block)) - 2;
/* Initialize the master block. */ /* Initialize the master block. */
mem3.szMaster = mem3.nPool; mem3.szMaster = mem3.nPool;
@@ -659,7 +659,7 @@ void sqlite3Memsys3Dump(const char *zFilename){
** linkage. ** linkage.
** **
** Populate the low-level memory allocation function pointers in ** 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. ** arguments specify the block of memory to manage.
** **
** This routine is only called by sqlite3_config(), and therefore ** This routine is only called by sqlite3_config(), and therefore

View File

@@ -23,7 +23,7 @@
** This version of the memory allocation subsystem is included ** This version of the memory allocation subsystem is included
** in the build only if SQLITE_ENABLE_MEMSYS5 is defined. ** 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" #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 ** 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 ** will already be held (obtained by code in malloc.c) if
** sqlite3Config.bMemStat is true. ** sqlite3GlobalConfig.bMemStat is true.
*/ */
static void memsys5Enter(void){ 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); mem5.mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MEM);
} }
sqlite3_mutex_enter(mem5.mutex); sqlite3_mutex_enter(mem5.mutex);
@@ -406,8 +406,8 @@ static int memsys5Log(int iValue){
*/ */
static int memsys5Init(void *NotUsed){ static int memsys5Init(void *NotUsed){
int ii; int ii;
int nByte = sqlite3Config.nHeap; int nByte = sqlite3GlobalConfig.nHeap;
u8 *zByte = (u8 *)sqlite3Config.pHeap; u8 *zByte = (u8 *)sqlite3GlobalConfig.pHeap;
int nMinLog; /* Log of minimum allocation size in bytes*/ int nMinLog; /* Log of minimum allocation size in bytes*/
int iOffset; int iOffset;
@@ -415,7 +415,7 @@ static int memsys5Init(void *NotUsed){
return SQLITE_ERROR; return SQLITE_ERROR;
} }
nMinLog = memsys5Log(sqlite3Config.mnReq); nMinLog = memsys5Log(sqlite3GlobalConfig.mnReq);
mem5.nAtom = (1<<nMinLog); mem5.nAtom = (1<<nMinLog);
while( sizeof(Mem5Link)>mem5.nAtom ){ while( sizeof(Mem5Link)>mem5.nAtom ){
mem5.nAtom = mem5.nAtom << 1; mem5.nAtom = mem5.nAtom << 1;

View File

@@ -32,7 +32,7 @@
** fragmentation. On some systems, heap fragmentation can cause a ** fragmentation. On some systems, heap fragmentation can cause a
** significant real-time slowdown. ** 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 #ifdef SQLITE_ENABLE_MEMSYS6
@@ -456,10 +456,10 @@ static int memsys6Roundup(int n){
} }
static int memsys6Init(void *pCtx){ static int memsys6Init(void *pCtx){
u8 bMemstat = sqlite3Config.bMemstat; u8 bMemstat = sqlite3GlobalConfig.bMemstat;
mem6.nMinAlloc = (1 << LOG2_MINALLOC); mem6.nMinAlloc = (1 << LOG2_MINALLOC);
mem6.pChunk = 0; mem6.pChunk = 0;
mem6.nThreshold = sqlite3Config.nSmall; mem6.nThreshold = sqlite3GlobalConfig.nSmall;
if( mem6.nThreshold<=0 ){ if( mem6.nThreshold<=0 ){
mem6.nThreshold = SMALL_MALLOC_DEFAULT_THRESHOLD; mem6.nThreshold = SMALL_MALLOC_DEFAULT_THRESHOLD;
} }

View File

@@ -19,7 +19,7 @@
** implementation is suitable for testing. ** implementation is suitable for testing.
** debugging purposes ** 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" #include "sqliteInt.h"
@@ -29,17 +29,17 @@
*/ */
int sqlite3MutexInit(void){ int sqlite3MutexInit(void){
int rc = SQLITE_OK; int rc = SQLITE_OK;
if( sqlite3Config.bCoreMutex ){ if( sqlite3GlobalConfig.bCoreMutex ){
if( !sqlite3Config.mutex.xMutexAlloc ){ if( !sqlite3GlobalConfig.mutex.xMutexAlloc ){
/* If the xMutexAlloc method has not been set, then the user did not /* If the xMutexAlloc method has not been set, then the user did not
** install a mutex implementation via sqlite3_config() prior to ** install a mutex implementation via sqlite3_config() prior to
** sqlite3_initialize() being called. This block copies pointers 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 ** The danger is that although sqlite3_config() is not a threadsafe
** API, sqlite3_initialize() is, and so multiple threads may be ** API, sqlite3_initialize() is, and so multiple threads may be
** attempting to run this function simultaneously. To guard write ** 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. ** is obtained before modifying it.
*/ */
sqlite3_mutex_methods *p = sqlite3DefaultMutex(); sqlite3_mutex_methods *p = sqlite3DefaultMutex();
@@ -50,16 +50,16 @@ int sqlite3MutexInit(void){
pMaster = p->xMutexAlloc(SQLITE_MUTEX_STATIC_MASTER); pMaster = p->xMutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
assert(pMaster); assert(pMaster);
p->xMutexEnter(pMaster); p->xMutexEnter(pMaster);
assert( sqlite3Config.mutex.xMutexAlloc==0 assert( sqlite3GlobalConfig.mutex.xMutexAlloc==0
|| sqlite3Config.mutex.xMutexAlloc==p->xMutexAlloc || sqlite3GlobalConfig.mutex.xMutexAlloc==p->xMutexAlloc
); );
if( !sqlite3Config.mutex.xMutexAlloc ){ if( !sqlite3GlobalConfig.mutex.xMutexAlloc ){
sqlite3Config.mutex = *p; sqlite3GlobalConfig.mutex = *p;
} }
p->xMutexLeave(pMaster); p->xMutexLeave(pMaster);
} }
}else{ }else{
rc = sqlite3Config.mutex.xMutexInit(); rc = sqlite3GlobalConfig.mutex.xMutexInit();
} }
} }
@@ -72,7 +72,7 @@ int sqlite3MutexInit(void){
*/ */
int sqlite3MutexEnd(void){ int sqlite3MutexEnd(void){
int rc = SQLITE_OK; int rc = SQLITE_OK;
rc = sqlite3Config.mutex.xMutexEnd(); rc = sqlite3GlobalConfig.mutex.xMutexEnd();
return rc; return rc;
} }
@@ -83,14 +83,14 @@ sqlite3_mutex *sqlite3_mutex_alloc(int id){
#ifndef SQLITE_OMIT_AUTOINIT #ifndef SQLITE_OMIT_AUTOINIT
if( sqlite3_initialize() ) return 0; if( sqlite3_initialize() ) return 0;
#endif #endif
return sqlite3Config.mutex.xMutexAlloc(id); return sqlite3GlobalConfig.mutex.xMutexAlloc(id);
} }
sqlite3_mutex *sqlite3MutexAlloc(int id){ sqlite3_mutex *sqlite3MutexAlloc(int id){
if( !sqlite3Config.bCoreMutex ){ if( !sqlite3GlobalConfig.bCoreMutex ){
return 0; 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){ void sqlite3_mutex_free(sqlite3_mutex *p){
if( 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){ void sqlite3_mutex_enter(sqlite3_mutex *p){
if( 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 sqlite3_mutex_try(sqlite3_mutex *p){
int rc = SQLITE_OK; int rc = SQLITE_OK;
if( p ){ if( p ){
return sqlite3Config.mutex.xMutexTry(p); return sqlite3GlobalConfig.mutex.xMutexTry(p);
} }
return rc; return rc;
} }
@@ -132,7 +132,7 @@ int sqlite3_mutex_try(sqlite3_mutex *p){
*/ */
void sqlite3_mutex_leave(sqlite3_mutex *p){ void sqlite3_mutex_leave(sqlite3_mutex *p){
if( 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. ** intended for use inside assert() statements.
*/ */
int sqlite3_mutex_held(sqlite3_mutex *p){ 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){ int sqlite3_mutex_notheld(sqlite3_mutex *p){
return p==0 || sqlite3Config.mutex.xMutexNotheld(p); return p==0 || sqlite3GlobalConfig.mutex.xMutexNotheld(p);
} }
#endif #endif

View File

@@ -11,7 +11,7 @@
************************************************************************* *************************************************************************
** This file implements that page cache. ** 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" #include "sqliteInt.h"
@@ -606,7 +606,7 @@ static int pcacheRecycleOrAlloc(PCache *pCache, PgHdr **ppPage){
int sqlite3PcacheInitialize(void){ int sqlite3PcacheInitialize(void){
assert( pcache.isInit==0 ); assert( pcache.isInit==0 );
memset(&pcache, 0, sizeof(pcache)); memset(&pcache, 0, sizeof(pcache));
if( sqlite3Config.bCoreMutex ){ if( sqlite3GlobalConfig.bCoreMutex ){
/* No need to check the return value of sqlite3_mutex_alloc(). /* No need to check the return value of sqlite3_mutex_alloc().
** Allocating a static mutex cannot fail. ** Allocating a static mutex cannot fail.
*/ */

View File

@@ -30,7 +30,7 @@
** the version number) and changes its name to "sqlite3.h" as ** the version number) and changes its name to "sqlite3.h" as
** part of the build process. ** 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_ #ifndef _SQLITE3_H_
#define _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); 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} <H17200> ** CAPI3REF: Status Parameters {H17250} <H17200>
** EXPERIMENTAL ** EXPERIMENTAL

View File

@@ -11,7 +11,7 @@
************************************************************************* *************************************************************************
** Internal interface definitions for SQLite. ** 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_ #ifndef _SQLITEINT_H_
#define _SQLITEINT_H_ #define _SQLITEINT_H_
@@ -441,6 +441,16 @@ struct BusyHandler {
*/ */
#define SQLITE_DYNAMIC ((sqlite3_destructor_type)sqlite3DbFree) #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 ** Forward references to structures
*/ */
@@ -2317,8 +2327,8 @@ int sqlite3ValueFromExpr(sqlite3 *, Expr *, u8, u8, sqlite3_value **);
void sqlite3ValueApplyAffinity(sqlite3_value *, u8, u8); void sqlite3ValueApplyAffinity(sqlite3_value *, u8, u8);
#ifndef SQLITE_AMALGAMATION #ifndef SQLITE_AMALGAMATION
extern const unsigned char sqlite3UpperToLower[]; extern const unsigned char sqlite3UpperToLower[];
extern struct Sqlite3Config sqlite3Config; extern SQLITE_WSD struct Sqlite3Config sqlite3Config;
extern FuncDefHash sqlite3GlobalFunctions; extern SQLITE_WSD FuncDefHash sqlite3GlobalFunctions;
#endif #endif
void sqlite3RootPageMoved(Db*, int, int); void sqlite3RootPageMoved(Db*, int, int);
void sqlite3Reindex(Parse*, Token*, Token*); void sqlite3Reindex(Parse*, Token*, Token*);

87
src/test_wsd.c Normal file
View File

@@ -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; i<sizeof(void*); i++){
iHash = (iHash<<3) + ((unsigned char *)K)[i];
}
iHash = iHash%PLS_HASHSIZE;
/* Search the hash table for K. */
for(pVar=pGlobal->aData[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