You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by ca...@apache.org on 2005/06/21 21:02:16 UTC

svn commit: r191708 - in /xerces/c/branches/xerces-2.7/src/xercesc/parsers: AbstractDOMParser.cpp AbstractDOMParser.hpp DOMBuilderImpl.cpp DOMBuilderImpl.hpp XercesDOMParser.cpp XercesDOMParser.hpp

Author: cargilld
Date: Tue Jun 21 12:02:15 2005
New Revision: 191708

URL: http://svn.apache.org/viewcvs?rev=191708&view=rev
Log:
Add back changes Bertoni made that were overwritten.

Modified:
    xerces/c/branches/xerces-2.7/src/xercesc/parsers/AbstractDOMParser.cpp
    xerces/c/branches/xerces-2.7/src/xercesc/parsers/AbstractDOMParser.hpp
    xerces/c/branches/xerces-2.7/src/xercesc/parsers/DOMBuilderImpl.cpp
    xerces/c/branches/xerces-2.7/src/xercesc/parsers/DOMBuilderImpl.hpp
    xerces/c/branches/xerces-2.7/src/xercesc/parsers/XercesDOMParser.cpp
    xerces/c/branches/xerces-2.7/src/xercesc/parsers/XercesDOMParser.hpp

Modified: xerces/c/branches/xerces-2.7/src/xercesc/parsers/AbstractDOMParser.cpp
URL: http://svn.apache.org/viewcvs/xerces/c/branches/xerces-2.7/src/xercesc/parsers/AbstractDOMParser.cpp?rev=191708&r1=191707&r2=191708&view=diff
==============================================================================
--- xerces/c/branches/xerces-2.7/src/xercesc/parsers/AbstractDOMParser.cpp (original)
+++ xerces/c/branches/xerces-2.7/src/xercesc/parsers/AbstractDOMParser.cpp Tue Jun 21 12:02:15 2005
@@ -69,6 +69,12 @@
 // ---------------------------------------------------------------------------
 //  AbstractDOMParser: Constructors and Destructor
 // ---------------------------------------------------------------------------
+
+
+typedef JanitorMemFunCall<AbstractDOMParser>    CleanupType;
+typedef JanitorMemFunCall<AbstractDOMParser>    ResetInProgressType;
+
+
 AbstractDOMParser::AbstractDOMParser( XMLValidator* const   valToAdopt
                                     , MemoryManager* const  manager
                                     , XMLGrammarPool* const gramPool) :
@@ -98,19 +104,22 @@
 , fInternalSubset(fBufMgr.bidOnBuffer())
 , fPSVIHandler(0)
 {
+    CleanupType cleanup(this, &AbstractDOMParser::cleanUp);
+
     try
     {
         initialize();
     }
     catch(const OutOfMemoryException&)
     {
+        // Don't cleanup when out of memory, since executing the
+        // code can cause problems.
+        cleanup.release();
+
         throw;
     }
-    catch(...)
-    {
-       cleanUp();
-       throw;
-    }
+
+    cleanup.release();
 }
 
 
@@ -185,6 +194,12 @@
 }
 
 
+void AbstractDOMParser::resetInProgress()
+{
+    fParseInProgress = false;
+}
+
+
 void AbstractDOMParser::resetPool()
 {
     //  We cannot enter here while a regular parse is in progress.
@@ -492,21 +507,19 @@
     if (fParseInProgress)
         ThrowXMLwithMemMgr(IOException, XMLExcepts::Gen_ParseInProgress, fMemoryManager);
 
+    ResetInProgressType     resetInProgress(this, &AbstractDOMParser::resetInProgress);
+
     try
     {
         fParseInProgress = true;
         fScanner->scanDocument(source);
-        fParseInProgress = false;
     }
     catch(const OutOfMemoryException&)
     {
+        resetInProgress.release();
+
         throw;
     }    
-    catch(...)
-    {
-        fParseInProgress = false;
-        throw;
-    }
 }
 
 void AbstractDOMParser::parse(const XMLCh* const systemId)
@@ -515,21 +528,19 @@
     if (fParseInProgress)
         ThrowXMLwithMemMgr(IOException, XMLExcepts::Gen_ParseInProgress, fMemoryManager);
 
