Continuing work on adding full support for the SQLITE_OMIT_WSD

compile-time option. (CVS 5658)

FossilOrigin-Name: ef26ea5c46d3915d206f8ff7f82a24f4c8955f1f
This commit is contained in:
drh 2008-09-02 00:52:52 +00:00
parent 171fa295c3
commit 78f82d1e6c
13 changed files with 252 additions and 145 deletions

View File

@ -1,5 +1,5 @@
C Add\sdefine\sfor\sINVALID_FILE_ATTRIBUTES\sif\sit\sis\snot\salready\sdefined,\sas\ssome\solder\sWindows\scompilers\sdo\snot\sdefine\sit.\s(CVS\s5657)
D 2008-09-01T22:15:19
C Continuing\swork\son\sadding\sfull\ssupport\sfor\sthe\sSQLITE_OMIT_WSD\r\ncompile-time\soption.\s(CVS\s5658)
D 2008-09-02T00:52:52
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
F Makefile.in 689e14735f862a5553bceef206d8c13e29504e44
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@ -97,7 +97,7 @@ F src/attach.c db3f4a60538733c1e4dcb9d0217a6e0d6ccd615b
F src/auth.c c8b2ab5c8bad4bd90ed7c294694f48269162c627
F src/bitvec.c 95c86bd18d8fedf0533f5af196192546e10a7e7d
F src/btmutex.c 709cad2cdca0afd013f0f612363810e53f59ec53
F src/btree.c deb7e145e4e287763e317ff36a805826f5ed2e56
F src/btree.c a12044e500d4cd8d030e6ce9d59855ada7008564
F src/btree.h 6371c5e599fab391a150c96afbc10062b276d107
F src/btreeInt.h ab18c7b4980314e9e4b402e5dcde09f3c2545576
F src/build.c 160c71acca8f643f436ed6c1ee2f684c88df4dfe
@ -106,7 +106,7 @@ F src/complete.c cb14e06dbe79dee031031f0d9e686ff306afe07c
F src/date.c 6609557446f2d6788e64e18c09e03fdaf4dd55cc
F src/delete.c bae6684aa02e1f7cf6328023157c91d9cf94200b
F src/expr.c 6413795aa13ceb05994e6b2b453a77df3b892e7b
F src/fault.c 3638519d1e0b82bccfafcb9f5ff491918b28f8e1
F src/fault.c dc88c821842157460750d2d61a8a8b4197d047ff
F src/func.c c02615eafbe415d32d02499d31bbb1f72f052868
F src/global.c 9ced7c26127f04fb4baaebed1f5bf6d7063b089f
F src/hash.c eb64e48f3781100e5934f759fbe72a63a8fe78cb
@ -115,7 +115,7 @@ F src/hwtime.h 4a1d45f4cae1f402ea19686acf24acf4f0cb53cb
F src/insert.c 110cca7845ed5a66c08fdd413b02e706ae34455f
F src/journal.c cffd2cd214e58c0e99c3ff632b3bee6c7cbb260e
F src/legacy.c aac57bd984e666059011ea01ec4383892a253be3
F src/loadext.c eb1fe4f44d7c8ff53fc0c6a4388ab79fbd34cd64
F src/loadext.c 6581a5bbc4d74fcd46dbbcfd695a6a5417f778a2
F src/main.c 47ce9da041a5aa9a1adadd92be795bde887e2dc9
F src/malloc.c 2ffd62fb4a299cf3945e50a4c53d27ec1813f8b1
F src/mem1.c 5a529ff121c55ab067be14de00f86f6dcc4f4fb9
@ -140,21 +140,21 @@ F src/pager.h c45380ca9d0933ea5bc4ecb3a43958b6d2ec5a9c
F src/parse.y d0f76d2cb8d6883d5600dc20beb961a6022b94b8
F src/pcache.c 200de27e85b123840a30a11f5055544e06845569
F src/pcache.h 53730c33310cdf7a5c94e8333c853d59a3b30226
F src/pragma.c f5b271b090af7fcedd308d7c5807a5503f7a853d
F src/pragma.c 9d8127ac1527617cfb31392cd8832bb2c9a02115
F src/prepare.c c197041e0c4770672cda75e6bfe10242f885e510
F src/printf.c 785f87120589c1db672e37c6eb1087c456e6f84d
F src/random.c 5c754319d38abdd6acd74601ee0105504adc508a
F src/random.c 11bbdf7def3746a762fbdb56c9d04648135ad6d8
F src/resolve.c a6abf83125bce0c80ba04acc27c3565155ad305c
F src/select.c eec7c5f28a0c75fdd8500630435af176bba73219
F src/shell.c d83b578a8ccdd3e0e7fef4388a0887ce9f810967
F src/sqlite.h.in 81c37dcbd5bb1b1a5f6cdd96a67e82e6a0c3d1da
F src/sqlite3ext.h 1e3887c9bd3ae66cb599e922824b04cd0d0f2c3e
F src/sqliteInt.h 4ac6c25d217307c1d95800ee50b29292806693e0
F src/sqliteInt.h 796e1b04a34462a451cd1672b68a1820c2b9c70a
F src/sqliteLimit.h f435e728c6b620ef7312814d660a81f9356eb5c8
F src/status.c 8caa772cd9310bc297280f7cf0ede4d69ed5b801
F src/status.c 237b193efae0cf6ac3f0817a208de6c6c6ef6d76
F src/table.c 22744786199c9195720c15a7a42cb97b2e2728d8
F src/tclsqlite.c 01312c2af41189ff20335d6ac64e3dbda57e627b
F src/test1.c 1b641aca173d8dfd2faf8f28aee0a4db20ac1534
F src/test1.c 07f56e5495a2abc3ed1cec74836dedd5f829eb00
F src/test2.c eaa77124786649eedf47d3c5e94d8070c0da228f
F src/test3.c e85b7ce5c28c3ce7fbdbf7f98e1467b19786c62b
F src/test4.c 41056378671e7b00e6305fa9ac6fa27e6f96f406
@ -165,8 +165,8 @@ F src/test8.c 3637439424d0d21ff2dcf9b015c30fcc1e7bcb24
F src/test9.c 904ebe0ed1472d6bad17a81e2ecbfc20017dc237
F src/test_async.c da9f58f49faccd3a26ba89f58de125862351b6e2
F src/test_autoext.c f53b0cdf7bf5f08100009572a5d65cdb540bd0ad
F src/test_btree.c 7170e0c922ed3979f2d38f4a3f84728e5740dfc3
F src/test_config.c 224f699a34d45eb8ac5c22a7ad6cdbb8edf0ba28
F src/test_btree.c 8d5b835054f1dd15992e09864a8bc04386bab701
F src/test_config.c 9dbbe29af32ad3ff79946497f35de24981cc1ce3
F src/test_devsym.c 6012cb8e3acf812513511025a4fa5d626e0ba19b
F src/test_func.c a55c4d5479ff2eb5c0a22d4d88e9528ab59c953b
F src/test_hexio.c 2f1122aa3f012fa0142ee3c36ce5c902a70cd12f
@ -449,7 +449,7 @@ F test/pageropt.test 3ee6578891baaca967f0bd349e4abfa736229e1a
F test/pagesize.test 0d9ff3fedfce6e5ffe8fa7aca9b6d3433a2e843b
F test/pcache.test a0fc9e965d039c4de24f9af929f9a25eb8be8539
F test/permutations.test e4509095a9870ae13b6184b3b957f78675716e6f
F test/pragma.test b55931bbd5dd543e56fd942dbf4b7439619b09a6
F test/pragma.test 4461cb1004084b907dd28f9d517af7bcf8f5b35f
F test/pragma2.test 5364893491b9231dd170e3459bfc2e2342658b47
F test/printf.test 262a5acd3158f788e9bdf7f18d718f3af32ff6ef
F test/progress.test 5b075c3c790c7b2a61419bc199db87aaf48b8301 x
@ -630,7 +630,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81
F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
F tool/speedtest8.c 1dbced29de5f59ba2ebf877edcadf171540374d1
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
P 4bcaed08a1b50aef9f4f8a447a35d8678df92050
R 5a278aaa54c5ca28c8bb36a9539cf368
U shane
Z 7989bd87da9eb95ab7ab6fcd6ecbf5bb
P e0461f8755daa9f57e056810de9ea347ff8dd986
R c8df4ae84b8bc405c32994ac1b521fda
U drh
Z 207cb363f97da2fc9bf5418da8660bf8

