-
Notifications
You must be signed in to change notification settings - Fork 171
Modify the handling of exit code in lpython.cpp #1352
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
Modify the handling of exit code in lpython.cpp #1352
Conversation
src/bin/lpython.cpp
Outdated
@@ -1657,6 +1657,8 @@ int main(int argc, char *argv[]) | |||
if (err != 0) { | |||
if (0 < err && err < 256) { | |||
return err; | |||
} else if (err % 256 == 0) { | |||
return err / 256; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this do exactly? Let's document it in a comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In Linux, the exit values are multiplied by 256
https://stackoverflow.com/a/3736358
https://unix.stackexchange.com/questions/394639/why-do-high-exit-codes-on-linux-shells-256-not-work-as-expected
So, when we do:
quit(10)
>> echo $?
2560
4d128d0
to
a29c095
Compare
src/bin/lpython.cpp
Outdated
return 1; | ||
// https://stackoverflow.com/a/27117435/15913193 | ||
// https://linux.die.net/man/3/system | ||
return WEXITSTATUS(err); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not compile on Windows:
D:\a\lpython\lpython\lpython-0.8.0-14-gb2d00ab00\src\bin\lpython.cpp(1663): error C3861: 'WEXITSTATUS': identifier not found
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
0e99951
to
7a80bd2
Compare
src/bin/lpython.cpp
Outdated
@@ -1658,7 +1658,9 @@ int main(int argc, char *argv[]) | |||
if (0 < err && err < 256) { | |||
return err; | |||
} else { | |||
return 1; | |||
// https://stackoverflow.com/a/27117435/15913193 | |||
// https://linux.die.net/man/3/system |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move these two links into the utils.cpp
file to document get_exit_status
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this looks good, I just left some minor comments.
@@ -12,6 +12,8 @@ std::string get_runtime_library_header_dir(); | |||
bool is_directory(std::string path); | |||
bool path_exists(std::string path); | |||
|
|||
int32_t get_exit_status(int32_t err); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Document here what the function does, you can put the links above here as well.
Thanks for the approval. Let's merge this. |
5c7c4eb
to
a814362
Compare
Closes: #1316