From b975a32d25e6eb732dbb8d07a3d4289b0a84aa92 Mon Sep 17 00:00:00 2001 From: Alberto Massari <amassari@apache.org> Date: Wed, 27 Oct 2010 15:07:29 +0000 Subject: [PATCH] Use the DOMDocument's pool to allocate the return value of getWholeText (XERCESC-1949) git-svn-id: https://svn.apache.org/repos/asf/xerces/c/trunk@1027994 13f79535-47bb-0310-9956-ffa450edef68 --- src/xercesc/dom/impl/DOMCDATASectionImpl.cpp | 9 +++++++-- src/xercesc/dom/impl/DOMTextImpl.cpp | 9 +++++++-- tests/src/MemHandlerTest/MemoryMonitor.cpp | 5 +++++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/xercesc/dom/impl/DOMCDATASectionImpl.cpp b/src/xercesc/dom/impl/DOMCDATASectionImpl.cpp index 6b9871770..74055522e 100644 --- a/src/xercesc/dom/impl/DOMCDATASectionImpl.cpp +++ b/src/xercesc/dom/impl/DOMCDATASectionImpl.cpp @@ -135,7 +135,12 @@ bool DOMCDATASectionImpl::getIsElementContentWhitespace() const const XMLCh* DOMCDATASectionImpl::getWholeText() const { DOMDocument *doc = getOwnerDocument(); - DOMTreeWalker* pWalker=doc->createTreeWalker(doc->getDocumentElement(), DOMNodeFilter::SHOW_ALL, NULL, true); + if (!doc) { + throw DOMException(DOMException::NOT_SUPPORTED_ERR, 0, GetDOMNodeMemoryManager); + return 0; + } + DOMNode* root=doc->getDocumentElement(); + DOMTreeWalker* pWalker=doc->createTreeWalker(root!=NULL?root:(DOMNode*)this, DOMNodeFilter::SHOW_ALL, NULL, true); pWalker->setCurrentNode((DOMNode*)this); // Logically-adjacent text nodes are Text or CDATASection nodes that can be visited sequentially in document order or in // reversed document order without entering, exiting, or passing over Element, Comment, or ProcessingInstruction nodes. @@ -156,7 +161,7 @@ const XMLCh* DOMCDATASectionImpl::getWholeText() const } pWalker->release(); - XMLCh* wholeString = (XMLCh*) (GetDOMNodeMemoryManager->allocate((buff.getLen()+1)*sizeof(XMLCh))); + XMLCh* wholeString = (XMLCh*)((DOMDocumentImpl*)doc)->allocate((buff.getLen()+1) * sizeof(XMLCh)); XMLString::copyString(wholeString, buff.getRawBuffer()); return wholeString; } diff --git a/src/xercesc/dom/impl/DOMTextImpl.cpp b/src/xercesc/dom/impl/DOMTextImpl.cpp index 7b87b6f0d..715002247 100644 --- a/src/xercesc/dom/impl/DOMTextImpl.cpp +++ b/src/xercesc/dom/impl/DOMTextImpl.cpp @@ -145,7 +145,12 @@ bool DOMTextImpl::getIsElementContentWhitespace() const const XMLCh* DOMTextImpl::getWholeText() const { DOMDocument *doc = getOwnerDocument(); - DOMTreeWalker* pWalker=doc->createTreeWalker(doc->getDocumentElement(), DOMNodeFilter::SHOW_ALL, NULL, true); + if (!doc) { + throw DOMException(DOMException::NOT_SUPPORTED_ERR, 0, GetDOMNodeMemoryManager); + return 0; + } + DOMNode* root=doc->getDocumentElement(); + DOMTreeWalker* pWalker=doc->createTreeWalker(root!=NULL?root:(DOMNode*)this, DOMNodeFilter::SHOW_ALL, NULL, true); pWalker->setCurrentNode((DOMNode*)this); // Logically-adjacent text nodes are Text or CDATASection nodes that can be visited sequentially in document order or in // reversed document order without entering, exiting, or passing over Element, Comment, or ProcessingInstruction nodes. @@ -166,7 +171,7 @@ const XMLCh* DOMTextImpl::getWholeText() const } pWalker->release(); - XMLCh* wholeString = (XMLCh*) (GetDOMNodeMemoryManager->allocate((buff.getLen()+1)*sizeof(XMLCh))); + XMLCh* wholeString = (XMLCh*)((DOMDocumentImpl*)doc)->allocate((buff.getLen()+1) * sizeof(XMLCh)); XMLString::copyString(wholeString, buff.getRawBuffer()); return wholeString; } diff --git a/tests/src/MemHandlerTest/MemoryMonitor.cpp b/tests/src/MemHandlerTest/MemoryMonitor.cpp index d81583d27..7ccda7f6e 100644 --- a/tests/src/MemHandlerTest/MemoryMonitor.cpp +++ b/tests/src/MemHandlerTest/MemoryMonitor.cpp @@ -378,6 +378,11 @@ int main (int argC, char *argV[]) XERCES_STD_QUALIFIER cout << "getElementsByTagName didn't return a valid DOMNodeList." << XERCES_STD_QUALIFIER endl; else if(list->item(0)!=doc->getDocumentElement()) XERCES_STD_QUALIFIER cout << "getElementsByTagName didn't find the root element." << XERCES_STD_QUALIFIER endl; + + DOMTreeWalker* pWalker=doc->createTreeWalker(doc->getDocumentElement(), DOMNodeFilter::SHOW_TEXT, NULL, true); + DOMText* textNode=(DOMText*)pWalker->nextNode(); + pWalker->release(); + const XMLCh* txt=(textNode!=NULL?textNode->getWholeText():NULL); } sax2parser->parse(xmlFile); saxParser->parse(xmlFile); -- GitLab