changeset 9caba3b84a9b in /z/repo/gem5
details: http://repo.gem5.org/gem5?cmd=changeset;node=9caba3b84a9b
description:
        config: Fix handling of parents for simobject vectors

        SimObjectVector objects did not provide the same interface to
        the _parent attribute through get_parent() like a normal
        SimObject.  It also handled assigning a _parent incorrectly
        if objects in a SimObjectVector were changed post-creation,
        leading to errors later when the simulator tried to execute.
        This patch fixes these two omissions.

diffstat:

 src/python/m5/SimObject.py |   5 +++++
 src/python/m5/params.py    |  13 +++++++++++++
 2 files changed, 18 insertions(+), 0 deletions(-)

diffs (38 lines):

diff -r 7437cc334df1 -r 9caba3b84a9b src/python/m5/SimObject.py
--- a/src/python/m5/SimObject.py        Thu Oct 31 13:41:13 2013 -0500
+++ b/src/python/m5/SimObject.py        Thu Oct 31 13:41:13 2013 -0500
@@ -784,6 +784,11 @@
         self._parent = parent
         self._name = name
 
+    # Return parent object of this SimObject, not implemented by 
SimObjectVector
+    # because the elements in a SimObjectVector may not share the same parent
+    def get_parent(self):
+        return self._parent
+
     # Also implemented by SimObjectVector
     def get_name(self):
         return self._name
diff -r 7437cc334df1 -r 9caba3b84a9b src/python/m5/params.py
--- a/src/python/m5/params.py   Thu Oct 31 13:41:13 2013 -0500
+++ b/src/python/m5/params.py   Thu Oct 31 13:41:13 2013 -0500
@@ -247,6 +247,19 @@
             a.append(v.get_config_as_dict())
         return a
 
+    # If we are replacing an item in the vector, make sure to set the
+    # parent reference of the new SimObject to be the same as the parent
+    # of the SimObject being replaced. Useful to have if we created
+    # a SimObjectVector of temporary objects that will be modified later in
+    # configuration scripts.
+    def __setitem__(self, key, value):
+        val = self[key]
+        if value.has_parent():
+            warn("SimObject %s already has a parent" % value.get_name() +\
+                 " that is being overwritten by a SimObjectVector")
+        value.set_parent(val.get_parent(), val._name)
+        super(SimObjectVector, self).__setitem__(key, value)
+
 class VectorParamDesc(ParamDesc):
     # Convert assigned value to appropriate type.  If the RHS is not a
     # list or tuple, it generates a single-element list.
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to