-C Website\schanges\sin\spreparation\sfor\sthe\srelease\sof\s2.8.17.\s(CVS\s2834)
-D 2005-12-19T17:53:36
+C Add\ssimple\stests\sand\sfixes\sfor\ssqlite3_soft_heap_limit()\s(CVS\s2837)
+D 2005-12-20T09:19:37
F Makefile.in e3c6b3a38d734d41574c04f2fc90d18de2b87102
F Makefile.linux-gcc aee18d8a05546dcf1888bd4547e442008a49a092
F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
F src/os_unix.h 5768d56d28240d3fe4537fac08cc85e4fb52279e
F src/os_win.c 9feb97f49b93d451f8ef7c5dd388e05a44647dc6
F src/os_win.h 41a946bea10f61c158ce8645e7646b29d44f122b
-F src/pager.c f1969539777ee52900e740b0404a323a3e419c8b
+F src/pager.c 5227ea29acbea4b6a9c6f1dfd3e8493de5fc2a93
F src/pager.h e0acb095b3ad0bca48f2ab00c87346665643f64f
F src/parse.y 142a4b347c82217332e2d3dfa317ff2b7ac32f9c
F src/pragma.c 8883b4d34796efa315bdd0ec1b03f580ef1575b9
F src/random.c ff5e9a8cad790e2a51cd4d2e7737dc8540e09d1d
F src/select.c 2292b065bc6be61e01aad39a2e1b93e332fb7e57
F src/shell.c 4872acee1d2a826c73c914961e469e563204b7f9
-F src/sqlite.h.in 5b16b66db128f5aac5e82721b9012bfa88958bd7
-F src/sqliteInt.h 4e822139dc9322795a9644a3d3b281d53f6d99ed
+F src/sqlite.h.in 015e02efa9e8bafa31b6c270116369ddff4e9803
+F src/sqliteInt.h b8b2b2da145c15c8577316f0b8899ba65c098ccc
F src/table.c 486dcfce532685b53b5a2b5da8bba0ded6fb2316
F src/tclsqlite.c ce481c0a21a20641cdfe87c9cbbb328cfb3a58b9
-F src/test1.c d6924b182773b2ad3b22e435e4d3bfd5a846da9e
+F src/test1.c 4691cc7235683324791a0be560308ca338de36de
F src/test2.c 36390cdfc70c08e5ee0b466d0654a117f398bbff
F src/test3.c 7c97833e33496c2b69f4fe6b9882ac60a481da97
F src/test4.c a8fd681e139e1c61f22a77d07fc3a99cb28fff3f
F src/trigger.c 2925ba96d964d9b717e74006bf7e64b8a6b70d97
F src/update.c ec8e540617b116725b5a55c8d6b4db8bc67fdd7d
F src/utf.c b7bffac4260177ae7f83c01d025fe0f5ed70ce71
-F src/util.c 0ed80dea0cd12dc09d4c576f6a132fd5cf963b51
+F src/util.c 7e9ebebb0c8b773490dcacd67a77fe6b6bb4e5e1
F src/vacuum.c fbfdd3967fd34e2f260fafed88dcbf3c10856b94
F src/vdbe.c 09aaed71f076bfd4286607ee4845100b910a492f
F src/vdbe.h 8729a4ee16ff9aeab2af9667df3cf300ff978e13
F test/malloc2.test e6e321db96d6c94cb18bf82ad7215070c41e624e
F test/malloc3.test 9797d39eca7087a1022bcc0eb0b22215475c9698
F test/malloc4.test 2e29d155eb4b4808019ef47eeedfcbe9e09e0f05
-F test/malloc5.test 2418a9d667a50175744ba4c147ee1c75de6cfe5c
+F test/malloc5.test 8dd58affc441a726d16448a7188ab175bc9e7280
F test/manydb.test d81debbf5871242e3b5df1d3bb5e14c50431b6f8
F test/memdb.test 1860e060be810bf0775bc57408a5b7c4954bcaea
F test/memleak.test df2b2b96e77f8ba159a332299535b1e5f18e49ac
F test/sync.test 6e8b885cec5ccba2090e92c90f747a7142f53c88
F test/table.test ec0e6c2186bb8f6824f470caa118524dfd8fe057
F test/tableapi.test 6a66d58b37d46dc0f2b3c7d4bd2617d209399bd1
-F test/tclsqlite.test 26ee144ca70738ee0f3d8b5c1113b2f13652658b
+F test/tclsqlite.test 19578d32a7692311918caf0ae3521d19525bcb62
F test/temptable.test 7927261befdbc7b0a7ffebb85ecc70a74fa7b15b
F test/tester.tcl a06c798a653daefb5bce2c85fc3a7d06450a1875
F test/thread1.test 776c9e459b75ba905193b351926ac4019b049f35
F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
F www/version3.tcl a99cf5f6d8bd4d5537584a2b342f0fb9fa601d8b
F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513
-P 2f7ec117ded31f2c13f2e3ab9dd4e9a483434601
-R 547dcd4429db02f81b0ea35f4c0b8368
-U drh
-Z 84cc1eb94b056fe4069873bc16aa8466
+P a927696ba30da39cb94ba666a10b7311d46826c9
+R 47b8829eca445dbf0a3ed9bcb5e9f642
+U danielk1977
+Z 8e415cd6471fe4543f7c65503e6ef9ab
-a927696ba30da39cb94ba666a10b7311d46826c9
\ No newline at end of file
+c2c5285442f4558dfca61b52f31b5a9cbefaed10
\ No newline at end of file
** file simultaneously, or one process from reading the database while
** another is writing.
**
-** @(#) $Id: pager.c,v 1.227 2005/12/19 16:15:31 drh Exp $
+** @(#) $Id: pager.c,v 1.228 2005/12/20 09:19:37 danielk1977 Exp $
*/
#ifndef SQLITE_OMIT_DISKIO
#include "sqliteInt.h"
}
}
+/*
+** Try to find a page in the cache that can be recycled.
+*/
static int pager_recycle(Pager *pPager, int syncOk, PgHdr **ppPg){
PgHdr *pPg;
*ppPg = 0;
** very slow operation, so we work hard to avoid it. But sometimes
** it can't be helped.
*/
- if( pPg==0 && pPager->pFirst && syncOk ){
+ if( pPg==0 && pPager->pFirst && syncOk && !MEMDB){
int rc = syncJournal(pPager);
if( rc!=0 ){
sqlite3pager_rollback(pPager);
** This header file defines the interface that the SQLite library
** presents to client programs.
**
-** @(#) $Id: sqlite.h.in,v 1.150 2005/12/19 14:18:11 danielk1977 Exp $
+** @(#) $Id: sqlite.h.in,v 1.151 2005/12/20 09:19:37 danielk1977 Exp $
*/
#ifndef _SQLITE3_H_
#define _SQLITE3_H_
** This function is only available if the library was compiled without the
** SQLITE_OMIT_MEMORY_MANAGEMENT option set.
*/
-void sqlite3_soft_heap_limit(int);
+void sqlite3_soft_heap_limit(sqlite_int64);
/*
** Register a callback function with the database connection identified by the
*************************************************************************
** Internal interface definitions for SQLite.
**
-** @(#) $Id: sqliteInt.h,v 1.441 2005/12/19 14:18:11 danielk1977 Exp $
+** @(#) $Id: sqliteInt.h,v 1.442 2005/12/20 09:19:37 danielk1977 Exp $
*/
#ifndef _SQLITEINT_H_
#define _SQLITEINT_H_
/*
** An instance of this structure is allocated for each thread that uses SQLite.
*/
-typedef struct SqliteTsd SqliteTsd;
struct SqliteTsd {
- int isInit; /* True if structure has been initialised */
- int mallocFailed; /* True after a malloc() has failed */
+ u8 isInit; /* True if structure has been initialised */
+ u8 mallocFailed; /* True after a malloc() has failed */
+
#ifndef SQLITE_OMIT_MEMORY_MANAGEMENT
- unsigned int nSoftHeapLimit; /* (uint)-1 for unlimited */
- unsigned int nAlloc; /* Number of bytes currently allocated */
- Pager *pPager; /* Linked list of all pagers in this thread */
+ i64 nSoftHeapLimit; /* -ve for unlimited */
+ i64 nAlloc; /* Number of bytes currently allocated */
+ Pager *pPager; /* Linked list of all pagers in this thread */
#endif
-#ifndef NDEBUG
- int mallocAllowed; /* assert() in sqlite3Malloc() if not set */
-#endif
#ifdef SQLITE_MEMDEBUG
+ i64 nMaxAlloc; /* High water mark of SqliteTsd.nAlloc */
+ int mallocAllowed; /* assert() in sqlite3Malloc() if not set */
int isFail; /* True if all malloc() calls should fail */
const char *zFile; /* Filename to associate debugging info with */
int iLine; /* Line number to associate debugging info with */
typedef struct Parse Parse;
typedef struct Select Select;
typedef struct SrcList SrcList;
+typedef struct SqliteTsd SqliteTsd;
typedef struct Table Table;
typedef struct Token Token;
typedef struct TriggerStack TriggerStack;
** is not included in the SQLite library. It is used for automated
** testing of the SQLite library.
**
-** $Id: test1.c,v 1.176 2005/12/14 20:11:30 drh Exp $
+** $Id: test1.c,v 1.177 2005/12/20 09:19:37 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include "tcl.h"
char **argv /* Text of each argument */
){
char zBuf[200];
- sprintf(zBuf, "%d %d %d", sqlite3_nMalloc, sqlite3_nFree, sqlite3_iMallocFail);
+ sprintf(zBuf, "%d %d %d", sqlite3_nMalloc,sqlite3_nFree,sqlite3_iMallocFail);
Tcl_AppendResult(interp, zBuf, 0);
return TCL_OK;
}
+
+/*
+** This function implements a Tcl command that may be invoked using any of
+** the four forms enumerated below.
+**
+** sqlite_malloc_outstanding
+** Return a summary of all unfreed blocks of memory allocated by the
+** current thread. See comments above function sqlite3OutstandingMallocs()
+** in util.c for a description of the returned value.
+**
+** sqlite_malloc_outstanding -bytes
+** Return the total amount of unfreed memory (in bytes) allocated by
+** this thread.
+**
+** sqlite_malloc_outstanding -maxbytes
+** Return the maximum amount of dynamic memory in use at one time
+** by this thread.
+**
+** sqlite_malloc_outstanding -clearmaxbytes
+** Set the value returned by [sqlite_malloc_outstanding -maxbytes]
+** to the current value of [sqlite_malloc_outstanding -bytes].
+*/
static int sqlite_malloc_outstanding(
- void *NotUsed,
+ ClientData clientData,
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
- int argc, /* Number of arguments */
- char **argv /* Text of each argument */
+ int objc, /* Number of arguments */
+ Tcl_Obj *CONST objv[] /* Command arguments */
){
extern int sqlite3OutstandingMallocs(Tcl_Interp *interp);
+
+ if( objc!=1 && objc!=2 ){
+ Tcl_WrongNumArgs(interp, 1, objv, "?-bytes?");
+ return TCL_ERROR;
+ }
+
+ if( objc==2 ){
+ const char *zArg = Tcl_GetString(objv[1]);
+ if( 0==strcmp(zArg, "-bytes") ){
+ Tcl_SetObjResult(interp, Tcl_NewIntObj(sqlite3Tsd()->nAlloc));
+#ifndef SQLITE_OMIT_MEMORY_MANAGEMENT
+ }else if( 0==strcmp(zArg, "-maxbytes") ){
+ Tcl_SetObjResult(interp, Tcl_NewWideIntObj(sqlite3Tsd()->nMaxAlloc));
+ }else if( 0==strcmp(zArg, "-clearmaxbytes") ){
+ sqlite3Tsd()->nMaxAlloc = sqlite3Tsd()->nAlloc;
+#endif
+ }else{
+ Tcl_AppendResult(interp, "bad option \"", zArg,
+ "\": must be -bytes, -maxbytes or -clearmaxbytes", 0
+ );
+ return TCL_ERROR;
+ }
+
+ return TCL_OK;
+ }
+
return sqlite3OutstandingMallocs(interp);
}
#endif
#ifdef SQLITE_MEMDEBUG
{ "sqlite_malloc_fail", (Tcl_CmdProc*)sqlite_malloc_fail },
{ "sqlite_malloc_stat", (Tcl_CmdProc*)sqlite_malloc_stat },
- { "sqlite_malloc_outstanding", (Tcl_CmdProc*)sqlite_malloc_outstanding},
#endif
{ "sqlite_bind", (Tcl_CmdProc*)test_bind },
{ "breakpoint", (Tcl_CmdProc*)test_breakpoint },
{ "add_test_collate", test_collate, 0 },
{ "add_test_collate_needed", test_collate_needed, 0 },
{ "add_test_function", test_function, 0 },
+#endif
+#ifdef SQLITE_MEMDEBUG
+ { "sqlite_malloc_outstanding", sqlite_malloc_outstanding, 0},
#endif
{ "sqlite3_test_errstr", test_errstr, 0 },
{ "tcl_variable_type", tcl_variable_type, 0 },
** This file contains functions for allocating memory, comparing
** strings, and stuff like that.
**
-** $Id: util.c,v 1.156 2005/12/19 14:18:11 danielk1977 Exp $
+** $Id: util.c,v 1.157 2005/12/20 09:19:37 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include "os.h"
** * Audit outstanding memory allocations (i.e check for leaks).
*/
+#define MAX(x,y) ((x)>(y)?(x):(y))
+
#ifdef SQLITE_MEMDEBUG
/*--------------------------------------------------------------------------
** Begin code for memory allocation system test layer.
#ifndef SQLITE_OMIT_MEMORY_MANAGEMENT
/*
-** Set the soft heap-size limit for the current thread.
+** Set the soft heap-size limit for the current thread. Passing a negative
+** value indicates no limit.
*/
-void sqlite3_soft_heap_limit(int n){
- unsigned int N;
- if( n<0 ){
- /* No limit */
- N = 0xFFFFFFFF;
- }else{
- N = n;
- }
- sqlite3Tsd()->nSoftHeapLimit = N;
+void sqlite3_soft_heap_limit(sqlite_int64 n){
+ sqlite3Tsd()->nSoftHeapLimit = n;
}
/*
** This is the test layer's wrapper around sqlite3Os.xMalloc().
*/
static void * OSMALLOC(int n){
+#ifndef SQLITE_OMIT_MEMORY_MANAGEMENT
+ SqliteTsd *pTsd = sqlite3Tsd();
+ pTsd->nMaxAlloc = MAX(pTsd->nMaxAlloc, pTsd->nAlloc);
+#endif
if( !failMalloc() ){
u32 *p;
p = (u32 *)sqlite3Os.xMalloc(n + TESTALLOC_OVERHEAD);
** This is the test layer's wrapper around sqlite3Os.xRealloc().
*/
void * OSREALLOC(void *pRealloc, int n){
+#ifndef SQLITE_OMIT_MEMORY_MANAGEMENT
+ SqliteTsd *pTsd = sqlite3Tsd();
+ pTsd->nMaxAlloc = MAX(pTsd->nMaxAlloc, pTsd->nAlloc);
+#endif
if( !failMalloc() ){
u32 *p = (u32 *)getOsPointer(pRealloc);
checkGuards(p);
#ifndef SQLITE_OMIT_MEMORY_MANAGEMENT
static void handleSoftLimit(int n){
SqliteTsd *pTsd = sqlite3Tsd();
- pTsd->nAlloc += n;
- while( pTsd->nAlloc>pTsd->nSoftHeapLimit && sqlite3_release_memory(n) );
+ pTsd->nAlloc += (i64)n;
+ if( n>0 && pTsd->nSoftHeapLimit>0 ){
+ while( pTsd->nAlloc>pTsd->nSoftHeapLimit && sqlite3_release_memory(n) );
+ }
}
#else
#define handleSoftLimit()
handleSoftLimit(n);
while( !(p = OSMALLOC(n)) && sqlite3_release_memory(n) );
if( !p ){
+ /* If the allocation failed, call handleSoftLimit() again, this time
+ ** with the additive inverse of the argument passed to
+ ** handleSoftLimit() above. This is so the SqliteTsd.nAlloc variable is
+ ** still correct after a malloc() failure.
+ */
+ handleSoftLimit(n * -1);
sqlite3Tsd()->mallocFailed = 1;
OSMALLOC_FAILED();
}
handleSoftLimit(n - OSSIZEOF(p));
while( !(np = OSREALLOC(p, n)) && sqlite3_release_memory(n) );
if( !np ){
+ /* If the allocation failed, call handleSoftLimit() again, this time
+ ** with the additive inverse of the argument passed to
+ ** handleSoftLimit() above. This is so the SqliteTsd.nAlloc variable is
+ ** still correct after a malloc() failure.
+ */
+ handleSoftLimit(OSSIZEOF(p) - n);
pTsd->mallocFailed = 1;
OSMALLOC_FAILED();
}
** value returned by a previous call to sqlite3Malloc() or sqlite3Realloc().
*/
void sqlite3FreeX(void *p){
+ handleSoftLimit(0 - OSSIZEOF(p));
if( p ){
OSFREE(p);
}
SqliteTsd *sqlite3Tsd(){
SqliteTsd *pTsd = sqlite3Os.xThreadSpecificData(sizeof(SqliteTsd));
if( pTsd && !pTsd->isInit ){
- pTsd->nSoftHeapLimit = 0xFFFFFFFF;
+ pTsd->nSoftHeapLimit = -1;
#ifndef NDEBUG
pTsd->mallocAllowed = 1;
#endif
#
#***********************************************************************
#
-# $Id: malloc5.test,v 1.1 2005/12/19 14:18:12 danielk1977 Exp $
+# $Id: malloc5.test,v 1.2 2005/12/20 09:19:38 danielk1977 Exp $
#---------------------------------------------------------------------------
# NOTES ON EXPECTED BEHAVIOUR
}
} {}
-
do_test malloc5-2.1 {
# Put some data in tables abc and def. Both tables are still wholly
# contained within their root pages.
BEGIN;
SELECT * FROM def;
}
+ set data [list]
db eval {SELECT * FROM abc} {
incr nRelease [db release_memory]
lappend data $a $b $c
}
+ execsql {
+ COMMIT;
+ }
list $nRelease $data
} [list $pgalloc [list 1 2 3 4 5 6]]
+do_test malloc5-3.1 {
+ # Simple test to show that if two pagers are opened from within this
+ # thread, memory is freed from both when sqlite3_release_memory() is
+ # called.
+ execsql {
+ BEGIN;
+ SELECT * FROM abc;
+ }
+ execsql {
+ SELECT * FROM sqlite_master;
+ BEGIN;
+ SELECT * FROM def;
+ } db2
+ db release_memory
+} [expr $::pgalloc * 2]
+do_test malloc5-3.2 {
+ concat \
+ [execsql {SELECT * FROM abc; COMMIT}] \
+ [execsql {SELECT * FROM def; COMMIT} db2]
+} {1 2 3 4 5 6 7 8 9 10 11 12}
+
+db2 close
+sqlite_malloc_outstanding -clearmaxbytes
+
+# The following two test cases each execute a transaction in which
+# 10000 rows are inserted into table abc. The first test case is used
+# to ensure that more than 1MB of dynamic memory is used to perform
+# the transaction.
+#
+# The second test case sets the "soft-heap-limit" to 100,000 bytes (0.1 MB)
+# and tests to see that this limit is not exceeded at any point during
+# transaction execution.
+#
+do_test malloc5-4.1 {
+ execsql {BEGIN;}
+ execsql {DELETE FROM abc;}
+ for {set i 0} {$i < 10000} {incr i} {
+ execsql "INSERT INTO abc VALUES($i, $i, '[string repeat X 100]');"
+ }
+ execsql {COMMIT;}
+ set ::nMaxBytes [sqlite_malloc_outstanding -maxbytes]
+ expr $::nMaxBytes > 1000000
+} {1}
+do_test malloc5-4.2 {
+ db release_memory
+ sqlite_malloc_outstanding -clearmaxbytes
+ db soft_heap_limit 100000
+ execsql {BEGIN;}
+ for {set i 0} {$i < 10000} {incr i} {
+ execsql "INSERT INTO abc VALUES($i, $i, '[string repeat X 100]');"
+ }
+ execsql {COMMIT;}
+ set ::nMaxBytes [sqlite_malloc_outstanding -maxbytes]
+ expr $::nMaxBytes <= 100000
+} {1}
+do_test malloc5-4.3 {
+ # Check that the content of table abc is at least roughly as expected.
+ execsql {
+ SELECT count(*), sum(a), sum(b) FROM abc;
+ }
+} [list 20000 [expr int(20000.0 * 4999.5)] [expr int(20000.0 * 4999.5)]]
+
+# Unset the soft-heap-limit value.
+db soft_heap_limit -1
+
finish_test
# interface is pretty well tested. This file contains some addition
# tests for fringe issues that the main test suite does not cover.
#
-# $Id: tclsqlite.test,v 1.47 2005/12/16 06:54:03 danielk1977 Exp $
+# $Id: tclsqlite.test,v 1.48 2005/12/20 09:19:38 danielk1977 Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
do_test tcl-1.2 {
set v [catch {db bogus} msg]
lappend v $msg
-} {1 {bad option "bogus": must be authorizer, busy, cache, changes, close, collate, collation_needed, commit_hook, complete, copy, errorcode, eval, exists, function, last_insert_rowid, nullvalue, onecolumn, profile, progress, rekey, rollback_hook, soft_heap_limit, timeout, total_changes, trace, transaction, update_hook, or version}}
+} {1 {bad option "bogus": must be authorizer, busy, cache, changes, close, collate, collation_needed, commit_hook, complete, copy, errorcode, eval, exists, function, last_insert_rowid, nullvalue, onecolumn, profile, progress, rekey, rollback_hook, release_memory, soft_heap_limit, timeout, total_changes, trace, transaction, update_hook, or version}}
do_test tcl-1.3 {
execsql {CREATE TABLE t1(a int, b int)}
execsql {INSERT INTO t1 VALUES(10,20)}