Skip to content

Commit

Permalink
fix(emscripten): save and restore the stack with a run
Browse files Browse the repository at this point in the history
Addresses issues with multiple invocations. #760

Co-authored-by: Forrest Li <forrest.li@kitware.com>
  • Loading branch information
thewtex and floryst committed Oct 11, 2023
1 parent 24f8230 commit e99c3e4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/pipeline/PipelineEmscriptenModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ interface PipelineEmscriptenModule extends EmscriptenModule {
writeArrayToMemory: typeof writeArrayToMemory;
writeAsciiToMemory: typeof writeAsciiToMemory;
AsciiToString: (ptr: number) => string;
stackSave: () => number;
stackRestore: (ptr: number) => void;

resetModuleStdout: () => void;
resetModuleStderr: () => void;
Expand Down
3 changes: 3 additions & 0 deletions src/pipeline/internal/runPipelineEmscripten.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ function runPipelineEmscripten (pipelineModule: PipelineEmscriptenModule, args:

pipelineModule.resetModuleStdout()
pipelineModule.resetModuleStderr()
const stackPtr = pipelineModule.stackSave()
let returnValue = 0
try {
returnValue = pipelineModule.callMain(args.slice())
Expand All @@ -308,6 +309,8 @@ function runPipelineEmscripten (pipelineModule: PipelineEmscriptenModule, args:
}
}
throw exception
} finally {
pipelineModule.stackRestore(stackPtr)
}
const stdout = pipelineModule.getModuleStdout()
const stderr = pipelineModule.getModuleStderr()
Expand Down

0 comments on commit e99c3e4

Please sign in to comment.