From 6de20f33ae2c14779227ff158829acb0f2051a98 Mon Sep 17 00:00:00 2001 From: Saulius Krasuckas Date: Thu, 21 Jul 2005 10:34:08 +0000 Subject: [PATCH] - Declare implemented functions inside #ifndef _DEBUG block. - Make MSVCRTD_operator_new_dbg recognize types of memory blocks. --- dlls/msvcrtd/Makefile.in | 1 + dlls/msvcrtd/debug.c | 25 ++++++++++++++++++++++++- dlls/msvcrtd/tests/debug.c | 4 +++- include/msvcrt/crtdbg.h | 30 +++++++++++++++++++++++------- 4 files changed, 51 insertions(+), 9 deletions(-) diff --git a/dlls/msvcrtd/Makefile.in b/dlls/msvcrtd/Makefile.in index 8ce9810819a..fa6ebc6461a 100644 --- a/dlls/msvcrtd/Makefile.in +++ b/dlls/msvcrtd/Makefile.in @@ -5,6 +5,7 @@ VPATH = @srcdir@ MODULE = msvcrtd.dll IMPORTLIB = libmsvcrtd.$(IMPLIBEXT) IMPORTS = msvcrt kernel32 +EXTRAINCL = -I$(TOPSRCDIR)/include/msvcrt C_SRCS = \ debug.c diff --git a/dlls/msvcrtd/debug.c b/dlls/msvcrtd/debug.c index 5bca7af1153..90995ad6d29 100644 --- a/dlls/msvcrtd/debug.c +++ b/dlls/msvcrtd/debug.c @@ -22,6 +22,9 @@ #include "winbase.h" +#define _DEBUG +#include "crtdbg.h" + WINE_DEFAULT_DEBUG_CHANNEL(msvcrt); int _crtAssertBusy = -1; @@ -39,10 +42,30 @@ void *MSVCRTD_operator_new_dbg( const char *szFileName, int nLine) { - void *retval = HeapAlloc(GetProcessHeap(), 0, nSize); + void *retval = NULL; TRACE("(%lu, %d, '%s', %d) returning %p\n", nSize, nBlockUse, szFileName, nLine, retval); + switch(_BLOCK_TYPE(nBlockUse)) + { + case _NORMAL_BLOCK: + break; + case _CLIENT_BLOCK: + FIXME("Unimplemented case for nBlockUse = _CLIENT_BLOCK\n"); + return NULL; + case _FREE_BLOCK: + FIXME("Native code throws an exception here\n"); + case _CRT_BLOCK: + case _IGNORE_BLOCK: + ERR("Not allowed nBlockUse value: %d\n", _BLOCK_TYPE(nBlockUse)); + return NULL; + default: + ERR("Unknown nBlockUse value: %d\n", _BLOCK_TYPE(nBlockUse)); + return NULL; + } + + retval = HeapAlloc(GetProcessHeap(), 0, nSize); + if (!retval) _callnewh(nSize); diff --git a/dlls/msvcrtd/tests/debug.c b/dlls/msvcrtd/tests/debug.c index 81a533a1276..d9a1a1cddce 100644 --- a/dlls/msvcrtd/tests/debug.c +++ b/dlls/msvcrtd/tests/debug.c @@ -24,6 +24,8 @@ #include "winbase.h" #include "winnt.h" +#include "crtdbg.h" + #include "wine/test.h" /**********************************************************************/ @@ -55,7 +57,7 @@ static void test_new(void) { void *mem; - mem = pMSVCRTD_operator_new_dbg(42, 0, __FILE__, __LINE__); + mem = pMSVCRTD_operator_new_dbg(42, _NORMAL_BLOCK, __FILE__, __LINE__); ok(mem != NULL, "memory not allocated\n"); } diff --git a/include/msvcrt/crtdbg.h b/include/msvcrt/crtdbg.h index d8320832276..f520bf4d559 100644 --- a/include/msvcrt/crtdbg.h +++ b/include/msvcrt/crtdbg.h @@ -39,6 +39,8 @@ #define _CLIENT_BLOCK 4 #define _MAX_BLOCKS 5 +#define _BLOCK_TYPE(block) (block & 0xFFFF) +#define _BLOCK_SUBTYPE(block) (block >> 16 & 0xFFFF) typedef struct _CrtMemState { @@ -56,6 +58,14 @@ typedef struct _CrtMemState #define _ASSERTE(expr) ((void)0) #define _CrtDbgBreak() ((void)0) +#define _CrtCheckMemory() ((int)1) +#define _CrtDbgReport(...) ((int)0) +#define _CrtDumpMemoryLeaks() ((int)0) +#define _CrtSetBreakAlloc(a) ((long)0) +#define _CrtSetDbgFlag(f) ((int)0) +#define _CrtSetDumpClient(f) ((void)0) +#define _CrtSetReportMode(t,m) ((int)0) + #else /* _DEBUG */ #include @@ -67,12 +77,22 @@ typedef struct _CrtMemState #define _CrtDbgBreak() ((void)0) #endif +extern int _crtAssertBusy; +extern int _crtBreakAlloc; +extern int _crtDbgFlag; + +int _CrtCheckMemory(); +int _CrtDbgReport(int reportType, const char *filename, int linenumber, + const char *moduleName, const char *format, ...); +int _CrtDumpMemoryLeaks(); +int _CrtSetBreakAlloc(int new); +int _CrtSetDbgFlag(int new); +void *_CrtSetDumpClient(void *dumpClient); +int _CrtSetReportMode(int reportType, int reportMode); + #endif /* _DEBUG */ -#define _CrtCheckMemory() ((int)1) -#define _CrtDbgReport(...) ((int)0) #define _CrtDoForAllClientObjects(f,c) ((void)0) -#define _CrtDumpMemoryLeaks() ((int)0) #define _CrtIsMemoryBlock(p,s,r,f,l) ((int)1) #define _CrtIsValidHeapPointer(p) ((int)1) #define _CrtIsValidPointer(p,s,a) ((int)1) @@ -81,10 +101,6 @@ typedef struct _CrtMemState #define _CrtMemDumpAllObjectsSince(s) ((void)0) #define _CrtMemDumpStatistics(s) ((void)0) #define _CrtSetAllocHook(f) ((void)0) -#define _CrtSetBreakAlloc(a) ((long)0) -#define _CrtSetDbgFlag(f) ((int)0) -#define _CrtSetDumpClient(f) ((void)0) -#define _CrtSetReportMode(t,m) ((int)0) #define _RPT0(t,m) #define _RPT1(t,m,p1)