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 <noreply+kokoro@google.com> Reviewed-by: Jason Lowe-Power <power.jg@gmail.com> Maintainer: Jason Lowe-Power <power.jg@gmail.com>
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user