Skip to contentSkip to conversation

data_smart: Don't use mutable objects as default args

PATCH In review Richard Purdie 2 participants 2 messages Jan 29, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 data_smart: Don't use mutable objects as default args

These only have one instance created which means your subsequent datastores can contain echos of previous ones. Obviously this is not the behaviour we want/expect. It doesn't affect bitbake too badly as we only have one datastore, it does massively potentially break our selftests though.

Thanks to Tim Amsell for pointing out the now obvious problem!

bitbake/lib/bb/data_smart.py +6 -1
index 68d273b..b1ea33f 100644
@@ -296,9 +296,14 @@ class VariableHistory(object):
                 self.variables[var] = []
 
 class DataSmart(MutableMapping):
-    def __init__(self, special = COWDictBase.copy(), seen = COWDictBase.copy() ):
+    def __init__(self, special = None, seen = None ):
         self.dict = {}
 
+        if special is None:
+            special = COWDictBase.copy()
+        if seen is None:
+            seen = COWDictBase.copy()
+
         self.inchistory = IncludeHistory()
         self.varhistory = VariableHistory(self)
         self._tracking = False
#1 lore raw
Quoted 9 lines · Richard Purdie

These only have one instance created which means your subsequent datastores can contain echos of previous ones. Obviously this is not the behaviour we want/expect. It doesn't affect bitbake too badly as we only have one datastore, it does massively potentially break our selftests though.

Thanks to Tim Amsell for pointing out the now obvious problem!

Wow, obvious indeed, once you look at it. Nicely spotted, Tim.

Signature · 5 lines
Christopher Larson
clarson at kergoth dot com
Founder - BitBake, OpenEmbedded, OpenZaurus
Maintainer - Tslib
Senior Software Engineer, Mentor Graphics