Skip to content

Commit

Permalink
Modifications to test code so that the sqlite3MemdebugHastype() asser…
Browse files Browse the repository at this point in the history
…t() statements are enabled for Tcl tests.
  • Loading branch information
danielk-1977 committed Jul 16, 2020
1 parent a51a2a0 commit 9e22659
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 39 deletions.
6 changes: 3 additions & 3 deletions src/mem2.c
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ void sqlite3MemSetDefault(void){
** Set the "type" of an allocation.
*/
void sqlite3MemdebugSetType(void *p, u8 eType){
if( p && sqlite3GlobalConfig.m.xMalloc==sqlite3MemMalloc ){
if( p && sqlite3GlobalConfig.m.xFree==sqlite3MemFree ){
struct MemBlockHdr *pHdr;
pHdr = sqlite3MemsysGetHeader(p);
assert( pHdr->iForeGuard==FOREGUARD );
Expand All @@ -398,7 +398,7 @@ void sqlite3MemdebugSetType(void *p, u8 eType){
*/
int sqlite3MemdebugHasType(void *p, u8 eType){
int rc = 1;
if( p && sqlite3GlobalConfig.m.xMalloc==sqlite3MemMalloc ){
if( p && sqlite3GlobalConfig.m.xFree==sqlite3MemFree ){
struct MemBlockHdr *pHdr;
pHdr = sqlite3MemsysGetHeader(p);
assert( pHdr->iForeGuard==FOREGUARD ); /* Allocation is valid */
Expand All @@ -420,7 +420,7 @@ int sqlite3MemdebugHasType(void *p, u8 eType){
*/
int sqlite3MemdebugNoType(void *p, u8 eType){
int rc = 1;
if( p && sqlite3GlobalConfig.m.xMalloc==sqlite3MemMalloc ){
if( p && sqlite3GlobalConfig.m.xFree==sqlite3MemFree ){
struct MemBlockHdr *pHdr;
pHdr = sqlite3MemsysGetHeader(p);
assert( pHdr->iForeGuard==FOREGUARD ); /* Allocation is valid */
Expand Down
39 changes: 3 additions & 36 deletions src/test_malloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,32 +112,6 @@ static void *faultsimRealloc(void *pOld, int n){
return p;
}

/*
** The following method calls are passed directly through to the underlying
** malloc system:
**
** xFree
** xSize
** xRoundup
** xInit
** xShutdown
*/
static void faultsimFree(void *p){
memfault.m.xFree(p);
}
static int faultsimSize(void *p){
return memfault.m.xSize(p);
}
static int faultsimRoundup(int n){
return memfault.m.xRoundup(n);
}
static int faultsimInit(void *p){
return memfault.m.xInit(memfault.m.pAppData);
}
static void faultsimShutdown(void *p){
memfault.m.xShutdown(memfault.m.pAppData);
}

/*
** This routine configures the malloc failure simulation. After
** calling this routine, the next nDelay mallocs will succeed, followed
Expand Down Expand Up @@ -204,16 +178,6 @@ static void faultsimEndBenign(void){
** the argument is non-zero, the
*/
static int faultsimInstall(int install){
static struct sqlite3_mem_methods m = {
faultsimMalloc, /* xMalloc */
faultsimFree, /* xFree */
faultsimRealloc, /* xRealloc */
faultsimSize, /* xSize */
faultsimRoundup, /* xRoundup */
faultsimInit, /* xInit */
faultsimShutdown, /* xShutdown */
0 /* pAppData */
};
int rc;

install = (install ? 1 : 0);
Expand All @@ -227,6 +191,9 @@ static int faultsimInstall(int install){
rc = sqlite3_config(SQLITE_CONFIG_GETMALLOC, &memfault.m);
assert(memfault.m.xMalloc);
if( rc==SQLITE_OK ){
sqlite3_mem_methods m = memfault.m;
m.xMalloc = faultsimMalloc;
m.xRealloc = faultsimRealloc;
rc = sqlite3_config(SQLITE_CONFIG_MALLOC, &m);
}
sqlite3_test_control(SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS,
Expand Down
1 change: 1 addition & 0 deletions test/tester.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ if {[info command sqlite_orig]==""} {
set ::dbhandle [lindex $args 0]
uplevel #0 $::G(perm:dbconfig)
}
[lindex $args 0] cache size 3
set res
} else {
# This command is not opening a new database connection. Pass the
Expand Down

0 comments on commit 9e22659

Please sign in to comment.