Author: Armin Rigo <[email protected]>
Branch:
Changeset: r1407:d830b07122a6
Date: 2013-11-10 09:18 +0100
http://bitbucket.org/cffi/cffi/changeset/d830b07122a6/
Log: Bah, setdefault() is not atomic on WeakValueDictionary.
diff --git a/cffi/model.py b/cffi/model.py
--- a/cffi/model.py
+++ b/cffi/model.py
@@ -1,4 +1,6 @@
import weakref
+from .lock import allocate_lock
+
class BaseTypeByIdentity(object):
is_array_type = False
@@ -452,8 +454,10 @@
tp = StructType(structname, None, None, None)
return NamedPointerType(tp, name)
+
+global_lock = allocate_lock()
+
def global_cache(srctype, ffi, funcname, *args, **kwds):
- # NB. multithread: careful code that should work without an explicit lock
key = kwds.pop('key', (funcname, args))
assert not kwds
try:
@@ -473,7 +477,10 @@
res = getattr(ffi._backend, funcname)(*args)
except NotImplementedError as e:
raise NotImplementedError("%r: %s" % (srctype, e))
- return ffi._backend.__typecache.setdefault(key, res)
+ # note that setdefault() on WeakValueDictionary is not atomic,
+ # which means that we have to use a lock too
+ with global_lock:
+ return ffi._backend.__typecache.setdefault(key, res)
def pointer_cache(ffi, BType):
return global_cache('?', ffi, 'new_pointer_type', BType)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit