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

Change subject: scons,python,sim: Eliminate a redundant member of EmbeddedPython.
......................................................................

scons,python,sim: Eliminate a redundant member of EmbeddedPython.

The filename member was just a less specific version of the abspath
member, and can be replaced by it to simplify things a little.

Change-Id: I61b312f2c356045e03462159e3232ac717954669
---
M src/SConscript
M src/python/importer.py
M src/sim/init.cc
M src/sim/init.hh
4 files changed, 12 insertions(+), 18 deletions(-)



diff --git a/src/SConscript b/src/SConscript
index 34ba841..589a0e4 100644
--- a/src/SConscript
+++ b/src/SConscript
@@ -361,16 +361,14 @@
         assert ext == '.py'

         if package:
-            path = package.split('.')
+            modpath = package.split('.')
         else:
-            path = []
+            modpath = []

-        modpath = path[:]
         if modname != '__init__':
             modpath += [ modname ]
         modpath = '.'.join(modpath)

-        arcpath = path + [ basename ]
         abspath = self.snode.abspath
         if not os.path.exists(abspath):
             abspath = self.tnode.abspath
@@ -378,7 +376,6 @@
         self.package = package
         self.modname = modname
         self.modpath = modpath
-        self.arcname = os.path.join(*arcpath)
         self.abspath = abspath
         self.cpp = File(self.filename + '.cc')

@@ -1263,7 +1260,6 @@
     bytesToCppArray(code, 'embedded_module_data', data)
     code('''
 EmbeddedPython embedded_module_info(
-    ${{c_str(pysource.arcname)}},
     ${{c_str(pysource.abspath)}},
     ${{c_str(pysource.modpath)}},
     embedded_module_data,
diff --git a/src/python/importer.py b/src/python/importer.py
index 4e5e907..76c0fa5 100644
--- a/src/python/importer.py
+++ b/src/python/importer.py
@@ -44,23 +44,23 @@
         override_var = os.environ.get('M5_OVERRIDE_PY_SOURCE', 'false')
         self.override = (override_var.lower() in ('true', 'yes'))

-    def add_module(self, filename, abspath, modpath, code):
+    def add_module(self, abspath, modpath, code):
         if modpath in self.modules:
             raise AttributeError("%s already found in importer" % modpath)

-        self.modules[modpath] = (filename, abspath, code)
+        self.modules[modpath] = (abspath, code)

     def find_spec(self, fullname, path, target=None):
         if fullname not in self.modules:
             return None

-        srcfile, abspath, code = self.modules[fullname]
+        abspath, code = self.modules[fullname]

         if self.override and os.path.exists(abspath):
             src = open(abspath, 'r').read()
             code = compile(src, abspath, 'exec')

-        is_package = (os.path.basename(srcfile) == '__init__.py')
+        is_package = (os.path.basename(abspath) == '__init__.py')
         spec = importlib.util.spec_from_loader(
                 name=fullname, loader=ByteCodeLoader(code),
                 is_package=is_package)
diff --git a/src/sim/init.cc b/src/sim/init.cc
index f9ab8b2..238bf54 100644
--- a/src/sim/init.cc
+++ b/src/sim/init.cc
@@ -75,10 +75,9 @@

 EmbeddedPython *EmbeddedPython::importer = NULL;
 PyObject *EmbeddedPython::importerModule = NULL;
-EmbeddedPython::EmbeddedPython(const char *filename, const char *abspath,
-    const char *modpath, const unsigned char *code, int zlen, int len)
-    : filename(filename), abspath(abspath), modpath(modpath), code(code),
-      zlen(zlen), len(len)
+EmbeddedPython::EmbeddedPython(const char *abspath, const char *modpath,
+        const unsigned char *code, int zlen, int len)
+    : abspath(abspath), modpath(modpath), code(code), zlen(zlen), len(len)
 {
     // if we've added the importer keep track of it because we need it
     // to bootstrap.
@@ -117,7 +116,7 @@
 {
     PyObject *code = getCode();
PyObject *result = PyObject_CallMethod(importerModule, PyCC("add_module"),
-        PyCC("sssO"), filename, abspath, modpath, code);
+        PyCC("ssO"), abspath, modpath, code);
     if (!result) {
         PyErr_Print();
         return false;
diff --git a/src/sim/init.hh b/src/sim/init.hh
index a20d3b6..c2f4cf2 100644
--- a/src/sim/init.hh
+++ b/src/sim/init.hh
@@ -62,15 +62,14 @@
  */
 struct EmbeddedPython
 {
-    const char *filename;
     const char *abspath;
     const char *modpath;
     const uint8_t *code;
     int zlen;
     int len;

-    EmbeddedPython(const char *filename, const char *abspath,
- const char *modpath, const uint8_t *code, int zlen, int len);
+    EmbeddedPython(const char *abspath, const char *modpath,
+            const uint8_t *code, int zlen, int len);

     PyObject *getCode() const;
     bool addModule() const;

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/48365
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: I61b312f2c356045e03462159e3232ac717954669
Gerrit-Change-Number: 48365
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

Reply via email to