sboag 00/12/31 03:06:36
Modified: java/src/org/apache/xpath/axes AttributeIterator.java
ChildTestIterator.java DescendantIterator.java
Log:
Fix really nasty bug where variable context was not being set in
simple iterators. Reported by "Will Allan" <[EMAIL PROTECTED]>.
Revision Changes Path
1.6 +57 -26
xml-xalan/java/src/org/apache/xpath/axes/AttributeIterator.java
Index: AttributeIterator.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xpath/axes/AttributeIterator.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- AttributeIterator.java 2000/12/27 22:24:11 1.5
+++ AttributeIterator.java 2000/12/31 11:06:35 1.6
@@ -202,40 +202,71 @@
resetProximityPositions();
}
- Node next;
-
- do
+ org.apache.xpath.VariableStack vars;
+ int savedStart;
+ if (-1 != m_varStackPos)
{
- m_lastFetched = next =
- (null == m_attributeList || m_attrListPos >= m_nAttrs)
- ? null : m_attributeList.item(m_attrListPos++);
+ vars = m_execContext.getVarStack();
- if (null != next)
+ // These three statements need to be combined into one operation.
+ savedStart = vars.getSearchStart();
+
+ vars.setSearchStart(m_varStackPos);
+ vars.pushContextPosition(m_varStackContext);
+ }
+ else
+ {
+ // Yuck. Just to shut up the compiler!
+ vars = null;
+ savedStart = 0;
+ }
+
+ try
+ {
+ Node next;
+
+ do
{
- if(NodeFilter.FILTER_ACCEPT == acceptNode(next))
- break;
+ m_lastFetched = next =
+ (null == m_attributeList || m_attrListPos >= m_nAttrs)
+ ? null : m_attributeList.item(m_attrListPos++);
+
+ if (null != next)
+ {
+ if(NodeFilter.FILTER_ACCEPT == acceptNode(next))
+ break;
+ else
+ continue;
+ }
else
- continue;
+ break;
+ }
+ while (next != null);
+
+ if (null != next)
+ {
+ if (null != m_cachedNodes)
+ m_cachedNodes.addElement(m_lastFetched);
+
+ m_next++;
+
+ return next;
}
else
- break;
- }
- while (next != null);
-
- if (null != next)
- {
- if (null != m_cachedNodes)
- m_cachedNodes.addElement(m_lastFetched);
-
- m_next++;
-
- return next;
+ {
+ m_foundLast = true;
+
+ return null;
+ }
}
- else
+ finally
{
- m_foundLast = true;
-
- return null;
+ if (-1 != m_varStackPos)
+ {
+ // These two statements need to be combined into one operation.
+ vars.setSearchStart(savedStart);
+ vars.popContextPosition();
+ }
}
}
1.7 +58 -26
xml-xalan/java/src/org/apache/xpath/axes/ChildTestIterator.java
Index: ChildTestIterator.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xpath/axes/ChildTestIterator.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- ChildTestIterator.java 2000/12/27 22:24:11 1.6
+++ ChildTestIterator.java 2000/12/31 11:06:35 1.7
@@ -70,7 +70,7 @@
/**
* <meta name="usage" content="advanced"/>
* This class implements an optimized iterator for
- * children patterns that have a node test, but no predicate.
+ * children patterns that have a node test, and possibly a predicate.
* @see org.apache.xpath.axes.WalkerFactory#newLocPathIterator
*/
public class ChildTestIterator extends LocPathIterator
@@ -160,39 +160,71 @@
}
Node next;
-
- do
+
+ org.apache.xpath.VariableStack vars;
+ int savedStart;
+ if (-1 != m_varStackPos)
{
- m_lastFetched = next = (null == m_lastFetched)
- ? m_context.getFirstChild()
- : m_lastFetched.getNextSibling();
+ vars = m_execContext.getVarStack();
- if (null != next)
+ // These three statements need to be combined into one operation.
+ savedStart = vars.getSearchStart();
+
+ vars.setSearchStart(m_varStackPos);
+ vars.pushContextPosition(m_varStackContext);
+ }
+ else
+ {
+ // Yuck. Just to shut up the compiler!
+ vars = null;
+ savedStart = 0;
+ }
+
+ try
+ {
+ do
{
- if(NodeFilter.FILTER_ACCEPT == acceptNode(next))
- break;
+ m_lastFetched = next = (null == m_lastFetched)
+ ? m_context.getFirstChild()
+ : m_lastFetched.getNextSibling();
+
+ if (null != next)
+ {
+ if(NodeFilter.FILTER_ACCEPT == acceptNode(next))
+ break;
+ else
+ continue;
+ }
else
- continue;
+ break;
+ }
+ while (next != null);
+
+ if (null != next)
+ {
+ if (null != m_cachedNodes)
+ m_cachedNodes.addElement(m_lastFetched);
+
+ m_next++;
+
+ return next;
}
else
- break;
- }
- while (next != null);
-
- if (null != next)
- {
- if (null != m_cachedNodes)
- m_cachedNodes.addElement(m_lastFetched);
-
- m_next++;
-
- return next;
+ {
+ m_foundLast = true;
+
+ return null;
+ }
}
- else
+ finally
{
- m_foundLast = true;
-
- return null;
+ if (-1 != m_varStackPos)
+ {
+ // These two statements need to be combined into one operation.
+ vars.setSearchStart(savedStart);
+ vars.popContextPosition();
+ }
}
}
+
}
1.6 +78 -47
xml-xalan/java/src/org/apache/xpath/axes/DescendantIterator.java
Index: DescendantIterator.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xpath/axes/DescendantIterator.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- DescendantIterator.java 2000/12/27 22:24:11 1.5
+++ DescendantIterator.java 2000/12/31 11:06:35 1.6
@@ -206,65 +206,96 @@
getSelf = false; // never process the start node at this point.
}
- Node top = m_startContext; // tells us when to stop.
- Node next = null;
+ org.apache.xpath.VariableStack vars;
+ int savedStart;
+ if (-1 != m_varStackPos)
+ {
+ vars = m_execContext.getVarStack();
+
+ // These three statements need to be combined into one operation.
+ savedStart = vars.getSearchStart();
- // non-recursive depth-first traversal.
- while (null != pos)
+ vars.setSearchStart(m_varStackPos);
+ vars.pushContextPosition(m_varStackContext);
+ }
+ else
{
- if(getSelf)
+ // Yuck. Just to shut up the compiler!
+ vars = null;
+ savedStart = 0;
+ }
+
+ try
+ {
+ Node top = m_startContext; // tells us when to stop.
+ Node next = null;
+
+ // non-recursive depth-first traversal.
+ while (null != pos)
{
- if(NodeFilter.FILTER_ACCEPT == acceptNode(pos))
+ if(getSelf)
{
- next = pos;
- break;
+ if(NodeFilter.FILTER_ACCEPT == acceptNode(pos))
+ {
+ next = pos;
+ break;
+ }
}
- }
- else
- getSelf = true;
-
- Node nextNode = pos.getFirstChild();
-
- while (null == nextNode)
- {
- if (top.equals(pos))
- break;
-
- nextNode = pos.getNextSibling();
-
- if (null == nextNode)
+ else
+ getSelf = true;
+
+ Node nextNode = pos.getFirstChild();
+
+ while (null == nextNode)
{
- pos = pos.getParentNode();
-
- if ((null == pos) || (top.equals(pos)))
- {
- nextNode = null;
-
+ if (top.equals(pos))
break;
+
+ nextNode = pos.getNextSibling();
+
+ if (null == nextNode)
+ {
+ pos = pos.getParentNode();
+
+ if ((null == pos) || (top.equals(pos)))
+ {
+ nextNode = null;
+
+ break;
+ }
}
}
+
+ pos = nextNode;
}
-
- pos = nextNode;
- }
-
- m_lastFetched = next;
-
- if (null != next)
- {
- if (null != m_cachedNodes)
- m_cachedNodes.addElement(next);
-
- m_next++;
-
- return next;
+
+ m_lastFetched = next;
+
+ if (null != next)
+ {
+ if (null != m_cachedNodes)
+ m_cachedNodes.addElement(next);
+
+ m_next++;
+
+ return next;
+ }
+ else
+ {
+ m_foundLast = true;
+ m_startContext = null;
+
+ return null;
+ }
}
- else
+ finally
{
- m_foundLast = true;
- m_startContext = null;
-
- return null;
+ if (-1 != m_varStackPos)
+ {
+ // These two statements need to be combined into one operation.
+ vars.setSearchStart(savedStart);
+ vars.popContextPosition();
+ }
}
}