python: Avoid re-adding child when cloning SimObject
For SimObject type param, we should avoid duplicated addChild
call if it already belongs to other parent.
In the original implementation, the following code:
```
class A(SimObject):
...
class B(SimObject):
a = Param.A(...)
class Top(RealView):
a = A()
b = B(a=a)
```
will generate incorrect warning:
```
warn: <orphan B>.a already has parent not resetting parent.
Note: a is not a parameter of B
warn: (Previously declared as <orphan Top>.a)
```
The code tries to add `a` as the child of `Top` as well as child of
`Top.b`, which is incorrect.
Change-Id: I8c55c5dd4cc0dd45c68169a2b08450ff053c07aa
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/60789
Reviewed-by: Yu-hsin Wang <yuhsingw@google.com>
Maintainer: Jason Lowe-Power <power.jg@gmail.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Jason Lowe-Power <power.jg@gmail.com>
This commit is contained in:
@@ -697,7 +697,9 @@ class SimObject(object, metaclass=MetaSimObject):
|
||||
# are also param values get cloned properly.
|
||||
self._children = {}
|
||||
for key,val in ancestor._children.items():
|
||||
self.add_child(key, val(_memo=memo_dict))
|
||||
newval = val(_memo=memo_dict)
|
||||
if not newval.has_parent():
|
||||
self.add_child(key, newval)
|
||||
|
||||
# Inherit parameter values from class using multidict so
|
||||
# individual value settings can be overridden but we still
|
||||
|
||||
Reference in New Issue
Block a user