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) { ...@@ -154,8 +154,11 @@ int main(int argc, char** argv) {
main_module = createAndRunModule("__main__", fn); main_module = createAndRunModule("__main__", fn);
} catch (ExcInfo e) { } catch (ExcInfo e) {
if (e.matches(SystemExit)) { if (e.matches(SystemExit)) {
printf("Warning: ignoring SystemExit code\n"); Box* code = e.value->getattr("code");
return 1; int rtncode = 1;
if (code && isSubclass(code->cls, pyston::int_cls))
rtncode = static_cast<BoxedInt*>(code)->n;
return rtncode;
} else { } else {
e.printExcAndTraceback(); e.printExcAndTraceback();
return 1; return 1;
...@@ -221,8 +224,11 @@ int main(int argc, char** argv) { ...@@ -221,8 +224,11 @@ int main(int argc, char** argv) {
compileAndRunModule(m, main_module); compileAndRunModule(m, main_module);
} catch (ExcInfo e) { } catch (ExcInfo e) {
if (e.matches(SystemExit)) { if (e.matches(SystemExit)) {
printf("Warning: ignoring SystemExit code\n"); Box* code = e.value->getattr("code");
return 1; int rtncode = 1;
if (code && isSubclass(code->cls, pyston::int_cls))
rtncode = static_cast<BoxedInt*>(code)->n;
return rtncode;
} else { } else {
e.printExcAndTraceback(); e.printExcAndTraceback();
} }
......
...@@ -55,10 +55,12 @@ Box* sysExcClear() { ...@@ -55,10 +55,12 @@ Box* sysExcClear() {
} }
static Box* sysExit(Box* arg) { static Box* sysExit(Box* arg) {
if (arg) assert(arg);
raiseExc(exceptionNew1(SystemExit)); Box* exc = exceptionNew2(SystemExit, arg);
else // TODO this should be handled by the SystemExit constructor
raiseExc(exceptionNew2(SystemExit, arg)); exc->giveAttr("code", arg);
raiseExc(exc);
} }
BoxedDict* getSysModulesDict() { 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