+    ResetInProgressType     resetInProgress(this, &AbstractDOMParser::resetInProgress);
+
     try
     {
         fParseInProgress = true;
         fScanner->scanDocument(systemId);
-        fParseInProgress = false;
     }
     catch(const OutOfMemoryException&)
     {
+        resetInProgress.release();
+
         throw;
-    }
-    catch(...)
-    {
-        fParseInProgress = false;
-        throw;
-    }
+    }    
 }
 
 void AbstractDOMParser::parse(const char* const systemId)
@@ -538,21 +549,19 @@
     if (fParseInProgress)
         ThrowXMLwithMemMgr(IOException, XMLExcepts::Gen_ParseInProgress, fMemoryManager);
 
+    ResetInProgressType     resetInProgress(this, &AbstractDOMParser::resetInProgress);
+
     try
     {
         fParseInProgress = true;
         fScanner->scanDocument(systemId);
-        fParseInProgress = false;
     }
     catch(const OutOfMemoryException&)
     {
+        resetInProgress.release();
+
         throw;
-    }
-    catch(...)
-    {
-        fParseInProgress = false;
-        throw;
-    }
+    }    
 }
 
 

Modified: xerces/c/branches/xerces-2.7/src/xercesc/parsers/AbstractDOMParser.hpp
URL: http://svn.apache.org/viewcvs/xerces/c/branches/xerces-2.7/src/xercesc/parsers/AbstractDOMParser.hpp?rev=191708&r1=191707&r2=191708&view=diff
==============================================================================
--- xerces/c/branches/xerces-2.7/src/xercesc/parsers/AbstractDOMParser.hpp (original)
+++ xerces/c/branches/xerces-2.7/src/xercesc/parsers/AbstractDOMParser.hpp Tue Jun 21 12:02:15 2005
@@ -1648,6 +1648,7 @@
     // -----------------------------------------------------------------------
     void initialize();
     void cleanUp();
+    void resetInProgress();
 
     // -----------------------------------------------------------------------
     //  Unimplemented constructors and operators

Modified: xerces/c/branches/xerces-2.7/src/xercesc/parsers/DOMBuilderImpl.cpp
URL: http://svn.apache.org/viewcvs/xerces/c/branches/xerces-2.7/src/xercesc/parsers/DOMBuilderImpl.cpp?rev=191708&r1=191707&r2=191708&view=diff
==============================================================================
--- xerces/c/branches/xerces-2.7/src/xercesc/parsers/DOMBuilderImpl.cpp (original)
+++ xerces/c/branches/xerces-2.7/src/xercesc/parsers/DOMBuilderImpl.cpp Tue Jun 21 12:02:15 2005
@@ -605,6 +605,8 @@
     return 0;
 }
 
+typedef JanitorMemFunCall<DOMBuilderImpl>    ResetParseType;
+
 // ---------------------------------------------------------------------------
 //  DOMBuilderImpl: Grammar preparsing methods
 // ---------------------------------------------------------------------------
@@ -616,7 +618,10 @@
     if (getParseInProgress())
         ThrowXMLwithMemMgr(IOException, XMLExcepts::Gen_ParseInProgress, fMemoryManager);
 
+    ResetParseType  resetParse(this, &DOMBuilderImpl::resetParse);
+
 	Grammar* grammar = 0;
+
     try
     {
         setParseInProgress(true);
@@ -628,20 +633,11 @@
         DOMDocument* doc = adoptDocument();
         if (doc)
             doc->release();
-        
-        if (grammarType == Grammar::DTDGrammarType) 
-            getScanner()->setDocTypeHandler(this);
-        setParseInProgress(false);
     }
     catch(const OutOfMemoryException&)
     {
-        throw;
-    }
-    catch(...)
-    {
-        if (grammarType == Grammar::DTDGrammarType) 
-            getScanner()->setDocTypeHandler(this);
-        setParseInProgress(false);
+        resetParse.release();
+
         throw;
     }
 
@@ -656,7 +652,10 @@
     if (getParseInProgress())
         ThrowXMLwithMemMgr(IOException, XMLExcepts::Gen_ParseInProgress, fMemoryManager);
 
