1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-15 11:41:13 +03:00

Add error logging to native Win32 heap support.

FossilOrigin-Name: 7fca5a284cded6d7531060da6e99a57aed50cf8f
This commit is contained in:
mistachkin
2011-08-24 17:42:22 +00:00
parent 1b186a9947
commit 468690ef60
4 changed files with 63 additions and 34 deletions

View File

@@ -52,6 +52,7 @@ TCC = $(TCC) -D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS
# Use native Win32 heap. # Use native Win32 heap.
# #
TCC = $(TCC) -DSQLITE_WIN32_MALLOC=1 TCC = $(TCC) -DSQLITE_WIN32_MALLOC=1
# TCC = $(TCC) -DSQLITE_WIN32_MALLOC_VALIDATE=1
# The locations of the Tcl header and library files. Also, the library that # The locations of the Tcl header and library files. Also, the library that
# non-stubs enabled programs using Tcl must link against. These variables # non-stubs enabled programs using Tcl must link against. These variables

View File

@@ -1,9 +1,9 @@
C Experimental\swork\sto\sallow\sSQLite\sto\suse\sthe\snative\sWin32\sheap\sAPI. C Add\serror\slogging\sto\snative\sWin32\sheap\ssupport.
D 2011-08-24T16:13:57.329 D 2011-08-24T17:42:22.399
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in 8c930e7b493d59099ea1304bd0f2aed152eb3315 F Makefile.in 8c930e7b493d59099ea1304bd0f2aed152eb3315
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
F Makefile.msc 8ebd89ed4493641a9e2316a941d776e2bcc5ad39 F Makefile.msc baf6b7037a8e0838387f8bfc9baacfcc57dc5902
F Makefile.vxworks c85ec1d8597fe2f7bc225af12ac1666e21379151 F Makefile.vxworks c85ec1d8597fe2f7bc225af12ac1666e21379151
F README cd04a36fbc7ea56932a4052d7d0b7f09f27c33d6 F README cd04a36fbc7ea56932a4052d7d0b7f09f27c33d6
F VERSION f724de7326e87b7f3b0a55f16ef4b4d993680d54 F VERSION f724de7326e87b7f3b0a55f16ef4b4d993680d54
@@ -166,7 +166,7 @@ F src/os.h 9dbed8c2b9c1f2f2ebabc09e49829d4777c26bf9
F src/os_common.h 65a897143b64667d23ed329a7984b9b405accb58 F src/os_common.h 65a897143b64667d23ed329a7984b9b405accb58
F src/os_os2.c 4a75888ba3dfc820ad5e8177025972d74d7f2440 F src/os_os2.c 4a75888ba3dfc820ad5e8177025972d74d7f2440
F src/os_unix.c 81341980c52a44106b10c1e28a0d5c5247476452 F src/os_unix.c 81341980c52a44106b10c1e28a0d5c5247476452
F src/os_win.c a9950bf0f32753418ab6f74417aebd432bde2383 F src/os_win.c f9958ef76430472cd3b43ec45643949b2876daa4
F src/pager.c 120550e7ef01dafaa2cbb4a0528c0d87c8f12b41 F src/pager.c 120550e7ef01dafaa2cbb4a0528c0d87c8f12b41
F src/pager.h 3f8c783de1d4706b40b1ac15b64f5f896bcc78d1 F src/pager.h 3f8c783de1d4706b40b1ac15b64f5f896bcc78d1
F src/parse.y 12b7ebd61ea54f0e1b1083ff69cc2c8ce9353d58 F src/parse.y 12b7ebd61ea54f0e1b1083ff69cc2c8ce9353d58
@@ -961,10 +961,7 @@ F tool/symbols.sh caaf6ccc7300fd43353318b44524853e222557d5
F tool/tostr.awk 11760e1b94a5d3dcd42378f3cc18544c06cfa576 F tool/tostr.awk 11760e1b94a5d3dcd42378f3cc18544c06cfa576
F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
F tool/warnings.sh b7fdb2cc525f5ef4fa43c80e771636dd3690f9d2 F tool/warnings.sh b7fdb2cc525f5ef4fa43c80e771636dd3690f9d2
P 988998fe7b0a21ed113b67f812e51f357045bef4 P bf3d0ab53829350637283442f75071fe6d925245
R 0396c522791d26a46580a50de4d03044 R 0f7433104155ca1c8873be3fedc86cf8
T *branch * winNativeHeap
T *sym-winNativeHeap *
T -sym-trunk *
U mistachkin U mistachkin
Z 6f33f4bfa3c296caae6e295d0a3da4b8 Z 3b4d0724e0585445008e0568091ed65d

View File

