1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-29 08:01:23 +03:00

Add the sqlite3_os_routine_set()/get() functions. (CVS 2818)

FossilOrigin-Name: c1ed79f594fb85009c2e9e5e281cbe66a9d2fa17
This commit is contained in:
danielk1977
2005-12-15 10:11:30 +00:00
parent af9a7c22b5
commit 13a68c3f61
14 changed files with 198 additions and 45 deletions

View File

@ -133,6 +133,7 @@ TESTSRC = \
$(TOP)/src/test4.c \ $(TOP)/src/test4.c \
$(TOP)/src/test5.c \ $(TOP)/src/test5.c \
$(TOP)/src/test6.c \ $(TOP)/src/test6.c \
$(TOP)/src/test_async.c \
$(TOP)/src/utf.c \ $(TOP)/src/utf.c \
$(TOP)/src/util.c \ $(TOP)/src/util.c \
$(TOP)/src/vdbe.c \ $(TOP)/src/vdbe.c \

View File

@ -1,5 +1,5 @@
C Fix\smemory\sallocation\sproblems\son\sthe\sutf-16\sversions\sof\scollating\sfunction\ncontrol\sroutines.\s(CVS\s2817) C Add\sthe\ssqlite3_os_routine_set()/get()\sfunctions.\s(CVS\s2818)
D 2005-12-15T03:04:10 D 2005-12-15T10:11:31
F Makefile.in e3c6b3a38d734d41574c04f2fc90d18de2b87102 F Makefile.in e3c6b3a38d734d41574c04f2fc90d18de2b87102
F Makefile.linux-gcc aee18d8a05546dcf1888bd4547e442008a49a092 F Makefile.linux-gcc aee18d8a05546dcf1888bd4547e442008a49a092
F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
@ -19,7 +19,7 @@ F doc/lemon.html f0f682f50210928c07e562621c3b7e8ab912a538
F doc/report1.txt a031aaf37b185e4fa540223cb516d3bccec7eeac F doc/report1.txt a031aaf37b185e4fa540223cb516d3bccec7eeac
F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895
F ltmain.sh f6b283068efa69f06eb8aa1fe4bddfdbdeb35826 F ltmain.sh f6b283068efa69f06eb8aa1fe4bddfdbdeb35826
F main.mk 19f33320f3ce5fc000de87abafca07ef4b6dffb4 F main.mk 1376cec5c19b087d00d679527cfab9fa6598c2c3
F mkdll.sh 5ec23622515d5bf8969404e80cfb5e220ddf0512 F mkdll.sh 5ec23622515d5bf8969404e80cfb5e220ddf0512
F mkopcodec.awk bd46ad001c98dfbab07b1713cb8e692fa0e5415d F mkopcodec.awk bd46ad001c98dfbab07b1713cb8e692fa0e5415d
F mkopcodeh.awk 071dbba4eaf56c8d643baf4604a043af35683316 F mkopcodeh.awk 071dbba4eaf56c8d643baf4604a043af35683316
@ -50,14 +50,14 @@ F src/insert.c 5393479164f317ea0aeec954c6500cafa097ef33
F src/legacy.c 59757d857ab95fcbb0ac27692d3201e35f093dd7 F src/legacy.c 59757d857ab95fcbb0ac27692d3201e35f093dd7
F src/main.c a12aa72335036bb22249418e222124abfc581b85 F src/main.c a12aa72335036bb22249418e222124abfc581b85
F src/md5.c c5fdfa5c2593eaee2e32a5ce6c6927c986eaf217 F src/md5.c c5fdfa5c2593eaee2e32a5ce6c6927c986eaf217
F src/os.c bdd3a2fd089777e7ad18b57c896f1141d5a0c1fd F src/os.c 7b4a002d9c9421580276db55d2329636a604e8ef
F src/os.h d5ae3f4c1c7731437b6cddec279b7c06f761c44e F src/os.h df6babd4fd74bb659470c31fa5a27de31b1c474e
F src/os_common.h d74a11728ad2444b6b695b94c28c06881f049e49 F src/os_common.h d74a11728ad2444b6b695b94c28c06881f049e49
F src/os_test.c 49833426101f99aee4bb5f6a44b7c4b2029fda1c F src/os_test.c 49833426101f99aee4bb5f6a44b7c4b2029fda1c
F src/os_test.h 903c93554c23d88f34f667f1979e4a1cee792af3 F src/os_test.h 903c93554c23d88f34f667f1979e4a1cee792af3
F src/os_unix.c f11eba69eea2ae2723f5ae1bdad8b1ef12e224b9 F src/os_unix.c df6e4972099aa5263183009fb947083633236dd3
F src/os_unix.h 5768d56d28240d3fe4537fac08cc85e4fb52279e F src/os_unix.h 5768d56d28240d3fe4537fac08cc85e4fb52279e
F src/os_win.c d962ac2dd0e482847e42b846d46cd044f97d1c32 F src/os_win.c 2da77ddc03de8c51688cca648ced766b5dad8a6a
F src/os_win.h 41a946bea10f61c158ce8645e7646b29d44f122b F src/os_win.h 41a946bea10f61c158ce8645e7646b29d44f122b
F src/pager.c 49f63a54b57164a70df0b1539141003fd27856c6 F src/pager.c 49f63a54b57164a70df0b1539141003fd27856c6
F src/pager.h e7b41ce8e7b5f629d456708b7ad9a8c8ede37140 F src/pager.h e7b41ce8e7b5f629d456708b7ad9a8c8ede37140
@ -68,10 +68,10 @@ F src/printf.c f47a2f4b5387cd2ebb12e9117a1a5d6bd9a2b812
F src/random.c ff5e9a8cad790e2a51cd4d2e7737dc8540e09d1d F src/random.c ff5e9a8cad790e2a51cd4d2e7737dc8540e09d1d
F src/select.c 2292b065bc6be61e01aad39a2e1b93e332fb7e57 F src/select.c 2292b065bc6be61e01aad39a2e1b93e332fb7e57
F src/shell.c 4872acee1d2a826c73c914961e469e563204b7f9 F src/shell.c 4872acee1d2a826c73c914961e469e563204b7f9
F src/sqlite.h.in a52db91dfa4f90e8e42361f6c7824c09b4e101ad F src/sqlite.h.in 9d587d1f78129f08f8923b544afb7774563125e1
F src/sqliteInt.h babeb60d34dbaa95a0f1d336e65039ae7ade5aab F src/sqliteInt.h 09f9addda8de78e2b632597840b0ec6bb70a7c99
F src/table.c 486dcfce532685b53b5a2b5da8bba0ded6fb2316 F src/table.c 486dcfce532685b53b5a2b5da8bba0ded6fb2316
F src/tclsqlite.c c155bf5f9ce9ae8950037931f7f7efcc0d92d9c5 F src/tclsqlite.c 5753ac020a9a6619190d8dc125cb00bb0bc61c96
F src/test1.c d6924b182773b2ad3b22e435e4d3bfd5a846da9e F src/test1.c d6924b182773b2ad3b22e435e4d3bfd5a846da9e
F src/test2.c 36390cdfc70c08e5ee0b466d0654a117f398bbff F src/test2.c 36390cdfc70c08e5ee0b466d0654a117f398bbff
F src/test3.c 7c97833e33496c2b69f4fe6b9882ac60a481da97 F src/test3.c 7c97833e33496c2b69f4fe6b9882ac60a481da97
@ -82,7 +82,7 @@ F src/tokenize.c 7a3a3d3cc734f684a77c4dfd09eb46fcee25394c
F src/trigger.c 2925ba96d964d9b717e74006bf7e64b8a6b70d97 F src/trigger.c 2925ba96d964d9b717e74006bf7e64b8a6b70d97
F src/update.c ec8e540617b116725b5a55c8d6b4db8bc67fdd7d F src/update.c ec8e540617b116725b5a55c8d6b4db8bc67fdd7d
F src/utf.c d2360f55ecd666f3e472738191f8dae717b95e5e F src/utf.c d2360f55ecd666f3e472738191f8dae717b95e5e
F src/util.c e525154652f7aecb8773cae55ada9f43024bb2c4 F src/util.c 06ab728430ae55191076cdf4075be36f621a7183
F src/vacuum.c fbfdd3967fd34e2f260fafed88dcbf3c10856b94 F src/vacuum.c fbfdd3967fd34e2f260fafed88dcbf3c10856b94
F src/vdbe.c d09c185f4badac6c79f2a919cbf661e7b5618293 F src/vdbe.c d09c185f4badac6c79f2a919cbf661e7b5618293
F src/vdbe.h 8729a4ee16ff9aeab2af9667df3cf300ff978e13 F src/vdbe.h 8729a4ee16ff9aeab2af9667df3cf300ff978e13
@ -93,7 +93,7 @@ F src/vdbefifo.c 9efb94c8c3f4c979ebd0028219483f88e57584f5
F src/vdbemem.c deba8d6e3727643924b210a8c531a496c2b8d386 F src/vdbemem.c deba8d6e3727643924b210a8c531a496c2b8d386
F src/where.c 269569f380ddc018518f67765fe2f0d3c8760e28 F src/where.c 269569f380ddc018518f67765fe2f0d3c8760e28
F tclinstaller.tcl 046e3624671962dc50f0481d7c25b38ef803eb42 F tclinstaller.tcl 046e3624671962dc50f0481d7c25b38ef803eb42
F test/all.test 7f0988442ab811dfa41793b5b550f5828ce316f3 F test/all.test 55706917a12cd616440d50c35323747b4a9f03c3
F test/alter.test 9d6837a3d946b73df692b7cef2a7644d2e2f6bc6 F test/alter.test 9d6837a3d946b73df692b7cef2a7644d2e2f6bc6
F test/alter2.test 60ba0a7057dc71ad630a1cc7c487104346849d50 F test/alter2.test 60ba0a7057dc71ad630a1cc7c487104346849d50
F test/alter3.test d4eecd8dbd008d0e66f1c201fa6dc2edca853c38 F test/alter3.test d4eecd8dbd008d0e66f1c201fa6dc2edca853c38
@ -201,14 +201,14 @@ F test/pagesize.test cbc6a312b6f6c0f02619b189985df2a14164b690
F test/pragma.test 95ea907adf68459e1be6f310c9ae94d1d59c465b F test/pragma.test 95ea907adf68459e1be6f310c9ae94d1d59c465b
F test/printf.test 9e10c74e16bf889f8495ddb3d6f5f891e75ff1b7 F test/printf.test 9e10c74e16bf889f8495ddb3d6f5f891e75ff1b7
F test/progress.test 16496001da445e6534afb94562c286708316d82f x F test/progress.test 16496001da445e6534afb94562c286708316d82f x
F test/quick.test 84138c0fcc959a5e7761625aa52d37d55e56b748 F test/quick.test 4be1733beae790f4a61fb7c7827b396c95375d7e
F test/quote.test 5891f2338980916cf7415484b4ce785294044adb F test/quote.test 5891f2338980916cf7415484b4ce785294044adb
F test/reindex.test 38b138abe36bf9a08c791ed44d9f76cd6b97b78b F test/reindex.test 38b138abe36bf9a08c791ed44d9f76cd6b97b78b
F test/rollback.test 94cd981ee3a627d9f6466f69dcf1f7dbfe695d7a F test/rollback.test 94cd981ee3a627d9f6466f69dcf1f7dbfe695d7a
F test/rowid.test 040a3bef06f970c45f5fcd14b2355f7f4d62f0cf F test/rowid.test 040a3bef06f970c45f5fcd14b2355f7f4d62f0cf
F test/safety.test 907b64fee719554a3622853812af3886fddbbb4f F test/safety.test 907b64fee719554a3622853812af3886fddbbb4f
F test/schema.test 8a2ae440fb15f5798a68059e8746402f3137be46 F test/schema.test 8a2ae440fb15f5798a68059e8746402f3137be46
F test/select1.test 20275797efe032a56e97687aa06ba65d7a0b9b2b F test/select1.test 386cc42da2d0fade5dfb25c85118009c0ef26637
F test/select2.test f3c2678c3a9f3cf08ec4988a3845bda64be6d9e3 F test/select2.test f3c2678c3a9f3cf08ec4988a3845bda64be6d9e3
F test/select3.test 8fece41cd8f2955131b3f973a7123bec60b6e65e F test/select3.test 8fece41cd8f2955131b3f973a7123bec60b6e65e
F test/select4.test c239f516aa31f42f2ef7c6d7cd01105f08f934ca F test/select4.test c239f516aa31f42f2ef7c6d7cd01105f08f934ca
@ -327,7 +327,7 @@ F www/tclsqlite.tcl ddcf912ea48695603c8ed7efb29f0812ef8d1b49
F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
F www/version3.tcl a99cf5f6d8bd4d5537584a2b342f0fb9fa601d8b F www/version3.tcl a99cf5f6d8bd4d5537584a2b342f0fb9fa601d8b
F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513 F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513
P ab6241af29b2e9f5f094b83c13afebe44a8ad6bc P ad292e27336b8c5afc0acdf111944a456bd23c32
R 12c15b60aaac20b8ef3a98bcc49cb762 R 079783b8421fc6a8eada9a4aa8fe00c7
U drh U danielk1977
Z 29b97667c2714272591c690c9c9d58c8 Z 21e315959d3bb7c348f1a6f926708fc0

