def test_ffi_type_not_immortal():
import weakref, gc
ffi = _cffi1_backend.FFI()
t1 = ffi.typeof("int **")
t2 = ffi.typeof("int *")
w1 = weakref.ref(t1)
w2 = weakref.ref(t2)
del t1, ffi
gc.collect()
assert w1() is None
assert w2() is t2
ffi = _cffi1_backend.FFI()
assert ffi.typeof(ffi.new("int **")[0]) is t2
#
ffi = _cffi1_backend.FFI()
t1 = ffi.typeof("int ***")
t2 = ffi.typeof("int **")
w1 = weakref.ref(t1)
w2 = weakref.ref(t2)
del t2, ffi
gc.collect()
assert w1() is t1
assert w2() is not None # kept alive by t1
ffi = _cffi1_backend.FFI()
assert ffi.typeof("int * *") is t1.item
评论列表
文章目录