-    Grammar* grammar = 0;
+    ResetParseType  resetParse(this, &DOMBuilderImpl::resetParse);
+
+	Grammar* grammar = 0;
+
     try
     {
         setParseInProgress(true);
@@ -668,20 +667,11 @@
         DOMDocument* doc = adoptDocument();
         if (doc)
             doc->release();
-
-        if (grammarType == Grammar::DTDGrammarType) 
-            getScanner()->setDocTypeHandler(this);
-        setParseInProgress(false);
     }
     catch(const OutOfMemoryException&)
     {
-        throw;
-    }
-    catch(...)
-    {
-        if (grammarType == Grammar::DTDGrammarType) 
-            getScanner()->setDocTypeHandler(this);
-        setParseInProgress(false);
+        resetParse.release();
+
         throw;
     }
 
@@ -696,7 +686,10 @@
     if (getParseInProgress())
         ThrowXMLwithMemMgr(IOException, XMLExcepts::Gen_ParseInProgress, fMemoryManager);
 
+    ResetParseType  resetParse(this, &DOMBuilderImpl::resetParse);
+
     Grammar* grammar = 0;
+
     try
     {
         Wrapper4DOMInputSource isWrapper((DOMInputSource*) &source, false, getMemoryManager());
@@ -710,20 +703,11 @@
         DOMDocument* doc = adoptDocument();
         if (doc)
             doc->release();
-
-        if (grammarType == Grammar::DTDGrammarType) 
-            getScanner()->setDocTypeHandler(this);
-        setParseInProgress(false);
     }
     catch(const OutOfMemoryException&)
     {
-        throw;
-    }
-    catch(...)
-    {
-        if (grammarType == Grammar::DTDGrammarType) 
-            getScanner()->setDocTypeHandler(this);
-        setParseInProgress(false);
+        resetParse.release();
+
         throw;
     }
 
@@ -733,6 +717,16 @@
 void DOMBuilderImpl::resetCachedGrammarPool()
 {
     getGrammarResolver()->resetCachedGrammar();
+}
+
+void DOMBuilderImpl::resetParse()
+{
+    if (getScanner()->getDocTypeHandler() == 0)
+    {
+        getScanner()->setDocTypeHandler(this);
+    }
+
+    setParseInProgress(false);
 }
 
 Grammar* DOMBuilderImpl::getGrammar(const XMLCh* const nameSpaceKey) const

Modified: xerces/c/branches/xerces-2.7/src/xercesc/parsers/DOMBuilderImpl.hpp
URL: http://svn.apache.org/viewcvs/xerces/c/branches/xerces-2.7/src/xercesc/parsers/DOMBuilderImpl.hpp?rev=191708&r1=191707&r2=191708&view=diff
==============================================================================
--- xerces/c/branches/xerces-2.7/src/xercesc/parsers/DOMBuilderImpl.hpp (original)
+++ xerces/c/branches/xerces-2.7/src/xercesc/parsers/DOMBuilderImpl.hpp Tue Jun 21 12:02:15 2005
@@ -837,6 +837,11 @@
 
 private :
     // -----------------------------------------------------------------------
+    //  Initialize/Cleanup methods
+    // -----------------------------------------------------------------------
+    void resetParse();
+
+    // -----------------------------------------------------------------------
     //  Private data members
     //
     //  fEntityResolver

Modified: xerces/c/branches/xerces-2.7/src/xercesc/parsers/XercesDOMParser.cpp
URL: http://svn.apache.org/viewcvs/xerces/c/branches/xerces-2.7/src/xercesc/parsers/XercesDOMParser.cpp?rev=191708&r1=191707&r2=191708&view=diff
==============================================================================
--- xerces/c/branches/xerces-2.7/src/xercesc/parsers/XercesDOMParser.cpp (original)
+++ xerces/c/branches/xerces-2.7/src/xercesc/parsers/XercesDOMParser.cpp Tue Jun 21 12:02:15 2005
@@ -251,6 +251,8 @@
     return 0;
 }
 
+typedef JanitorMemFunCall<XercesDOMParser>  ResetParseType;
+
 // ---------------------------------------------------------------------------
 //  XercesDOMParser: Grammar preparsing methods
 // ---------------------------------------------------------------------------
