Skip to content

Commit e99c3e4

Browse files
thewtexfloryst
andcommitted
fix(emscripten): save and restore the stack with a run
Addresses issues with multiple invocations. #760 Co-authored-by: Forrest Li <forrest.li@kitware.com>
1 parent 24f8230 commit e99c3e4

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

src/pipeline/PipelineEmscriptenModule.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ interface PipelineEmscriptenModule extends EmscriptenModule {
1212
writeArrayToMemory: typeof writeArrayToMemory;
1313
writeAsciiToMemory: typeof writeAsciiToMemory;
1414
AsciiToString: (ptr: number) => string;
15+
stackSave: () => number;
16+
stackRestore: (ptr: number) => void;
1517

1618
resetModuleStdout: () => void;
1719
resetModuleStderr: () => void;

src/pipeline/internal/runPipelineEmscripten.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ function runPipelineEmscripten (pipelineModule: PipelineEmscriptenModule, args:
291291

292292
pipelineModule.resetModuleStdout()
293293
pipelineModule.resetModuleStderr()
294+
const stackPtr = pipelineModule.stackSave()
294295
let returnValue = 0
295296
try {
296297
returnValue = pipelineModule.callMain(args.slice())
@@ -308,6 +309,8 @@ function runPipelineEmscripten (pipelineModule: PipelineEmscriptenModule, args:
308309
}
309310
}
310311
throw exception
312+
} finally {
313+
pipelineModule.stackRestore(stackPtr)
311314
}
312315
const stdout = pipelineModule.getModuleStdout()
313316
const stderr = pipelineModule.getModuleStderr()

0 commit comments

Comments
 (0)