python: Fix Param initialization issue in Python 3
authorAndreas Sandberg <andreas.sandberg@arm.com>
Sat, 26 Jan 2019 08:40:40 +0000 (08:40 +0000)
committerAndreas Sandberg <andreas.sandberg@arm.com>
Wed, 20 Feb 2019 18:27:10 +0000 (18:27 +0000)
When initializing a param with a SimObject NULL pointer, convert()
checks if the 'ptype' attribute has been created and whether the value
is NULL. In that case, it assumes that the object is being
initizalized as a part of SimObject initialization and defers the
conversion. This check is implemented using hasattr() which in turn is
implemented using the __getattr__ implementation that asserts because
all SimObjects haven't been initialized yet.

Implement the check using a lookup in the object's dictionary instead
to prevent the SimObject lookup.

Change-Id: I7367563c4fb71f6d2be541ebdc0be418e9f73d48
Signed-off-by: Andreas Sandberg <andreas.sandberg@arm.com>
Reviewed-on: https://gem5-review.googlesource.com/c/15990
Reviewed-by: Nikos Nikoleris <nikos.nikoleris@arm.com>
src/python/m5/params.py

index b5de6ef6d5d2a3ba77763ec4ab518c1046f92167..5eabce1cd64da4bea47911c19cc929b2f0959049 100644 (file)
@@ -200,7 +200,7 @@ class ParamDesc(object):
         if isinstance(value, proxy.BaseProxy):
             value.set_param_desc(self)
             return value
-        if not hasattr(self, 'ptype') and isNullPointer(value):
+        if 'ptype' not in self.__dict__ and isNullPointer(value):
             # deferred evaluation of SimObject; continue to defer if
             # we're just assigning a null pointer
             return value