Gabe Black has uploaded this change for review. (
https://gem5-review.googlesource.com/c/public/gem5/+/48382 )
Change subject: python: Minor cleanups in the marshal program source.
......................................................................
python: Minor cleanups in the marshal program source.
Fix some minor style issues, use a "raw" string constant to make the
marshal script more readable, get rid of a redundant \n in the help
text, and make argv const.
Change-Id: I1dc3181a67b50286e3a0b833bb7251b7efd01978
---
M src/python/marshal.cc
1 file changed, 15 insertions(+), 9 deletions(-)
diff --git a/src/python/marshal.cc b/src/python/marshal.cc
index 394b783..7e05c3a 100644
--- a/src/python/marshal.cc
+++ b/src/python/marshal.cc
@@ -42,23 +42,29 @@
namespace py = pybind11;
using namespace pybind11::literals;
+constexpr auto MarshalScript = R"(
+import marshal
+
+with open(source, 'r') as f:
+ src = f.read()
+
+compiled = compile(src, source, 'exec')
+marshalled = marshal.dumps(compiled)
+)";
+
int
-main(int argc, char **argv) {
- py::scoped_interpreter guard{};
+main(int argc, const char **argv)
+{
+ py::scoped_interpreter guard;
if (argc != 2) {
- std::cerr << "Usage: marshal PYSOURCE\n" << std::endl;
+ std::cerr << "Usage: marshal PYSOURCE" << std::endl;
exit(1);
}
auto locals = py::dict("source"_a=argv[1]);
- py::exec(
- "import marshal\n"
- "with open(source, 'r') as f: src = f.read()\n"
- "compiled = compile(src, source, 'exec')\n"
- "marshalled = marshal.dumps(compiled)\n",
- py::globals(), locals);
+ py::exec(MarshalScript, py::globals(), locals);
auto marshalled = locals["marshalled"].cast<std::string>();
std::cout << marshalled;
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/48382
To unsubscribe, or for help writing mail filters, visit
https://gem5-review.googlesource.com/settings
Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: I1dc3181a67b50286e3a0b833bb7251b7efd01978
Gerrit-Change-Number: 48382
Gerrit-PatchSet: 1
Gerrit-Owner: Gabe Black <[email protected]>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s