How to create a python extension module from a shared library?

Etienne Robillard tkadm30 at yandex.com
Fri Dec 29 20:00:54 EST 2017


Hi all,

I would like to extend uWSGI by creating a CPython extension module for 
the libuwsgi.so shared library included in the distribution.

My goal is to use this automatically generated CPython module for 
extending uWSGI.

I have summarized my current approach here:

https://mail.python.org/pipermail/tutor/2017-December/112475.html

So far, I have tried to use CFFI and pycparser to generate the Python 
bindings, however CFFI and pycparser doesn't handle C directives like 
#include and #define.

I also attempted using clang to preprocess the "uwsgi.h" header found in 
the uWSGI distro with pycparser.parse_file() to generate a AST, however 
the generated AST object seems incorrect.

Is there any way to reflect a shared library into a CPython module?

I know that using "nm -D libuwsgi.so" I can get a list of available 
functions for this module. However, I have very little experience with 
ctypes and CFFI.

Do I need to modify CFFI to allow it to parse a C header with libclang?

I'm guessing CFFI/clang or ctypes should allow me to reflect the shared 
library, but I'm not sure about which method is the most appropriate.


What do you think?

Sincerely,

Etienne

-- 
Etienne Robillard
tkadm30 at yandex.com
https://www.isotopesoftware.ca/




More information about the Python-list mailing list