You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by zo...@apache.org on 2004/02/11 21:44:44 UTC

cvs commit: xml-xalan/java/src/org/apache/xalan/templates ElemExsltFunction.java

zongaro     2004/02/11 12:44:44

  Modified:    java/src/org/apache/xalan/templates ElemExsltFunction.java
  Log:
  Fix for bugzilla bug report 24302.
  
  Fields in the object representing an EXSLT function element (ElemExsltFunction)
  were being used to store execution state information for references to that
  function.  That caused problems with multi-threaded code that used Transformer
  objects created from the same Templates object - each Transformer shares the
  same instances of ElemExsltFunction.
  
  The fix was to replace the fields ElemExsltFunction.m_result and
  ElemExsltFunction.m_isResultSet with a new ObjectStack field in TransformerImpl
  named m_currentFuncResult.
  
  Also, changed how VariableStack was being updated in the execute method for a
  function reference - this change was modelled on equivalent code in
  ElemCallTemplate.
  
  Reviewed by Morris Kwan (mkwan () ca!ibm!com)
  
  Revision  Changes    Path
  1.8       +27 -84    xml-xalan/java/src/org/apache/xalan/templates/ElemExsltFunction.java
  
  Index: ElemExsltFunction.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/templates/ElemExsltFunction.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- ElemExsltFunction.java	17 Oct 2003 20:59:20 -0000	1.7
  +++ ElemExsltFunction.java	11 Feb 2004 20:44:44 -0000	1.8
  @@ -74,16 +74,6 @@
    */
   public class ElemExsltFunction extends ElemTemplate
   {
  -  
  -  // A flag indicating whether the return result is set
  -  private boolean m_isResultSet = false;
  -  
  -  // The return result
  -  private XObject m_result;
  -  
  -  // The frame size of the current caller
  -  private int m_callerFrameSize = 0;
  -  
     /**
      * Get an integer representation of the element type.
      *
  @@ -111,35 +101,38 @@
     public void execute(TransformerImpl transformer, XObject[] args)
             throws TransformerException
     {
  -    // Reset the result before starting a function execution.
  -    m_isResultSet = false;
  -    m_result = null;
  -    
       XPathContext xctxt = transformer.getXPathContext();
       VariableStack vars = xctxt.getVarStack();
       
       // Increment the frame bottom of the variable stack by the
  -    // frame size of the caller template or EXSLT function.
  -    int oldStackFrame = vars.getStackFrame();
  -    vars.setStackFrame(m_callerFrameSize + oldStackFrame);
  +    // frame size
  +    int thisFrame = vars.getStackFrame();
  +    int nextFrame = vars.link(m_frameSize);
  +
  +    if (m_inArgsSize < args.length) {
  +      throw new TransformerException ("function called with too many args");
  +    }
       
       // Set parameters,
       // have to clear the section of the stack frame that has params.
  -    vars.clearLocalSlots(vars.getStackFrame(), VariableStack.CLEARLIMITATION);
  -    NodeList children = this.getChildNodes();
  -    int numparams =0;
  -    for (int i = 0; i < args.length; i ++)
  -    {
  -      Node child = children.item(i);
  -      if (children.item(i) instanceof ElemParam)
  -      {
  -        numparams++;
  -        ElemParam param = (ElemParam)children.item(i);
  -        vars.setLocalVariable (param.getIndex(), args[i]);
  +    if (m_inArgsSize > 0) {
  +      vars.clearLocalSlots(0, m_inArgsSize);
  +
  +      if (args.length > 0) {
  +        vars.setStackFrame(thisFrame);
  +        NodeList children = this.getChildNodes();
  +        
  +        for (int i = 0; i < args.length; i ++) {
  +          Node child = children.item(i);
  +          if (children.item(i) instanceof ElemParam) {
  +            ElemParam param = (ElemParam)children.item(i);
  +            vars.setLocalVariable(param.getIndex(), args[i], nextFrame);
  +          }
  +        }
  +        
  +        vars.setStackFrame(nextFrame);
         }
       }
  -    if (numparams < args.length)
  -      throw new TransformerException ("function called with too many args");
   
       //  Removed ElemTemplate 'push' and 'pop' of RTFContext, in order to avoid losing the RTF context 
       //  before a value can be returned. ElemExsltFunction operates in the scope of the template that called 
  @@ -149,15 +142,15 @@
       if (TransformerImpl.S_DEBUG)
         transformer.getTraceManager().fireTraceEvent(this);
       
  +    vars.setStackFrame(nextFrame);
       transformer.executeChildTemplates(this, true);
       
       // Reset the stack frame after the function call
  -    vars.setStackFrame(oldStackFrame);
  -    m_callerFrameSize = 0;
  +    vars.unlink(thisFrame);
   
       if (TransformerImpl.S_DEBUG)
         transformer.getTraceManager().fireTraceEndEvent(this);
  -    
  +
       // Following ElemTemplate 'pop' removed -- see above.
       // xctxt.popRTFContext(); 
       
  @@ -190,54 +183,4 @@
         sroot.getExtensionNamespacesManager().registerExtension(extNsSpt);
       }
     }
  -  
  -  /**
  -   * Return the result of this EXSLT function
  -   *
  -   * @return The result of this EXSLT function
  -   */
  -  public XObject getResult()
  -  {
  -    return m_result;
  -  }
  -  
  -  /**
  -   * Set the return result of this EXSLT function
  -   *
  -   * @param result The return result
  -   */
  -  public void setResult(XObject result)
  -  {
  -    m_isResultSet = true;
  -    m_result = result;
  -  }
  -  
  -  /**
  -   * Return true if the result has been set
  -   *
  -   * @return true if the result has been set
  -   */
  -  public boolean isResultSet()
  -  {
  -    return m_isResultSet;
  -  }
  -  
  -  /**
  -   * Clear the return result of this EXSLT function
  -   */
  -  public void clearResult()
  -  {
  -    m_isResultSet = false;
  -    m_result = null;    
  -  }
  -  
  -  /**
  -   * Set the frame size of the current caller for use in the variable stack.
  -   *
  -   * @param callerFrameSize The frame size of the caller
  -   */
  -  public void setCallerFrameSize(int callerFrameSize)
  -  {
  -    m_callerFrameSize = callerFrameSize;
  -  }
  -}
  \ No newline at end of file
  +}
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org