You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by bo...@apache.org on 2010/04/11 19:40:34 UTC

svn commit: r932949 - in /xerces/c/branches/xerces-3.1/src/xercesc: dom/impl/DOMDocumentImpl.cpp xinclude/XIncludeLocation.cpp xinclude/XIncludeUtils.cpp

Author: borisk
Date: Sun Apr 11 17:40:33 2010
New Revision: 932949

URL: http://svn.apache.org/viewvc?rev=932949&view=rev
Log:
Fix problems with multi-level XInclude (XERCESC-1918). While at it, fix a few
bugs and memory leaks in XInclude code.

Modified:
    xerces/c/branches/xerces-3.1/src/xercesc/dom/impl/DOMDocumentImpl.cpp
    xerces/c/branches/xerces-3.1/src/xercesc/xinclude/XIncludeLocation.cpp
    xerces/c/branches/xerces-3.1/src/xercesc/xinclude/XIncludeUtils.cpp

Modified: xerces/c/branches/xerces-3.1/src/xercesc/dom/impl/DOMDocumentImpl.cpp
URL: http://svn.apache.org/viewvc/xerces/c/branches/xerces-3.1/src/xercesc/dom/impl/DOMDocumentImpl.cpp?rev=932949&r1=932948&r2=932949&view=diff
==============================================================================
--- xerces/c/branches/xerces-3.1/src/xercesc/dom/impl/DOMDocumentImpl.cpp (original)
+++ xerces/c/branches/xerces-3.1/src/xercesc/dom/impl/DOMDocumentImpl.cpp Sun Apr 11 17:40:33 2010
@@ -200,6 +200,13 @@ void DOMDocumentImpl::setDocumentType(DO
 
 DOMDocumentImpl::~DOMDocumentImpl()
 {
+    // While DOMConfiguration is allocated on the Document's heap, itself
+    // it uses the memory manager directly. This means that while we cannot
+    // delete with operator delete, we need to call its d-tor.
+    //
+    if (fDOMConfiguration)
+      fDOMConfiguration->~DOMConfiguration ();
+
     //  Clean up the fNodeListPool
     if (fNodeListPool)
         fNodeListPool->cleanup();

Modified: xerces/c/branches/xerces-3.1/src/xercesc/xinclude/XIncludeLocation.cpp
URL: http://svn.apache.org/viewvc/xerces/c/branches/xerces-3.1/src/xercesc/xinclude/XIncludeLocation.cpp?rev=932949&r1=932948&r2=932949&view=diff
==============================================================================
--- xerces/c/branches/xerces-3.1/src/xercesc/xinclude/XIncludeLocation.cpp (original)
+++ xerces/c/branches/xerces-3.1/src/xercesc/xinclude/XIncludeLocation.cpp Sun Apr 11 17:40:33 2010
@@ -61,7 +61,6 @@ XIncludeLocation::prependPath(const XMLC
     if (fHref == NULL){
         return NULL;
     }
-    XMLSize_t fileLength = XMLString::stringLen(fHref);
 
     if (baseToAdd == NULL){
         return fHref;
@@ -76,13 +75,19 @@ XIncludeLocation::prependPath(const XMLC
         lastSlash = XMLString::lastIndexOf(baseToAdd, chBackSlash);
     }
 
-    relativeHref = (XMLCh *)XMLPlatformUtils::fgMemoryManager->allocate((fileLength + baseLength + 2) * sizeof(XMLCh));
+    // Skip the scheme (e.g., file://) if fHref has one. Ideally we
+    // should detect also if the URI is absolute.
+    //
+    const XMLCh* hrefPath = findEndOfProtocol (fHref);
+    XMLSize_t hrefPathLength = XMLString::stringLen(hrefPath);
+
+    relativeHref = (XMLCh *)XMLPlatformUtils::fgMemoryManager->allocate((hrefPathLength + baseLength + 2) * sizeof(XMLCh));
     if (relativeHref == NULL){
         return NULL;
     }
     XMLString::copyNString(relativeHref, baseToAdd, lastSlash + 1);
     relativeHref[lastSlash + 1] = chNull;
-    XMLString::catString(relativeHref, fHref);
+    XMLString::catString(relativeHref, hrefPath);
 
     /* free the old reference */
     deallocate((void *)fHref);

Modified: xerces/c/branches/xerces-3.1/src/xercesc/xinclude/XIncludeUtils.cpp
URL: http://svn.apache.org/viewvc/xerces/c/branches/xerces-3.1/src/xercesc/xinclude/XIncludeUtils.cpp?rev=932949&r1=932948&r2=932949&view=diff
==============================================================================
--- xerces/c/branches/xerces-3.1/src/xercesc/xinclude/XIncludeUtils.cpp (original)
+++ xerces/c/branches/xerces-3.1/src/xercesc/xinclude/XIncludeUtils.cpp Sun Apr 11 17:40:33 2010
@@ -265,7 +265,6 @@ XIncludeUtils::doDOMNodeXInclude(DOMNode
             XMLUri includedURI(fallback->getBaseURI());
 
             if (fallback->hasChildNodes()){
-                DOMDocumentFragment* frag = parsedDocument->createDocumentFragment();
                 DOMNode *child = fallback->getFirstChild();
                 /* add the content of the fallback element, and remove the fallback elem itself */
                 for ( ; child != NULL ; child=child->getNextSibling()){
@@ -288,11 +287,10 @@ XIncludeUtils::doDOMNodeXInclude(DOMNode
                             ((DOMElement*)newNode)->setAttribute(fgXIBaseAttrName, xil.getLocation());
                         }
                     }
-                    DOMNode *newChild = frag->appendChild(newNode);
-                    parseDOMNodeDoingXInclude(newChild, parsedDocument, entityResolver);
+                    includeParent->insertBefore (newNode, xincludeNode);
+                    parseDOMNodeDoingXInclude(newNode, parsedDocument, entityResolver);
                 }
-                includeParent->replaceChild(frag, xincludeNode);
-                frag->release();
+                includeParent->removeChild(xincludeNode);
                 modifiedNode = true;
             } else {
                 /* empty fallback element - simply remove it! */
@@ -309,8 +307,6 @@ XIncludeUtils::doDOMNodeXInclude(DOMNode
             /* record the successful include while we process the children */
             addDocumentURIToCurrentInclusionHistoryStack(hrefLoc.getLocation());
 
-            DOMDocumentFragment* frag = parsedDocument->createDocumentFragment();
-            /* need to import the document prolog here */
             DOMNode *child = includedDoc->getFirstChild();
             for (; child != NULL; child = child->getNextSibling()) {
                 if (child->getNodeType() == DOMNode::DOCUMENT_TYPE_NODE)
@@ -377,11 +373,10 @@ XIncludeUtils::doDOMNodeXInclude(DOMNode
                     }
                 }
                 DOMNode *newNode = parsedDocument->importNode(child, true);
-                DOMNode *newChild = frag->appendChild(newNode);
-                parseDOMNodeDoingXInclude(newChild, parsedDocument, entityResolver);
+                includeParent->insertBefore (newNode, xincludeNode);
+                parseDOMNodeDoingXInclude(newNode, parsedDocument, entityResolver);
             }
-            includeParent->replaceChild(frag, xincludeNode);
-            frag->release();
+            includeParent->removeChild(xincludeNode);
             popFromCurrentInclusionHistoryStack(NULL);
             modifiedNode = true;
         } else if (includedText){
@@ -687,14 +682,12 @@ XIncludeUtils::popFromCurrentInclusionHi
         historyCursor = historyCursor->next;
     }
 
-    if (penultimateCursor == fIncludeHistoryHead){
-        historyCursor = fIncludeHistoryHead;
+    if (historyCursor == fIncludeHistoryHead){
         fIncludeHistoryHead = NULL;
     } else {
         penultimateCursor->next = NULL;
     }
 
-    // XERCES_STD_QUALIFIER cerr << "poppinURIofStack " << XMLString::transcode(historyCursor->URI) << XERCES_STD_QUALIFIER endl;
     XMLString::release(&(historyCursor->URI));
     XMLPlatformUtils::fgMemoryManager->deallocate((void *)historyCursor);
     return NULL;
@@ -705,8 +698,8 @@ XIncludeUtils::freeInclusionHistory(){
     XIncludeHistoryNode *historyCursor = XIncludeUtils::fIncludeHistoryHead;
     while (historyCursor != NULL){
         XIncludeHistoryNode *next = historyCursor->next;
-        /* XMLString::release(&(historyCursor->URI));
-           XMLPlatformUtils::fgMemoryManager->deallocate((void *)historyCursor); */
+        XMLString::release(&(historyCursor->URI));
+        XMLPlatformUtils::fgMemoryManager->deallocate((void *)historyCursor);
         historyCursor = next;
     }
     XIncludeUtils::fIncludeHistoryHead = NULL;



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xerces.apache.org
For additional commands, e-mail: commits-help@xerces.apache.org