From 1253c15ebed5936f017b8be76390129e496fee0a Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Sat, 17 Jul 2021 05:11:45 -0700 Subject: [PATCH] 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 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/48365 Tested-by: kokoro Reviewed-by: Jason Lowe-Power Maintainer: Jason Lowe-Power --- src/SConscript | 8 ++------ src/python/importer.py | 8 ++++---- src/sim/init.cc | 9 ++++----- src/sim/init.hh | 5 ++--- 4 files changed, 12 insertions(+), 18 deletions(-) diff --git a/src/SConscript b/src/SConscript index 2c941ca618..31c82c191d 100644 --- a/src/SConscript +++ b/src/SConscript @@ -363,16 +363,14 @@ class PySource(SourceFile): 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 @@ -380,7 +378,6 @@ class PySource(SourceFile): self.package = package self.modname = modname self.modpath = modpath - self.arcname = os.path.join(*arcpath) self.abspath = abspath self.cpp = File(self.filename + '.cc') @@ -1235,7 +1232,6 @@ namespace # into a global list. 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 ccedf48c27..7fa1641ec6 100644 --- a/src/python/importer.py +++ b/src/python/importer.py @@ -46,23 +46,23 @@ class CodeImporter(object): 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 afecd73255..0c69958f43 100644 --- a/src/sim/init.cc +++ b/src/sim/init.cc @@ -75,10 +75,9 @@ namespace gem5 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 @@ EmbeddedPython::addModule() const { 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 a20d3b65b7..c2f4cf2f58 100644 --- a/src/sim/init.hh +++ b/src/sim/init.hh @@ -62,15 +62,14 @@ namespace gem5 */ 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;