diff options
author | danielk1977 <danielk1977@noemail.net> | 2005-12-19 14:18:11 +0000 |
---|---|---|
committer | danielk1977 <danielk1977@noemail.net> | 2005-12-19 14:18:11 +0000 |
commit | 0190d1da466f4ba92e2e84ad038476861c9600b4 (patch) | |
tree | 961cae25e3835e9071347d0df7912988ffa743d0 /src/util.c | |
parent | 13f7299bbe4490460dc4915279ecb167c1d9931b (diff) | |
download | sqlite-0190d1da466f4ba92e2e84ad038476861c9600b4.tar.gz sqlite-0190d1da466f4ba92e2e84ad038476861c9600b4.zip |
Add some very simple test cases (and resulting bug fixes) for release_memory(). (CVS 2826)
FossilOrigin-Name: 154282fca54bf03d310d6931660f99805bb5477f
Diffstat (limited to 'src/util.c')
-rw-r--r-- | src/util.c | 61 |
1 files changed, 37 insertions, 24 deletions
diff --git a/src/util.c b/src/util.c index 109f12fe5..360f27a33 100644 --- a/src/util.c +++ b/src/util.c @@ -14,7 +14,7 @@ ** This file contains functions for allocating memory, comparing ** strings, and stuff like that. ** -** $Id: util.c,v 1.155 2005/12/18 08:51:24 danielk1977 Exp $ +** $Id: util.c,v 1.156 2005/12/19 14:18:11 danielk1977 Exp $ */ #include "sqliteInt.h" #include "os.h" @@ -35,7 +35,7 @@ ** sqlite3AllocSize() ** ** The function sqlite3FreeX performs the same task as sqlite3Free and is -** guaranteed to be a real function. +** guaranteed to be a real function. The same holds for sqlite3MallocX ** ** The above APIs are implemented in terms of the functions provided at the Os ** level (not in this file). The Os level interface is never accessed directly @@ -48,7 +48,8 @@ ** ** Functions sqlite3MallocRaw() and sqlite3Realloc() may invoke ** sqlite3_release_memory() if a call to sqlite3Os.xMalloc() or -** sqlite3Os.xRealloc() fails. Function sqlite3Malloc() usually invokes +** sqlite3Os.xRealloc() fails (or if the soft-heap-limit for the thread is +** exceeded). Function sqlite3Malloc() usually invokes ** sqlite3MallocRaw(). ** ** MALLOC TEST WRAPPER ARCHITECTURE @@ -63,11 +64,6 @@ ** * Audit outstanding memory allocations (i.e check for leaks). */ -/* -** TODO! -*/ -#define sqlite3_release_memory(x) 0 - #ifdef SQLITE_MEMDEBUG /*-------------------------------------------------------------------------- ** Begin code for memory allocation system test layer. @@ -156,6 +152,37 @@ const char *sqlite3_malloc_id = 0; TESTALLOC_STACKSIZE /* backtrace() stack */ \ ) + +#ifndef SQLITE_OMIT_MEMORY_MANAGEMENT +/* +** Set the soft heap-size limit for the current thread. +*/ +void sqlite3_soft_heap_limit(int n){ + unsigned int N; + if( n<0 ){ + /* No limit */ + N = 0xFFFFFFFF; + }else{ + N = n; + } + sqlite3Tsd()->nSoftHeapLimit = N; +} + +/* +** Release memory held by SQLite instances created by the current thread. +*/ +int sqlite3_release_memory(int n){ + return sqlite3pager_release_memory(n); +} +#else +/* If SQLITE_OMIT_MEMORY_MANAGEMENT is defined, then define a version +** of sqlite3_release_memory() to be used by other code in this file. +** This is done for no better reason than to reduce the number of +** pre-processor #ifndef statements. +*/ +#define sqlite3_release_memory(x) 0 /* 0 == no memory freed */ +#endif + /* ** For keeping track of the number of mallocs and frees. This ** is used to check for memory leaks. The iMallocFail and iMallocReset @@ -452,7 +479,8 @@ void OSMALLOC_FAILED(){ int OSSIZEOF(void *p){ if( p ){ - return sqlite3Os.xAllocationSize(p) - TESTALLOC_OVERHEAD; + u32 *pOs = (u32 *)getOsPointer(p); + return sqlite3Os.xAllocationSize(pOs) - TESTALLOC_OVERHEAD; } return 0; } @@ -1264,21 +1292,6 @@ void sqlite3MallocClearFailed(){ sqlite3Tsd()->mallocFailed = 0; } -#ifndef SQLITE_OMIT_MEMORY_MANAGEMENT -/* -** Set the soft heap-size limit for the current thread. -*/ -void sqlite3_soft_heap_limit(int n){ - unsigned int N; - if( n<0 ){ - /* No limit */ - N = 0xFFFFFFFF; - }else{ - N = n; - } - sqlite3Tsd()->nSoftHeapLimit = N; -} -#endif #ifndef NDEBUG /* |