From: Marc P. <ma...@an...> - 2003-04-15 23:02:19
|
Hi, There's some kind of weird problem going on with #macro and recursion I think. I'm trying to traverse a tiny XML node tree and getting stack overflows. Trouble is I can't reproduce this with a simpler template. I'm 99% sure it is a bug because: If I leave a call to the macro in the template, it spews, even if variables required to execute the macro are not defined, implying that the overflow is occurring during the macro build process, which rules out my XML and templat code I think because it shouldn't be possible for me to cause the overflow given that the values I am passing to the macro (XML nodes) do not exist yet (i.e. you remove the #set required to get the node tree). Here's the template - the macro that "causes" the problem is likely the top one, and the code that calls it is at the end - inline comments there to explain what I mean. FWIW you will also see that I have some "redundant" #else clauses in my #if statements. Those are required if the template is to get as far as the overflow. Remove them and it pukes expecting more "#end"s. This is bizarre, as i can't isolate this in small #macro templates either. Maybe I'm being a dunce, but something seems very screwy here. Simple templates demonstrate that macro recursion per se is not broken, but it is hard to test without a big #bean template (and enabling #bean) which I haven't yet had time to do. Only just worked out that this isn't my problem, AFAICS. #include "includes/header.wmt" #set $headingDepth = 1 #macro renderChildren( $baseNode) #foreach $node in $baseNode.Children Node: $node.Name #if ($node.IsElement) #if ($node.Name == "title") #renderTitle($node) #elseif ($node.Name == "para") #renderPara($node) #elseif ($node.Name == "code") #renderCode($node) #elseif ($node.Name == "bulletlist") #renderBulletList($node) #elseif ($node.Name == "listitem") #renderListItem($node) #elseif ($node.Name == "directive") #renderDirective($node) #else #end #elseif ($node.IsText || $node.IsCDATA) $node.Value #else #end #end #end #macro renderTitle($node) <h$headingDepth class="wmdoc_directive"> #renderChildren($node) </h$headingDepth> #end #macro renderPara($node) <p class="wmdoc_directive"> #set $headingDepth = $headingDepth + 1 #renderChildren($node) #set $headingDepth = $headingDepth - 1 </p> #end #macro renderCode($node) <code class="wmdoc_directive"> #renderChildren($node) </code> #end #macro renderBulletList($node) <ul class="wmdoc_directive"> #renderChildren($node) </ul> #end #macro renderListItem($node) <item class="wmdoc_directive"> #renderChildren($node) </item> #end #macro renderDirective($node) <span class="wmdoc_directive"> #renderChildren($node) </span> #end <h1>WebMacro Ignition Documentation</h1> #set $docName = $Form.DocName #set $xmlDocURL = "$(Ignition.ServerURL)$(Ignition.DocumentBaseURI) /docs/data/$(docName)" #set $xmlDoc = $xml.open($xmlDocURL) #set $xmlDoc.Complex = true #comment !!!!!!!!!! Look this is commented out, so the node var DOES NOT EXIST BUT... the template still gets a stack overflow if the #renderChildren call is left in #set $wmdocNode = $xmlDoc.getFirstChild("wmdoc") #end #comment The next line calls the recursive macro. Remove/comment it and the page "works" but leave it in, even with the previous #set commented out, and you get the overflow. #end #renderChildren( $wmdocNode) #include "includes/footer.wmt" -- Marc Palmer (Wangjammer5) http://www.wangjammers.org Java Consultants |