Gabe Black has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/54310 )

Change subject: ext: In sst, set sys.argv up even when not initializing python.
......................................................................

ext: In sst, set sys.argv up even when not initializing python.

pybind11 gives us a simple way to set up sys.argv when initializing the
python interpreter, but we need to set that up even if the python
interpreter is already running. We need to do that manually, which we do
like gem5's main() used to.

Change-Id: If9b79a80e05158226d13f68bf06a2a98a36c2602
---
M ext/sst/gem5.cc
1 file changed, 35 insertions(+), 2 deletions(-)



diff --git a/ext/sst/gem5.cc b/ext/sst/gem5.cc
index 01ea3eb..8eab6281 100644
--- a/ext/sst/gem5.cc
+++ b/ext/sst/gem5.cc
@@ -382,8 +382,27 @@
     // Initialize gem5 special signal handling.
     gem5::initSignals();

-    if (!Py_IsInitialized())
-        py::initialize_interpreter(false, argc, _argv);
+    if (!Py_IsInitialized()) {
+        py::initialize_interpreter(true, argc, _argv);
+    } else {
+ // pybind doesn't provide a way to set sys.argv if not initializing the + // interpreter, so we have to do that manually if it's already running.
+        py::list py_argv;
+        auto sys = py::module::import("sys");
+        if (py::hasattr(sys, "argv")) {
+            // sys.argv already exists, so grab that.
+            py_argv = sys.attr("argv");
+        } else {
+            // sys.argv doesn't exist, so create it.
+            sys.add_object("argv", py_argv);
+        }
+        // Clear out argv just in case it has something in it.
+        py_argv.attr("clear")();
+
+        // Fill it with our argvs.
+        for (int i = 0; i < argc; i++)
+            py_argv.append(_argv[i]);
+    }

     auto importer = py::module_::import("importer");
     importer.attr("install")();

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/54310
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: release-staging-v21-2
Gerrit-Change-Id: If9b79a80e05158226d13f68bf06a2a98a36c2602
Gerrit-Change-Number: 54310
Gerrit-PatchSet: 1
Gerrit-Owner: Gabe Black <gabe.bl...@gmail.com>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- gem5-dev@gem5.org
To unsubscribe send an email to gem5-dev-le...@gem5.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

Reply via email to