mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-08 14:02:16 +03:00
Test infrastructure for the new memory subsystem. (CVS 4229)
FossilOrigin-Name: 9e506656720fb3a3205b8cc398152272ce56f6f3
This commit is contained in:
1
main.mk
1
main.mk
@@ -195,6 +195,7 @@ TESTSRC = \
|
|||||||
$(TOP)/src/test_btree.c \
|
$(TOP)/src/test_btree.c \
|
||||||
$(TOP)/src/test_config.c \
|
$(TOP)/src/test_config.c \
|
||||||
$(TOP)/src/test_hexio.c \
|
$(TOP)/src/test_hexio.c \
|
||||||
|
$(TOP)/src/test_malloc.c \
|
||||||
$(TOP)/src/test_md5.c \
|
$(TOP)/src/test_md5.c \
|
||||||
$(TOP)/src/test_schema.c \
|
$(TOP)/src/test_schema.c \
|
||||||
$(TOP)/src/test_server.c \
|
$(TOP)/src/test_server.c \
|
||||||
|
19
manifest
19
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)
|
C Test\sinfrastructure\sfor\sthe\snew\smemory\ssubsystem.\s(CVS\s4229)
|
||||||
D 2007-08-15T17:08:46
|
D 2007-08-15T19:16:43
|
||||||
F Makefile.in 0c0e53720f658c7a551046442dd7afba0b72bfbe
|
F Makefile.in 0c0e53720f658c7a551046442dd7afba0b72bfbe
|
||||||
F Makefile.linux-gcc 65241babba6faf1152bf86574477baab19190499
|
F Makefile.linux-gcc 65241babba6faf1152bf86574477baab19190499
|
||||||
F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
|
F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
|
||||||
@@ -51,7 +51,7 @@ F ext/icu/README.txt 3b130aa66e7a681136f6add198b076a2f90d1e33
|
|||||||
F ext/icu/icu.c 61a345d8126686aa3487aa8d2d0f68abd655f7a4
|
F ext/icu/icu.c 61a345d8126686aa3487aa8d2d0f68abd655f7a4
|
||||||
F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895
|
F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895
|
||||||
F ltmain.sh 56abb507100ed2d4261f6dd1653dec3cf4066387
|
F ltmain.sh 56abb507100ed2d4261f6dd1653dec3cf4066387
|
||||||
F main.mk 4b70d380336187ddfb3e2f24394fad74e6266f92
|
F main.mk dad2269dd2a097892536482c12acaab001e930c2
|
||||||
F mkdll.sh 37fa8a7412e51b5ab2bc6d4276135f022a0feffb
|
F mkdll.sh 37fa8a7412e51b5ab2bc6d4276135f022a0feffb
|
||||||
F mkextu.sh 416f9b7089d80e5590a29692c9d9280a10dbad9f
|
F mkextu.sh 416f9b7089d80e5590a29692c9d9280a10dbad9f
|
||||||
F mkextw.sh 1a866b53637dab137191341cc875575a5ca110fb
|
F mkextw.sh 1a866b53637dab137191341cc875575a5ca110fb
|
||||||
@@ -89,7 +89,7 @@ F src/main.c f12d230c1226d3f43c1f4595af1c25ccbe3017c7
|
|||||||
F src/malloc.c 3850ab4a2edfb190ffee353c5674ebd8c6b4ccc7
|
F src/malloc.c 3850ab4a2edfb190ffee353c5674ebd8c6b4ccc7
|
||||||
F src/md5.c c5fdfa5c2593eaee2e32a5ce6c6927c986eaf217
|
F src/md5.c c5fdfa5c2593eaee2e32a5ce6c6927c986eaf217
|
||||||
F src/mem1.c ef73642a171d174cd556d0168f8edbceaf94933b
|
F src/mem1.c ef73642a171d174cd556d0168f8edbceaf94933b
|
||||||
F src/mem2.c b8173ddcca23e99829617185154a35a6f046b214
|
F src/mem2.c 1f3745eae124b08706a9e582b1e75bae614d0f5a
|
||||||
F src/mutex.c 667dae0de95f8fb92a3ffc8c3f20c0d26115a1a6
|
F src/mutex.c 667dae0de95f8fb92a3ffc8c3f20c0d26115a1a6
|
||||||
F src/os.c e2faefbe0f5a8ca5e3b1c49ee1b5c6cfa0f0e279
|
F src/os.c e2faefbe0f5a8ca5e3b1c49ee1b5c6cfa0f0e279
|
||||||
F src/os.h 8eff07babf74e5bc3f895f8a6c7c294dad5ff997
|
F src/os.h 8eff07babf74e5bc3f895f8a6c7c294dad5ff997
|
||||||
@@ -117,7 +117,7 @@ F src/sqlite3ext.h a27bedc222df5e5f0f458ac99726d0483b953a91
|
|||||||
F src/sqliteInt.h fc9f6e8d916e182c04983a089c4ce4057fac5003
|
F src/sqliteInt.h fc9f6e8d916e182c04983a089c4ce4057fac5003
|
||||||
F src/sqliteLimit.h f14609c27636ebc217c9603ade26dbdd7d0f6afa
|
F src/sqliteLimit.h f14609c27636ebc217c9603ade26dbdd7d0f6afa
|
||||||
F src/table.c a8de75bcedf84d4060d804264b067ab3b1a3561d
|
F src/table.c a8de75bcedf84d4060d804264b067ab3b1a3561d
|
||||||
F src/tclsqlite.c 648e6f53041ce4974234d4963e71680926760925
|
F src/tclsqlite.c 0606c4f31711492eb4d7480a981eebb80914f3d9
|
||||||
F src/test1.c 94bd41c24a4d8d782e39c1275421511587d8b293
|
F src/test1.c 94bd41c24a4d8d782e39c1275421511587d8b293
|
||||||
F src/test2.c 5c3edc610852a8f67990cd08c5d5dbb79e3f8db9
|
F src/test2.c 5c3edc610852a8f67990cd08c5d5dbb79e3f8db9
|
||||||
F src/test3.c a280931fb40222b7c90da45eea926459beee8904
|
F src/test3.c a280931fb40222b7c90da45eea926459beee8904
|
||||||
@@ -133,6 +133,7 @@ F src/test_btree.c 882d59acad48bab3b1fe3daf3645059b590cfc79
|
|||||||
F src/test_config.c 26389b032216e0fb2b544ff48a5e9101bd7b1fb4
|
F src/test_config.c 26389b032216e0fb2b544ff48a5e9101bd7b1fb4
|
||||||
F src/test_hexio.c 14c007252285c6dabcec4a28fcf08e9177e85178
|
F src/test_hexio.c 14c007252285c6dabcec4a28fcf08e9177e85178
|
||||||
F src/test_loadext.c 22065d601a18878e5542191001f0eaa5d77c0ed8
|
F src/test_loadext.c 22065d601a18878e5542191001f0eaa5d77c0ed8
|
||||||
|
F src/test_malloc.c 3f47498aba913d0d555e392211b9d3355f69c21b
|
||||||
F src/test_md5.c d9f828765b242ff86f58cd879259c3da4eaede02
|
F src/test_md5.c d9f828765b242ff86f58cd879259c3da4eaede02
|
||||||
F src/test_schema.c 89c526e4b1e9a8fb540550f6ebc69242bf57d3ce
|
F src/test_schema.c 89c526e4b1e9a8fb540550f6ebc69242bf57d3ce
|
||||||
F src/test_server.c 76c0baf509abe65ca6e5c7974ab0097cfdd8b833
|
F src/test_server.c 76c0baf509abe65ca6e5c7974ab0097cfdd8b833
|
||||||
@@ -528,7 +529,7 @@ F www/tclsqlite.tcl 8be95ee6dba05eabcd27a9d91331c803f2ce2130
|
|||||||
F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
|
F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
|
||||||
F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
|
F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
|
||||||
F www/whentouse.tcl fc46eae081251c3c181bd79c5faef8195d7991a5
|
F www/whentouse.tcl fc46eae081251c3c181bd79c5faef8195d7991a5
|
||||||
P 8d2d1c4ff9dca61f75e3048107ee9712d346a28c
|
P af9503daf3f7703fcddad754bc1dc9e179830b6e
|
||||||
R 7d9819ae0c3408fa1555b7b8d9a48850
|
R 637b616a5b01e055657d69b5613c0e1b
|
||||||
U danielk1977
|
U drh
|
||||||
Z 41f21c80ce49e631fe5dbf7930bb9145
|
Z 56bc577909e0d6bde5f25aac7f6e7b86
|
||||||
|
@@ -1 +1 @@
|
|||||||
af9503daf3f7703fcddad754bc1dc9e179830b6e
|
9e506656720fb3a3205b8cc398152272ce56f6f3
|
13
src/mem2.c
13
src/mem2.c
@@ -12,7 +12,7 @@
|
|||||||
** This file contains the C functions that implement a memory
|
** This file contains the C functions that implement a memory
|
||||||
** allocation subsystem for use by SQLite.
|
** 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->iForeGuard = FOREGUARD;
|
||||||
pHdr->nBacktraceSlots = backtraceLevels;
|
pHdr->nBacktraceSlots = backtraceLevels;
|
||||||
if( 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{
|
}else{
|
||||||
pHdr->nBacktrace = 0;
|
pHdr->nBacktrace = 0;
|
||||||
}
|
}
|
||||||
@@ -304,13 +306,12 @@ void sqlite3_free(void *pPrior){
|
|||||||
void *sqlite3_realloc(void *pPrior, unsigned int nByte){
|
void *sqlite3_realloc(void *pPrior, unsigned int nByte){
|
||||||
struct MemBlockHdr *pOldHdr;
|
struct MemBlockHdr *pOldHdr;
|
||||||
void *pNew;
|
void *pNew;
|
||||||
unsigned nOld;
|
|
||||||
if( pPrior==0 ){
|
if( pPrior==0 ){
|
||||||
return sqlite3_malloc(nByte);
|
return sqlite3_malloc(nByte);
|
||||||
}
|
}
|
||||||
if( nByte==0 ){
|
if( nByte==0 ){
|
||||||
sqlite3_free(pPrior);
|
sqlite3_free(pPrior);
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
pOldHdr = sqlite3MemsysGetHeader(pPrior);
|
pOldHdr = sqlite3MemsysGetHeader(pPrior);
|
||||||
pNew = sqlite3_malloc(nByte);
|
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
|
** A value of zero turns of backtracing. The number is always rounded
|
||||||
** up to a multiple of 2.
|
** 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<0 ){ depth = 0; }
|
||||||
if( depth>20 ){ depth = 20; }
|
if( depth>20 ){ depth = 20; }
|
||||||
depth = (depth+1)&~1;
|
depth = (depth+1)&0xfe;
|
||||||
backtraceLevels = depth;
|
backtraceLevels = depth;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -12,7 +12,7 @@
|
|||||||
** A TCL Interface to SQLite. Append this file to sqlite3.c and
|
** A TCL Interface to SQLite. Append this file to sqlite3.c and
|
||||||
** compile the whole thing to build a TCL-enabled version of SQLite.
|
** 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 "tcl.h"
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
@@ -2483,6 +2483,8 @@ int TCLSH_MAIN(int argc, char **argv){
|
|||||||
Sqlite3_Init(interp);
|
Sqlite3_Init(interp);
|
||||||
#ifdef SQLITE_TEST
|
#ifdef SQLITE_TEST
|
||||||
{
|
{
|
||||||
|
extern int Md5_Init(Tcl_Interp*);
|
||||||
|
extern int Sqliteconfig_Init(Tcl_Interp*);
|
||||||
extern int Sqlitetest1_Init(Tcl_Interp*);
|
extern int Sqlitetest1_Init(Tcl_Interp*);
|
||||||
extern int Sqlitetest2_Init(Tcl_Interp*);
|
extern int Sqlitetest2_Init(Tcl_Interp*);
|
||||||
extern int Sqlitetest3_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 Sqlitetest7_Init(Tcl_Interp*);
|
||||||
extern int Sqlitetest8_Init(Tcl_Interp*);
|
extern int Sqlitetest8_Init(Tcl_Interp*);
|
||||||
extern int Sqlitetest9_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 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_autoext_Init(Tcl_Interp*);
|
||||||
extern int Sqlitetest_hexio_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);
|
Sqlitetest1_Init(interp);
|
||||||
Sqlitetest2_Init(interp);
|
Sqlitetest2_Init(interp);
|
||||||
Sqlitetest3_Init(interp);
|
Sqlitetest3_Init(interp);
|
||||||
@@ -2511,12 +2514,11 @@ int TCLSH_MAIN(int argc, char **argv){
|
|||||||
Sqlitetest8_Init(interp);
|
Sqlitetest8_Init(interp);
|
||||||
Sqlitetest9_Init(interp);
|
Sqlitetest9_Init(interp);
|
||||||
Sqlitetestasync_Init(interp);
|
Sqlitetestasync_Init(interp);
|
||||||
Sqlitetesttclvar_Init(interp);
|
|
||||||
Sqlitetestschema_Init(interp);
|
|
||||||
Sqlitetest_autoext_Init(interp);
|
Sqlitetest_autoext_Init(interp);
|
||||||
Sqlitetest_hexio_Init(interp);
|
Sqlitetest_hexio_Init(interp);
|
||||||
Sqliteconfig_Init(interp);
|
Sqlitetest_malloc_Init(interp);
|
||||||
Md5_Init(interp);
|
Sqlitetestschema_Init(interp);
|
||||||
|
Sqlitetesttclvar_Init(interp);
|
||||||
#ifdef SQLITE_SSE
|
#ifdef SQLITE_SSE
|
||||||
Sqlitetestsse_Init(interp);
|
Sqlitetestsse_Init(interp);
|
||||||
#endif
|
#endif
|
||||||
|
251
src/test_malloc.c
Normal file
251
src/test_malloc.c
Normal file
@@ -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 <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
** 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<sizeof(p)*2; i++, k--){
|
||||||
|
z[k] = zHex[n&0xf];
|
||||||
|
n >>= 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<sizeof(void*)*2 && z[0]; i++){
|
||||||
|
int v;
|
||||||
|
v = hexToInt(*z++);
|
||||||
|
if( v<0 ) return TCL_ERROR;
|
||||||
|
n = n*16 + v;
|
||||||
|
}
|
||||||
|
if( *z!=0 ) return TCL_ERROR;
|
||||||
|
*pp = (void*)n;
|
||||||
|
return TCL_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Usage: sqlite3_malloc NBYTES
|
||||||
|
**
|
||||||
|
** Raw test interface for sqlite3_malloc().
|
||||||
|
*/
|
||||||
|
static int test_malloc(
|
||||||
|
void * clientData,
|
||||||
|
Tcl_Interp *interp,
|
||||||
|
int objc,
|
||||||
|
Tcl_Obj *CONST objv[]
|
||||||
|
){
|
||||||
|
int nByte;
|
||||||
|
void *p;
|
||||||
|
char zOut[100];
|
||||||
|
if( objc!=2 ){
|
||||||
|
Tcl_WrongNumArgs(interp, 1, objv, "NBYTES");
|
||||||
|
return TCL_ERROR;
|
||||||
|
}
|
||||||
|
if( Tcl_GetIntFromObj(interp, objv[1], &nByte) ) return TCL_ERROR;
|
||||||
|
p = sqlite3_malloc((unsigned)nByte);
|
||||||
|
pointerToText(p, zOut);
|
||||||
|
Tcl_AppendResult(interp, zOut, NULL);
|
||||||
|
return TCL_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Usage: sqlite3_realloc PRIOR NBYTES
|
||||||
|
**
|
||||||
|
** Raw test interface for sqlite3_realloc().
|
||||||
|
*/
|
||||||
|
static int test_realloc(
|
||||||
|
void * clientData,
|
||||||
|
Tcl_Interp *interp,
|
||||||
|
int objc,
|
||||||
|
Tcl_Obj *CONST objv[]
|
||||||
|
){
|
||||||
|
int nByte;
|
||||||
|
void *pPrior, *p;
|
||||||
|
char zOut[100];
|
||||||
|
if( objc!=3 ){
|
||||||
|
Tcl_WrongNumArgs(interp, 1, objv, "PRIOR NBYTES");
|
||||||
|
return TCL_ERROR;
|
||||||
|
}
|
||||||
|
if( Tcl_GetIntFromObj(interp, objv[2], &nByte) ) return TCL_ERROR;
|
||||||
|
if( textToPointer(Tcl_GetString(objv[1]), &pPrior) ){
|
||||||
|
Tcl_AppendResult(interp, "bad pointer: ", Tcl_GetString(objv[1]), (char*)0);
|
||||||
|
return TCL_ERROR;
|
||||||
|
}
|
||||||
|
p = sqlite3_realloc(pPrior, (unsigned)nByte);
|
||||||
|
pointerToText(p, zOut);
|
||||||
|
Tcl_AppendResult(interp, zOut, NULL);
|
||||||
|
return TCL_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Usage: sqlite3_free PRIOR
|
||||||
|
**
|
||||||
|
** Raw test interface for sqlite3_free().
|
||||||
|
*/
|
||||||
|
static int test_free(
|
||||||
|
void * clientData,
|
||||||
|
Tcl_Interp *interp,
|
||||||
|
int objc,
|
||||||
|
Tcl_Obj *CONST objv[]
|
||||||
|
){
|
||||||
|
void *pPrior;
|
||||||
|
if( objc!=2 ){
|
||||||
|
Tcl_WrongNumArgs(interp, 1, objv, "PRIOR");
|
||||||
|
return TCL_ERROR;
|
||||||
|
}
|
||||||
|
if( textToPointer(Tcl_GetString(objv[1]), &pPrior) ){
|
||||||
|
Tcl_AppendResult(interp, "bad pointer: ", Tcl_GetString(objv[1]), (char*)0);
|
||||||
|
return TCL_ERROR;
|
||||||
|
}
|
||||||
|
sqlite3_free(pPrior);
|
||||||
|
return TCL_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Usage: sqlite3_memory_used
|
||||||
|
**
|
||||||
|
** Raw test interface for sqlite3_memory_used().
|
||||||
|
*/
|
||||||
|
static int test_memory_used(
|
||||||
|
void * clientData,
|
||||||
|
Tcl_Interp *interp,
|
||||||
|
int objc,
|
||||||
|
Tcl_Obj *CONST objv[]
|
||||||
|
){
|
||||||
|
Tcl_SetObjResult(interp, Tcl_NewWideIntObj(sqlite3_memory_used()));
|
||||||
|
return TCL_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Usage: sqlite3_memory_highwater ?RESETFLAG?
|
||||||
|
**
|
||||||
|
** Raw test interface for sqlite3_memory_highwater().
|
||||||
|
*/
|
||||||
|
static int test_memory_highwater(
|
||||||
|
void * clientData,
|
||||||
|
Tcl_Interp *interp,
|
||||||
|
int objc,
|
||||||
|
Tcl_Obj *CONST objv[]
|
||||||
|
){
|
||||||
|
int resetFlag = 0;
|
||||||
|
if( objc!=1 && objc!=2 ){
|
||||||
|
Tcl_WrongNumArgs(interp, 1, objv, "?RESET?");
|
||||||
|
return TCL_ERROR;
|
||||||
|
}
|
||||||
|
if( objc==2 ){
|
||||||
|
if( Tcl_GetBooleanFromObj(interp, objv[1], &resetFlag) ) return TCL_ERROR;
|
||||||
|
}
|
||||||
|
Tcl_SetObjResult(interp,
|
||||||
|
Tcl_NewWideIntObj(sqlite3_memory_highwater(resetFlag)));
|
||||||
|
return TCL_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Usage: sqlite3_memdebug_backtrace DEPTH
|
||||||
|
**
|
||||||
|
** Set the depth of backtracing. If SQLITE_MEMDEBUG is not defined
|
||||||
|
** then this routine is a no-op.
|
||||||
|
*/
|
||||||
|
static int test_memdebug_backtrace(
|
||||||
|
void * clientData,
|
||||||
|
Tcl_Interp *interp,
|
||||||
|
int objc,
|
||||||
|
Tcl_Obj *CONST objv[]
|
||||||
|
){
|
||||||
|
int depth;
|
||||||
|
if( objc!=2 ){
|
||||||
|
Tcl_WrongNumArgs(interp, 1, objv, "DEPT");
|
||||||
|
return TCL_ERROR;
|
||||||
|
}
|
||||||
|
if( Tcl_GetIntFromObj(interp, objv[1], &depth) ) return TCL_ERROR;
|
||||||
|
#ifdef SQLITE_MEMDEBUG
|
||||||
|
{
|
||||||
|
extern void sqlite3_memdebug_backtrace(int);
|
||||||
|
sqlite3_memdebug_backtrace(depth);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return TCL_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Usage: sqlite3_memdebug_dump FILENAME
|
||||||
|
**
|
||||||
|
** Write a summary of unfreed memory to FILENAME.
|
||||||
|
*/
|
||||||
|
static int test_memdebug_dump(
|
||||||
|
void * clientData,
|
||||||
|
Tcl_Interp *interp,
|
||||||
|
int objc,
|
||||||
|
Tcl_Obj *CONST objv[]
|
||||||
|
){
|
||||||
|
if( objc!=2 ){
|
||||||
|
Tcl_WrongNumArgs(interp, 1, objv, "FILENAME");
|
||||||
|
return TCL_ERROR;
|
||||||
|
}
|
||||||
|
#ifdef SQLITE_MEMDEBUG
|
||||||
|
{
|
||||||
|
extern void sqlite3_memdebug_dump(const char*);
|
||||||
|
sqlite3_memdebug_dump(Tcl_GetString(objv[1]));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return TCL_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Register commands with the TCL interpreter.
|
||||||
|
*/
|
||||||
|
int Sqlitetest_malloc_Init(Tcl_Interp *interp){
|
||||||
|
static struct {
|
||||||
|
char *zName;
|
||||||
|
Tcl_ObjCmdProc *xProc;
|
||||||
|
} aObjCmd[] = {
|
||||||
|
{ "sqlite3_malloc", test_malloc },
|
||||||
|
{ "sqlite3_realloc", test_realloc },
|
||||||
|
{ "sqlite3_free", test_free },
|
||||||
|
{ "sqlite3_memory_used", test_memory_used },
|
||||||
|
{ "sqlite3_memory_highwater", test_memory_highwater },
|
||||||
|
{ "sqlite3_memdebug_backtrace", test_memdebug_backtrace },
|
||||||
|
{ "sqlite3_memdebug_dump", test_memdebug_dump },
|
||||||
|
};
|
||||||
|
int i;
|
||||||
|
for(i=0; i<sizeof(aObjCmd)/sizeof(aObjCmd[0]); i++){
|
||||||
|
Tcl_CreateObjCommand(interp, aObjCmd[i].zName, aObjCmd[i].xProc, 0, 0);
|
||||||
|
}
|
||||||
|
return TCL_OK;
|
||||||
|
}
|
Reference in New Issue
Block a user