From: drh Date: Wed, 15 Aug 2007 19:16:43 +0000 (+0000) Subject: Test infrastructure for the new memory subsystem. (CVS 4229) X-Git-Tag: version-3.5.0~162 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2f999a67580d10dfe23e6b5fdd3cfb956f589ad4;p=thirdparty%2Fsqlite.git Test infrastructure for the new memory subsystem. (CVS 4229) FossilOrigin-Name: 9e506656720fb3a3205b8cc398152272ce56f6f3 --- diff --git a/main.mk b/main.mk index c1d5c9b97e..ed3db27fb4 100644 --- a/main.mk +++ b/main.mk @@ -195,6 +195,7 @@ TESTSRC = \ $(TOP)/src/test_btree.c \ $(TOP)/src/test_config.c \ $(TOP)/src/test_hexio.c \ + $(TOP)/src/test_malloc.c \ $(TOP)/src/test_md5.c \ $(TOP)/src/test_schema.c \ $(TOP)/src/test_server.c \ diff --git a/manifest b/manifest index bf7b4faa69..58c15ea59e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Modify\sthe\scrash-recovery\stest\scode\sin\stest6.c\sfor\s3.5.\sAlso\schange\ssome\sother\scode\sto\suse\sthe\snew\ssqlite3_io_methods\sinterface.\sLots\sof\sthings\sare\sbroken\snow.\s(CVS\s4228) -D 2007-08-15T17:08:46 +C Test\sinfrastructure\sfor\sthe\snew\smemory\ssubsystem.\s(CVS\s4229) +D 2007-08-15T19:16:43 F Makefile.in 0c0e53720f658c7a551046442dd7afba0b72bfbe F Makefile.linux-gcc 65241babba6faf1152bf86574477baab19190499 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028 @@ -51,7 +51,7 @@ F ext/icu/README.txt 3b130aa66e7a681136f6add198b076a2f90d1e33 F ext/icu/icu.c 61a345d8126686aa3487aa8d2d0f68abd655f7a4 F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 F ltmain.sh 56abb507100ed2d4261f6dd1653dec3cf4066387 -F main.mk 4b70d380336187ddfb3e2f24394fad74e6266f92 +F main.mk dad2269dd2a097892536482c12acaab001e930c2 F mkdll.sh 37fa8a7412e51b5ab2bc6d4276135f022a0feffb F mkextu.sh 416f9b7089d80e5590a29692c9d9280a10dbad9f F mkextw.sh 1a866b53637dab137191341cc875575a5ca110fb @@ -89,7 +89,7 @@ F src/main.c f12d230c1226d3f43c1f4595af1c25ccbe3017c7 F src/malloc.c 3850ab4a2edfb190ffee353c5674ebd8c6b4ccc7 F src/md5.c c5fdfa5c2593eaee2e32a5ce6c6927c986eaf217 F src/mem1.c ef73642a171d174cd556d0168f8edbceaf94933b -F src/mem2.c b8173ddcca23e99829617185154a35a6f046b214 +F src/mem2.c 1f3745eae124b08706a9e582b1e75bae614d0f5a F src/mutex.c 667dae0de95f8fb92a3ffc8c3f20c0d26115a1a6 F src/os.c e2faefbe0f5a8ca5e3b1c49ee1b5c6cfa0f0e279 F src/os.h 8eff07babf74e5bc3f895f8a6c7c294dad5ff997 @@ -117,7 +117,7 @@ F src/sqlite3ext.h a27bedc222df5e5f0f458ac99726d0483b953a91 F src/sqliteInt.h fc9f6e8d916e182c04983a089c4ce4057fac5003 F src/sqliteLimit.h f14609c27636ebc217c9603ade26dbdd7d0f6afa F src/table.c a8de75bcedf84d4060d804264b067ab3b1a3561d -F src/tclsqlite.c 648e6f53041ce4974234d4963e71680926760925 +F src/tclsqlite.c 0606c4f31711492eb4d7480a981eebb80914f3d9 F src/test1.c 94bd41c24a4d8d782e39c1275421511587d8b293 F src/test2.c 5c3edc610852a8f67990cd08c5d5dbb79e3f8db9 F src/test3.c a280931fb40222b7c90da45eea926459beee8904 @@ -133,6 +133,7 @@ F src/test_btree.c 882d59acad48bab3b1fe3daf3645059b590cfc79 F src/test_config.c 26389b032216e0fb2b544ff48a5e9101bd7b1fb4 F src/test_hexio.c 14c007252285c6dabcec4a28fcf08e9177e85178 F src/test_loadext.c 22065d601a18878e5542191001f0eaa5d77c0ed8 +F src/test_malloc.c 3f47498aba913d0d555e392211b9d3355f69c21b F src/test_md5.c d9f828765b242ff86f58cd879259c3da4eaede02 F src/test_schema.c 89c526e4b1e9a8fb540550f6ebc69242bf57d3ce F src/test_server.c 76c0baf509abe65ca6e5c7974ab0097cfdd8b833 @@ -528,7 +529,7 @@ F www/tclsqlite.tcl 8be95ee6dba05eabcd27a9d91331c803f2ce2130 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0 F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b F www/whentouse.tcl fc46eae081251c3c181bd79c5faef8195d7991a5 -P 8d2d1c4ff9dca61f75e3048107ee9712d346a28c -R 7d9819ae0c3408fa1555b7b8d9a48850 -U danielk1977 -Z 41f21c80ce49e631fe5dbf7930bb9145 +P af9503daf3f7703fcddad754bc1dc9e179830b6e +R 637b616a5b01e055657d69b5613c0e1b +U drh +Z 56bc577909e0d6bde5f25aac7f6e7b86 diff --git a/manifest.uuid b/manifest.uuid index ce612004a4..9adba8fb59 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -af9503daf3f7703fcddad754bc1dc9e179830b6e \ No newline at end of file +9e506656720fb3a3205b8cc398152272ce56f6f3 \ No newline at end of file diff --git a/src/mem2.c b/src/mem2.c index 35f41eb2e2..d538619645 100644 --- a/src/mem2.c +++ b/src/mem2.c @@ -12,7 +12,7 @@ ** This file contains the C functions that implement a memory ** allocation subsystem for use by SQLite. ** -** $Id: mem2.c,v 1.1 2007/08/15 17:07:57 drh Exp $ +** $Id: mem2.c,v 1.2 2007/08/15 19:16:43 drh Exp $ */ /* @@ -239,7 +239,9 @@ void *sqlite3_malloc(unsigned int nByte){ pHdr->iForeGuard = FOREGUARD; pHdr->nBacktraceSlots = backtraceLevels; if( backtraceLevels ){ - pHdr->nBacktrace = backtrace(pBt, backtraceLevels); + void *aAddr[40]; + pHdr->nBacktrace = backtrace(aAddr, backtraceLevels+1)-1; + memcpy(pBt, &aAddr[1], pHdr->nBacktrace*sizeof(void*)); }else{ pHdr->nBacktrace = 0; } @@ -304,13 +306,12 @@ void sqlite3_free(void *pPrior){ void *sqlite3_realloc(void *pPrior, unsigned int nByte){ struct MemBlockHdr *pOldHdr; void *pNew; - unsigned nOld; if( pPrior==0 ){ return sqlite3_malloc(nByte); } if( nByte==0 ){ sqlite3_free(pPrior); - return; + return 0; } pOldHdr = sqlite3MemsysGetHeader(pPrior); pNew = sqlite3_malloc(nByte); @@ -329,10 +330,10 @@ void *sqlite3_realloc(void *pPrior, unsigned int nByte){ ** A value of zero turns of backtracing. The number is always rounded ** up to a multiple of 2. */ -void sqlite3_memdebug_backtrace_depth(int depth){ +void sqlite3_memdebug_backtrace(int depth){ if( depth<0 ){ depth = 0; } if( depth>20 ){ depth = 20; } - depth = (depth+1)&~1; + depth = (depth+1)&0xfe; backtraceLevels = depth; } diff --git a/src/tclsqlite.c b/src/tclsqlite.c index 83a79cddc3..d3fbc375a9 100644 --- a/src/tclsqlite.c +++ b/src/tclsqlite.c @@ -12,7 +12,7 @@ ** A TCL Interface to SQLite. Append this file to sqlite3.c and ** compile the whole thing to build a TCL-enabled version of SQLite. ** -** $Id: tclsqlite.c,v 1.194 2007/08/07 17:13:04 drh Exp $ +** $Id: tclsqlite.c,v 1.195 2007/08/15 19:16:43 drh Exp $ */ #include "tcl.h" #include @@ -2483,6 +2483,8 @@ int TCLSH_MAIN(int argc, char **argv){ Sqlite3_Init(interp); #ifdef SQLITE_TEST { + extern int Md5_Init(Tcl_Interp*); + extern int Sqliteconfig_Init(Tcl_Interp*); extern int Sqlitetest1_Init(Tcl_Interp*); extern int Sqlitetest2_Init(Tcl_Interp*); extern int Sqlitetest3_Init(Tcl_Interp*); @@ -2492,15 +2494,16 @@ int TCLSH_MAIN(int argc, char **argv){ extern int Sqlitetest7_Init(Tcl_Interp*); extern int Sqlitetest8_Init(Tcl_Interp*); extern int Sqlitetest9_Init(Tcl_Interp*); - extern int Md5_Init(Tcl_Interp*); - extern int Sqlitetestsse_Init(Tcl_Interp*); extern int Sqlitetestasync_Init(Tcl_Interp*); - extern int Sqlitetesttclvar_Init(Tcl_Interp*); - extern int Sqlitetestschema_Init(Tcl_Interp*); extern int Sqlitetest_autoext_Init(Tcl_Interp*); extern int Sqlitetest_hexio_Init(Tcl_Interp*); - extern int Sqliteconfig_Init(Tcl_Interp*); + extern int Sqlitetest_malloc_Init(Tcl_Interp*); + extern int Sqlitetestschema_Init(Tcl_Interp*); + extern int Sqlitetestsse_Init(Tcl_Interp*); + extern int Sqlitetesttclvar_Init(Tcl_Interp*); + Md5_Init(interp); + Sqliteconfig_Init(interp); Sqlitetest1_Init(interp); Sqlitetest2_Init(interp); Sqlitetest3_Init(interp); @@ -2511,12 +2514,11 @@ int TCLSH_MAIN(int argc, char **argv){ Sqlitetest8_Init(interp); Sqlitetest9_Init(interp); Sqlitetestasync_Init(interp); - Sqlitetesttclvar_Init(interp); - Sqlitetestschema_Init(interp); Sqlitetest_autoext_Init(interp); Sqlitetest_hexio_Init(interp); - Sqliteconfig_Init(interp); - Md5_Init(interp); + Sqlitetest_malloc_Init(interp); + Sqlitetestschema_Init(interp); + Sqlitetesttclvar_Init(interp); #ifdef SQLITE_SSE Sqlitetestsse_Init(interp); #endif diff --git a/src/test_malloc.c b/src/test_malloc.c new file mode 100644 index 0000000000..0b2ed77b48 --- /dev/null +++ b/src/test_malloc.c @@ -0,0 +1,251 @@ +/* +** 2007 August 15 +** +** 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. +** +************************************************************************* +** +** This file contains code used to implement test interfaces to the +** memory allocation subsystem. +** +** $Id: test_malloc.c,v 1.1 2007/08/15 19:16:43 drh Exp $ +*/ +#include "sqliteInt.h" +#include "tcl.h" +#include +#include +#include + +/* +** Transform pointers to text and back again +*/ +static void pointerToText(void *p, char *z){ + static const char zHex[] = "0123456789abcdef"; + int i, k; + sqlite3_uint64 n = (sqlite3_uint64)p; + for(i=0, k=sizeof(p)*2-1; i>= 4; + } + z[sizeof(p)*2] = 0; +} +static int hexToInt(int h){ + if( h>='0' && h<='9' ){ + return h - '0'; + }else if( h>='a' && h<='f' ){ + return h - 'a' + 10; + }else{ + return -1; + } +} +static int textToPointer(const char *z, void **pp){ + sqlite3_uint64 n = 0; + int i; + for(i=0; i