@@ -262,26 +264,21 @@
     if (getParseInProgress())
         ThrowXMLwithMemMgr(IOException, XMLExcepts::Gen_ParseInProgress, fMemoryManager);
 
+    ResetParseType  resetParse(this, &XercesDOMParser::resetParse);
+
     Grammar* grammar = 0;
+
     try
     {
         setParseInProgress(true);
         if (grammarType == Grammar::DTDGrammarType) 
             getScanner()->setDocTypeHandler(0);
         grammar = getScanner()->loadGrammar(systemId, grammarType, toCache);
-        if (grammarType == Grammar::DTDGrammarType) 
-            getScanner()->setDocTypeHandler(this);
-        setParseInProgress(false);
     }
     catch(const OutOfMemoryException&)
     {
-        throw;
-    }
-    catch(...)
-    {
-        if (grammarType == Grammar::DTDGrammarType) 
-            getScanner()->setDocTypeHandler(this);        
-        setParseInProgress(false);
+        resetParse.release();
+
         throw;
     }
 
@@ -296,26 +293,21 @@
     if (getParseInProgress())
         ThrowXMLwithMemMgr(IOException, XMLExcepts::Gen_ParseInProgress, fMemoryManager);
 
+    ResetParseType  resetParse(this, &XercesDOMParser::resetParse);
+
     Grammar* grammar = 0;
+
     try
     {
         setParseInProgress(true);
         if (grammarType == Grammar::DTDGrammarType) 
             getScanner()->setDocTypeHandler(0);
         grammar = getScanner()->loadGrammar(systemId, grammarType, toCache);
-        if (grammarType == Grammar::DTDGrammarType) 
-            getScanner()->setDocTypeHandler(this);
-        setParseInProgress(false);
     }
     catch(const OutOfMemoryException&)
     {
-        throw;
-    }
-    catch(...)
-    {
-        if (grammarType == Grammar::DTDGrammarType) 
-            getScanner()->setDocTypeHandler(this);        
-        setParseInProgress(false);
+        resetParse.release();
+
         throw;
     }
 
@@ -330,7 +322,10 @@
     if (getParseInProgress())
         ThrowXMLwithMemMgr(IOException, XMLExcepts::Gen_ParseInProgress, fMemoryManager);
 
-   Grammar* grammar = 0;
+    ResetParseType  resetParse(this, &XercesDOMParser::resetParse);
+
+    Grammar* grammar = 0;
+
     try
     {
         setParseInProgress(true);
@@ -343,17 +338,22 @@
     }
     catch(const OutOfMemoryException&)
     {
+        resetParse.release();
+
         throw;
     }
-    catch(...)
+
+    return grammar;
+}
+
+void XercesDOMParser::resetParse()
+{
+    if (getScanner()->getDocTypeHandler() == 0)
     {
-        if (grammarType == Grammar::DTDGrammarType) 
-            getScanner()->setDocTypeHandler(this);
-        setParseInProgress(false);
-        throw;
+        getScanner()->setDocTypeHandler(this);
     }
 
-    return grammar;
+    setParseInProgress(false);
 }
 
 void XercesDOMParser::resetCachedGrammarPool()

Modified: xerces/c/branches/xerces-2.7/src/xercesc/parsers/XercesDOMParser.hpp
URL: http://svn.apache.org/viewcvs/xerces/c/branches/xerces-2.7/src/xercesc/parsers/XercesDOMParser.hpp?rev=191708&r1=191707&r2=191708&view=diff
==============================================================================
--- xerces/c/branches/xerces-2.7/src/xercesc/parsers/XercesDOMParser.hpp (original)
+++ xerces/c/branches/xerces-2.7/src/xercesc/parsers/XercesDOMParser.hpp Tue Jun 21 12:02:15 2005
@@ -640,6 +640,11 @@
 
 private :
     // -----------------------------------------------------------------------
+    //  Initialize/Cleanup methods
+    // -----------------------------------------------------------------------
+    void resetParse();
+
+    // -----------------------------------------------------------------------
     //  Unimplemented constructors and operators
     // -----------------------------------------------------------------------
     XercesDOMParser(const XercesDOMParser&);



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