How to use API mode?

18 views
Skip to first unread message

dagost...@gmail.com

unread,
Sep 14, 2017, 5:27:42 PM9/14/17
to python-cffi
I've always been confused about how to go about using the API mode.  I followed the docs and got stuck.

In the issue filed below, I'm trying to show how I created the API wrapper by reading the contents of my header directly into set_source().  The result doesn't work.

with open(os.path.join(_script_path, 'mylib/myheader.h'), 'r') as myfile:
    source
= myfile.read()
    ffibuilder
.set_source("_mylib", source, libraries=['mylib'])

I have also tried to do it like this and it doesn't work either.

ffibuilder.set_source("_mylib", "#include <mylib/myheader.h>", libraries=['mylib'])

What doesn't work is the resulting proxy/wrapper.  When I go to use the wrapper library, the functions are not available/exported.  Clearly, I'm missing something.  Can someone offer me some coding advice?

I've documented this issue more completely here:


TitanSnow

unread,
Sep 16, 2017, 9:12:42 PM9/16/17
to python-cffi
The code passed to ``.set_source()`` is passed to the C compiler, cffi does not process it. You need to call ``.cdef()`` to tell cffi what to export.
Reply all
Reply to author
Forward
0 new messages