MSVCRTD: extend MSVCRTD_operator_new_dbg

Saulius Krasuckas saulius2 at ar.fi.lt
Thu Jul 21 04:13:21 CDT 2005


This patch also makes dlls/msvcrtd/tests/ to fail in Wine, as the tests 
contains one bug.


ChangeLog:
	Saulius Krasuckas <saulius.krasuckas_at_ieee.org>
	-Declare implemented functions inside #ifndef _DEBUG block.
	-Make MSVCRTD_operator_new_dbg recognize types of memory blocks.


Index: include/msvcrt/crtdbg.h
===================================================================
RCS file: /home/wine/wine/include/msvcrt/crtdbg.h,v
retrieving revision 1.5
diff -p -u -r1.5 crtdbg.h
--- include/msvcrt/crtdbg.h     18 Jul 2003 22:57:15 -0000      1.5
+++ include/msvcrt/crtdbg.h     21 Jul 2005 08:59:54 -0000
@@ -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 <assert.h>
@@ -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)
Index: dlls/msvcrtd/Makefile.in
===================================================================
RCS file: /home/wine/wine/dlls/msvcrtd/Makefile.in,v
retrieving revision 1.4
diff -p -u -r1.4 Makefile.in
--- dlls/msvcrtd/Makefile.in    9 May 2005 14:42:33 -0000       1.4
+++ dlls/msvcrtd/Makefile.in    21 Jul 2005 08:59:57 -0000
@@ -5,6 +5,7 @@ VPATH     = @srcdir@
 MODULE    = msvcrtd.dll
 IMPORTLIB = libmsvcrtd.$(IMPLIBEXT)
 IMPORTS   = msvcrt kernel32
+EXTRAINCL = -I$(TOPSRCDIR)/include/msvcrt
 
 C_SRCS = \
        debug.c
Index: dlls/msvcrtd/debug.c
===================================================================
RCS file: /home/wine/wine/dlls/msvcrtd/debug.c,v
retrieving revision 1.4
diff -p -u -r1.4 debug.c
--- dlls/msvcrtd/debug.c        14 Jun 2004 17:57:06 -0000      1.4
+++ dlls/msvcrtd/debug.c        21 Jul 2005 08:59:57 -0000
@@ -22,6 +22,9 @@
 
 #include "winbase.h"
 
+#define  _DEBUG
+#include "crtdbg.h"
+
 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
 
 int _crtAssertBusy = -1;
@@ -39,9 +42,29 @@ 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);




More information about the wine-patches mailing list