View File

@ -1 +1 @@
ad292e27336b8c5afc0acdf111944a456bd23c32 c1ed79f594fb85009c2e9e5e281cbe66a9d2fa17

View File

@ -69,3 +69,42 @@ int sqlite3OsLockState(OsFile *id){
int sqlite3OsCheckReservedLock(OsFile *id){ int sqlite3OsCheckReservedLock(OsFile *id){
return id->pMethod->xCheckReservedLock(id); return id->pMethod->xCheckReservedLock(id);
} }
static void**getOsRoutinePtr(int eRoutine){
switch( eRoutine ){
case SQLITE_OS_ROUTINE_OPENREADWRITE:
return (void **)(&sqlite3Os.xOpenReadWrite);
case SQLITE_OS_ROUTINE_OPENREADONLY:
return (void **)(&sqlite3Os.xOpenReadOnly);
case SQLITE_OS_ROUTINE_OPENEXCLUSIVE:
return (void **)(&sqlite3Os.xOpenExclusive);
case SQLITE_OS_ROUTINE_DELETE:
return (void **)(&sqlite3Os.xDelete);
case SQLITE_OS_ROUTINE_FILEEXISTS:
return (void **)(&sqlite3Os.xFileExists);
case SQLITE_OS_ROUTINE_SYNCDIRECTORY:
return (void **)(&sqlite3Os.xSyncDirectory);
default:
assert(!"Illegal eRoutine value");
}
return 0;
}
void *sqlite3_os_routine_get(int eRoutine){
return *getOsRoutinePtr(eRoutine);
}
void *sqlite3_os_routine_set(int eRoutine, void *pRoutine){
void **ppRet = getOsRoutinePtr(eRoutine);
void *pRet = *ppRet;
*ppRet = pRoutine;
return pRet;
}
void sqlite3_os_enter_mutex(){
sqlite3Os.xEnterMutex();
}
void sqlite3_os_leave_mutex(){
sqlite3Os.xLeaveMutex();
}

View File

@ -222,8 +222,30 @@ extern struct sqlite3OsVtbl {
int (*xCurrentTime)(double*); int (*xCurrentTime)(double*);
void (*xEnterMutex)(void); void (*xEnterMutex)(void);
void (*xLeaveMutex)(void); void (*xLeaveMutex)(void);
void *(*xThreadSpecificData)(int);
} sqlite3Os; } sqlite3Os;
/*
** The semi-published API for setting and getting methods from the
** global sqlite3OsVtbl structure. Neither sqlite3_os_routine_XXX() function
** is intriniscally thread-safe.
**
** External get/set access is only provided to the routines identified
** by the hash-defined SQLITE_OS_ROUTINE symbols.
*/
#define SQLITE_OS_ROUTINE_OPENREADWRITE 1
#define SQLITE_OS_ROUTINE_OPENREADONLY 2
#define SQLITE_OS_ROUTINE_OPENEXCLUSIVE 3
#define SQLITE_OS_ROUTINE_DELETE 4
#define SQLITE_OS_ROUTINE_FILEEXISTS 5
#define SQLITE_OS_ROUTINE_SYNCDIRECTORY 6
void *sqlite3_os_routine_get(int);
void *sqlite3_os_routine_set(int, void *);
void sqlite3_os_enter_mutex();
void sqlite3_os_leave_mutex();
/* /*
** Prototypes for routines found in os.c ** Prototypes for routines found in os.c
*/ */

