sim: Only consider non-NULL elements in SimObjectVector.has_parent.
authorGabe Black <gabeblack@google.com>
Mon, 25 Sep 2017 22:17:30 +0000 (15:17 -0700)
committerGabe Black <gabeblack@google.com>
Tue, 26 Sep 2017 21:16:35 +0000 (21:16 +0000)
NullSimObject doesn't have a has_parent function, and it's not clear what its
return value should be if one were added. The appropriate value seems to
depend on why some other bit of code is checking if there's a parent in the
first place.

In SimObjectVector, the has_parent function is checking whether all of its
elements have a parent. In this particular case, the most reasonable thing
to do seems to be to just skip those elements.

Change-Id: I5f8cad66d1b22c5e37962492fd77cff9371e5af8
Reviewed-on: https://gem5-review.googlesource.com/4841
Reviewed-by: Jason Lowe-Power <jason@lowepower.com>
Maintainer: Gabe Black <gabeblack@google.com>

src/python/m5/params.py

index b49f811d1ff49625d3565ffe393074719bcca984..e5f47e6946b8372a93828e88cbaa87f646482e6d 100644 (file)
@@ -270,7 +270,8 @@ class SimObjectVector(VectorParamValue):
                 v.set_parent(parent, "%s%0*d" % (name, width, i))
 
     def has_parent(self):
-        return reduce(lambda x,y: x and y, [v.has_parent() for v in self])
+        elements = [e for e in self if not isNullPointer(e)]
+        return reduce(lambda x,y: x and y, [v.has_parent() for v in elements])
 
     # return 'cpu0 cpu1' etc. for print_ini()
     def get_name(self):