dbertoni    00/08/22 16:28:00

  Modified:    c/src/XSLT StylesheetHandler.cpp StylesheetHandler.hpp
  Log:
  Track elements that have already been parented, so that they are not 
doubly-deleted.
  
  Revision  Changes    Path
  1.39      +41 -11    xml-xalan/c/src/XSLT/StylesheetHandler.cpp
  
  Index: StylesheetHandler.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XSLT/StylesheetHandler.cpp,v
  retrieving revision 1.38
  retrieving revision 1.39
  diff -u -r1.38 -r1.39
  --- StylesheetHandler.cpp     2000/08/22 20:21:28     1.38
  +++ StylesheetHandler.cpp     2000/08/22 23:27:58     1.39
  @@ -129,6 +129,7 @@
        m_stylesheet(stylesheetTree),
        m_constructionContext(constructionContext),
        m_elemStack(),
  +     m_elemStackParentedElements(),
        m_strayElements(),
        m_whiteSpaceElems(),
        m_pTemplate(0),
  @@ -152,10 +153,30 @@
        using std::for_each;
   #endif
   
  -     // Clean up the element stack vector
  -     for_each(m_elemStack.begin(),
  -                      m_elemStack.end(),
  -                      DeleteFunctor<ElemTemplateElement>());
  +     // Clean up the element stack vector...
  +     ElemTemplateStackType::const_iterator   i = m_elemStack.begin();
  +
  +     while(i != m_elemStack.end())
  +     {
  +             // See if the element is in the set of elements that have
  +             // already been parented, so we don't try to delete it after
  +             // it's parent has already deleted it...
  +             const ElemTemplateSetType::iterator             j =
  +                             m_elemStackParentedElements.find(*i);
  +
  +             if (j == m_elemStackParentedElements.end())
  +             {
  +                     // Not found, so delete it...
  +                     delete *i;
  +             }
  +             else
  +             {
  +                     // Found, so erase it from the set...
  +                     m_elemStackParentedElements.erase(j);
  +             }
  +
  +             ++i;
  +     }
   
        // Clean up the whitespace elements.
        for_each(m_whiteSpaceElems.begin(),
  @@ -166,6 +187,8 @@
        for_each(m_strayElements.begin(),
                         m_strayElements.end(),
                         DeleteFunctor<ElemTemplateElement>());
  +
  +     m_elemStackParentedElements.clear();
   }
   
   
  @@ -309,6 +332,7 @@
                                                                                
                m_stylesheet,
                                                                                
                name, atts, lineNumber, columnNumber);
                                        m_elemStack.push_back(m_pTemplate);
  +                                     
m_elemStackParentedElements.insert(m_pTemplate);
                                        m_inTemplate = true;
                                        m_stylesheet.addTemplate(m_pTemplate, 
m_constructionContext);
                                        break;
  @@ -318,7 +342,6 @@
                                        {
                                                m_constructionContext.warn("Old 
syntax: the functions instruction should use a url of " + 
m_constructionContext.getXalanXSLNameSpaceURL());
                                        }
  -                                     // 
m_constructionContext.handleFunctionsInstruction((Element)child);
                                break;
   
                                case Constants::ELEMNAME_VARIABLE:
  @@ -337,6 +360,7 @@
                                        m_elemStack.push_back(varelem);
                                        m_inTemplate = true; // fake it out
                                        
m_stylesheet.setTopLevelVariable(varelem);
  +                                     
m_elemStackParentedElements.insert(varelem);
                                        varelem->setTopLevel(true);
                                }
                                break;
  @@ -651,6 +675,8 @@
                                        
foreach->getSortElems().push_back(sortElem);
   
                                        sortElem->setParentNodeElem(foreach);
  +
  +                                     
