python: remove SimObject children on NULL assignment

Before this commit, on assigning NULL to an 'attr' that is a SimObject,
the corresponding children SimObject was not set to NULL.

This makes some SimObject being initialized in the c++ world
even if they are not needed.

This commit set the children to NULL in that case.

Change-Id: I2030d9d1b80c020fa28e50c0eca4f87b756763d6
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/51647
Reviewed-by: Andreas Sandberg <andreas.sandberg@arm.com>
Reviewed-by: Jason Lowe-Power <power.jg@gmail.com>
Maintainer: Jason Lowe-Power <power.jg@gmail.com>
Tested-by: kokoro <noreply+kokoro@google.com>
This commit is contained in:
Nathanael Premillieu
2021-10-04 16:46:46 +02:00
committed by Tom Rollet
parent 66a056b828
commit 7eb8fb927f

View File

@@ -1443,6 +1443,12 @@ class SimObject(object, metaclass=MetaSimObject):
e.args = (msg, )
raise
self._values[attr] = value
# If we assign NULL to an attr that is a SimObject,
# remove the corresponding children
if attr in self._children and isNullPointer(value):
self.clear_child(attr)
# implicitly parent unparented objects assigned as params
if isSimObjectOrVector(value) and not value.has_parent():
self.add_child(attr, value)