DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=22178>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=22178

XMemory is incompatible with Visual C++ debug macros

           Summary: XMemory is incompatible with Visual C++ debug macros
           Product: Xerces-C++
           Version: 2.3.0
          Platform: PC
        OS/Version: Windows XP
            Status: NEW
          Severity: Normal
          Priority: Other
         Component: Miscellaneous
        AssignedTo: [EMAIL PROTECTED]
        ReportedBy: [EMAIL PROTECTED]


When using Visual C++ with MFC, is common to have such a declaration in every 
file of a project:

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

This will replace, in debug mode, the standard "new" operator with a version 
that tracks the allocation with the file name and line number where the it was 
performed; when the program is shut down, a report is printed containing the 
allocations that weren't matched by the corresponding delete.

The problem is: if a file contains that macro definition and some code 
belonging to a class derived from XMemory (say, you have derived SAXParser and 
inside the constructor you allocate some data using "new"), you get an error 
telling you that no "operator new" with 3 arguments can be found.

The solution is to add to the XMemory interface the declaration for this 
operator, routing the call to the standard one, like in the patch attached.

===================================================================
RCS file: /home/cvspublic/xml-xerces/c/src/xercesc/util/XMemory.cpp,v
retrieving revision 1.7
diff -u -r1.7 XMemory.cpp
--- XMemory.cpp 14 Jul 2003 18:51:05 -0000      1.7
+++ XMemory.cpp 6 Aug 2003 15:01:05 -0000
@@ -83,6 +83,11 @@
     return (char*)block + headerSize;
 }
 
+void* XMemory::operator new(size_t size, const char* file, int line)
+{
+       return operator new(size);
+}
+
 void* XMemory::operator new(size_t size, MemoryManager* manager)
 {
     assert(manager != 0);
@@ -111,6 +116,11 @@
 
 //The HP compiler is complaining about duplicate overloading of delete
 #if !defined(XML_HPUX) && !defined(XML_BORLAND)
+
+void XMemory::operator delete(void* p, const char* file, int line)
+{
+       operator delete(p);
+}
 
 void XMemory::operator delete(void* p, MemoryManager* manager)
 {

===================================================================
RCS file: /home/cvspublic/xml-xerces/c/src/xercesc/util/XMemory.hpp,v
retrieving revision 1.4
diff -u -r1.4 XMemory.hpp
--- XMemory.hpp 14 Jul 2003 18:51:05 -0000      1.4
+++ XMemory.hpp 6 Aug 2003 15:01:05 -0000
@@ -94,6 +94,15 @@
     void* operator new(size_t size);
 
     /**
+      * This method overrides the MFC debug version of the operator new
+      *
+      * @param size   The requested memory size
+      * @param file   The file where the allocation was requested
+      * @param line   The line where the allocation was requested
+      */
+    void* operator new(size_t size, const char* file, int line);
+
+    /**
       * This method overrides placement operator new
       *
       * @param size   The requested memory size
@@ -111,10 +120,19 @@
      //The HP compiler is complaining about duplicate overloading of delete
 #if !defined(XML_HPUX) && !defined(XML_BORLAND)
     /**
+      * This method provide a matching delete for the MFC debug new
+      *
+      * @param p      The pointer to the allocated memory
+      * @param file   The file where the allocation was requested
+      * @param line   The line where the allocation was requested
+     */
+    void operator delete(void* p, const char* file, int line);
+
+    /**
       * This method provide a matching delete for the placement new
       *
       * @param p      The pointer to the allocated memory
-      * @param memMgr An appliation's memory manager
+      * @param memMgr An application's memory manager
       */
     void operator delete(void* p, MemoryManager* memMgr);
 #endif



Alberto

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to