ResourceWarnings raised on Python 3.11 with pydebug
See https://bugs.debian.org/1024767 for a full description.
This raises a ResourceWarning under Python 3.11 pydebug builds:
from cffi import FFI
ffi = FFI()
p = ffi.new("int *", 123)
ffi.gc(p, lambda x: None)
gc:0: ResourceWarning: Object of type _cffi_backend.__CDataGCP is not untracked before destruction
You can find similar code in testing/cffi0/test_ffi_backend.py
, so just running that and looking for warning is good enough.
To add a test for the warning, we could:
with warnings.catch_warnings(record=True) as w:
ffi.gc(p, lambda x: None)
assert w == []
Python 3.11 added ResourceWarnings if PyObject_GC_UnTrack
isn't called.
In some cases, this warning seems to trigger an assertion failure on big-endian PPC, which is why I looked at it.