Author: Armin Rigo <ar...@tunes.org>
Branch: 
Changeset: r1408:1e317570f885
Date: 2013-11-10 10:03 +0100
http://bitbucket.org/cffi/cffi/changeset/1e317570f885/

Log:    Due to a CPython bug, we cannot use setdefault() here

diff --git a/cffi/model.py b/cffi/model.py
--- a/cffi/model.py
+++ b/cffi/model.py
@@ -477,10 +477,17 @@
         res = getattr(ffi._backend, funcname)(*args)
     except NotImplementedError as e:
         raise NotImplementedError("%r: %s" % (srctype, e))
-    # note that setdefault() on WeakValueDictionary is not atomic,
-    # which means that we have to use a lock too
+    # note that setdefault() on WeakValueDictionary is not atomic
+    # and contains a rare bug (http://bugs.python.org/issue19542);
+    # we have to use a lock and do it ourselves
+    cache = ffi._backend.__typecache
     with global_lock:
-        return ffi._backend.__typecache.setdefault(key, res)
+        res1 = cache.get(key)
+        if res1 is None:
+            cache[key] = res
+            return res
+        else:
+            return res1
 
 def pointer_cache(ffi, BType):
     return global_cache('?', ffi, 'new_pointer_type', BType)
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to