From d015c1f122d94adc66a3ad3287a58be60c52247c Mon Sep 17 00:00:00 2001 From: Boris Kolpackov <borisk@apache.org> Date: Fri, 14 Mar 2008 12:40:55 +0000 Subject: [PATCH] Allow providing a separate memory manager for exceptions (XERCESC-1730). Remove unused MemoryManagerArrayImpl. git-svn-id: https://svn.apache.org/repos/asf/xerces/c/trunk@637083 13f79535-47bb-0310-9956-ffa450edef68 --- .../XercesLib/XercesLib.xcode/project.pbxproj | 16 --- .../BCB6/Xerces-all/XercesLib/XercesLib.bpr | 2 - .../Xerces-all/XercesLib/XercesLib.mak | 1 - .../VC6/xerces-all/XercesLib/XercesLib.dsp | 8 -- .../VC6/xerces-all/XercesLib/XercesLib.mak | 14 --- .../xerces-all/XercesLib/XercesLib.vcproj | 6 -- .../VC8/xerces-all/XercesLib/XercesLib.vcproj | 8 -- .../VC9/xerces-all/XercesLib/XercesLib.vcproj | 8 -- src/Makefile.am | 2 - src/xercesc/dom/DOMException.cpp | 15 ++- src/xercesc/framework/MemoryManager.hpp | 16 ++- .../internal/MemoryManagerArrayImpl.cpp | 56 ---------- .../internal/MemoryManagerArrayImpl.hpp | 100 ------------------ src/xercesc/internal/MemoryManagerImpl.cpp | 9 +- src/xercesc/internal/MemoryManagerImpl.hpp | 14 ++- src/xercesc/util/PlatformUtils.cpp | 1 - src/xercesc/util/XMLException.cpp | 11 +- swig/perl/xerces-headers.txt | 1 - tests/src/MemHandlerTest/MemoryMonitor.cpp | 31 +++--- tests/src/MemHandlerTest/MemoryMonitor.hpp | 14 +-- 20 files changed, 76 insertions(+), 257 deletions(-) delete mode 100644 src/xercesc/internal/MemoryManagerArrayImpl.cpp delete mode 100644 src/xercesc/internal/MemoryManagerArrayImpl.hpp diff --git a/Projects/MacOS/Xcode/XercesLib/XercesLib.xcode/project.pbxproj b/Projects/MacOS/Xcode/XercesLib/XercesLib.xcode/project.pbxproj index 345cf1f19..b1baa4141 100644 --- a/Projects/MacOS/Xcode/XercesLib/XercesLib.xcode/project.pbxproj +++ b/Projects/MacOS/Xcode/XercesLib/XercesLib.xcode/project.pbxproj @@ -9227,22 +9227,6 @@ settings = { }; }; - 9067ED1604FC0A9600A80082 = { - fileEncoding = 30; - isa = PBXFileReference; - lastKnownFileType = sourcecode.cpp.h; - path = MemoryManagerArrayImpl.hpp; - refType = 4; - sourceTree = "<group>"; - }; - 9067ED1704FC0A9600A80082 = { - fileEncoding = 30; - isa = PBXFileReference; - lastKnownFileType = sourcecode.cpp.cpp; - path = MemoryManagerArrayImpl.cpp; - refType = 4; - sourceTree = "<group>"; - }; 906C9B3F06FF69AA00D1DCE1 = { fileEncoding = 30; isa = PBXFileReference; diff --git a/Projects/Win32/BCB6/Xerces-all/XercesLib/XercesLib.bpr b/Projects/Win32/BCB6/Xerces-all/XercesLib/XercesLib.bpr index aaabf75e7..048cab81c 100644 --- a/Projects/Win32/BCB6/Xerces-all/XercesLib/XercesLib.bpr +++ b/Projects/Win32/BCB6/Xerces-all/XercesLib/XercesLib.bpr @@ -117,7 +117,6 @@ ..\..\..\..\..\Build\Win32\BCB6\obj\ElemStack.obj ..\..\..\..\..\Build\Win32\BCB6\obj\IGXMLScanner.obj ..\..\..\..\..\Build\Win32\BCB6\obj\IGXMLScanner2.obj - ..\..\..\..\..\Build\Win32\BCB6\obj\MemoryManagerArrayImpl.obj ..\..\..\..\..\Build\Win32\BCB6\obj\MemoryManagerImpl.obj ..\..\..\..\..\Build\Win32\BCB6\obj\ReaderMgr.obj ..\..\..\..\..\Build\Win32\BCB6\obj\SGXMLScanner.obj @@ -487,7 +486,6 @@ <FILE FILENAME="..\..\..\..\..\src\xercesc\internal\ElemStack.cpp" FORMNAME="" UNITNAME="ElemStack" CONTAINERID="CCompiler" DESIGNCLASS="" LOCALCOMMAND=""/> <FILE FILENAME="..\..\..\..\..\src\xercesc\internal\IGXMLScanner.cpp" FORMNAME="" UNITNAME="IGXMLScanner" CONTAINERID="CCompiler" DESIGNCLASS="" LOCALCOMMAND=""/> <FILE FILENAME="..\..\..\..\..\src\xercesc\internal\IGXMLScanner2.cpp" FORMNAME="" UNITNAME="IGXMLScanner2" CONTAINERID="CCompiler" DESIGNCLASS="" LOCALCOMMAND=""/> - <FILE FILENAME="..\..\..\..\..\src\xercesc\internal\MemoryManagerArrayImpl.cpp" FORMNAME="" UNITNAME="MemoryManagerArrayImpl" CONTAINERID="CCompiler" DESIGNCLASS="" LOCALCOMMAND=""/> <FILE FILENAME="..\..\..\..\..\src\xercesc\internal\MemoryManagerImpl.cpp" FORMNAME="" UNITNAME="MemoryManagerImpl" CONTAINERID="CCompiler" DESIGNCLASS="" LOCALCOMMAND=""/> <FILE FILENAME="..\..\..\..\..\src\xercesc\internal\ReaderMgr.cpp" FORMNAME="" UNITNAME="ReaderMgr" CONTAINERID="CCompiler" DESIGNCLASS="" LOCALCOMMAND=""/> <FILE FILENAME="..\..\..\..\..\src\xercesc\internal\SGXMLScanner.cpp" FORMNAME="" UNITNAME="SGXMLScanner" CONTAINERID="CCompiler" DESIGNCLASS="" LOCALCOMMAND=""/> diff --git a/Projects/Win32/BCC.551/Xerces-all/XercesLib/XercesLib.mak b/Projects/Win32/BCC.551/Xerces-all/XercesLib/XercesLib.mak index 4cf6f83b4..207e7e2d3 100644 --- a/Projects/Win32/BCC.551/Xerces-all/XercesLib/XercesLib.mak +++ b/Projects/Win32/BCC.551/Xerces-all/XercesLib/XercesLib.mak @@ -281,7 +281,6 @@ OBJFILES = $(TARGETPATH)\obj\XercesLib.obj \ $(TARGETPATH)\obj\XProtoType.obj \ $(TARGETPATH)\obj\XSerializeEngine.obj \ $(TARGETPATH)\obj\XTemplateSerializer.obj \ - $(TARGETPATH)\obj\MemoryManagerArrayImpl.obj \ $(TARGETPATH)\obj\ValidationContextImpl.obj \ $(TARGETPATH)\obj\XMLRefInfo.obj \ $(TARGETPATH)\obj\XMLAttDefList.obj \ diff --git a/Projects/Win32/VC6/xerces-all/XercesLib/XercesLib.dsp b/Projects/Win32/VC6/xerces-all/XercesLib/XercesLib.dsp index 98b0524b4..ac4741e92 100644 --- a/Projects/Win32/VC6/xerces-all/XercesLib/XercesLib.dsp +++ b/Projects/Win32/VC6/xerces-all/XercesLib/XercesLib.dsp @@ -1724,14 +1724,6 @@ SOURCE=..\..\..\..\..\src\xercesc\internal\IGXMLScanner2.cpp # End Source File # Begin Source File -SOURCE=..\..\..\..\..\src\xercesc\internal\MemoryManagerArrayImpl.cpp -# End Source File -# Begin Source File - -SOURCE=..\..\..\..\..\src\xercesc\internal\MemoryManagerArrayImpl.hpp -# End Source File -# Begin Source File - SOURCE=..\..\..\..\..\src\xercesc\internal\MemoryManagerImpl.cpp # End Source File # Begin Source File diff --git a/Projects/Win32/VC6/xerces-all/XercesLib/XercesLib.mak b/Projects/Win32/VC6/xerces-all/XercesLib/XercesLib.mak index 164951c5e..3e39e8614 100644 --- a/Projects/Win32/VC6/xerces-all/XercesLib/XercesLib.mak +++ b/Projects/Win32/VC6/xerces-all/XercesLib/XercesLib.mak @@ -174,7 +174,6 @@ CLEAN : -@erase "$(INTDIR)\Match.obj" -@erase "$(INTDIR)\MemBufFormatTarget.obj" -@erase "$(INTDIR)\MemBufInputSource.obj" - -@erase "$(INTDIR)\MemoryManagerArrayImpl.obj" -@erase "$(INTDIR)\MemoryManagerImpl.obj" -@erase "$(INTDIR)\MixedContentModel.obj" -@erase "$(INTDIR)\ModifierToken.obj" @@ -504,7 +503,6 @@ LINK32_OBJS= \ "$(INTDIR)\ElemStack.obj" \ "$(INTDIR)\IGXMLScanner.obj" \ "$(INTDIR)\IGXMLScanner2.obj" \ - "$(INTDIR)\MemoryManagerArrayImpl.obj" \ "$(INTDIR)\MemoryManagerImpl.obj" \ "$(INTDIR)\ReaderMgr.obj" \ "$(INTDIR)\SGXMLScanner.obj" \ @@ -821,7 +819,6 @@ CLEAN : -@erase "$(INTDIR)\Match.obj" -@erase "$(INTDIR)\MemBufFormatTarget.obj" -@erase "$(INTDIR)\MemBufInputSource.obj" - -@erase "$(INTDIR)\MemoryManagerArrayImpl.obj" -@erase "$(INTDIR)\MemoryManagerImpl.obj" -@erase "$(INTDIR)\MixedContentModel.obj" -@erase "$(INTDIR)\ModifierToken.obj" @@ -1152,7 +1149,6 @@ LINK32_OBJS= \ "$(INTDIR)\ElemStack.obj" \ "$(INTDIR)\IGXMLScanner.obj" \ "$(INTDIR)\IGXMLScanner2.obj" \ - "$(INTDIR)\MemoryManagerArrayImpl.obj" \ "$(INTDIR)\MemoryManagerImpl.obj" \ "$(INTDIR)\ReaderMgr.obj" \ "$(INTDIR)\SGXMLScanner.obj" \ @@ -1469,7 +1465,6 @@ CLEAN : -@erase "$(INTDIR)\Match.obj" -@erase "$(INTDIR)\MemBufFormatTarget.obj" -@erase "$(INTDIR)\MemBufInputSource.obj" - -@erase "$(INTDIR)\MemoryManagerArrayImpl.obj" -@erase "$(INTDIR)\MemoryManagerImpl.obj" -@erase "$(INTDIR)\MixedContentModel.obj" -@erase "$(INTDIR)\ModifierToken.obj" @@ -1801,7 +1796,6 @@ LINK32_OBJS= \ "$(INTDIR)\ElemStack.obj" \ "$(INTDIR)\IGXMLScanner.obj" \ "$(INTDIR)\IGXMLScanner2.obj" \ - "$(INTDIR)\MemoryManagerArrayImpl.obj" \ "$(INTDIR)\MemoryManagerImpl.obj" \ "$(INTDIR)\ReaderMgr.obj" \ "$(INTDIR)\SGXMLScanner.obj" \ @@ -2118,7 +2112,6 @@ CLEAN : -@erase "$(INTDIR)\Match.obj" -@erase "$(INTDIR)\MemBufFormatTarget.obj" -@erase "$(INTDIR)\MemBufInputSource.obj" - -@erase "$(INTDIR)\MemoryManagerArrayImpl.obj" -@erase "$(INTDIR)\MemoryManagerImpl.obj" -@erase "$(INTDIR)\MixedContentModel.obj" -@erase "$(INTDIR)\ModifierToken.obj" @@ -2449,7 +2442,6 @@ LINK32_OBJS= \ "$(INTDIR)\ElemStack.obj" \ "$(INTDIR)\IGXMLScanner.obj" \ "$(INTDIR)\IGXMLScanner2.obj" \ - "$(INTDIR)\MemoryManagerArrayImpl.obj" \ "$(INTDIR)\MemoryManagerImpl.obj" \ "$(INTDIR)\ReaderMgr.obj" \ "$(INTDIR)\SGXMLScanner.obj" \ @@ -3590,12 +3582,6 @@ SOURCE=..\..\..\..\..\src\xercesc\internal\IGXMLScanner2.cpp $(CPP) $(CPP_PROJ) $(SOURCE) -SOURCE=..\..\..\..\..\src\xercesc\internal\MemoryManagerArrayImpl.cpp - -"$(INTDIR)\MemoryManagerArrayImpl.obj" : $(SOURCE) "$(INTDIR)" - $(CPP) $(CPP_PROJ) $(SOURCE) - - SOURCE=..\..\..\..\..\src\xercesc\internal\MemoryManagerImpl.cpp "$(INTDIR)\MemoryManagerImpl.obj" : $(SOURCE) "$(INTDIR)" diff --git a/Projects/Win32/VC7.1/xerces-all/XercesLib/XercesLib.vcproj b/Projects/Win32/VC7.1/xerces-all/XercesLib/XercesLib.vcproj index 79a7ea15d..e1a445ba3 100644 --- a/Projects/Win32/VC7.1/xerces-all/XercesLib/XercesLib.vcproj +++ b/Projects/Win32/VC7.1/xerces-all/XercesLib/XercesLib.vcproj @@ -1705,12 +1705,6 @@ copy $(InputDir)\$(InputName).msvc.hpp $(InputPath) <File RelativePath="..\..\..\..\..\src\xercesc\internal\IGXMLScanner2.cpp"> </File> - <File - RelativePath="..\..\..\..\..\src\xercesc\internal\MemoryManagerArrayImpl.cpp"> - </File> - <File - RelativePath="..\..\..\..\..\src\xercesc\internal\MemoryManagerArrayImpl.hpp"> - </File> <File RelativePath="..\..\..\..\..\src\xercesc\internal\MemoryManagerImpl.cpp"> </File> diff --git a/Projects/Win32/VC8/xerces-all/XercesLib/XercesLib.vcproj b/Projects/Win32/VC8/xerces-all/XercesLib/XercesLib.vcproj index bfe4f7285..27e50dfe6 100644 --- a/Projects/Win32/VC8/xerces-all/XercesLib/XercesLib.vcproj +++ b/Projects/Win32/VC8/xerces-all/XercesLib/XercesLib.vcproj @@ -3059,14 +3059,6 @@ RelativePath="..\..\..\..\..\src\xercesc\internal\IGXMLScanner2.cpp" > </File> - <File - RelativePath="..\..\..\..\..\src\xercesc\internal\MemoryManagerArrayImpl.cpp" - > - </File> - <File - RelativePath="..\..\..\..\..\src\xercesc\internal\MemoryManagerArrayImpl.hpp" - > - </File> <File RelativePath="..\..\..\..\..\src\xercesc\internal\MemoryManagerImpl.cpp" > diff --git a/Projects/Win32/VC9/xerces-all/XercesLib/XercesLib.vcproj b/Projects/Win32/VC9/xerces-all/XercesLib/XercesLib.vcproj index a227954c8..25230a441 100644 --- a/Projects/Win32/VC9/xerces-all/XercesLib/XercesLib.vcproj +++ b/Projects/Win32/VC9/xerces-all/XercesLib/XercesLib.vcproj @@ -3146,14 +3146,6 @@ RelativePath="..\..\..\..\..\src\xercesc\internal\IGXMLScanner2.cpp" > </File> - <File - RelativePath="..\..\..\..\..\src\xercesc\internal\MemoryManagerArrayImpl.cpp" - > - </File> - <File - RelativePath="..\..\..\..\..\src\xercesc\internal\MemoryManagerArrayImpl.hpp" - > - </File> <File RelativePath="..\..\..\..\..\src\xercesc\internal\MemoryManagerImpl.cpp" > diff --git a/src/Makefile.am b/src/Makefile.am index 9cb1f0885..5c698e303 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -472,7 +472,6 @@ internal_headers = \ xercesc/internal/EndOfEntityException.hpp \ xercesc/internal/IANAEncodings.hpp \ xercesc/internal/IGXMLScanner.hpp \ - xercesc/internal/MemoryManagerArrayImpl.hpp \ xercesc/internal/MemoryManagerImpl.hpp \ xercesc/internal/ReaderMgr.hpp \ xercesc/internal/SGXMLScanner.hpp \ @@ -500,7 +499,6 @@ internal_sources = \ xercesc/internal/ElemStack.cpp \ xercesc/internal/IGXMLScanner.cpp \ xercesc/internal/IGXMLScanner2.cpp \ - xercesc/internal/MemoryManagerArrayImpl.cpp \ xercesc/internal/MemoryManagerImpl.cpp \ xercesc/internal/ReaderMgr.cpp \ xercesc/internal/SGXMLScanner.cpp \ diff --git a/src/xercesc/dom/DOMException.cpp b/src/xercesc/dom/DOMException.cpp index 6bcf31bd2..5df14235d 100644 --- a/src/xercesc/dom/DOMException.cpp +++ b/src/xercesc/dom/DOMException.cpp @@ -5,9 +5,9 @@ * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -44,22 +44,26 @@ DOMException::DOMException() ,msg(0) ,fMemoryManager(0) ,fMsgOwned(false) -{ +{ } DOMException::DOMException( short exCode , short messageCode , MemoryManager* const memoryManager) :code((ExceptionCode) exCode) -,fMemoryManager(memoryManager) +,fMemoryManager(0) ,fMsgOwned(true) { + if (memoryManager) + fMemoryManager = memoryManager->getExceptionMemoryManager(); + const XMLSize_t msgSize = 2047; XMLCh errText[msgSize + 1]; // load the text if(messageCode==0) messageCode=XMLDOMMsg::DOMEXCEPTION_ERRX+exCode; + msg = XMLString::replicate ( DOMImplementationImpl::getMsgLoader4DOM()->loadMsg(messageCode, errText, msgSize) ? errText : XMLUni::fgDefErrMsg @@ -73,7 +77,8 @@ DOMException::DOMException(const DOMException &other) ,fMemoryManager(other.fMemoryManager) ,fMsgOwned(other.fMsgOwned) { - msg = other.fMsgOwned? XMLString::replicate(other.msg, other.fMemoryManager) : other.msg; + if (other.msg) + msg = other.fMsgOwned? XMLString::replicate(other.msg, other.fMemoryManager) : other.msg; } XERCES_CPP_NAMESPACE_END diff --git a/src/xercesc/framework/MemoryManager.hpp b/src/xercesc/framework/MemoryManager.hpp index 1b3dcf7b4..cfe6bfa11 100644 --- a/src/xercesc/framework/MemoryManager.hpp +++ b/src/xercesc/framework/MemoryManager.hpp @@ -5,9 +5,9 @@ * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -34,7 +34,7 @@ XERCES_CPP_NAMESPACE_BEGIN * Configurable memory manager * * <p>This interface allows outside applications to plug in their own memory - * manager to be used by Xerces for memory allocation/deallocation.</p> + * manager to be used by Xerces for memory allocation/deallocation.</p> */ class XMLPARSER_EXPORT MemoryManager { @@ -55,6 +55,16 @@ public: //@} + /** + * This method is called to obtain the memory manager that should be + * used to allocate memory used in exceptions. If the same memory + * manager can be used, simply return 'this' from this function. + * + * @return A pointer to the memory manager + */ + virtual MemoryManager* getExceptionMemoryManager() = 0; + + // ----------------------------------------------------------------------- // The virtual memory manager interface // ----------------------------------------------------------------------- diff --git a/src/xercesc/internal/MemoryManagerArrayImpl.cpp b/src/xercesc/internal/MemoryManagerArrayImpl.cpp deleted file mode 100644 index d4903feaa..000000000 --- a/src/xercesc/internal/MemoryManagerArrayImpl.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * $Id$ - */ - - -// --------------------------------------------------------------------------- -// Includes -// --------------------------------------------------------------------------- -#include <xercesc/internal/MemoryManagerArrayImpl.hpp> -#include <xercesc/util/OutOfMemoryException.hpp> - -XERCES_CPP_NAMESPACE_BEGIN - -void* MemoryManagerArrayImpl::allocate(size_t size) -{ - - void* memptr; - try { - //return ::operator new[](size); - //return new char[size]; - memptr = new char[size]; - } - catch(...) { - throw OutOfMemoryException(); - } - if (memptr != NULL) { - return memptr; - } - throw OutOfMemoryException(); -} - -void MemoryManagerArrayImpl::deallocate(void* p) -{ - //::operator delete[](p); - delete [] (char*)p; -} - -XERCES_CPP_NAMESPACE_END - diff --git a/src/xercesc/internal/MemoryManagerArrayImpl.hpp b/src/xercesc/internal/MemoryManagerArrayImpl.hpp deleted file mode 100644 index cda64eab2..000000000 --- a/src/xercesc/internal/MemoryManagerArrayImpl.hpp +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * $Id$ - */ - -#if !defined(XERCESC_INCLUDE_GUARD_MEMORYMANAGERARRAYIMPL_HPP) -#define XERCESC_INCLUDE_GUARD_MEMORYMANAGERARRAYIMPL_HPP - -#include <xercesc/framework/MemoryManager.hpp> - -XERCES_CPP_NAMESPACE_BEGIN - -/** - * Configurable memory manager - * - * <p>This is specialized version of a Xerces - * memory manager, which allocates memory using - * using new[](size) syntax. Such memory may - * legally be deleted with delete[]. - * </p> - * <p>This version is used in special cases where it is desired - * that allocated memory be able to be delete[]d. - * </p> - */ - -class XMLUTIL_EXPORT MemoryManagerArrayImpl : public MemoryManager -{ -public: - - /** @name Constructor */ - //@{ - - /** - * Default constructor - */ - MemoryManagerArrayImpl() - { - } - //@} - - /** @name Destructor */ - //@{ - - /** - * Default destructor - */ - virtual ~MemoryManagerArrayImpl() - { - } - //@} - - /** @name The virtual methods in MemoryManager */ - //@{ - - /** - * This method allocates requested memory. - * - * @param size The requested memory size - * - * @return A pointer to the allocated memory - */ - virtual void* allocate(size_t size); - - /** - * This method deallocates memory - * - * @param p The pointer to the allocated memory to be deleted - */ - virtual void deallocate(void* p); - - //@} - -private: - // ----------------------------------------------------------------------- - // Unimplemented constructors and operators - // ----------------------------------------------------------------------- - MemoryManagerArrayImpl(const MemoryManagerArrayImpl&); - MemoryManagerArrayImpl& operator=(const MemoryManagerArrayImpl&); - -}; - -XERCES_CPP_NAMESPACE_END - -#endif diff --git a/src/xercesc/internal/MemoryManagerImpl.cpp b/src/xercesc/internal/MemoryManagerImpl.cpp index 3d19d78d9..eb1500df8 100644 --- a/src/xercesc/internal/MemoryManagerImpl.cpp +++ b/src/xercesc/internal/MemoryManagerImpl.cpp @@ -5,9 +5,9 @@ * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -28,6 +28,11 @@ XERCES_CPP_NAMESPACE_BEGIN +MemoryManager* MemoryManagerImpl::getExceptionMemoryManager() +{ + return this; +} + void* MemoryManagerImpl::allocate(size_t size) { void* memptr; diff --git a/src/xercesc/internal/MemoryManagerImpl.hpp b/src/xercesc/internal/MemoryManagerImpl.hpp index 5a66dee0e..632b03354 100644 --- a/src/xercesc/internal/MemoryManagerImpl.hpp +++ b/src/xercesc/internal/MemoryManagerImpl.hpp @@ -5,9 +5,9 @@ * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -61,6 +61,16 @@ public: } //@} + + /** + * This method is called to obtain the memory manager that should be + * used to allocate memory used in exceptions. + * + * @return A pointer to the memory manager + */ + virtual MemoryManager* getExceptionMemoryManager(); + + /** @name The virtual methods in MemoryManager */ //@{ diff --git a/src/xercesc/util/PlatformUtils.cpp b/src/xercesc/util/PlatformUtils.cpp index a1ce5036e..563db1aad 100644 --- a/src/xercesc/util/PlatformUtils.cpp +++ b/src/xercesc/util/PlatformUtils.cpp @@ -49,7 +49,6 @@ #include <xercesc/util/DefaultPanicHandler.hpp> #include <xercesc/util/XMLInitializer.hpp> #include <xercesc/internal/MemoryManagerImpl.hpp> -#include <xercesc/internal/MemoryManagerArrayImpl.hpp> #include <xercesc/util/XMLFileMgr.hpp> #if XERCES_USE_FILEMGR_POSIX diff --git a/src/xercesc/util/XMLException.cpp b/src/xercesc/util/XMLException.cpp index ee858c7a8..f363cda8e 100644 --- a/src/xercesc/util/XMLException.cpp +++ b/src/xercesc/util/XMLException.cpp @@ -86,7 +86,8 @@ XMLException::XMLException() : , fSrcFile(0) , fSrcLine(0) , fMsg(0) - , fMemoryManager(XMLPlatformUtils::fgMemoryManager) + , fMemoryManager( + XMLPlatformUtils::fgMemoryManager->getExceptionMemoryManager()) { } @@ -99,10 +100,14 @@ XMLException::XMLException( const char* const srcFile , fSrcFile(0) , fSrcLine(srcLine) , fMsg(0) - , fMemoryManager(memoryManager) + , fMemoryManager(0) { if (!memoryManager) - fMemoryManager = XMLPlatformUtils::fgMemoryManager; + fMemoryManager = + XMLPlatformUtils::fgMemoryManager->getExceptionMemoryManager(); + else + fMemoryManager = memoryManager->getExceptionMemoryManager(); + fSrcFile = XMLString::replicate(srcFile, fMemoryManager); } diff --git a/swig/perl/xerces-headers.txt b/swig/perl/xerces-headers.txt index 0136eaa23..db24368a1 100644 --- a/swig/perl/xerces-headers.txt +++ b/swig/perl/xerces-headers.txt @@ -605,7 +605,6 @@ xercesc/dom/impl/DOMTextImpl.hpp xercesc/dom/impl/DOMTreeWalkerImpl.hpp xercesc/dom/impl/DOMTypeInfoImpl.hpp xercesc/dom/impl/XSDElementNSImpl.hpp -xercesc/internal/MemoryManagerArrayImpl.hpp xercesc/internal/MemoryManagerImpl.hpp xercesc/internal/ValidationContextImpl.hpp xercesc/internal/VecAttrListImpl.hpp diff --git a/tests/src/MemHandlerTest/MemoryMonitor.cpp b/tests/src/MemHandlerTest/MemoryMonitor.cpp index 9de796e98..20281253b 100755 --- a/tests/src/MemHandlerTest/MemoryMonitor.cpp +++ b/tests/src/MemHandlerTest/MemoryMonitor.cpp @@ -5,9 +5,9 @@ * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -36,6 +36,11 @@ #include <xercesc/util/OutOfMemoryException.hpp> #include <xercesc/dom/DOM.hpp> +MemoryManager* MemoryMonitor::getExceptionMemoryManager() +{ + return this; +} + void* MemoryMonitor::allocate(size_t size) { void *key = ::operator new(size); @@ -53,10 +58,10 @@ void MemoryMonitor::deallocate(void* p) ::operator delete(p); } -unsigned int MemoryMonitor::getTotalMemory() +unsigned int MemoryMonitor::getTotalMemory() { unsigned int total = 0; - ValueHashTableOfEnumerator<unsigned int> *memEnum = + ValueHashTableOfEnumerator<unsigned int> *memEnum = new ValueHashTableOfEnumerator<unsigned int>(fHashTable); while(memEnum->hasMoreElements()) { total += memEnum->nextElement(); @@ -81,28 +86,28 @@ static void usage() " -n Enable namespace processing. Defaults to off.\n" " -s Enable schema processing. Defaults to off.\n" " -f Enable full schema constraint checking. Defaults to off.\n" - " -r=n Run file through domBuilders n times.\n" + " -r=n Run file through domBuilders n times.\n" " -? Show this help.\n\n" " * = Default if not provided explicitly.\n" << XERCES_STD_QUALIFIER endl; } -class DOMLSParserHandler : public DOMErrorHandler +class DOMLSParserHandler : public DOMErrorHandler { public: DOMLSParserHandler() {}; ~DOMLSParserHandler() {}; - bool handleError(const DOMError &error) + bool handleError(const DOMError &error) { char *message = 0; - XERCES_STD_QUALIFIER cerr << "Error occurred in DOMBuilder! Message: " << + XERCES_STD_QUALIFIER cerr << "Error occurred in DOMBuilder! Message: " << (message = XMLString::transcode(error.getMessage())) << " of severity " << error.getSeverity() << "." << XERCES_STD_QUALIFIER endl; XMLString::release(&message); return true; } }; -class SAXErrorHandler : public ErrorHandler +class SAXErrorHandler : public ErrorHandler { public: SAXErrorHandler() {}; @@ -143,7 +148,7 @@ public: * allocations/deallocations. */ -int main (int argC, char *argV[]) +int main (int argC, char *argV[]) { MemoryMonitor *staticMemMonitor = new MemoryMonitor(); @@ -271,7 +276,7 @@ int main (int argC, char *argV[]) SAXParser *saxParser = new (sax1MemMonitor) SAXParser(0, sax1MemMonitor); saxParser->setErrorHandler(&saxErrorHandler); - // set features + // set features domBuilder->getDomConfig()->setParameter(XMLUni::fgDOMNamespaces, doNamespaces); sax2parser->setFeature(XMLUni::fgSAX2CoreNameSpaces, doNamespaces); saxParser->setDoNamespaces(doNamespaces); @@ -378,7 +383,7 @@ int main (int argC, char *argV[]) } catch (const XMLException& toCatch) { - char *msg = XMLString::transcode(toCatch.getMessage()); + char *msg = XMLString::transcode(toCatch.getMessage()); XERCES_STD_QUALIFIER cerr << "\nError during parsing: '" << xmlFile << "'\n" << "Exception message is: \n" << msg << "\n" << XERCES_STD_QUALIFIER endl; @@ -395,7 +400,7 @@ int main (int argC, char *argV[]) if (DOMImplementation::loadDOMExceptionMsg(toCatch.code, errText, maxChars)) { - char * msg = XMLString::transcode(errText); + char * msg = XMLString::transcode(errText); XERCES_STD_QUALIFIER cerr << "Message is: " << msg << XERCES_STD_QUALIFIER endl; continue; diff --git a/tests/src/MemHandlerTest/MemoryMonitor.hpp b/tests/src/MemHandlerTest/MemoryMonitor.hpp index 1999efc40..a7868ae19 100755 --- a/tests/src/MemHandlerTest/MemoryMonitor.hpp +++ b/tests/src/MemHandlerTest/MemoryMonitor.hpp @@ -5,9 +5,9 @@ * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -42,8 +42,8 @@ XERCES_CPP_NAMESPACE_USE /** * Configurable memory manager * - * <p>This class is a memory manager implementation that keeps track of all - * allocations/deallocations to ensure that all memory that it allocated is + * <p>This class is a memory manager implementation that keeps track of all + * allocations/deallocations to ensure that all memory that it allocated is * deallocated. * </p> */ @@ -59,7 +59,7 @@ public: * Default constructor */ MemoryMonitor() - { + { fHashType = new SimpleHashPtr(); fHashTable = new SimpleValueHashTableOf<unsigned int>(1013, fHashType); } @@ -78,6 +78,8 @@ public: } //@} + virtual MemoryManager* getExceptionMemoryManager(); + /** @name The virtual methods in MemoryManager */ //@{ @@ -98,7 +100,7 @@ public: virtual void deallocate(void* p); //@} - + // Print out amount of currently allocated memory unsigned int getTotalMemory(); -- GitLab