Author: Armin Rigo <ar...@tunes.org> Branch: Changeset: r2174:471a9d09c7f3 Date: 2015-06-09 11:29 +0200 http://bitbucket.org/cffi/cffi/changeset/471a9d09c7f3/
Log: Issue #206: the rewrite of gc_weakref was not multithread-safe diff --git a/cffi/gc_weakref.py b/cffi/gc_weakref.py --- a/cffi/gc_weakref.py +++ b/cffi/gc_weakref.py @@ -4,25 +4,21 @@ class GcWeakrefs(object): def __init__(self, ffi): self.ffi = ffi - self.data = [] - self.freelist = None + self.data = {} + self.nextindex = 0 def build(self, cdata, destructor): # make a new cdata of the same type as the original one new_cdata = self.ffi.cast(self.ffi._backend.typeof(cdata), cdata) # def remove(key): - assert self.data[index] is key - self.data[index] = self.freelist - self.freelist = index + # careful, this function is not protected by any lock + old_key = self.data.pop(index) + assert old_key is key destructor(cdata) # key = ref(new_cdata, remove) - index = self.freelist - if index is None: - index = len(self.data) - self.data.append(key) - else: - self.freelist = self.data[index] - self.data[index] = key + index = self.nextindex + self.nextindex = index + 1 # we're protected by the lock here + self.data[index] = key return new_cdata _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit