Skip to content

Commit

Permalink
Merge pull request #35 from beeware/missing-module-error
Browse files Browse the repository at this point in the history
Allow for runpy returning non-integer results.
  • Loading branch information
mhsmith authored Jan 23, 2025
2 parents 559844e + 597bbed commit a7e1407
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions {{ cookiecutter.format }}/bootstrap/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,21 +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 {
// Non-SystemExit; likely an uncaught exception
ret = -6;
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

0 comments on commit a7e1407

Please sign in to comment.