View File

@ -1 +1 @@
e0461f8755daa9f57e056810de9ea347ff8dd986
ef26ea5c46d3915d206f8ff7f82a24f4c8955f1f

View File

@ -9,7 +9,7 @@
** May you share freely, never taking more than you give.
**
*************************************************************************
** $Id: btree.c,v 1.505 2008/09/01 18:34:20 danielk1977 Exp $
** $Id: btree.c,v 1.506 2008/09/02 00:52:52 drh Exp $
**
** This file implements a external (disk-based) database using BTrees.
** See the header comment on "btreeInt.h" for additional information.
@ -45,11 +45,11 @@ int sqlite3BtreeTrace=0; /* True to enable tracing */
** global for test builds.
*/
#ifdef SQLITE_TEST
BtShared *sqlite3SharedCacheList = 0;
int sqlite3SharedCacheEnabled = 0;
BtShared *SQLITE_WSD sqlite3SharedCacheList = 0;
SQLITE_WSD int sqlite3SharedCacheEnabled = 0;
#else
static BtShared *sqlite3SharedCacheList = 0;
static int sqlite3SharedCacheEnabled = 0;
static BtShared *SQLITE_WSD sqlite3SharedCacheList = 0;
static SQLITE_WSD int sqlite3SharedCacheEnabled = 0;
#endif
#endif /* SQLITE_OMIT_SHARED_CACHE */
@ -62,7 +62,7 @@ static int sqlite3SharedCacheEnabled = 0;
** sqlite3_open(), sqlite3_open16(), or sqlite3_open_v2().
*/
int sqlite3_enable_shared_cache(int enable){
sqlite3SharedCacheEnabled = enable;
GLOBAL(int,sqlite3SharedCacheEnabled) = enable;
return SQLITE_OK;
}
#endif
@ -1232,7 +1232,7 @@ int sqlite3BtreeOpen(
&& (db->flags & SQLITE_Vtab)==0
&& zFilename && zFilename[0]
){
if( sqlite3SharedCacheEnabled ){
if( GLOBAL(int,sqlite3SharedCacheEnabled) ){
int nFullPathname = pVfs->mxPathname+1;
char *zFullPathname = sqlite3Malloc(nFullPathname);
sqlite3_mutex *mutexShared;
@ -1245,7 +1245,7 @@ int sqlite3BtreeOpen(
sqlite3OsFullPathname(pVfs, zFilename, nFullPathname, zFullPathname);
mutexShared = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
sqlite3_mutex_enter(mutexShared);
for(pBt=sqlite3SharedCacheList; pBt; pBt=pBt->pNext){
for(pBt=GLOBAL(BtShared*,sqlite3SharedCacheList); pBt; pBt=pBt->pNext){
assert( pBt->nRef>0 );
if( 0==strcmp(zFullPathname, sqlite3PagerFilename(pBt->pPager))
&& sqlite3PagerVfs(pBt->pPager)==pVfs ){
@ -1349,8 +1349,8 @@ int sqlite3BtreeOpen(
}
}
sqlite3_mutex_enter(mutexShared);
pBt->pNext = sqlite3SharedCacheList;
sqlite3SharedCacheList = pBt;
pBt->pNext = GLOBAL(BtShared*,sqlite3SharedCacheList);
GLOBAL(BtShared*,sqlite3SharedCacheList) = pBt;
sqlite3_mutex_leave(mutexShared);
}
#endif
@ -1418,10 +1418,10 @@ static int removeFromSharingList(BtShared *pBt){
sqlite3_mutex_enter(pMaster);
pBt->nRef--;
if( pBt->nRef<=0 ){
if( sqlite3SharedCacheList==pBt ){
sqlite3SharedCacheList = pBt->pNext;
if( GLOBAL(BtShared*,sqlite3SharedCacheList)==pBt ){
GLOBAL(BtShared*,sqlite3SharedCacheList) = pBt->pNext;
}else{
pList = sqlite3SharedCacheList;
pList = GLOBAL(BtShared*,sqlite3SharedCacheList);
while( ALWAYS(pList) && pList->pNext!=pBt ){
pList=pList->pNext;
}

View File

@ -10,7 +10,7 @@
**
*************************************************************************
**
** $Id: fault.c,v 1.10 2008/06/22 12:37:58 drh Exp $
** $Id: fault.c,v 1.11 2008/09/02 00:52:52 drh Exp $
*/
/*
@ -35,10 +35,27 @@
/*
** Global variables.
*/
static struct BenignMallocHooks {
typedef struct BenignMallocHooks BenignMallocHooks;
static SQLITE_WSD struct BenignMallocHooks {
void (*xBenignBegin)(void);
void (*xBenignEnd)(void);
} hooks;
} sqlite3Hooks = { 0, 0 };
/* The "wsdHooks" macro will resolve to the appropriate BenignMallocHooks
** structure. If writable static data is unsupported on the target,
** we have to locate the state vector at run-time. In the more common
** case where writable static data is supported, wsdHooks can refer directly
** to the "sqlite3Hooks" state vector declared above.
*/
#ifdef SQLITE_OMIT_WSD
# define wsdHooksInit \
BenignMallocHooks *x = &GLOBAL(BenignMallocHooks,sqlite3Hooks)
# define wsdHooks x[0]
#else
# define wsdHooksInit
# define wsdHooks sqlite3Hooks
#endif
/*
** Register hooks to call when sqlite3BeginBenignMalloc() and
@ -48,8 +65,9 @@ void sqlite3BenignMallocHooks(
void (*xBenignBegin)(void),
void (*xBenignEnd)(void)
){
hooks.xBenignBegin = xBenignBegin;
hooks.xBenignEnd = xBenignEnd;
wsdHooksInit;
wsdHooks.xBenignBegin = xBenignBegin;
wsdHooks.xBenignEnd = xBenignEnd;
}
/*
@ -58,13 +76,15 @@ void sqlite3BenignMallocHooks(
** indicates that subsequent malloc failures are non-benign.
*/
void sqlite3BeginBenignMalloc(void){
if( hooks.xBenignBegin ){
hooks.xBenignBegin();
wsdHooksInit;
if( wsdHooks.xBenignBegin ){
wsdHooks.xBenignBegin();
}
}
void sqlite3EndBenignMalloc(void){
if( hooks.xBenignEnd ){
hooks.xBenignEnd();
wsdHooksInit;
if( wsdHooks.xBenignEnd ){
wsdHooks.xBenignEnd();
}
}

View File

@ -12,7 +12,7 @@
** This file contains code used to dynamically load extensions into
** the SQLite library.
**
** $Id: loadext.c,v 1.53 2008/08/02 03:50:39 drh Exp $
** $Id: loadext.c,v 1.54 2008/09/02 00:52:52 drh Exp $
*/
#ifndef SQLITE_CORE
@ -466,10 +466,26 @@ static const sqlite3_api_routines sqlite3Apis = { 0 };
** This list is shared across threads. The SQLITE_MUTEX_STATIC_MASTER
** mutex must be held while accessing this list.
*/
static struct {
typedef struct sqlite3ExtType sqlite3ExtType;
static SQLITE_WSD struct sqlite3ExtType {
int nExt; /* Number of entries in aExt[] */
void **aExt; /* Pointers to the extension init functions */
} autoext = { 0, 0 };
} sqlite3Autoext = { 0, 0 };
/* The "wsdAutoext" macro will resolve to the autoextension
** state vector. If writable static data is unsupported on the target,
** we have to locate the state vector at run-time. In the more common
** case where writable static data is supported, wsdStat can refer directly
** to the "sqlite3Autoext" state vector declared above.
*/
#ifdef SQLITE_OMIT_WSD
# define wsdAutoextInit \
sqlite3ExtType *x = &GLOBAL(sqlite3ExtType,sqlite3Autoext)
# define wsdAutoext x[0]
#else
# define wsdAutoextInit
# define wsdAutoext sqlite3Autoext
#endif
/*
@ -489,20 +505,21 @@ int sqlite3_auto_extension(void *xInit){
#ifndef SQLITE_MUTEX_NOOP
sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
#endif
wsdAutoextInit;
sqlite3_mutex_enter(mutex);
for(i=0; i<autoext.nExt; i++){
if( autoext.aExt[i]==xInit ) break;
for(i=0; i<wsdAutoext.nExt; i++){
if( wsdAutoext.aExt[i]==xInit ) break;
}
if( i==autoext.nExt ){
int nByte = (autoext.nExt+1)*sizeof(autoext.aExt[0]);
if( i==wsdAutoext.nExt ){
int nByte = (wsdAutoext.nExt+1)*sizeof(wsdAutoext.aExt[0]);
void **aNew;
aNew = sqlite3_realloc(autoext.aExt, nByte);
aNew = sqlite3_realloc(wsdAutoext.aExt, nByte);
if( aNew==0 ){
rc = SQLITE_NOMEM;
}else{
autoext.aExt = aNew;
autoext.aExt[autoext.nExt] = xInit;
autoext.nExt++;
wsdAutoext.aExt = aNew;
wsdAutoext.aExt[wsdAutoext.nExt] = xInit;
wsdAutoext.nExt++;
}
}
sqlite3_mutex_leave(mutex);
@ -522,10 +539,11 @@ void sqlite3_reset_auto_extension(void){
#ifndef SQLITE_MUTEX_NOOP
sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
#endif
wsdAutoextInit;
sqlite3_mutex_enter(mutex);
sqlite3_free(autoext.aExt);
autoext.aExt = 0;
autoext.nExt = 0;
sqlite3_free(wsdAutoext.aExt);
wsdAutoext.aExt = 0;
wsdAutoext.nExt = 0;
sqlite3_mutex_leave(mutex);
}
}
@ -539,7 +557,8 @@ int sqlite3AutoLoadExtensions(sqlite3 *db){
int rc = SQLITE_OK;
int (*xInit)(sqlite3*,char**,const sqlite3_api_routines*);
if( autoext.nExt==0 ){
wsdAutoextInit;
if( wsdAutoext.nExt==0 ){
/* Common case: early out without every having to acquire a mutex */
return SQLITE_OK;
}
@ -549,12 +568,12 @@ int sqlite3AutoLoadExtensions(sqlite3 *db){
sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
#endif
sqlite3_mutex_enter(mutex);
if( i>=autoext.nExt ){
if( i>=wsdAutoext.nExt ){
xInit = 0;
go = 0;
}else{
xInit = (int(*)(sqlite3*,char**,const sqlite3_api_routines*))
autoext.aExt[i];
wsdAutoext.aExt[i];
}
sqlite3_mutex_leave(mutex);
if( xInit && xInit(db, &zErrmsg, &sqlite3Apis) ){

View File

@ -11,7 +11,7 @@
*************************************************************************
** This file contains code used to implement the PRAGMA command.
**
** $Id: pragma.c,v 1.184 2008/08/20 16:34:24 danielk1977 Exp $
** $Id: pragma.c,v 1.185 2008/09/02 00:52:52 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@ -666,6 +666,7 @@ void sqlite3Pragma(
sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
}
}else{
#ifndef SQLITE_OMIT_WSD
if( zRight[0] ){
int res;
sqlite3OsAccess(db->pVfs, zRight, SQLITE_ACCESS_READWRITE, &res);
@ -686,6 +687,7 @@ void sqlite3Pragma(
}else{
sqlite3_temp_directory = 0;
}
#endif /* SQLITE_OMIT_WSD */
}
}else

View File

@ -15,7 +15,7 @@
** Random numbers are used by some of the database backends in order
** to generate random integer keys for tables or random filenames.
**
** $Id: random.c,v 1.25 2008/06/19 01:03:18 drh Exp $
** $Id: random.c,v 1.26 2008/09/02 00:52:52 drh Exp $
*/
#include "sqliteInt.h"
@ -23,11 +23,11 @@
/* All threads share a single random number generator.
** This structure is the current state of the generator.
*/
static struct sqlite3PrngType {
static SQLITE_WSD struct sqlite3PrngType {
unsigned char isInit; /* True if initialized */
unsigned char i, j; /* State variables */
unsigned char s[256]; /* State variables */
} sqlite3Prng;
} sqlite3Prng = { 0, };
/*
** Get a single 8-bit random value from the RC4 PRNG. The Mutex
@ -49,6 +49,20 @@ static int randomByte(void){
unsigned char t;
/* The "wsdPrng" macro will resolve to the pseudo-random number generator
** state vector. If writable static data is unsupported on the target,
** we have to locate the state vector at run-time. In the more common
** case where writable static data is supported, wsdPrng can refer directly
** to the "sqlite3Prng" state vector declared above.
*/
#ifdef SQLITE_OMIT_WSD
struct sqlite3PrngType *p = &GLOBAL(struct sqlite3PrngType, sqlite3Prng);
# define wsdPrng p[0]
#else
# define wsdPrng sqlite3Prng
#endif
/* Initialize the state of the random number generator once,
** the first time this routine is called. The seed value does
** not need to contain a lot of randomness since we are not
@ -58,33 +72,33 @@ static int randomByte(void){
** encryption. The RC4 algorithm is being used as a PRNG (pseudo-random
** number generator) not as an encryption device.
*/
if( !sqlite3Prng.isInit ){
if( !wsdPrng.isInit ){
int i;
char k[256];
sqlite3Prng.j = 0;
sqlite3Prng.i = 0;
wsdPrng.j = 0;
wsdPrng.i = 0;
sqlite3OsRandomness(sqlite3_vfs_find(0), 256, k);
for(i=0; i<256; i++){
sqlite3Prng.s[i] = i;
wsdPrng.s[i] = i;
}
for(i=0; i<256; i++){
sqlite3Prng.j += sqlite3Prng.s[i] + k[i];
t = sqlite3Prng.s[sqlite3Prng.j];
sqlite3Prng.s[sqlite3Prng.j] = sqlite3Prng.s[i];
sqlite3Prng.s[i] = t;
wsdPrng.j += wsdPrng.s[i] + k[i];
t = wsdPrng.s[wsdPrng.j];
wsdPrng.s[wsdPrng.j] = wsdPrng.s[i];
wsdPrng.s[i] = t;
}
sqlite3Prng.isInit = 1;
wsdPrng.isInit = 1;
}
/* Generate and return single random byte
*/
sqlite3Prng.i++;
t = sqlite3Prng.s[sqlite3Prng.i];
sqlite3Prng.j += t;
sqlite3Prng.s[sqlite3Prng.i] = sqlite3Prng.s[sqlite3Prng.j];
sqlite3Prng.s[sqlite3Prng.j] = t;
t += sqlite3Prng.s[sqlite3Prng.i];
return sqlite3Prng.s[t];
wsdPrng.i++;
t = wsdPrng.s[wsdPrng.i];
wsdPrng.j += t;
wsdPrng.s[wsdPrng.i] = wsdPrng.s[wsdPrng.j];
wsdPrng.s[wsdPrng.j] = t;
t += wsdPrng.s[wsdPrng.i];
return wsdPrng.s[t];
}
/*
@ -105,18 +119,29 @@ void sqlite3_randomness(int N, void *pBuf){
#ifndef SQLITE_OMIT_BUILTIN_TEST
/*
** For testing purposes, we sometimes want to preserve the state of
** PRNG and restore the PRNG to its saved state at a later time.
** PRNG and restore the PRNG to its saved state at a later time, or
** to reset the PRNG to its initial state. These routines accomplish
** those tasks.
**
** The sqlite3_test_control() interface calls these routines to
** control the PRNG.
*/
static struct sqlite3PrngType sqlite3SavedPrng;
static SQLITE_WSD struct sqlite3PrngType sqlite3SavedPrng = { 0, };
void sqlite3PrngSaveState(void){
memcpy(&sqlite3SavedPrng, &sqlite3Prng, sizeof(sqlite3Prng));
memcpy(
&GLOBAL(struct sqlite3PrngType, sqlite3SavedPrng),
&GLOBAL(struct sqlite3PrngType, sqlite3Prng),
sizeof(sqlite3Prng)
);
}
void sqlite3PrngRestoreState(void){
memcpy(&sqlite3Prng, &sqlite3SavedPrng, sizeof(sqlite3Prng));
memcpy(
&GLOBAL(struct sqlite3PrngType, sqlite3Prng),
&GLOBAL(struct sqlite3PrngType, sqlite3SavedPrng),
sizeof(sqlite3Prng)
);
}
void sqlite3PrngResetState(void){
sqlite3Prng.isInit = 0;
GLOBAL(struct sqlite3PrngType, sqlite3Prng).isInit = 0;
}
#endif /* SQLITE_OMIT_BUILTIN_TEST */

View File

@ -11,7 +11,7 @@
*************************************************************************
** Internal interface definitions for SQLite.
**
** @(#) $Id: sqliteInt.h,v 1.767 2008/09/01 21:59:43 shane Exp $
** @(#) $Id: sqliteInt.h,v 1.768 2008/09/02 00:52:52 drh Exp $
*/
#ifndef _SQLITEINT_H_
#define _SQLITEINT_H_
@ -441,6 +441,20 @@ struct BusyHandler {
*/
#define SQLITE_DYNAMIC ((sqlite3_destructor_type)sqlite3DbFree)
/*
** When SQLITE_OMIT_WSD is defined, it means that the target platform does
** not support Writable Static Data (WSD) such as global and static variables.
** All variables must either be on the stack or dynamically allocated from
** the heap. When WSD is unsupported, the variable declarations scattered
** throughout the SQLite code must become constants instead. The SQLITE_WSD
** macro is used for this purpose. And instead of referencing the variable
** directly, we use its constant as a key to lookup the run-time allocated
** buffer that holds real variable. The constant is also the initializer
** for the run-time allocated buffer.
**
** In the usually case where WSD is supported, the SQLITE_WSD and GLOBAL
** macros become no-ops and have zero performance impact.
*/
#ifdef SQLITE_OMIT_WSD
#define SQLITE_WSD const
#define GLOBAL(t,v) (*(t*)sqlite3_wsd_find((void*)&(v), sizeof(v)))

View File

@ -13,25 +13,41 @@
** This module implements the sqlite3_status() interface and related
** functionality.
**
** $Id: status.c,v 1.8 2008/08/12 15:21:12 drh Exp $
** $Id: status.c,v 1.9 2008/09/02 00:52:52 drh Exp $
*/
#include "sqliteInt.h"
/*
** Variables in which to record status information.
*/
static struct {
typedef struct sqlite3StatType sqlite3StatType;
static SQLITE_WSD struct sqlite3StatType {
int nowValue[9]; /* Current value */
int mxValue[9]; /* Maximum value */
} sqlite3Stat;
} sqlite3Stat = { {0,}, {0,} };
/* The "wsdStat" macro will resolve to the status information
** state vector. If writable static data is unsupported on the target,
** we have to locate the state vector at run-time. In the more common
** case where writable static data is supported, wsdStat can refer directly
** to the "sqlite3Stat" state vector declared above.
*/
#ifdef SQLITE_OMIT_WSD
# define wsdStatInit sqlite3StatType *x = &GLOBAL(sqlite3StatType,sqlite3Stat)
# define wsdStat x[0]
#else
# define wsdStatInit
# define wsdStat sqlite3Stat
#endif
/*
** Return the current value of a status parameter.
*/
int sqlite3StatusValue(int op){
assert( op>=0 && op<ArraySize(sqlite3Stat.nowValue) );
return sqlite3Stat.nowValue[op];
wsdStatInit;
assert( op>=0 && op<ArraySize(wsdStat.nowValue) );
return wsdStat.nowValue[op];
}
/*
@ -39,10 +55,11 @@ int sqlite3StatusValue(int op){
** caller holds appropriate locks.
*/
void sqlite3StatusAdd(int op, int N){
assert( op>=0 && op<ArraySize(sqlite3Stat.nowValue) );
sqlite3Stat.nowValue[op] += N;
if( sqlite3Stat.nowValue[op]>sqlite3Stat.mxValue[op] ){
sqlite3Stat.mxValue[op] = sqlite3Stat.nowValue[op];
wsdStatInit;
assert( op>=0 && op<ArraySize(wsdStat.nowValue) );
wsdStat.nowValue[op] += N;
if( wsdStat.nowValue[op]>wsdStat.mxValue[op] ){
wsdStat.mxValue[op] = wsdStat.nowValue[op];
}
}
@ -50,10 +67,11 @@ void sqlite3StatusAdd(int op, int N){
** Set the value of a status to X.
*/
void sqlite3StatusSet(int op, int X){
assert( op>=0 && op<ArraySize(sqlite3Stat.nowValue) );
sqlite3Stat.nowValue[op] = X;
if( sqlite3Stat.nowValue[op]>sqlite3Stat.mxValue[op] ){
sqlite3Stat.mxValue[op] = sqlite3Stat.nowValue[op];
wsdStatInit;
assert( op>=0 && op<ArraySize(wsdStat.nowValue) );
wsdStat.nowValue[op] = X;
if( wsdStat.nowValue[op]>wsdStat.mxValue[op] ){
wsdStat.mxValue[op] = wsdStat.nowValue[op];
}
}
@ -65,13 +83,14 @@ void sqlite3StatusSet(int op, int X){
** then this routine is not threadsafe.
*/
int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag){
if( op<0 || op>=ArraySize(sqlite3Stat.nowValue) ){
wsdStatInit;
if( op<0 || op>=ArraySize(wsdStat.nowValue) ){
return SQLITE_MISUSE;
}
*pCurrent = sqlite3Stat.nowValue[op];
*pHighwater = sqlite3Stat.mxValue[op];
*pCurrent = wsdStat.nowValue[op];
*pHighwater = wsdStat.mxValue[op];
if( resetFlag ){
sqlite3Stat.mxValue[op] = sqlite3Stat.nowValue[op];
wsdStat.mxValue[op] = wsdStat.nowValue[op];
}
return SQLITE_OK;
}

View File

@ -13,7 +13,7 @@
** is not included in the SQLite library. It is used for automated
** testing of the SQLite library.
**
** $Id: test1.c,v 1.322 2008/08/30 13:25:11 danielk1977 Exp $
** $Id: test1.c,v 1.323 2008/09/02 00:52:52 drh Exp $
*/
#include "sqliteInt.h"
#include "tcl.h"
@ -1387,7 +1387,7 @@ static int test_enable_shared(
Tcl_WrongNumArgs(interp, 1, objv, "?BOOLEAN?");
return TCL_ERROR;
}
ret = sqlite3SharedCacheEnabled;
ret = GLOBAL(int, sqlite3SharedCacheEnabled);
if( objc==2 ){
if( Tcl_GetBooleanFromObj(interp, objv[1], &enable) ){

View File

@ -13,7 +13,7 @@
** is not included in the SQLite library. It is used for automated
** testing of the SQLite library.
**
** $Id: test_btree.c,v 1.6 2008/07/15 00:27:35 drh Exp $
** $Id: test_btree.c,v 1.7 2008/09/02 00:52:52 drh Exp $
*/
#include "btreeInt.h"
#include <tcl.h>
@ -34,7 +34,7 @@ int sqlite3BtreeSharedCacheReport(
extern BtShared *sqlite3SharedCacheList;
BtShared *pBt;
Tcl_Obj *pRet = Tcl_NewObj();
for(pBt=sqlite3SharedCacheList; pBt; pBt=pBt->pNext){
for(pBt=GLOBAL(BtShared*,sqlite3SharedCacheList); pBt; pBt=pBt->pNext){
const char *zFile = sqlite3PagerFilename(pBt->pPager);
Tcl_ListObjAppendElement(interp, pRet, Tcl_NewStringObj(zFile, -1));
Tcl_ListObjAppendElement(interp, pRet, Tcl_NewIntObj(pBt->nRef));

View File

@ -16,7 +16,7 @@
** The focus of this file is providing the TCL testing layer
** access to compile-time constants.
**
** $Id: test_config.c,v 1.33 2008/07/31 02:05:05 shane Exp $
** $Id: test_config.c,v 1.34 2008/09/02 00:52:52 drh Exp $
*/
#include "sqliteLimit.h"
@ -437,6 +437,12 @@ Tcl_SetVar2(interp, "sqlite_options", "long_double",
Tcl_SetVar2(interp, "sqlite_options", "vtab", "1", TCL_GLOBAL_ONLY);
#endif
#ifdef SQLITE_OMIT_WSD
Tcl_SetVar2(interp, "sqlite_options", "wsd", "0", TCL_GLOBAL_ONLY);
#else
Tcl_SetVar2(interp, "sqlite_options", "wsd", "1", TCL_GLOBAL_ONLY);
#endif
#ifdef SQLITE_SECURE_DELETE
Tcl_SetVar2(interp, "sqlite_options", "secure_delete", "1", TCL_GLOBAL_ONLY);
#else

View File

@ -12,7 +12,7 @@
#
# This file implements tests for the PRAGMA command.
#
# $Id: pragma.test,v 1.65 2008/08/20 16:34:24 danielk1977 Exp $
# $Id: pragma.test,v 1.66 2008/09/02 00:52:52 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@ -925,46 +925,48 @@ do_test pragma-9.4 {
PRAGMA temp_store_directory;
}
} {}
do_test pragma-9.5 {
set pwd [string map {' ''} [pwd]]
execsql "
PRAGMA temp_store_directory='$pwd';
"
} {}
do_test pragma-9.6 {
execsql {
PRAGMA temp_store_directory;
ifcapable wsd {
do_test pragma-9.5 {
set pwd [string map {' ''} [pwd]]
execsql "
PRAGMA temp_store_directory='$pwd';
"
} {}
do_test pragma-9.6 {
execsql {
PRAGMA temp_store_directory;
}
} [list [pwd]]
do_test pragma-9.7 {
catchsql {
PRAGMA temp_store_directory='/NON/EXISTENT/PATH/FOOBAR';
}
} {1 {not a writable directory}}
do_test pragma-9.8 {
execsql {
PRAGMA temp_store_directory='';
}
} {}
if {![info exists TEMP_STORE] || $TEMP_STORE<=1} {
ifcapable tempdb {
do_test pragma-9.9 {
execsql {
PRAGMA temp_store_directory;
PRAGMA temp_store=FILE;
CREATE TEMP TABLE temp_store_directory_test(a integer);
INSERT INTO temp_store_directory_test values (2);
SELECT * FROM temp_store_directory_test;
}
} {2}
do_test pragma-9.10 {
catchsql "
PRAGMA temp_store_directory='$pwd';
SELECT * FROM temp_store_directory_test;
"
} {1 {no such table: temp_store_directory_test}}
}
}
} [list [pwd]]
do_test pragma-9.7 {
catchsql {
PRAGMA temp_store_directory='/NON/EXISTENT/PATH/FOOBAR';
}
} {1 {not a writable directory}}
do_test pragma-9.8 {
execsql {
PRAGMA temp_store_directory='';
}
} {}
if {![info exists TEMP_STORE] || $TEMP_STORE<=1} {
ifcapable tempdb {
do_test pragma-9.9 {
execsql {
PRAGMA temp_store_directory;
PRAGMA temp_store=FILE;
CREATE TEMP TABLE temp_store_directory_test(a integer);
INSERT INTO temp_store_directory_test values (2);
SELECT * FROM temp_store_directory_test;
}
} {2}
do_test pragma-9.10 {
catchsql "
PRAGMA temp_store_directory='$pwd';
SELECT * FROM temp_store_directory_test;
"
} {1 {no such table: temp_store_directory_test}}
}
}
}
do_test pragma-9.11 {
execsql {
PRAGMA temp_store = 0;