@@ -1 +1 @@
bf3d0ab53829350637283442f75071fe6d925245 7fca5a284cded6d7531060da6e99a57aed50cf8f

View File

@@ -154,6 +154,9 @@ struct winMemData {
static struct winMemData win_mem_data = { WINMEM_MAGIC, NULL, FALSE }; static struct winMemData win_mem_data = { WINMEM_MAGIC, NULL, FALSE };
#define winMemAssertMagic() assert( win_mem_data.magic==WINMEM_MAGIC )
#define winMemGetHeap() win_mem_data.hHeap
static void *winMemMalloc(int nBytes); static void *winMemMalloc(int nBytes);
static void winMemFree(void *pPrior); static void winMemFree(void *pPrior);
static void *winMemRealloc(void *pPrior, int nBytes); static void *winMemRealloc(void *pPrior, int nBytes);
@@ -222,16 +225,22 @@ static int sqlite3_os_type = 0;
*/ */
static void *winMemMalloc(int nBytes){ static void *winMemMalloc(int nBytes){
HANDLE hHeap; HANDLE hHeap;
void *p;
assert( win_mem_data.magic==WINMEM_MAGIC ); winMemAssertMagic();
hHeap = win_mem_data.hHeap; hHeap = winMemGetHeap();
assert( hHeap!=0 ); assert( hHeap!=0 );
assert( hHeap!=INVALID_HANDLE_VALUE ); assert( hHeap!=INVALID_HANDLE_VALUE );
#ifdef SQLITE_WIN32_MALLOC_VALIDATE #ifdef SQLITE_WIN32_MALLOC_VALIDATE
assert ( HeapValidate(hHeap, 0, NULL) ); assert ( HeapValidate(hHeap, 0, NULL) );
#endif #endif
assert( nBytes>=0 ); assert( nBytes>=0 );
return HeapAlloc(hHeap, 0, (SIZE_T)nBytes); p = HeapAlloc(hHeap, 0, (SIZE_T)nBytes);
if( !p ){
sqlite3_log(SQLITE_NOMEM, "failed to HeapAlloc %u bytes (%d), heap=%p",
nBytes, GetLastError(), (void*)hHeap);
}
return p;
} }
/* /*
@@ -240,15 +249,18 @@ static void *winMemMalloc(int nBytes){
static void winMemFree(void *pPrior){ static void winMemFree(void *pPrior){
HANDLE hHeap; HANDLE hHeap;
assert( win_mem_data.magic==WINMEM_MAGIC ); winMemAssertMagic();
hHeap = win_mem_data.hHeap; hHeap = winMemGetHeap();
assert( hHeap!=0 ); assert( hHeap!=0 );
assert( hHeap!=INVALID_HANDLE_VALUE ); assert( hHeap!=INVALID_HANDLE_VALUE );
#ifdef SQLITE_WIN32_MALLOC_VALIDATE #ifdef SQLITE_WIN32_MALLOC_VALIDATE
assert ( HeapValidate(hHeap, 0, pPrior) ); assert ( HeapValidate(hHeap, 0, pPrior) );
#endif #endif
if (!pPrior) return; /* Passing NULL to HeapFree is undefined. */ if( !pPrior ) return; /* Passing NULL to HeapFree is undefined. */
HeapFree(hHeap, 0, pPrior); if( !HeapFree(hHeap, 0, pPrior) ){
sqlite3_log(SQLITE_NOMEM, "failed to HeapFree block %p (%d), heap=%p",
pPrior, GetLastError(), (void*)hHeap);
}
} }
/* /*
@@ -256,17 +268,27 @@ static void winMemFree(void *pPrior){
*/ */
static void *winMemRealloc(void *pPrior, int nBytes){ static void *winMemRealloc(void *pPrior, int nBytes){
HANDLE hHeap; HANDLE hHeap;
void *p;
assert( win_mem_data.magic==WINMEM_MAGIC ); winMemAssertMagic();
hHeap = win_mem_data.hHeap; hHeap = winMemGetHeap();
assert( hHeap!=0 ); assert( hHeap!=0 );
assert( hHeap!=INVALID_HANDLE_VALUE ); assert( hHeap!=INVALID_HANDLE_VALUE );
#ifdef SQLITE_WIN32_MALLOC_VALIDATE #ifdef SQLITE_WIN32_MALLOC_VALIDATE
assert ( HeapValidate(hHeap, 0, pPrior) ); assert ( HeapValidate(hHeap, 0, pPrior) );
#endif #endif
assert( nBytes>=0 ); assert( nBytes>=0 );
if (!pPrior) return HeapAlloc(hHeap, 0, (SIZE_T)nBytes); if( !pPrior ){
return HeapReAlloc(hHeap, 0, pPrior, (SIZE_T)nBytes); p = HeapAlloc(hHeap, 0, (SIZE_T)nBytes);
}else{
p = HeapReAlloc(hHeap, 0, pPrior, (SIZE_T)nBytes);
}
if( !p ){
sqlite3_log(SQLITE_NOMEM, "failed to %s %u bytes (%d), heap=%p",
pPrior ? "HeapReAlloc" : "HeapAlloc", nBytes, GetLastError(),
(void*)hHeap);
}
return p;
} }
/* /*
@@ -276,16 +298,20 @@ static int winMemSize(void *p){
HANDLE hHeap; HANDLE hHeap;
SIZE_T n; SIZE_T n;
assert( win_mem_data.magic==WINMEM_MAGIC ); winMemAssertMagic();
hHeap = win_mem_data.hHeap; hHeap = winMemGetHeap();
assert( hHeap!=0 ); assert( hHeap!=0 );
assert( hHeap!=INVALID_HANDLE_VALUE ); assert( hHeap!=INVALID_HANDLE_VALUE );
#ifdef SQLITE_WIN32_MALLOC_VALIDATE #ifdef SQLITE_WIN32_MALLOC_VALIDATE
assert ( HeapValidate(hHeap, 0, NULL) ); assert ( HeapValidate(hHeap, 0, NULL) );
#endif #endif
if (!p) return 0; if( !p ) return 0;
n = HeapSize(hHeap, 0, p); n = HeapSize(hHeap, 0, p);
assert( n<=INT_MAX ); if( n==(SIZE_T)-1 ){
sqlite3_log(SQLITE_NOMEM, "failed to HeapSize block %p (%d), heap=%p",
p, GetLastError(), (void*)hHeap);
return 0;
}
return (int)n; return (int)n;
} }
@@ -302,12 +328,16 @@ static int winMemRoundup(int n){
static int winMemInit(void *pAppData){ static int winMemInit(void *pAppData){
winMemData *pWinMemData = (winMemData *)pAppData; winMemData *pWinMemData = (winMemData *)pAppData;
if (!pWinMemData) return SQLITE_ERROR; if( !pWinMemData ) return SQLITE_ERROR;
assert( pWinMemData->magic==WINMEM_MAGIC ); assert( pWinMemData->magic==WINMEM_MAGIC );
if (!pWinMemData->hHeap){ if( !pWinMemData->hHeap ){
pWinMemData->hHeap = HeapCreate(0, SQLITE_WIN32_HEAP_INIT_SIZE, pWinMemData->hHeap = HeapCreate(0, SQLITE_WIN32_HEAP_INIT_SIZE,
SQLITE_WIN32_HEAP_MAX_SIZE); SQLITE_WIN32_HEAP_MAX_SIZE);
if (!pWinMemData->hHeap){ if( !pWinMemData->hHeap ){
sqlite3_log(SQLITE_NOMEM,
"failed to HeapCreate (%d), initSize=%u, maxSize=%u",
GetLastError(), SQLITE_WIN32_HEAP_INIT_SIZE,
SQLITE_WIN32_HEAP_MAX_SIZE);
return SQLITE_NOMEM; return SQLITE_NOMEM;
} }
pWinMemData->bOwned = TRUE; pWinMemData->bOwned = TRUE;
@@ -326,15 +356,16 @@ static int winMemInit(void *pAppData){
static void winMemShutdown(void *pAppData){ static void winMemShutdown(void *pAppData){
winMemData *pWinMemData = (winMemData *)pAppData; winMemData *pWinMemData = (winMemData *)pAppData;
if (!pWinMemData) return; if( !pWinMemData ) return;
if (pWinMemData->hHeap){ if( pWinMemData->hHeap ){
assert( pWinMemData->hHeap!=INVALID_HANDLE_VALUE ); assert( pWinMemData->hHeap!=INVALID_HANDLE_VALUE );
#ifdef SQLITE_WIN32_MALLOC_VALIDATE #ifdef SQLITE_WIN32_MALLOC_VALIDATE
assert( HeapValidate(pWinMemData->hHeap, 0, NULL) ); assert( HeapValidate(pWinMemData->hHeap, 0, NULL) );
#endif #endif
if (pWinMemData->bOwned){ if( pWinMemData->bOwned ){
if (!HeapDestroy(pWinMemData->hHeap)){ if( !HeapDestroy(pWinMemData->hHeap) ){
/* TODO: Log this? */ sqlite3_log(SQLITE_NOMEM, "failed to HeapDestroy (%d), heap=%p",
GetLastError(), (void*)pWinMemData->hHeap);
} }
pWinMemData->bOwned = FALSE; pWinMemData->bOwned = FALSE;
} }