use of function pointers / c processor

73 views
Skip to first unread message

erik.j...@conceptive.be

unread,
Jun 8, 2015, 4:18:38 AM6/8/15
to pytho...@googlegroups.com
Hi,

I've tried building a cffi wrapper for pkcs11 modules, and was
amazed by how well it all works, thank you very much for
this excellen module.

code is at :

https://bitbucket.org/conceptive/python-pkcs11/

I have 2 questions though :

1. When a C function returns a struct containing function pointers,
    how would one call the functions to which the pointers point.
    The signature of the function is known, however the the function
    itself might depend on the exact hardware the compiled module
    is running.

2. As the cdef function does not support all C macro constructs,
    would it be an option to have the gcc C preprocessor process
    header files first, before feeding them to cffi, or is this a futile
    exercise ?

Thank you and best regars,

Erik

Armin Rigo

unread,
Jun 8, 2015, 5:05:24 AM6/8/15
to pytho...@googlegroups.com
Hi Eric,

On 8 June 2015 at 10:18, <erik.j...@conceptive.be> wrote:
> 1. When a C function returns a struct containing function pointers,
> how would one call the functions to which the pointers point.
> The signature of the function is known (...)

It should work out of box: if "p" is a cdata pointer to a struct where
the field "myfunc" is a function pointer, then you can say
"p.myfunc(1, 2, 3)".

> 2. As the cdef function does not support all C macro constructs,
> would it be an option to have the gcc C preprocessor process
> header files first, before feeding them to cffi, or is this a futile
> exercise ?

If you have a complex header situation, it is highly recommended to
use the "API mode" instead of the "ABI mode". See
http://cffi.readthedocs.org/en/latest/overview.html . You need to
paste the header and edit it a bit, notably to replace some real
definitions with the string ``...``, but the result is much closer to
what you'd do in C: the compiler is used, not to preprocess some
headers but to really compile an extension module.


A bientôt,

Armin.

Erik Janssens

unread,
Jun 8, 2015, 5:08:00 AM6/8/15
to pytho...@googlegroups.com
Thanks a lot Armin, I'll try it out that way !


--
-- python-cffi: To unsubscribe from this group, send email to python-cffi...@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/python-cffi?hl=en
---
You received this message because you are subscribed to a topic in the Google Groups "python-cffi" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/python-cffi/fqx74fbyn-g/unsubscribe.
To unsubscribe from this group and all its topics, send an email to python-cffi...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages