Skip to content

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

Merged
merged 3 commits into from
Dec 31, 2022
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions src/bin/lpython.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1649,7 +1649,7 @@ int main(int argc, char *argv[])
err = system(("js " + outfile +".js").c_str());
} else {
if (compiler_options.platform == LFortran::Platform::Windows) {
err = system(outfile.c_str());
return system(outfile.c_str());
} else {
err = system(("./" + outfile).c_str());
}
Expand All @@ -1658,7 +1658,7 @@ int main(int argc, char *argv[])
if (0 < err && err < 256) {
return err;
} else {
return 1;
return LFortran::get_exit_status(err);
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/lpython/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,12 @@ bool path_exists(std::string path) {
}
}

// Decodes the exit status code of the process (in Unix)
// See `WEXITSTATUS` for more information.
// https://stackoverflow.com/a/27117435/15913193
// https://linux.die.net/man/3/system
int32_t get_exit_status(int32_t err) {
return (((err) >> 8) & 0x000000ff);
}

}
3 changes: 3 additions & 0 deletions src/lpython/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ std::string get_runtime_library_header_dir();
bool is_directory(std::string path);
bool path_exists(std::string path);

// Decodes the exit status code of the process (in Unix)
int32_t get_exit_status(int32_t err);
Copy link
Contributor

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.


} // LFortran

#endif // LFORTRAN_UTILS_H
2 changes: 1 addition & 1 deletion tests/reference/runtime-test_quit_01-e98257c.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
"stdout_hash": null,
"stderr": "runtime-test_quit_01-e98257c.stderr",
"stderr_hash": "9c63ade47f347b4c61353d2af6e780092daa84d287747e19ac89fdf9",
"returncode": 1
"returncode": 10
}