How to create a python extension module from a shared library?
Etienne Robillard
tkadm30 at yandex.com
Mon Jan 1 14:21:28 EST 2018
So far I found the SWIG method quite good. But I really think that I
will try patching CFFI to use libclang natively.
Etienne
Le 2017-12-29 à 20:00, Etienne Robillard a écrit :
> 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