Hi all,
I'm one of the developers of PyCA cryptography. We've been using cffi
for many many years at this point.
Right now we're looking at doing something novel: rather than having
cffi emit a module that's normally imported, instead have it emit an
object file which is linked into another module, and that other module
is responsible for calling `PyInit_{module}` and adding it to the
module hierarchy. By putting both modules in a single .so, we ensure
that they link the same version of external libraries (in our case,
OpenSSL).
You can read about the motivation for this
https://github.com/pyca/cryptography/issues/6634 and see the PoC here
https://github.com/pyca/cryptography/pull/6695
Amazingly, this all seems to work fine, but only on CPython. On PyPy,
we encounter linker errors, because cffi modules on PyPy do not
actually emit `PyInit_{module}` symbols! They have an entirely
different API for module initialization
(
https://foss.heptapod.net/pypy/pypy/-/blob/branch/default/pypy/module/_cffi_backend/cffi1_module.py#L20).
What's the best way to accomplish this? Essentially we need some API
that can find a function ptr inside the same .so as the calling code
and return the freshly created module for it.
I suspect this requires a new API from cffi, but I'd appreciate any thoughts.
Alex
--
All that is necessary for evil to succeed is for good people to do nothing.