Skip to content
Permalink
Browse files

Fix issue #126 by making sure there's a finally clause to free the ru…

…ntime stack frame; also make sure we call finish
  • Loading branch information
ndw committed Oct 23, 2013
1 parent 6025947 commit 2df89cc4ebe9166019b56ab77c013452c68188a6
@@ -378,35 +378,37 @@ public void run() throws SaxonApiException {
data.openFrame(this);

runtime.start(this);
xstep.run();
runtime.finish(this);

// FIXME: Is it sufficient to only do this for atomic steps?
String cache = getInheritedExtensionAttribute(XProcConstants.cx_cache);
if ("true".equals(cache)) {
for (String port : outputs.keySet()) {
WritablePipe wpipe = outputs.get(port);
// FIXME: Hack. There should be a better way...
if (wpipe instanceof Pipe) {
ReadablePipe rpipe = new Pipe(runtime, ((Pipe) wpipe).documents());
rpipe.canReadSequence(true);
rpipe.setReader(step);
while (rpipe.moreDocuments()) {
XdmNode doc = rpipe.read();
runtime.cache(doc, step.getNode().getBaseURI());
try {
xstep.run();

// FIXME: Is it sufficient to only do this for atomic steps?
String cache = getInheritedExtensionAttribute(XProcConstants.cx_cache);
if ("true".equals(cache)) {
for (String port : outputs.keySet()) {
WritablePipe wpipe = outputs.get(port);
// FIXME: Hack. There should be a better way...
if (wpipe instanceof Pipe) {
ReadablePipe rpipe = new Pipe(runtime, ((Pipe) wpipe).documents());
rpipe.canReadSequence(true);
rpipe.setReader(step);
while (rpipe.moreDocuments()) {
XdmNode doc = rpipe.read();
runtime.cache(doc, step.getNode().getBaseURI());
}
}
}
} else if (!"false".equals(cache) && cache != null) {
throw XProcException.dynamicError(19);
}
} else if (!"false".equals(cache) && cache != null) {
throw XProcException.dynamicError(19);
}

for (String port : outputs.keySet()) {
WritablePipe wpipe = outputs.get(port);
wpipe.close(); // Indicate we're done
for (String port : outputs.keySet()) {
WritablePipe wpipe = outputs.get(port);
wpipe.close(); // Indicate we're done
}
} finally {
runtime.finish(this);
data.closeFrame();
}

data.closeFrame();
}

public void reportError(XdmNode doc) {
@@ -130,10 +130,11 @@ public void run() throws SaxonApiException {
}
}

xstep.run();

runtime.finish(this);

data.closeFrame();
try {
xstep.run();
} finally {
runtime.finish(this);
data.closeFrame();
}
}
}
@@ -254,25 +254,28 @@ public void run() throws SaxonApiException {
}

runtime.start(this);
for (XStep step : subpipeline) {
step.run();
}
runtime.finish(this);

for (String port : inputs.keySet()) {
if (port.startsWith("|")) {
String wport = port.substring(1);
WritablePipe pipe = outputs.get(wport);
for (ReadablePipe reader : inputs.get(port)) {
while (reader.moreDocuments()) {
XdmNode doc = reader.read();
pipe.write(doc);
finest(step.getNode(), "Compound output copy from " + reader + " to " + pipe);
try {
for (XStep step : subpipeline) {
step.run();
}

for (String port : inputs.keySet()) {
if (port.startsWith("|")) {
String wport = port.substring(1);
WritablePipe pipe = outputs.get(wport);
for (ReadablePipe reader : inputs.get(port)) {
while (reader.moreDocuments()) {
XdmNode doc = reader.read();
pipe.write(doc);
finest(step.getNode(), "Compound output copy from " + reader + " to " + pipe);
}
}
}
}
} finally {
runtime.finish(this);
data.closeFrame();
}

data.closeFrame();
}
}
@@ -86,78 +86,79 @@ public void run() throws SaxonApiException {

runtime.start(this);

for (XdmNode is_doc : nodes) {
// Setup the current port before we compute variables!
current.resetWriter();
current.write(is_doc);
finest(step.getNode(), "Copy to current");

sequencePosition++;
runtime.getXProcData().setIterationPosition(sequencePosition);

for (Variable var : step.getVariables()) {
RuntimeValue value = computeValue(var);
inScopeOptions.put(var.getName(), value);
}

// N.B. At this time, there are no compound steps that accept parameters or options,
// so the order in which we calculate them doesn't matter. That will change if/when
// there are such compound steps.

// Calculate all the variables
inScopeOptions = parent.getInScopeOptions();
for (Variable var : step.getVariables()) {
RuntimeValue value = computeValue(var);
inScopeOptions.put(var.getName(), value);
}
try {
for (XdmNode is_doc : nodes) {
// Setup the current port before we compute variables!
current.resetWriter();
current.write(is_doc);
finest(step.getNode(), "Copy to current");

sequencePosition++;
runtime.getXProcData().setIterationPosition(sequencePosition);

for (Variable var : step.getVariables()) {
RuntimeValue value = computeValue(var);
inScopeOptions.put(var.getName(), value);
}

for (XStep step : subpipeline) {
step.run();
}
// N.B. At this time, there are no compound steps that accept parameters or options,
// so the order in which we calculate them doesn't matter. That will change if/when
// there are such compound steps.

for (String port : inputs.keySet()) {
if (port.startsWith("|")) {
String wport = port.substring(1);
// Calculate all the variables
inScopeOptions = parent.getInScopeOptions();
for (Variable var : step.getVariables()) {
RuntimeValue value = computeValue(var);
inScopeOptions.put(var.getName(), value);
}

boolean seqOk = step.getOutput(wport).getSequence();
int docsCopied = 0;
for (XStep step : subpipeline) {
step.run();
}

WritablePipe pipe = outputs.get(wport);
// The output of a for-each is a sequence, irrespective of what the output says
pipe.canWriteSequence(true);

for (ReadablePipe reader : inputs.get(port)) {
reader.canReadSequence(true); // Hack again!
while (reader.moreDocuments()) {
XdmNode doc = reader.read();
pipe.write(doc);
docsCopied++;
finest(step.getNode(), "Output copy from " + reader + " to " + pipe);
for (String port : inputs.keySet()) {
if (port.startsWith("|")) {
String wport = port.substring(1);

boolean seqOk = step.getOutput(wport).getSequence();
int docsCopied = 0;

WritablePipe pipe = outputs.get(wport);
// The output of a for-each is a sequence, irrespective of what the output says
pipe.canWriteSequence(true);

for (ReadablePipe reader : inputs.get(port)) {
reader.canReadSequence(true); // Hack again!
while (reader.moreDocuments()) {
XdmNode doc = reader.read();
pipe.write(doc);
docsCopied++;
finest(step.getNode(), "Output copy from " + reader + " to " + pipe);
}
reader.resetReader();
}
reader.resetReader();
}

if (docsCopied != 1 && !seqOk) {
throw XProcException.dynamicError(6);
if (docsCopied != 1 && !seqOk) {
throw XProcException.dynamicError(6);
}
}
}
}

for (XStep step : subpipeline) {
step.reset();
for (XStep step : subpipeline) {
step.reset();
}
}
}

runtime.finish(this);

for (String port : inputs.keySet()) {
if (port.startsWith("|")) {
String wport = port.substring(1);
WritablePipe pipe = outputs.get(wport);
pipe.close(); // Indicate that we're done
for (String port : inputs.keySet()) {
if (port.startsWith("|")) {
String wport = port.substring(1);
WritablePipe pipe = outputs.get(wport);
pipe.close(); // Indicate that we're done
}
}
} finally {
runtime.finish(this);
data.closeFrame();
}

data.closeFrame();
}
}
@@ -139,10 +139,10 @@ public void run() throws SaxonApiException {
} catch (SaxonApiException ex) {
runtime.error(ex);
throw ex;
} finally {
runtime.finish(this);
data.closeFrame();
}
runtime.finish(this);

data.closeFrame();
}

private void setupParameters() {

0 comments on commit 2df89cc

Please sign in to comment.
You can’t perform that action at this time.