python-cffi / cffi

A Foreign Function Interface package for calling C libraries from Python.
https://cffi.readthedocs.io/en/latest/
Other
133 stars 42 forks source link

Make ffi_init_once thread-safe in free threaded build #143

Open colesbury opened 1 week ago

colesbury commented 1 week ago

Lock the FFI object when initializing the init_once_cache dictionary and use PyDict_GetItemRef in places where the dictionary's value may be concurrently modified.

See #126

colesbury commented 1 week ago

Hi @nitzmahone - I'm still working through the CFFI free-threading issues, but I figured it'd be helpful to get some feedback on a small change.

On that note:

To find thread-safety issues, in addition to reading through the code, I'm using https://github.com/Quansight-Labs/pytest-run-parallel, which I've found to be very effective.