summaryrefslogtreecommitdiff
path: root/src/python/m5
diff options
context:
space:
mode:
authorSteve Reinhardt <stever@eecs.umich.edu>2006-06-10 21:13:36 -0400
committerSteve Reinhardt <stever@eecs.umich.edu>2006-06-10 21:13:36 -0400
commitbb58e4b85163f263ebf5ea54fee5dba0109eb88c (patch)
tree9267f402eb8f301737751a9b674736507d83dc36 /src/python/m5
parent39f85a1de44789bf0afd1d492167d4fe4601bd82 (diff)
downloadgem5-bb58e4b85163f263ebf5ea54fee5dba0109eb88c.tar.xz
Don't allow SimObject-valued class params to be set
after the class has been instantiated or subclassed. This is one of the main situations that leads to confusing results. configs/test/fs.py: Clean up to avoid modifying BaseCPU after it's been subclassed. --HG-- extra : convert_revision : 335cb87bc3b211ecc8969cfb99ffc28f62f1f877
Diffstat (limited to 'src/python/m5')
-rw-r--r--src/python/m5/config.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/python/m5/config.py b/src/python/m5/config.py
index 9de768d18..3eb99972f 100644
--- a/src/python/m5/config.py
+++ b/src/python/m5/config.py
@@ -211,6 +211,7 @@ class MetaSimObject(type):
# initialize required attributes
cls._params = multidict()
cls._values = multidict()
+ cls._instantiated = False # really instantiated or subclassed
cls._anon_subclass_counter = 0
# We don't support multiple inheritance. If you want to, you
@@ -225,6 +226,7 @@ class MetaSimObject(type):
if isinstance(base, MetaSimObject):
cls._params.parent = base._params
cls._values.parent = base._values
+ base._instantiated = True
# now process the _init_dict items
for key,val in cls._init_dict.items():
@@ -299,6 +301,12 @@ class MetaSimObject(type):
param = cls._params.get(attr, None)
if param:
# It's ok: set attribute by delegating to 'object' class.
+ if (isSimObject(value) or isSimObjSequence(value)) \
+ and cls._instantiated:
+ raise AttributeError, \
+ "Cannot set SimObject parameter '%s' after\n" \
+ " class %s has been instantiated or subclassed" \
+ % (attr, cls.__name__)
try:
cls._values[attr] = param.convert(value)
except Exception, e:
@@ -386,6 +394,8 @@ class SimObject(object):
# instantiated objects.
_memo = {}
+ self.__class__._instantiated = True
+
self._children = {}
# Inherit parameter values from class using multidict so
# individual value settings can be overridden.