You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by db...@locus.apache.org on 2000/08/14 22:12:02 UTC

cvs commit: xml-xalan/c/src/XSLT ElemCallTemplate.cpp Stylesheet.cpp Stylesheet.hpp StylesheetRoot.cpp

dbertoni    00/08/14 13:11:57

  Modified:    c/src/XSLT ElemCallTemplate.cpp Stylesheet.cpp
                        Stylesheet.hpp StylesheetRoot.cpp
  Log:
  Fixes for thread-safety problem with storing priority in MatchPattern2.
  
  Revision  Changes    Path
  1.8       +2 -1      xml-xalan/c/src/XSLT/ElemCallTemplate.cpp
  
  Index: ElemCallTemplate.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XSLT/ElemCallTemplate.cpp,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- ElemCallTemplate.cpp	2000/08/01 19:45:13	1.7
  +++ ElemCallTemplate.cpp	2000/08/14 20:11:46	1.8
  @@ -68,6 +68,7 @@
   
   #include "AVT.hpp"
   #include "Constants.hpp"
  +#include "ElemTemplate.hpp"
   #include "Stylesheet.hpp"
   #include "StylesheetConstructionContext.hpp"
   #include "StylesheetExecutionContext.hpp"
  @@ -131,7 +132,7 @@
   
   	if(!isEmpty(m_templateName.getLocalPart()))
   	{
  -		ElemTemplateElement* const	theTemplate =
  +		const ElemTemplate* const	theTemplate =
   			getStylesheet().getStylesheetRoot().findNamedTemplate(m_templateName,
   					executionContext);
   
  
  
  
  1.31      +32 -36    xml-xalan/c/src/XSLT/Stylesheet.cpp
  
  Index: Stylesheet.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XSLT/Stylesheet.cpp,v
  retrieving revision 1.30
  retrieving revision 1.31
  diff -u -r1.30 -r1.31
  --- Stylesheet.cpp	2000/08/11 21:15:44	1.30
  +++ Stylesheet.cpp	2000/08/14 20:11:48	1.31
  @@ -513,35 +513,24 @@
   	  
   
   
  -/**
  - * Locate a macro via the "name" attribute.
  - * @exception XSLProcessorException thrown if the active ProblemListener and XMLParserLiaison decide 
  - * the error condition is severe enough to halt processing.
  - */
  -ElemTemplateElement*
  +const ElemTemplate*
   Stylesheet::findNamedTemplate(
   			const XalanDOMString&			name,
   			StylesheetExecutionContext& 	executionContext) const
  -//throws XSLProcessorException
   {
   	return findNamedTemplate(QName(name, m_namespaces), executionContext);
   }
   
   
   
  -/**
  - * Locate a macro via the "name" attribute.
  - * @exception XSLProcessorException thrown if the active ProblemListener and XMLParserLiaison decide 
  - * the error condition is severe enough to halt processing.
  - */
  -ElemTemplateElement*
  +const ElemTemplate*
   Stylesheet::findNamedTemplate(
   			const QName&					qname,
   			StylesheetExecutionContext& 	executionContext) const
   {
  -	ElemTemplateElement 	*namedTemplate = 0;
  +	const ElemTemplate*		namedTemplate = 0;
   
  -	ElemTemplateElementMapType::const_iterator it = m_namedTemplates.find(qname);
  +	ElemTemplateMapType::const_iterator it = m_namedTemplates.find(qname);
   
   	// Look for the template in the imports
   	if(it == m_namedTemplates.end())
  @@ -551,7 +540,9 @@
   		for(int i = 0; i < nImports; i++)
   		{
   			const Stylesheet* const stylesheet = m_imports[i];
  +
   			namedTemplate = stylesheet->findNamedTemplate(qname, executionContext);
  +
   			if(0 != namedTemplate)
   				break;
   		}
  @@ -572,7 +563,7 @@
   	
   
   
  -ElemTemplate*
  +const ElemTemplate*
   Stylesheet::findTemplate(
   			StylesheetExecutionContext& 	executionContext,
   			XalanNode*						sourceTree, 
  @@ -585,7 +576,7 @@
   
   
   
  -ElemTemplate*
  +const ElemTemplate*
   Stylesheet::findTemplate(
   			StylesheetExecutionContext& 	executionContext,
   			XalanNode*						sourceTree, 
  @@ -597,7 +588,7 @@
   	assert(sourceTree != 0);
   	assert(targetNode != 0);
   
  -	ElemTemplate*	theResult = 0;
  +	const ElemTemplate*		theResult = 0;
   
   	if(m_isWrapperless)
   	{
  @@ -607,16 +598,14 @@
   	{
   		bool					usedWildcard = false;
   
  -		ElemTemplate*			bestMatchedRule = 0;
  +		const ElemTemplate*		bestMatchedRule = 0;
   		const MatchPattern2*	bestMatchedPattern = 0; // Syncs with bestMatchedRule
  +		double					bestMatchPatPriority = XPath::s_MatchScoreNone;
   
   		PatternTableVectorType	conflicts;
   
   		if(useImports == false)
   		{
  -			//odd that this variable is only set, never read
  -			double highScore = XPath::s_MatchScoreNone;
  -
   			// Points to the current list of match patterns.  Note
   			// that this may point to more than one table.
   			const PatternTableListType* 	matchPatternList = 0;
  @@ -663,6 +652,7 @@
   			{
   				XalanDOMString			prevPat;
   				const MatchPattern2*	prevMatchPat = 0;
  +				double					prevMatchPatPriority = XPath::s_MatchScoreNone;
   
   				// These are iterators into the current table.
   				// Note that we may re-seat these iterators to
  @@ -677,9 +667,10 @@
   				while(theCurrentEntry != theTableEnd)
   				{
   					const MatchPattern2*	matchPat = *theCurrentEntry;
  +					double					matchPatPriority = XPath::s_MatchScoreNone;
   					assert(matchPat != 0);
   
  -					ElemTemplate*			rule = matchPat->getTemplate();
  +					const ElemTemplate*		rule = matchPat->getTemplate();
   
   					// We'll be needing to match rules according to what 
   					// mode we're in.
  @@ -705,6 +696,8 @@
   						{
   							prevPat = patterns;
   							prevMatchPat = matchPat;
  +							prevMatchPatPriority = matchPatPriority;
  +							matchPatPriority = XPath::s_MatchScoreNone;
   
   							const XPath* const	xpath = matchPat->getExpression();
   
  @@ -718,26 +711,26 @@
   									  = (XPath::s_MatchScoreNone != priorityVal) 
   															  ? priorityVal : score;
   
  -								matchPat->setPriority(priorityOfRule);
  +								matchPatPriority = priorityOfRule;
   								const double priorityOfBestMatched =
   										(0 != bestMatchedPattern) ?
  -												bestMatchedPattern->getPriority() : 
  +												bestMatchPatPriority : 
   												XPath::s_MatchScoreNone;
   
   								if(priorityOfRule > priorityOfBestMatched)
   								{
   									conflicts.clear();
  -									highScore = score;
   									bestMatchedRule = rule;
   									bestMatchedPattern = matchPat;
  +									bestMatchPatPriority = matchPatPriority;
   								}
   								else if(priorityOfRule == priorityOfBestMatched)
   								{
   									addObjectIfNotFound(bestMatchedPattern, conflicts);
   									conflicts.push_back(matchPat);
  -									highScore = score;
   									bestMatchedRule = rule;
   									bestMatchedPattern = matchPat;
  +									bestMatchPatPriority = matchPatPriority;
   								}
   							}
   						}
  @@ -757,7 +750,7 @@
   						{
   							assert(usedWildcard==false);	// Should only be here once ??
   							usedWildcard = true;
  -							PatternTableMapType::const_iterator 	theTableIterator =
  +							const PatternTableMapType::const_iterator 	theTableIterator =
   								m_patternTable.find(XALAN_STATIC_UCODE_STRING("*"));
   
   							assert(m_patternTable.size());
  @@ -780,9 +773,9 @@
   		// else
   		if(0 == bestMatchedRule)
   		{
  -			const int	nImports = m_imports.size();
  +			const unsigned int	nImports = m_imports.size();
   
  -			for(int i = 0; i < nImports; i++)
  +			for(unsigned int i = 0; i < nImports; i++)
   			{
   				const Stylesheet* const 	stylesheet =
   					m_imports[i];
  @@ -798,15 +791,19 @@
   			}
   		}
   		
  -		const int	nConflicts = conflicts.size();
  +		const unsigned int	nConflicts = conflicts.size();
  +
   		if(nConflicts > 0)
   		{
  -			const bool	quietConflictWarnings = executionContext.getQuietConflictWarnings();
  +			const bool		quietConflictWarnings = executionContext.getQuietConflictWarnings();
  +
   			XalanDOMString	conflictsString = (quietConflictWarnings == false) 
   									 ? XALAN_STATIC_UCODE_STRING("Specificity conflicts found: ") : XalanDOMString();
  -			for(int i = 0; i < nConflicts; i++)
  +
  +			for(unsigned int i = 0; i < nConflicts; i++)
   			{
   				const MatchPattern2* const	conflictPat = conflicts[i];
  +
   				if(0 != i)
   				{
   					if(quietConflictWarnings == false)
  @@ -1041,15 +1038,14 @@
   Stylesheet::MatchPattern2::MatchPattern2(
   			const XalanDOMString&	pat,
   			const XPath*			exp,
  -			ElemTemplate*			theTemplate,
  +			const ElemTemplate*		theTemplate,
   			int 					posInStylesheet, 
   			const XalanDOMString&	targetString,
  -			Stylesheet* 	stylesheet) :
  +			const Stylesheet* 	stylesheet) :
   	m_stylesheet(stylesheet),
   	m_targetString(targetString),
   	m_expression(exp),
   	m_posInStylesheet(posInStylesheet),
  -	m_priority(XPath::s_MatchScoreNone),
   	m_pattern(pat),
   	m_template(theTemplate)
   {
  
  
  
  1.22      +17 -48    xml-xalan/c/src/XSLT/Stylesheet.hpp
  
  Index: Stylesheet.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XSLT/Stylesheet.hpp,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- Stylesheet.hpp	2000/08/11 21:15:44	1.21
  +++ Stylesheet.hpp	2000/08/14 20:11:49	1.22
  @@ -128,7 +128,7 @@
   
   typedef XALAN_STD map<XalanDOMString, XalanDOMString>		PrefixAliasesMapType;
   typedef XALAN_STD map<XalanDOMString, ExtensionNSHandler*>	ExtensionNamespacesMapType;
  -typedef XALAN_STD map<QName, ElemTemplateElement*>			ElemTemplateElementMapType;
  +typedef XALAN_STD map<QName, ElemTemplate*>					ElemTemplateMapType;
   typedef XALAN_STD vector<ElemAttributeSet*> 				AttributeSetMapType;
   typedef XALAN_STD vector<ElemVariable*> 					ElemVariableVectorType;
   typedef XALAN_STD vector<KeyDeclaration>					KeyDeclarationVectorType;
  @@ -604,7 +604,7 @@
   	 * Thus, for a given key or keyref, look up hashtable by name, 
   	 * look up the nodelist by the given reference.
   	 */
  -	virtual void
  +	void
   	processKeyElement(
   			ElemTemplateElement*			nsContext,
   			const AttributeList&			atts,
  @@ -617,7 +617,7 @@
   	 * @param executionContext	 current execution context
   	 * @return pointer to template found or 0 if none found
   	 */
  -	virtual ElemTemplateElement*
  +	const ElemTemplate*
   	findNamedTemplate(
   			const XalanDOMString&			name,
   			StylesheetExecutionContext& 	executionContext) const;
  @@ -628,7 +628,7 @@
   	 * @param executionContext	 current execution context
   	 * @return pointer to template found or 0 if none found
   	 */
  -	virtual ElemTemplateElement*
  +	const ElemTemplate*
   	findNamedTemplate(
   			const QName&					qname,
   			StylesheetExecutionContext& 	executionContext) const;
  @@ -642,8 +642,7 @@
   	 * @param targetNode	   element that needs a rule
   	 * @return				   pointer to rule that best matches targetNode
   	 */
  -	virtual
  -	ElemTemplate*
  +	const ElemTemplate*
   	findTemplate(
   			StylesheetExecutionContext& 	executionContext,
   			XalanNode*						sourceTree,
  @@ -660,8 +659,7 @@
   	 * @param useImports        means that this is an xsl:apply-imports commend
   	 * @return pointer to rule that best matches targetElem
   	 */
  -	virtual
  -	ElemTemplate*
  +	const ElemTemplate*
   	findTemplate(
   			StylesheetExecutionContext& 	executionContext,
   			XalanNode*						sourceTree, 
  @@ -691,10 +689,10 @@
   		MatchPattern2(
   				const XalanDOMString&	pat,
   				const XPath*			exp,
  -				ElemTemplate*			theTemplate,
  +				const ElemTemplate*		theTemplate,
   				int 					posInStylesheet, 
   				const XalanDOMString&	targetString,
  -				Stylesheet* 			stylesheet); 
  +				const Stylesheet* 		stylesheet); 
   
   		~MatchPattern2();
   
  @@ -703,7 +701,7 @@
   		 * 
   		 * @return stylesheet for pattern
   		 */
  -		Stylesheet*
  +		const Stylesheet*
   		getStylesheet() const
   		{
   			return m_stylesheet;
  @@ -758,49 +756,20 @@
   		 * 
   		 * @return template node
   		 */
  -		ElemTemplate*
  +		const ElemTemplate*
   		getTemplate() const
   		{
   			return m_template;
   		}
   		
  -		/**
  -		 * Retrieve priority of pattern.
  -		 * 
  -		 * @return priority of pattern
  -		 */
  -		double
  -		getPriority() const
  -		{
  -			return m_priority;
  -		}
  -
  -		/**
  -		 * Set priority of pattern.
  -		 * 
  -		 * @param thePriority priority of pattern
  -		 */
  -		// This is const because m_priority is mutable, which is an artifact of
  -		// the design and our Java heritage.
  -		void
  -		setPriority(double	thePriority) const
  -		{ 
  -			m_priority = thePriority;
  -		}
  -
   	private:
   
  -		Stylesheet* 			m_stylesheet;
  -		const XalanDOMString	m_targetString;
  -		const XPath*			m_expression;
  -		const int				m_posInStylesheet;
  -		const XalanDOMString	m_pattern;
  -		ElemTemplate*			m_template; // ref to the corresponding template
  -		
  -		/**
  -		 * Transient... only used to track priority while processing.
  -		 */
  -		mutable double			m_priority;
  +		const Stylesheet* const		m_stylesheet;
  +		const XalanDOMString		m_targetString;
  +		const XPath* const			m_expression;
  +		const int					m_posInStylesheet;
  +		const XalanDOMString		m_pattern;
  +		const ElemTemplate*	const	m_template; // ref to the corresponding template
   
   		// Not implemented...
   		MatchPattern2();
  @@ -1254,7 +1223,7 @@
   	 * in the XSL DOM tree. Initialized in initMacroLookupTable, and used in
   	 * findNamedTemplate.
   	 */
  -	ElemTemplateElementMapType	m_namedTemplates;
  +	ElemTemplateMapType			m_namedTemplates;
     
   	/**
   	 * Table for defined constants, keyed on the names.
  
  
  
  1.22      +1 -1      xml-xalan/c/src/XSLT/StylesheetRoot.cpp
  
  Index: StylesheetRoot.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XSLT/StylesheetRoot.cpp,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- StylesheetRoot.cpp	2000/08/11 21:15:46	1.21
  +++ StylesheetRoot.cpp	2000/08/14 20:11:50	1.22
  @@ -168,7 +168,7 @@
   			StylesheetExecutionContext&		executionContext) const
   {
   	// Find the root pattern in the XSL.
  -	ElemTemplate* rootRule =
  +	const ElemTemplate* rootRule =
   			findTemplate(executionContext, sourceTree, sourceTree);
   
   	if(0 == rootRule)