From: danielk1977 Date: Mon, 6 Feb 2006 13:59:42 +0000 (+0000) Subject: Update the per-thread bytes allocated counter with the number of bytes actually alloc... X-Git-Tag: version-3.6.10~3111 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ab63989d426796da94a0b0a840a4d2ed164ac424;p=thirdparty%2Fsqlite.git Update the per-thread bytes allocated counter with the number of bytes actually allocated, not the number requested. Ticket #1660. (CVS 3056) FossilOrigin-Name: 3f0a0ff1973079956506daaba9b21912fc76982b --- diff --git a/manifest b/manifest index ac1d039e36..a727208cda 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Detect\scircularly\sdefined\sviews\sand\sissue\san\serror\smessage.\s\sTicket\s#1658.\s(CVS\s3055) -D 2006-02-05T18:55:20 +C Update\sthe\sper-thread\sbytes\sallocated\scounter\swith\sthe\snumber\sof\sbytes\sactually\sallocated,\snot\sthe\snumber\srequested.\sTicket\s#1660.\s(CVS\s3056) +D 2006-02-06T13:59:43 F Makefile.in 5d8dff443383918b700e495de42ec65bc1c8865b F Makefile.linux-gcc 74ba0eadf88748a9ce3fd03d2a3ede2e6715baec F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028 @@ -87,7 +87,7 @@ F src/tokenize.c 9ae9a59238eb97fbc61baea280563b91100518fb F src/trigger.c 4d3644cbd16959b568c95ae73493402be8021b08 F src/update.c 14be4ba2f438919b4217085c02feff569e6cf1f2 F src/utf.c 1199766bbb0157931a83aa6eede6b6381177be64 -F src/util.c 82ee598519b8193184bdeab06b51a4ffa05ad60b +F src/util.c 36ce845aa173c7347251e7462d61f937b78c88fb F src/vacuum.c 3865673cc66acd0717ecd517f6b8fdb2a5e7924b F src/vdbe.c 29c68f39ce8cba44814b0e1f3d909ef961eb28a7 F src/vdbe.h 8729a4ee16ff9aeab2af9667df3cf300ff978e13 @@ -350,7 +350,7 @@ F www/tclsqlite.tcl bb0d1357328a42b1993d78573e587c6dcbc964b9 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0 F www/version3.tcl a99cf5f6d8bd4d5537584a2b342f0fb9fa601d8b F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513 -P 3a04fc45ccc31f2009be812a9c9057844cf4ae3b -R 968f57515475ab9a4a37d0ebf71134f3 -U drh -Z a1def34602e0d016ada75d168beb6d52 +P f5341529d0cdbd63ce4c33606858158b6093969a +R 74794a57a00f0992fd89f2fde95755fd +U danielk1977 +Z eb9ce12217e4d8db003d2eaae05f7ed8 diff --git a/manifest.uuid b/manifest.uuid index d529bea34e..24a7d460ab 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -f5341529d0cdbd63ce4c33606858158b6093969a \ No newline at end of file +3f0a0ff1973079956506daaba9b21912fc76982b \ No newline at end of file diff --git a/src/util.c b/src/util.c index cb93a76c83..569a447218 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.182 2006/01/23 15:39:59 drh Exp $ +** $Id: util.c,v 1.183 2006/02/06 13:59:43 danielk1977 Exp $ */ #include "sqliteInt.h" #include "os.h" @@ -142,6 +142,13 @@ int sqlite3_release_memory(int n){ #define TESTALLOC_USERSIZE 64 const char *sqlite3_malloc_id = 0; +/* +** Always allocate blocks to be a multiple of the following size in bytes. +** For example, if TESTALLOC_QUANTA is 8 and a block of 21 bytes is +** requested, return a pointer to a block of 24 bytes. +*/ +#define TESTALLOC_QUANTA 8 + /* ** Blocks used by the test layer have the following format: ** @@ -399,7 +406,6 @@ int sqlite3OutstandingMallocs(Tcl_Interp *interp){ Tcl_Obj *pRes = Tcl_NewObj(); Tcl_IncrRefCount(pRes); - for(p=sqlite3_pFirst; p; p=((void **)p)[1]){ Tcl_Obj *pEntry = Tcl_NewObj(); Tcl_Obj *pStack = Tcl_NewObj(); @@ -448,6 +454,7 @@ static void * OSMALLOC(int n){ MAX(sqlite3_nMaxAlloc, sqlite3ThreadDataReadOnly()->nAlloc); #endif assert( !sqlite3_mallocDisallowed ); + n += (TESTALLOC_QUANTA - (n % TESTALLOC_QUANTA)) % TESTALLOC_QUANTA; if( !sqlite3TestMallocFail() ){ u32 *p; p = (u32 *)sqlite3OsMalloc(n + TESTALLOC_OVERHEAD); @@ -489,10 +496,14 @@ static void * OSREALLOC(void *pRealloc, int n){ sqlite3_nMaxAlloc = MAX(sqlite3_nMaxAlloc, sqlite3ThreadDataReadOnly()->nAlloc); #endif + n += (TESTALLOC_QUANTA - (n % TESTALLOC_QUANTA)) % TESTALLOC_QUANTA; assert( !sqlite3_mallocDisallowed ); if( !sqlite3TestMallocFail() ){ - u32 *p = (u32 *)getOsPointer(pRealloc); - checkGuards(p); + u32 *p = 0; + if( pRealloc ){ + u32 *p = (u32 *)getOsPointer(pRealloc); + checkGuards(p); + } p = sqlite3OsRealloc(p, n + TESTALLOC_OVERHEAD); applyGuards(p); relinkAlloc(p); @@ -558,15 +569,10 @@ static int handleSoftLimit(int n){ */ void *sqlite3MallocRaw(int n){ void *p = 0; - if( n>0 && !sqlite3MallocFailed() && !handleSoftLimit(n) ){ + if( n>0 && !sqlite3MallocFailed() ){ while( (p = OSMALLOC(n))==0 && 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 ThreadData.nAlloc variable is - ** still correct after a malloc() failure. - */ - (void)handleSoftLimit(n * -1); + if( !p || handleSoftLimit(OSSIZEOF(p)) ){ + OSFREE(p); sqlite3FailedMalloc(); OSMALLOC_FAILED(); } @@ -580,29 +586,19 @@ void *sqlite3MallocRaw(int n){ ** attempt to free memory by calling sqlite3_release_memory(). */ void *sqlite3Realloc(void *p, int n){ - if( sqlite3MallocFailed() ){ - return 0; - } - - if( !p ){ - return sqlite3Malloc(n); - }else{ - void *np = 0; - if( !handleSoftLimit(n - OSSIZEOF(p)) ){ - while( (np = OSREALLOC(p, n))==0 && 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 ThreadData.nAlloc variable is - ** still correct after a malloc() failure. - */ - (void)handleSoftLimit(OSSIZEOF(p) - n); - sqlite3FailedMalloc(); - OSMALLOC_FAILED(); - } + void *np = 0; + if( !sqlite3MallocFailed() ){ +#ifndef SQLITE_ENABLE_MEMORY_MANAGEMENT + int oldsize = OSSIZEOF(p); +#endif + while( (np = OSREALLOC(p, n))==0 && sqlite3_release_memory(n) ); + if( !np || handleSoftLimit(OSSIZEOF(np) - oldsize) ){ + OSFREE(np); + sqlite3FailedMalloc(); + OSMALLOC_FAILED(); } - return np; } + return np; } /*