m_elemStackParentedElements.insert(foreach);
                                }
                                break;
   
  @@ -997,6 +1023,7 @@
                        {
                                ElemTemplateElement* const      parent = 
m_elemStack.back();
                                parent->appendChildElem(elem);
  +                             m_elemStackParentedElements.insert(elem);
                        }
   
                        m_elemStack.push_back(elem);
  @@ -1013,6 +1040,8 @@
                        if (elem != 0)
                        {
                                delete elem;
  +
  +                             m_elemStackParentedElements.erase(elem);
                        }
                }
        } // end try
  @@ -1029,6 +1058,7 @@
                while(m_elemStack.empty() == false &&
                          m_elemStack.back()->getXSLToken() != 
Constants::ELEMNAME_UNDEFINED)
                {
  +                     m_elemStackParentedElements.erase(m_elemStack.back());
                        m_elemStack.pop_back();
                }
   
  @@ -1043,6 +1073,7 @@
                while(m_elemStack.empty() == false &&
                          m_elemStack.back()->getXSLToken() != 
Constants::ELEMNAME_UNDEFINED)
                {
  +                     m_elemStackParentedElements.erase(m_elemStack.back());
                        m_elemStack.pop_back();
                }
   
  @@ -1170,13 +1201,9 @@
                        StylesheetHandler tp(*importedStylesheet.get(), 
m_constructionContext);
   
                        m_constructionContext.parseXML(hrefUrl, &tp, 
importedStylesheet.get());
  -
  -                     // Add it to the front of the imports
  -                     m_stylesheet.addImport(importedStylesheet.get(), true);
   
  -                     // The imported stylesheet is now owned by the 
stylesheet, so
  -                     // release the XalanAutoPtr.
  -                     importedStylesheet.release();
  +                     // Add it to the front of the imports, releasing the 
XalanAutoPtr...
  +                     m_stylesheet.addImport(importedStylesheet.release(), 
true);
   
                        assert(equals(importStack.back(), hrefUrl));
                        importStack.pop_back();         
  @@ -1262,6 +1289,7 @@
   
        m_lastPopped = m_elemStack.back();
        m_elemStack.pop_back();
  +     m_elemStackParentedElements.erase(m_lastPopped);
        m_lastPopped->setFinishedConstruction(true);
   
        const int tok = m_lastPopped->getXSLToken();
  @@ -1592,6 +1620,7 @@
   
StylesheetHandler::PushPopIncludeState::PushPopIncludeState(StylesheetHandler&  
     theHandler) :
        m_handler(theHandler),
        m_elemStack(theHandler.m_elemStack),
  +     m_elemStackParentedElements(theHandler.m_elemStackParentedElements),
        m_pTemplate(theHandler.m_pTemplate),
        m_lastPopped(theHandler.m_lastPopped),
        m_inTemplate(theHandler.m_inTemplate),
  @@ -1629,6 +1658,7 @@
                         DeleteFunctor<ElemTemplateElement>());
   
        m_handler.m_elemStack = m_elemStack;
  +     m_handler.m_elemStackParentedElements = m_elemStackParentedElements;
        m_handler.m_pTemplate = m_pTemplate;
        m_handler.m_lastPopped = m_lastPopped;
        m_handler.m_inTemplate = m_inTemplate;
  
  
  
  1.16      +12 -0     xml-xalan/c/src/XSLT/StylesheetHandler.hpp
  
  Index: StylesheetHandler.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XSLT/StylesheetHandler.hpp,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- StylesheetHandler.hpp     2000/08/22 20:21:29     1.15
  +++ StylesheetHandler.hpp     2000/08/22 23:27:58     1.16
  @@ -67,6 +67,7 @@
   
   
   #include <vector>
  +#include <set>
   
   
   
  @@ -104,9 +105,11 @@
   #if defined(XALAN_NO_NAMESPACES)
        typedef vector<ElemTemplateElement*>            ElemTemplateStackType;
        typedef vector<ElemTextLiteral*>                        
ElemTextLiteralStackType;
  +     typedef set<ElemTemplateElement*>                       
ElemTemplateSetType;
   #else
        typedef std::vector<ElemTemplateElement*>       ElemTemplateStackType;
        typedef std::vector<ElemTextLiteral*>           
ElemTextLiteralStackType;
  +     typedef std::set<ElemTemplateElement*>          ElemTemplateSetType;
   #endif
   
        /**
  @@ -419,6 +422,13 @@
        ElemTemplateStackType   m_elemStack;
   
        /**
  +      * The set of elements in m_elemStack which have already
  +      * been parented.  This prevents us from deleting them
  +      * twice if an exception is thrown.
  +      */
  +     ElemTemplateSetType             m_elemStackParentedElements;
  +
  +     /**
         * The stack of stray elements, to be delete when finished.
         */
        ElemTemplateStackType   m_strayElements;
  @@ -491,6 +501,8 @@
                StylesheetHandler&                                      
m_handler;
   
                ElemTemplateStackType                           m_elemStack;
  +
  +             ElemTemplateSetType                                     
m_elemStackParentedElements;
   
                ElemTemplate* const                                     
m_pTemplate;
   
  
  
  

Reply via email to