This commit adds type checking to the result of dispatch() so
we catch non-None and non-int values. This prevents crashes
when we later try to "& 255" this value.
The Python 3 test failures introduced previously have all gone away.
admin | |
durin42 |
hg-reviewers |
This commit adds type checking to the result of dispatch() so
we catch non-None and non-int values. This prevents crashes
when we later try to "& 255" this value.
The Python 3 test failures introduced previously have all gone away.
Lint Skipped |
Unit Tests Skipped |
IIRC, SystemExit is caught at callcatch and translated to a status code.
+ # The logic here attempts to mimic how CPython's pythonrun.c does things.
+ # Essentially:
+ #
+ # * Exit is controlled by returning a value or raising SystemExit.
+ # * An integer value exits with that exit code.
+ # * A value of `None is interpreted as 0`.
+ # * A non-integer, non-None value results in that value being printed
+ # and an exit code of `1`.
+ # * SystemExit can have a `code` attribute containing the exit value.try:
- status = (dispatch(req) or 0)
+ code = dispatch(req) or 0
except error.StdioError as e: err = e
- status = -1
+ code = -1
+ except SystemExit as err:
+ try:
+ code = err.code
+ err = None
+ except AttributeError: