Skip to content

Commit

Permalink
Allow for runpy returning non-integer results. (#65)
Browse files Browse the repository at this point in the history
* Allow for runpy returning non-integer results.

* Rework exit path for SystemExit.

* Ensure no extra output for a SystemExit with error string.

* Handle the case of SystemExit()/SystemExit(None).
  • Loading branch information
freakboy3742 authored Jan 23, 2025
1 parent d5f7911 commit 17802e9
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions {{ cookiecutter.format }}/{{ cookiecutter.class_name }}/main.m
Original file line number Diff line number Diff line change
Expand Up @@ -247,23 +247,36 @@ int main(int argc, char *argv[]) {
exit(-5);
}

traceback_str = NULL;
if (PyErr_GivenExceptionMatches(exc_value, PyExc_SystemExit)) {
systemExit_code = PyObject_GetAttrString(exc_value, "code");
if (systemExit_code == NULL) {
debug_log(@"Could not determine exit code");
traceback_str = @"Could not determine exit code";
ret = -10;
}
else {
} else if (systemExit_code == Py_None) {
// SystemExit with a code of None; documented as a
// return code of 0.
ret = 0;
} else if (PyLong_Check(systemExit_code)) {
// SystemExit with error code
ret = (int) PyLong_AsLong(systemExit_code);
} else {
// Any other SystemExit value - convert to a string, and
// use the string as the traceback, and use the
// documented SystemExit return value of 1.
ret = 1;
traceback_str = [NSString stringWithUTF8String:PyUnicode_AsUTF8(PyObject_Str(systemExit_code))];
}
} else {
// Non-SystemExit; likely an uncaught exception
ret = -6;
info_log(@"---------------------------------------------------------------------------");
info_log(@"Application quit abnormally!");
ret = -6;
traceback_str = format_traceback(exc_type, exc_value, exc_traceback);
}

if (traceback_str != NULL) {
// Display stack trace in the crash dialog.
traceback_str = format_traceback(exc_type, exc_value, exc_traceback);
crash_dialog(traceback_str);
}
}
Expand Down

0 comments on commit 17802e9

Please # to comment.