View File

@ -1586,6 +1586,66 @@ static void unixLeaveMutex(){
#endif #endif
} }
/*
** This function is called automatically when a thread exists to delete
** the threads SqliteTsd structure.
**
** Because the SqliteTsd structure is required by higher level routines
** such as sqliteMalloc() we use OsFree() and OsMalloc() directly to
** allocate the thread specific data.
*/
static void deleteTsd(void *pTsd){
sqlite3OsFree(pTsd);
}
/*
** The first time this function is called from a specific thread, nByte
** bytes of data area are allocated and zeroed. A pointer to the new
** allocation is returned to the caller.
**
** Each subsequent call to this function from the thread returns the same
** pointer. The argument is ignored in this case.
*/
static void *unixThreadSpecificData(int nByte){
#ifdef SQLITE_UNIX_THREADS
static pthread_key_t key;
static int keyInit = 0;
void *pTsd;
if( !keyInit ){
sqlite3Os.xEnterMutex();
if( !keyInit ){
int rc;
rc = pthread_key_create(&key, deleteTsd);
if( rc ){
return 0;
}
keyInit = 1;
}
sqlite3Os.xLeaveMutex();
}
pTsd = (SqliteTsd *)pthread_getspecific(key);
if( !pTsd ){
pTsd = sqlite3OsMalloc(sizeof(SqliteTsd));
if( pTsd ){
memset(pTsd, 0, sizeof(SqliteTsd));
pthread_setspecific(key, pTsd);
}
}
return pTsd;
#else
static char tsd[sizeof(SqliteTsd)];
static isInit = 0;
assert( nByte==sizeof(SqliteTsd) );
if( !isInit ){
memset(tsd, 0, sizeof(SqliteTsd));
isInit = 1;
}
return (void *)tsd;
#endif
}
/* /*
** The following variable, if set to a non-zero value, becomes the result ** The following variable, if set to a non-zero value, becomes the result
** returned from sqlite3Os.xCurrentTime(). This is used for testing. ** returned from sqlite3Os.xCurrentTime(). This is used for testing.
@ -1644,6 +1704,7 @@ struct sqlite3OsVtbl sqlite3Os = {
unixCurrentTime, unixCurrentTime,
unixEnterMutex, unixEnterMutex,
unixLeaveMutex, unixLeaveMutex,
unixThreadSpecificData
}; };

View File

@ -1020,6 +1020,21 @@ static int winCurrentTime(double *prNow){
return 0; return 0;
} }
/*
** Todo: This is a place-holder only
*/
static void *winThreadSpecificData(int nByte){
static char tsd[sizeof(SqliteTsd)];
static isInit = 0;
assert( nByte==sizeof(SqliteTsd) );
if( !isInit ){
memset(tsd, 0, sizeof(SqliteTsd));
isInit = 1;
}
return (void *)tsd;
}
/* Macro used to comment out routines that do not exists when there is /* Macro used to comment out routines that do not exists when there is
** no disk I/O ** no disk I/O
*/ */
@ -1047,6 +1062,7 @@ struct sqlite3OsVtbl sqlite3Os = {
winCurrentTime, winCurrentTime,
winEnterMutex, winEnterMutex,
winLeaveMutex, winLeaveMutex,
winThreadSpecificData
}; };
#endif /* OS_WIN */ #endif /* OS_WIN */

