Commit 1cb51abb authored by Kevin Modzelewski's avatar Kevin Modzelewski

Propagate the SystemExit code as the process exit code

This doesn't handle all the cases that CPython does.
parent 078c5bfa
......@@ -154,8 +154,11 @@ int main(int argc, char** argv) {
main_module = createAndRunModule("__main__", fn);
} catch (ExcInfo e) {
if (e.matches(SystemExit)) {
printf("Warning: ignoring SystemExit code\n");
return 1;
Box* code = e.value->getattr("code");
int rtncode = 1;
if (code && isSubclass(code->cls, pyston::int_cls))
rtncode = static_cast<BoxedInt*>(code)->n;
return rtncode;
} else {
e.printExcAndTraceback();
return 1;
......@@ -221,8 +224,11 @@ int main(int argc, char** argv) {
compileAndRunModule(m, main_module);
} catch (ExcInfo e) {
if (e.matches(SystemExit)) {
printf("Warning: ignoring SystemExit code\n");
return 1;
Box* code = e.value->getattr("code");
int rtncode = 1;
if (code && isSubclass(code->cls, pyston::int_cls))
rtncode = static_cast<BoxedInt*>(code)->n;
return rtncode;
} else {
e.printExcAndTraceback();
}
......
......@@ -55,10 +55,12 @@ Box* sysExcClear() {
}
static Box* sysExit(Box* arg) {
if (arg)
raiseExc(exceptionNew1(SystemExit));
else
raiseExc(exceptionNew2(SystemExit, arg));
assert(arg);
Box* exc = exceptionNew2(SystemExit, arg);
// TODO this should be handled by the SystemExit constructor
exc->giveAttr("code", arg);
raiseExc(exc);
}
BoxedDict* getSysModulesDict() {
......
# no-collect-stats
import sys
sys.exit(0)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment