Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for runpy returning non-integer results. #57

Merged
merged 5 commits into from
Jan 23, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions {{ cookiecutter.format }}/src/bootstrap/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,20 +236,29 @@ int main(int argc, char *argv[]) {
if (systemExit_code == NULL) {
debug_log("Could not determine exit code\n");
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 {
// SystemExit with a string for an error code.
ret = 1;
}
} else {
ret = -6;
// Non-SystemExit; likely an uncaught exception
printf("---------------------------------------------------------------------------\n");
printf("Application quit abnormally!\n");
ret = -6;
}

// Restore the error state of the interpreter.
if (ret != 0) {
// Restore the error state of the interpreter, and print exception
// to stderr. In the case of a SystemExit, this will exit with a
// status of 1.
PyErr_Restore(exc_type, exc_value, exc_traceback);

// Print exception to stderr.
// In case of SystemExit, this will call exit()
PyErr_Print();
}
}
Expand Down
Loading