apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From John Mark Vandenberg <jay...@gmail.com>
Subject [patch 14/17] crtdbg.h
Date Sat, 15 Apr 2006 01:41:32 GMT
Move usage of MS VC++ crtdbg.h functionality into #if defined(_MSC_VER)

Index: include/arch/win32/apr_arch_misc.h
===================================================================
--- include/arch/win32/apr_arch_misc.h.orig
+++ include/arch/win32/apr_arch_misc.h
@@ -138,6 +138,29 @@ apr_status_t apr_get_oslevel(apr_oslevel
 #define ELSE_WIN_OS_IS_ANSI
 #endif /* WINNT */
 
+#if defined(_MSC_VER)
+#include "crtdbg.h"
+
+APR_INLINE void* apr_malloc_dbg(size_t size, const char* filename, int linenumber) {
+    return _malloc_dbg(size, _CRT_BLOCK, filename, linenumber);
+}
+
+APR_INLINE void* apr_realloc_dbg(void* userData, size_t newSize, const char* filename, int
linenumber) {
+    return _realloc_dbg(userData, newSize, _CRT_BLOCK, filename, linenumber);
+}
+
+#else
+
+APR_INLINE void* apr_malloc_dbg(size_t size, const char* filename, int linenumber) {
+    return malloc(size);
+}
+
+APR_INLINE void* apr_realloc_dbg(void* userData, size_t newSize, const char* filename, int
linenumber) {
+    return realloc(userData, newSize);
+}
+
+#endif  /* ! _MSC_VER */
+
 typedef enum {
     DLL_WINBASEAPI = 0,    // kernel32 From WinBase.h
     DLL_WINADVAPI = 1,     // advapi32 From WinBase.h
Index: misc/win32/apr_app.c
===================================================================
--- misc/win32/apr_app.c.orig
+++ misc/win32/apr_app.c
@@ -36,7 +36,6 @@
 #include "apr_general.h"
 #include "apr_private.h"
 #include "ShellAPI.h"
-#include "crtdbg.h"
 #include "wchar.h"
 #include "apr_arch_file_io.h"
 #include "assert.h"
@@ -57,8 +56,8 @@ int wmain(int argc, const wchar_t **warg
 
     dupenv = apr_wastrtoastr(&env, wenv, -1);
 
-    _environ = _malloc_dbg((dupenv + 1) * sizeof (char *), 
-                           _CRT_BLOCK, __FILE__, __LINE__ );
+    _environ = apr_malloc_dbg((dupenv + 1) * sizeof (char *),
+                              __FILE__, __LINE__ );
     memcpy(_environ, env, (dupenv + 1) * sizeof (char *));
 
     /* MSVCRT will attempt to maintain the wide environment calls
Index: misc/win32/internal.c
===================================================================
--- misc/win32/internal.c.orig
+++ misc/win32/internal.c
@@ -18,7 +18,6 @@
 
 #include "apr_arch_misc.h"
 #include "apr_arch_file_io.h"
-#include <crtdbg.h>
 #include <assert.h>
 
 /* This module is the source of -static- helper functions that are
@@ -52,8 +51,8 @@ int apr_wastrtoastr(char const * const *
             ;
     }
 
-    newarr = _malloc_dbg((args + 1) * sizeof(char *),
-                         _CRT_BLOCK, __FILE__, __LINE__);
+    newarr = apr_malloc_dbg((args + 1) * sizeof(char *),
+                            __FILE__, __LINE__);
 
     for (arg = 0; arg < args; ++arg) {
         newarr[arg] = (void*)(wcslen(arr[arg]) + 1);
@@ -66,8 +65,8 @@ int apr_wastrtoastr(char const * const *
      * 4 ucs bytes will hold a wchar_t pair value (20 bits)
      */
     elesize = elesize * 3 + 1;
-    ele = elements = _malloc_dbg(elesize * sizeof(char), 
-                                 _CRT_BLOCK, __FILE__, __LINE__);
+    ele = elements = apr_malloc_dbg(elesize * sizeof(char),
+                                    __FILE__, __LINE__);
 
     for (arg = 0; arg < args; ++arg) {
         apr_size_t len = (apr_size_t)newarr[arg];
@@ -87,8 +86,8 @@ int apr_wastrtoastr(char const * const *
 
     /* Return to the free store if the heap realloc is the least bit optimized
      */
-    ele = _realloc_dbg(elements, ele - elements, 
-                       _CRT_BLOCK, __FILE__, __LINE__);
+    ele = apr_realloc_dbg(elements, ele - elements,
+                          __FILE__, __LINE__);
 
     if (ele != elements) {
         apr_size_t diff = ele - elements;
Index: misc/win32/start.c
===================================================================
--- misc/win32/start.c.orig
+++ misc/win32/start.c
@@ -23,7 +23,6 @@
 #include "apr_arch_misc.h"       /* for WSAHighByte / WSALowByte */
 #include "wchar.h"
 #include "apr_arch_file_io.h"
-#include "crtdbg.h"
 #include "assert.h"
 
 /* This symbol is _private_, although it must be exported.
@@ -54,8 +53,8 @@ static int warrsztoastr(const char * con
     }
     wsize = 1 + wch - arrsz;
 
-    newarr = _malloc_dbg((args + 1) * sizeof(char *),
-                         _CRT_BLOCK, __FILE__, __LINE__);
+    newarr = apr_malloc_dbg((args + 1) * sizeof(char *),
+                            __FILE__, __LINE__);
 
     /* This is a safe max allocation, we will realloc after
      * processing and return the excess to the free store.
@@ -63,8 +62,8 @@ static int warrsztoastr(const char * con
      * 4 ucs bytes will hold a wchar_t pair value (20 bits)
      */
     newlen = totlen = wsize * 3 + 1;
-    newarr[0] = _malloc_dbg(newlen * sizeof(char), 
-                            _CRT_BLOCK, __FILE__, __LINE__);
+    newarr[0] = apr_malloc_dbg(newlen * sizeof(char),
+                               __FILE__, __LINE__);
 
     (void)apr_conv_ucs2_to_utf8(arrsz, &wsize,
                                 newarr[0], &newlen);
@@ -72,8 +71,8 @@ static int warrsztoastr(const char * con
     assert(newlen && !wsize);
     /* Return to the free store if the heap realloc is the least bit optimized
      */
-    newarr[0] = _realloc_dbg(newarr[0], totlen - newlen, 
-                             _CRT_BLOCK, __FILE__, __LINE__);
+    newarr[0] = apr_realloc_dbg(newarr[0], totlen - newlen,
+                                __FILE__, __LINE__);
 
     for (arg = 1; arg < args; ++arg) {
         newarr[arg] = newarr[arg - 1] + 2;
@@ -128,8 +127,8 @@ APR_DECLARE(apr_status_t) apr_app_initia
         dupenv = warrsztoastr(&_environ, sysstr, -1);
 
 	if (env) {
-            *env = _malloc_dbg((dupenv + 1) * sizeof (char *), 
-                               _CRT_BLOCK, __FILE__, __LINE__ );
+            *env = apr_malloc_dbg((dupenv + 1) * sizeof (char *),
+                                  __FILE__, __LINE__ );
             memcpy((void*)*env, _environ, (dupenv + 1) * sizeof (char *));
         }
         else {
Index: misc/win32/misc.c
===================================================================
--- misc/win32/misc.c.orig
+++ misc/win32/misc.c
@@ -16,7 +16,6 @@
 
 #include "apr_private.h"
 #include "apr_arch_misc.h"
-#include "crtdbg.h"
 #include "apr_arch_file_io.h"
 #include "assert.h"
 #include "apr_lib.h"

--

Mime
View raw message