[pypy-dev] using libffi from rpython - a better way?

Amaury Forgeot d'Arc amauryfa at gmail.com
Thu Jun 17 13:35:03 CEST 2010


2010/6/17 Ryan Kelly <ryan at rfk.id.au>:
>              #  Find the python DLL and extract needed functions
>              py = CDLL(libpython)
>              Py_Initialize = py.getpointer("Py_Initialize",[],ffi_type_void)
>              Py_Finalize = py.getpointer("Py_Finalize",[],ffi_type_void)
>              PyRun_SimpleString = py.getpointer("PyRun_SimpleString",[ffi_type_pointer],ffi_type_sint)
>  As you can imagine, the real application has a lot more of these
> boilerplate declarations.  Any suggestions on how to do this in
> less/cleaner code?

For the cpyext module, we used the documentation to generate stubs for
every function of the API.
It's easy to write a sphinx extension that processes every "cfunction"
directive in the documentation.

You could start with pypy/module/cpyext/stubgen.py and modify it for
your needs, which are
obviously different.

It's poorly documented, but the comment for r72933 says:
The stub generator works as follows:
 1. Go to Doc (in your CPython checkout).
 2. Run make text and stop it after it downloaded the prerequisites.
 3. Apply the patch Doc_stubgen_enable.patch in your CPython checkout
 4. Run make text again with PyPy in your Python path.
 5. Voila, the stubs.py file will be updated.

Amaury Forgeot d'Arc

More information about the Pypy-dev mailing list