Debian Codegraph @

lib_pypy/cffi/gc_weakref.py

raw symbols SCIP
1 from weakref import ref
2
3
4 class GcWeakrefs(object):
5 def __init__(self, ffi):
6 self.ffi = ffi
7 self.data = {}
8
9 def build(self, cdata, destructor):
10 # make a new cdata of the same type as the original one
11 new_cdata = self.ffi.cast(self.ffi._backend.typeof(cdata), cdata)
12 #
13 def remove(key):
14 # careful, this function is not protected by any lock
15 old_key = self.data.pop(index)
16 assert old_key is key
17 destructor(cdata)
18 #
19 key = ref(new_cdata, remove)
20 index = object()
21 self.data[index] = key
22 return new_cdata