View File

@ -12,7 +12,7 @@
** This header file defines the interface that the SQLite library ** This header file defines the interface that the SQLite library
** presents to client programs. ** presents to client programs.
** **
** @(#) $Id: sqlite.h.in,v 1.144 2005/12/12 06:53:05 danielk1977 Exp $ ** @(#) $Id: sqlite.h.in,v 1.145 2005/12/15 10:11:32 danielk1977 Exp $
*/ */
#ifndef _SQLITE3_H_ #ifndef _SQLITE3_H_
#define _SQLITE3_H_ #define _SQLITE3_H_
@ -1291,6 +1291,10 @@ sqlite3 *sqlite3_db_handle(sqlite3_stmt*);
*/ */
void sqlite3_soft_heap_limit(int); void sqlite3_soft_heap_limit(int);
int sqlite3_set_io_routine(int, void *);
void *sqlite3_get_io_routine(int);
/* /*
** Undo the hack that converts floating point types to integer for ** Undo the hack that converts floating point types to integer for
** builds on processors without floating point support. ** builds on processors without floating point support.

View File

@ -11,7 +11,7 @@
************************************************************************* *************************************************************************
** Internal interface definitions for SQLite. ** Internal interface definitions for SQLite.
** **
** @(#) $Id: sqliteInt.h,v 1.435 2005/12/15 03:04:11 drh Exp $ ** @(#) $Id: sqliteInt.h,v 1.436 2005/12/15 10:11:32 danielk1977 Exp $
*/ */
#ifndef _SQLITEINT_H_ #ifndef _SQLITEINT_H_
#define _SQLITEINT_H_ #define _SQLITEINT_H_
@ -268,6 +268,7 @@ extern int sqlite3_iMallocReset; /* Set iMallocFail to this when it reaches 0 */
*/ */
typedef struct SqliteTsd SqliteTsd; typedef struct SqliteTsd SqliteTsd;
struct SqliteTsd { struct SqliteTsd {
int isInit; /* True if structure has been initialised */
int mallocFailed; /* True after a malloc() has failed */ int mallocFailed; /* True after a malloc() has failed */
#ifndef SQLITE_OMIT_SOFTHEAPLIMIT #ifndef SQLITE_OMIT_SOFTHEAPLIMIT
unsigned int nSoftHeapLimit; /* (uint)-1 for unlimited */ unsigned int nSoftHeapLimit; /* (uint)-1 for unlimited */

View File

@ -11,7 +11,7 @@
************************************************************************* *************************************************************************
** A TCL Interface to SQLite ** A TCL Interface to SQLite
** **
** $Id: tclsqlite.c,v 1.137 2005/12/12 06:53:05 danielk1977 Exp $ ** $Id: tclsqlite.c,v 1.138 2005/12/15 10:11:32 danielk1977 Exp $
*/ */
#ifndef NO_TCL /* Omit this whole file if TCL is unavailable */ #ifndef NO_TCL /* Omit this whole file if TCL is unavailable */
@ -2092,6 +2092,7 @@ int TCLSH_MAIN(int argc, char **argv){
extern int Sqlitetest4_Init(Tcl_Interp*); extern int Sqlitetest4_Init(Tcl_Interp*);
extern int Sqlitetest5_Init(Tcl_Interp*); extern int Sqlitetest5_Init(Tcl_Interp*);
extern int Sqlitetest6_Init(Tcl_Interp*); extern int Sqlitetest6_Init(Tcl_Interp*);
extern int Sqlitetestasync_Init(Tcl_Interp*);
extern int Md5_Init(Tcl_Interp*); extern int Md5_Init(Tcl_Interp*);
extern int Sqlitetestsse_Init(Tcl_Interp*); extern int Sqlitetestsse_Init(Tcl_Interp*);
@ -2101,6 +2102,7 @@ int TCLSH_MAIN(int argc, char **argv){
Sqlitetest4_Init(interp); Sqlitetest4_Init(interp);
Sqlitetest5_Init(interp); Sqlitetest5_Init(interp);
Sqlitetest6_Init(interp); Sqlitetest6_Init(interp);
Sqlitetestasync_Init(interp);
Md5_Init(interp); Md5_Init(interp);
#ifdef SQLITE_SSE #ifdef SQLITE_SSE
Sqlitetestsse_Init(interp); Sqlitetestsse_Init(interp);

View File

@ -14,9 +14,10 @@
** This file contains functions for allocating memory, comparing ** This file contains functions for allocating memory, comparing
** strings, and stuff like that. ** strings, and stuff like that.
** **
** $Id: util.c,v 1.152 2005/12/12 06:53:05 danielk1977 Exp $ ** $Id: util.c,v 1.153 2005/12/15 10:11:32 danielk1977 Exp $
*/ */
#include "sqliteInt.h" #include "sqliteInt.h"
#include "os.h"
#include <stdarg.h> #include <stdarg.h>
#include <ctype.h> #include <ctype.h>
@ -107,6 +108,10 @@ int sqlite3OsAllocationSize(void *p){
** Begin code for memory allocation system test layer. ** Begin code for memory allocation system test layer.
** **
** Memory debugging is turned on by defining the SQLITE_MEMDEBUG macro. ** Memory debugging is turned on by defining the SQLITE_MEMDEBUG macro.
**
** SQLITE_MEMDEBUG==1 -> Fence-posting only (thread safe)
** SQLITE_MEMDEBUG==2 -> Fence-posting + linked list of allocations (not ts)
** SQLITE_MEMDEBUG==3 -> Above + backtraces (not thread safe, req. glibc)
*/ */
/* Figure out whether or not to store backtrace() information for each malloc. /* Figure out whether or not to store backtrace() information for each malloc.
@ -114,7 +119,7 @@ int sqlite3OsAllocationSize(void *p){
** greater and glibc is in use. If we don't want to use backtrace(), then just ** greater and glibc is in use. If we don't want to use backtrace(), then just
** define it as an empty macro and set the amount of space reserved to 0. ** define it as an empty macro and set the amount of space reserved to 0.
*/ */
#if defined(__GLIBC__) && SQLITE_MEMDEBUG>1 #if defined(__GLIBC__) && SQLITE_MEMDEBUG>2
extern int backtrace(void **, int); extern int backtrace(void **, int);
#define TESTALLOC_STACKSIZE 128 #define TESTALLOC_STACKSIZE 128
#define TESTALLOC_STACKFRAMES ((TESTALLOC_STACKSIZE-8)/sizeof(void*)) #define TESTALLOC_STACKFRAMES ((TESTALLOC_STACKSIZE-8)/sizeof(void*))
@ -302,6 +307,8 @@ static void *getOsPointer(void *p)
return (void *)(&z[-1 * TESTALLOC_OFFSET_DATA(p)]); return (void *)(&z[-1 * TESTALLOC_OFFSET_DATA(p)]);
} }
#if SQLITE_MEMDEBUG>1
/* /*
** The argument points to an Os level allocation. Link it into the threads list ** The argument points to an Os level allocation. Link it into the threads list
** of allocations. ** of allocations.
@ -363,6 +370,11 @@ static void relinkAlloc(void *p)
((void **)(pp[1]))[0] = p; ((void **)(pp[1]))[0] = p;
} }
} }
#else
#define linkAlloc(x)
#define relinkAlloc(x)
#define unlinkAlloc(x)
#endif
/* /*
** This function sets the result of the Tcl interpreter passed as an argument ** This function sets the result of the Tcl interpreter passed as an argument
@ -1248,26 +1260,17 @@ void *sqlite3TextToPtr(const char *z){
/* /*
** Return a pointer to the SqliteTsd associated with the calling thread. ** Return a pointer to the SqliteTsd associated with the calling thread.
** TODO: Actually return thread-specific-data instead of this global pointer.
*/ */
SqliteTsd *sqlite3Tsd(){ SqliteTsd *sqlite3Tsd(){
static SqliteTsd tsd = { SqliteTsd *pTsd = sqlite3Os.xThreadSpecificData(sizeof(SqliteTsd));
0 /* mallocFailed flag */ if( pTsd && !pTsd->isInit ){
#ifndef SQLITE_OMIT_SOFTHEAPLIMIT pTsd->nSoftHeapLimit = 0xFFFFFFFF;
, 0xFFFFFFFF /* nSoftHeapLimit */ #ifndef NDEBUG
, 0 /* nAlloc */ pTsd->mallocAllowed = 1;
#endif #endif
#ifndef NDEBUG pTsd->isInit = 1;
, 1 /* mallocAllowed flag */ }
#endif return pTsd;
#ifdef SQLITE_MEMDEBUG
, 0
, 0
, 0
, 0
#endif
};
return &tsd;
} }
/* /*

View File

@ -10,7 +10,7 @@
#*********************************************************************** #***********************************************************************
# This file runs all tests. # This file runs all tests.
# #
# $Id: all.test,v 1.30 2005/01/17 07:53:44 danielk1977 Exp $ # $Id: all.test,v 1.31 2005/12/15 10:11:32 danielk1977 Exp $
set testdir [file dirname $argv0] set testdir [file dirname $argv0]
source $testdir/tester.tcl source $testdir/tester.tcl
@ -49,6 +49,7 @@ set LeakList {}
set EXCLUDE { set EXCLUDE {
all.test all.test
async.test
crash.test crash.test
autovacuum_crash.test autovacuum_crash.test
quick.test quick.test

View File

@ -6,7 +6,7 @@
#*********************************************************************** #***********************************************************************
# This file runs all tests. # This file runs all tests.
# #
# $Id: quick.test,v 1.37 2005/12/07 06:27:45 danielk1977 Exp $ # $Id: quick.test,v 1.38 2005/12/15 10:11:32 danielk1977 Exp $
set testdir [file dirname $argv0] set testdir [file dirname $argv0]
source $testdir/tester.tcl source $testdir/tester.tcl
@ -16,6 +16,7 @@ set ISQUICK 1
set EXCLUDE { set EXCLUDE {
all.test all.test
async.test
btree2.test btree2.test
btree3.test btree3.test
btree4.test btree4.test

View File

@ -11,7 +11,7 @@
# This file implements regression tests for SQLite library. The # This file implements regression tests for SQLite library. The
# focus of this file is testing the SELECT statement. # focus of this file is testing the SELECT statement.
# #
# $Id: select1.test,v 1.44 2005/12/09 14:25:12 danielk1977 Exp $ # $Id: select1.test,v 1.45 2005/12/15 10:11:32 danielk1977 Exp $
set testdir [file dirname $argv0] set testdir [file dirname $argv0]
source $testdir/tester.tcl source $testdir/tester.tcl
@ -23,6 +23,7 @@ do_test select1-1.1 {
lappend v $msg lappend v $msg
} {1 {no such table: test1}} } {1 {no such table: test1}}
execsql {CREATE TABLE test1(f1 int, f2 int)} execsql {CREATE TABLE test1(f1 int, f2 int)}
do_test select1-1.2 { do_test select1-1.2 {
@ -799,4 +800,5 @@ ifcapable {compound && subquery} {
} {x 1 x 3} } {x 1 x 3}
} ;# ifcapable compound } ;# ifcapable compound
finish_test finish_test