Antonio Cuni avatar Antonio Cuni committed 305aba0

tentative checkin: implement WeakValueDictionary in rpython, without using the
implementation in rlib.rweakref. This way it works also with ootype

Comments (0)

Files changed (2)


     # extra optimizations with the JIT
     if level == 'jit':
-        if type_system != 'ootype':
-            config.objspace.std.suggest(withsharingdict=True)
+        config.objspace.std.suggest(withsharingdict=True)


 from pypy.objspace.std.dictmultiobject import IteratorImplementation
 from pypy.objspace.std.dictmultiobject import W_DictMultiObject, _is_sane_hash
 from pypy.rlib.jit import purefunction_promote, hint, we_are_jitted, unroll_safe
-from pypy.rlib.rweakref import RWeakValueDictionary
+#from pypy.rlib.rweakref import RWeakValueDictionary
+import weakref
+class WeakValueDictionary:
+    def __init__(self):
+        self._dict = {}
+    def get(self, key):
+        wref = self._dict.get(key, None)
+        if wref is None:
+            return None
+        return wref()
+    def set(self, key, value):
+        if value is None:
+            self._dict.pop(key, None)
+        else:
+            #assert isinstance(value, self._valueclass)
+            self._dict[key] = weakref.ref(value)
         self.keys = keys
         self.length = length
         self.back_struct = back_struct
-        other_structs = RWeakValueDictionary(SharedStructure)
+        #other_structs = RWeakValueDictionary(SharedStructure)
+        other_structs = WeakValueDictionary()
         self.other_structs = other_structs
         self.last_key = last_key
         self._size_estimate = length << NUM_DIGITS
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.