Index: main.mk ================================================================== --- main.mk +++ main.mk @@ -75,11 +75,11 @@ func.o global.o hash.o \ icu.o insert.o kv.o kvlsm.o kvmem.o legacy.o \ lsm_ckpt.o lsm_file.o lsm_log.o lsm_main.o lsm_mem.o lsm_mutex.o \ lsm_shared.o lsm_str.o lsm_sorted.o lsm_tree.o \ lsm_unix.o lsm_varint.o \ - main.o malloc.o math.o mem.o mem0.o mem1.o mem2.o mem3.o mem5.o \ + main.o malloc.o math.o mem.o mem0.o mem2.o mem3.o mem5.o \ mutex.o mutex_noop.o mutex_unix.o mutex_w32.o \ opcodes.o os.o \ pragma.o prepare.o printf.o \ random.o resolve.o rowset.o rtree.o select.o status.o \ tokenize.o trigger.o \ @@ -135,11 +135,10 @@ $(TOP)/src/main.c \ $(TOP)/src/malloc.c \ $(TOP)/src/math.c \ $(TOP)/src/mem.c \ $(TOP)/src/mem0.c \ - $(TOP)/src/mem1.c \ $(TOP)/src/mem2.c \ $(TOP)/src/mem3.c \ $(TOP)/src/mem5.c \ $(TOP)/src/mutex.c \ $(TOP)/src/mutex.h \ Index: src/env.c ================================================================== --- src/env.c +++ src/env.c @@ -43,13 +43,10 @@ SQLITE4_THREADSAFE==1, /* bFullMutex */ 0x7ffffffe, /* mxStrlen */ 0, /* szLookaside */ 0, /* nLookaside */ &sqlite4MMSystem, /* pMM */ -#if 0 - {0,0,0,0,0,0,0,0,0}, /* m */ -#endif {0,0,0,0,0,0,0,0,0,0}, /* mutex */ (void*)0, /* pHeap */ 0, /* nHeap */ 0, 0, /* mnHeap, mxHeap */ 0, /* mxParserStack */ Index: src/sqlite.h.in ================================================================== --- src/sqlite.h.in +++ src/sqlite.h.in @@ -731,87 +731,10 @@ ** ** Return the sqlite4_env object to which the database connection ** belongs. */ sqlite4_env *sqlite4_db_env(sqlite4*); - -/* -** CAPIREF: Memory Allocation Routines -** -** An instance of this object defines the interface between SQLite -** and low-level memory allocation routines. -** -** This object is used in only one place in the SQLite interface. -** A pointer to an instance of this object is the argument to -** [sqlite4_env_config()] when the configuration option is -** [SQLITE4_ENVCONFIG_MALLOC] or [SQLITE4_ENVCONFIG_GETMALLOC]. -** By creating an instance of this object -** and passing it to [sqlite4_env_config]([SQLITE4_ENVCONFIG_MALLOC]) -** during configuration, an application can specify an alternative -** memory allocation subsystem for SQLite to use for all of its -** dynamic memory needs. -** -** Note that SQLite comes with several [built-in memory allocators] -** that are perfectly adequate for the overwhelming majority of applications -** and that this object is only useful to a tiny minority of applications -** with specialized memory allocation requirements. This object is -** also used during testing of SQLite in order to specify an alternative -** memory allocator that simulates memory out-of-memory conditions in -** order to verify that SQLite recovers gracefully from such -** conditions. -** -** The xMalloc, xRealloc, and xFree methods must work like the -** malloc(), realloc() and free() functions from the standard C library. -** ^SQLite guarantees that the second argument to -** xRealloc is always a value returned by a prior call to xRoundup. -** -** xSize should return the allocated size of a memory allocation -** previously obtained from xMalloc or xRealloc. The allocated size -** is always at least as big as the requested size but may be larger. -** -** The xRoundup method returns what would be the allocated size of -** a memory allocation given a particular requested size. Most memory -** allocators round up memory allocations at least to the next multiple -** of 8. Some allocators round up to a larger multiple or to a power of 2. -** Every memory allocation request coming in through [sqlite4_malloc()] -** or [sqlite4_realloc()] first calls xRoundup. If xRoundup returns 0, -** that causes the corresponding memory allocation to fail. -** -** The xInit method initializes the memory allocator. (For example, -** it might allocate any require mutexes or initialize internal data -** structures. The xShutdown method is invoked (indirectly) by -** [sqlite4_shutdown()] and should deallocate any resources acquired -** by xInit. The pMemEnv pointer is used as the only parameter to -** xInit and xShutdown. -** -** SQLite holds the [SQLITE4_MUTEX_STATIC_MASTER] mutex when it invokes -** the xInit method, so the xInit method need not be threadsafe. The -** xShutdown method is only called from [sqlite4_shutdown()] so it does -** not need to be threadsafe either. For all other methods, SQLite -** holds the [SQLITE4_MUTEX_STATIC_MEM] mutex as long as the -** [SQLITE4_CONFIG_MEMSTATUS] configuration option is turned on (which -** it is by default) and so the methods are automatically serialized. -** However, if [SQLITE4_CONFIG_MEMSTATUS] is disabled, then the other -** methods must be threadsafe or else make their own arrangements for -** serialization. -** -** SQLite will never invoke xInit() more than once without an intervening -** call to xShutdown(). -*/ -typedef struct sqlite4_mem_methods sqlite4_mem_methods; -struct sqlite4_mem_methods { - void *(*xMalloc)(void*,sqlite4_size_t); /* Memory allocation function */ - void (*xFree)(void*,void*); /* Free a prior allocation */ - void *(*xRealloc)(void*,void*,int); /* Resize an allocation */ - sqlite4_size_t (*xSize)(void*,void*); /* Return the size of an allocation */ - int (*xInit)(void*); /* Initialize the memory allocator */ - void (*xShutdown)(void*); /* Deinitialize the allocator */ - void (*xBeginBenign)(void*); /* Enter a benign malloc region */ - void (*xEndBenign)(void*); /* Leave a benign malloc region */ - void *pMemEnv; /* 1st argument to all routines */ -}; - /* ** CAPIREF: Database Connection Configuration Options ** ** These constants are the available integer configuration options that Index: src/sqliteInt.h ================================================================== --- src/sqliteInt.h +++ src/sqliteInt.h @@ -2408,13 +2408,10 @@ int bFullMutex; /* True to enable full mutexing */ int mxStrlen; /* Maximum string length */ int szLookaside; /* Default lookaside buffer size */ int nLookaside; /* Default lookaside buffer count */ sqlite4_mm *pMM; /* Memory allocator for this environment */ -#if 0 - sqlite4_mem_methods m; /* Low-level memory allocation interface */ -#endif sqlite4_mutex_methods mutex; /* Low-level mutex interface */ void *pHeap; /* Heap storage space */ int nHeap; /* Size of pHeap[] */ int mnReq, mxReq; /* Min and max heap requests sizes */ int mxParserStack; /* maximum depth of the parser stack */ Index: src/update.c ================================================================== --- src/update.c +++ src/update.c @@ -264,12 +264,15 @@ /* Allocate memory for the array aRegIdx[]. There is one entry in the ** array for each index associated with table being updated. Fill in ** the value with a register number for indices that are to be used ** and with zero for unused indices. */ for(nIdx=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, nIdx++){} - aRegIdx = sqlite4DbMallocZero(db, sizeof(Index*) * nIdx ); - if( aRegIdx==0 ) goto update_cleanup; + assert( nIdx>0 || isView ); + if( nIdx ){ + aRegIdx = sqlite4DbMallocZero(db, sizeof(Index*) * nIdx ); + if( aRegIdx==0 ) goto update_cleanup; + } /* Allocate registers for and populate the aRegIdx array. */ for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){ if( pIdx==pPk || hasFK || bChngPk ){ aRegIdx[j] = ++pParse->nMem; Index: test/auth.test ================================================================== --- test/auth.test +++ test/auth.test @@ -2210,10 +2210,11 @@ SELECT * FROM v1; } } {115 117} do_test auth-4.3 { set authargs {} + breakpoint execsql { UPDATE v1 SET x=1 WHERE x=117 } set authargs } [list \ Index: test/fts5snippet.test ================================================================== --- test/fts5snippet.test +++ test/fts5snippet.test @@ -118,11 +118,10 @@ if {$DO_MALLOC_TEST || $enc=="utf16"} continue db close forcedelete test.db sqlite4 db test.db - sqlite4_db_config_lookaside db 0 0 0 db eval "PRAGMA encoding = \"$enc\"" # Set variable $T to the test name prefix for this iteration of the loop. # set T "fts5snippet-$enc" Index: test/malloc_common.tcl ================================================================== --- test/malloc_common.tcl +++ test/malloc_common.tcl @@ -156,15 +156,15 @@ proc faultsim_save {args} { uplevel db_save $args } proc faultsim_save_and_close {args} { uplevel db_save_and_close $args } proc faultsim_restore {args} { uplevel db_restore $args } proc faultsim_restore_and_reopen {args} { uplevel db_restore_and_reopen $args - sqlite4_db_config_lookaside db 0 0 0 + #sqlite4_db_config_lookaside db 0 0 0 } proc faultsim_delete_and_reopen {args} { uplevel db_delete_and_reopen $args - sqlite4_db_config_lookaside db 0 0 0 + #sqlite4_db_config_lookaside db 0 0 0 } proc faultsim_integrity_check {{db db}} { set ic [$db eval { PRAGMA integrity_check }] if {$ic != "ok"} { error "Integrity check: $ic" } @@ -424,11 +424,11 @@ forcedelete test2.db-wal if {[info exists ::mallocopts(-testdb)]} { copy_file $::mallocopts(-testdb) test.db } catch { sqlite4 db test.db } - sqlite4_db_config_lookaside db 0 0 0 + #sqlite4_db_config_lookaside db 0 0 0 # Execute any -tclprep and -sqlprep scripts. # if {[info exists ::mallocopts(-tclprep)]} { eval $::mallocopts(-tclprep) Index: test/test_config.c ================================================================== --- test/test_config.c +++ test/test_config.c @@ -79,11 +79,11 @@ Tcl_SetVar2(interp, "sqlite_options", "lfs", "0", TCL_GLOBAL_ONLY); #else Tcl_SetVar2(interp, "sqlite_options", "lfs", "1", TCL_GLOBAL_ONLY); #endif -#if 1 /* def SQLITE4_MEMDEBUG */ +#if 0 /* def SQLITE4_MEMDEBUG */ Tcl_SetVar2(interp, "sqlite_options", "memdebug", "1", TCL_GLOBAL_ONLY); #else Tcl_SetVar2(interp, "sqlite_options", "memdebug", "0", TCL_GLOBAL_ONLY); #endif Index: test/test_malloc.c ================================================================== --- test/test_malloc.c +++ test/test_malloc.c @@ -19,10 +19,11 @@ #include #include #include "testInt.h" +#if 0 /* ** This structure is used to encapsulate the global state variables used ** by malloc() fault simulation. */ static struct MemFault { @@ -231,11 +232,14 @@ } return rc; #endif } +#endif #ifdef SQLITE4_TEST + +#if 0 /* ** This function is implemented in test1.c. Returns a pointer to a static ** buffer containing the symbolic SQLite error code that corresponds to ** the least-significant 8-bits of the integer passed as an argument. @@ -1122,10 +1126,12 @@ rc = sqlite4_env_config(0, SQLITE4_ENVCONFIG_MALLOC, sqlite4MemGetMemsys3()); #endif Tcl_SetResult(interp, (char *)sqlite4TestErrorName(rc), TCL_VOLATILE); return TCL_OK; } + +#endif static sqlite4_mm *pMMDebug = 0; /* ** tclcmd: test_mm_install ?debug? ?backtrace? ?stats? @@ -1266,10 +1272,11 @@ static struct { char *zName; Tcl_ObjCmdProc *xProc; int clientData; } aObjCmd[] = { +#if 0 { "sqlite4_malloc", test_malloc ,0 }, { "sqlite4_realloc", test_realloc ,0 }, { "sqlite4_free", test_free ,0 }, { "memset", test_memset ,0 }, { "memget", test_memget ,0 }, @@ -1286,10 +1293,11 @@ { "sqlite4_env_config_memstatus", test_config_memstatus ,0 }, { "sqlite4_envconfig_lookaside", test_envconfig_lookaside ,0 }, { "sqlite4_config_error", test_config_error ,0 }, { "sqlite4_db_config_lookaside", test_db_config_lookaside ,0 }, { "sqlite4_install_memsys3", test_install_memsys3 ,0 }, +#endif { "test_mm_install", test_mm_install ,0 }, { "test_mm_stat", test_mm_stat ,0 }, { "test_mm_report", test_mm_report ,0 }, }; Index: test/tester.tcl ================================================================== --- test/tester.tcl +++ test/tester.tcl @@ -83,12 +83,10 @@ # very large database files. # set tcl_precision 15 #sqlite4_test_control_pending_byte 0x0010000 -test_mm_install stats debug - # If the pager codec is available, create a wrapper for the [sqlite4] # command that appends "-key {xyzzy}" to the command line. i.e. this: # # sqlite4 db test.db @@ -361,19 +359,22 @@ } } } set argv $leftover - # Install the malloc layer used to inject OOM errors. And the 'automatic' - # extensions. This only needs to be done once for the process. - # + # Install the various malloc wrappers. This only needs to be done + # once for the process. sqlite4_shutdown + set mm stats + if {$cmdlinearg(malloctrace)} { lappend mm debug } + test_mm_install {*}$mm + + # install_malloc_faultsim 1 - if {$cmdlinearg(malloctrace)} { testmem install } kvwrap install - sqlite4_initialize #autoinstall_test_functions + sqlite4_initialize # If the --binarylog option was specified, create the logging VFS. This # call installs the new VFS as the default for all SQLite connections. # if {$cmdlinearg(binarylog)} { @@ -406,14 +407,10 @@ # Abort early if this script has been run before. # if {[info exists TC(count)]} return -# Make sure memory statistics are enabled. -# -sqlite4_env_config_memstatus 1 - # Initialize the test counters and set up commands to access them. # Or, if this is a slave interpreter, set up aliases to write the # counters in the parent interpreter. # if {0==[info exists ::SLAVE]} { @@ -468,11 +465,11 @@ global argv cmdlinearg fix_testname name - sqlite4_memdebug_settitle $name + #sqlite4_memdebug_settitle $name # if {[llength $argv]==0} { # set go 1 # } else { # set go 0 @@ -772,11 +769,14 @@ puts "Unfreed memory: $nOut bytes in $nUnit allocations" } else { puts "All memory allocations freed - no leaks" } show_memstats - test_mm_report malloc.txt + if {$::cmdlinearg(malloctrace)} { + puts "Writing malloc() report to malloc.txt..." + test_mm_report malloc.txt + } # if {[lindex [sqlite4_env_status SQLITE4_ENVSTATUS_MALLOC_COUNT 0] 1]>0 || # [sqlite4_memory_used]>0} { # puts "Unfreed memory: [sqlite4_memory_used] bytes in\ # [lindex [sqlite4_env_status SQLITE4_ENVSTATUS_MALLOC_COUNT 0] 1] allocations" @@ -794,14 +794,10 @@ #puts "Maximum memory usage: [sqlite4_memory_highwater 1] bytes" #puts "Current memory usage: [sqlite4_memory_highwater] bytes" #if {[info commands sqlite4_memdebug_malloc_count] ne ""} { # puts "Number of malloc() : [sqlite4_memdebug_malloc_count] calls" #} - if {$::cmdlinearg(malloctrace)} { - puts "Writing malloc() report to malloc.txt..." - testmem report malloc.txt - } foreach f [glob -nocomplain test.db-*-journal] { forcedelete $f } foreach f [glob -nocomplain test.db-mj*] { forcedelete $f Index: test/tkt-9d68c883.test ================================================================== --- test/tkt-9d68c883.test +++ test/tkt-9d68c883.test @@ -12,10 +12,15 @@ # is fixed. # set testdir [file dirname $argv0] source $testdir/tester.tcl + +ifcapable !memdebug { + finish_test + return +} do_test tkt-9d68c88-1.1 { execsql { PRAGMA page_size = 1024; PRAGMA auto_vacuum = 2; Index: test/where8.test ================================================================== --- test/where8.test +++ test/where8.test @@ -680,11 +680,11 @@ # that this bug could cause a query to return bad data. # do_test where8-5.1 { db close sqlite4 db test.db - sqlite4_db_config_lookaside db 0 0 0 + #sqlite4_db_config_lookaside db 0 0 0 execsql { CREATE TABLE tA( a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p );