Andreas Sandberg has submitted this change and it was merged. ( https://gem5-review.googlesource.com/c/public/gem5/+/15977 )

Change subject: sim: Prepare C++ side for Python 3
......................................................................

sim: Prepare C++ side for Python 3

Python 3 uses wide strings instead of ordinary strings for many
APIs. Add the necessary conversions to comply with the new API.

Change-Id: I6f45c9c532537d50d54b542f34eb8fd8cb375874
Signed-off-by: Andreas Sandberg <[email protected]>
Reviewed-on: https://gem5-review.googlesource.com/c/15977
Reviewed-by: Gabe Black <[email protected]>
Reviewed-by: Nikos Nikoleris <[email protected]>
---
M src/sim/init.cc
M src/sim/main.cc
2 files changed, 26 insertions(+), 1 deletion(-)

Approvals:
  Nikos Nikoleris: Looks good to me, approved
  Gabe Black: Looks good to me, but someone else must approve
  Andreas Sandberg: Looks good to me, approved



diff --git a/src/sim/init.cc b/src/sim/init.cc
index 5061289..66ec408 100644
--- a/src/sim/init.cc
+++ b/src/sim/init.cc
@@ -51,6 +51,7 @@
 #include <iostream>
 #include <list>
 #include <string>
+#include <vector>

 #include "base/cprintf.hh"
 #include "base/logging.hh"
@@ -249,7 +250,7 @@
  * main function.
  */
 int
-m5Main(int argc, char **argv)
+m5Main(int argc, char **_argv)
 {
 #if HAVE_PROTOBUF
     // Verify that the version of the protobuf library that we linked
@@ -258,6 +259,23 @@
     GOOGLE_PROTOBUF_VERIFY_VERSION;
 #endif

+
+#if PY_MAJOR_VERSION >= 3
+    typedef std::unique_ptr<wchar_t[], decltype(&PyMem_RawFree)> WArgUPtr;
+    std::vector<WArgUPtr> v_argv;
+    std::vector<wchar_t *> vp_argv;
+    v_argv.reserve(argc);
+    vp_argv.reserve(argc);
+    for (int i = 0; i < argc; i++) {
+ v_argv.emplace_back(Py_DecodeLocale(_argv[i], NULL), &PyMem_RawFree);
+        vp_argv.emplace_back(v_argv.back().get());
+    }
+
+    wchar_t **argv = vp_argv.data();
+#else
+    char **argv = _argv;
+#endif
+
     PySys_SetArgv(argc, argv);

     // We have to set things up in the special __main__ module
diff --git a/src/sim/main.cc b/src/sim/main.cc
index 48b1592..a77c5f5 100644
--- a/src/sim/main.cc
+++ b/src/sim/main.cc
@@ -45,7 +45,14 @@
     // Initialize m5 special signal handling.
     initSignals();

+#if PY_MAJOR_VERSION >= 3
+    std::unique_ptr<wchar_t[], decltype(&PyMem_RawFree)> program(
+        Py_DecodeLocale(argv[0], NULL),
+        &PyMem_RawFree);
+    Py_SetProgramName(program.get());
+#else
     Py_SetProgramName(argv[0]);
+#endif

     // initialize embedded Python interpreter
     Py_Initialize();

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

Gerrit-Project: public/gem5
Gerrit-Branch: master
Gerrit-Change-Id: I6f45c9c532537d50d54b542f34eb8fd8cb375874
Gerrit-Change-Number: 15977
Gerrit-PatchSet: 3
Gerrit-Owner: Andreas Sandberg <[email protected]>
Gerrit-Reviewer: Andreas Sandberg <[email protected]>
Gerrit-Reviewer: Gabe Black <[email protected]>
Gerrit-Reviewer: Nikos Nikoleris <[email protected]>
Gerrit-MessageType: merged
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to