SimObject: make get_config_as_dict() tolerate undefined params
authorSteve Reinhardt <steve.reinhardt@amd.com>
Mon, 20 Feb 2012 16:11:14 +0000 (08:11 -0800)
committerSteve Reinhardt <steve.reinhardt@amd.com>
Mon, 20 Feb 2012 16:11:14 +0000 (08:11 -0800)
Without this patch, undefined params cause a cryptic KeyError
in multidict inside get_config_as_dict().  This patch lets
undefined params through get_config_as_dict() so they can
once again generate meaningful error messages later on in
the configuration process.

src/python/m5/SimObject.py

index 78138b083742af657ebc714490ee5045fe62d060..a2de7a0861b423e5ab3722d0562c1558102b3163 100644 (file)
@@ -922,18 +922,19 @@ class SimObject(object):
 
         for param in sorted(self._params.keys()):
             value = self._values.get(param)
-            try:
-                # Use native type for those supported by JSON and 
-                # strings for everything else. skipkeys=True seems
-                # to not work as well as one would hope
-                if type(self._values[param].value) in \
-                        [str, unicode, int, long, float, bool, None]:
-                    d[param] = self._values[param].value
-                else:
-                    d[param] = str(self._values[param])
-
-            except AttributeError:
-                pass
+            if value != None:
+                try:
+                    # Use native type for those supported by JSON and
+                    # strings for everything else. skipkeys=True seems
+                    # to not work as well as one would hope
+                    if type(self._values[param].value) in \
+                            [str, unicode, int, long, float, bool, None]:
+                        d[param] = self._values[param].value
+                    else:
+                        d[param] = str(self._values[param])
+
+                except AttributeError:
+                    pass
 
         for n in sorted(self._children.keys()):
             d[self._children[n].get_name()] =  self._children[n].get_config_as_dict()