docstrings for cffi-wrapped C entities

66 views
Skip to first unread message

_k...@yahoo.com

unread,
May 4, 2013, 5:42:24 AM5/4/13
to pytho...@googlegroups.com
Hi group!

The cffi-wrapped C code has a good notion of the number and type of arguments functions accept, the values needed to initialize a structured C data type etc. - and it should even know the names of formal parameters.

I would like to somehow extract this information and ideally have it appear as a docstring somewhere further up in my python code. Is there a way to acces this information from python?

Kay

Armin Rigo

unread,
May 7, 2013, 4:35:59 AM5/7/13
to pytho...@googlegroups.com
Hi Kay,
Good point. Right now you only have ffi.typeof(c_function), which
gives the signature as a string reconstructed from the internal
representation, without the names of formal parameters. It would be
nice if these c_function's also had a __doc__ that contains, say, the
original declaration. Patches welcome, and bonus points if the
__doc__ also includes the relevant /*comments*/ from the cdef :-)


A bientôt,

Armin.

_k...@yahoo.com

unread,
May 10, 2013, 6:06:38 AM5/10/13
to pytho...@googlegroups.com, ar...@tunes.org


On Tuesday, May 7, 2013 10:35:59 AM UTC+2, Armin Rigo wrote:
Hi Kay,

On Sat, May 4, 2013 at 11:42 AM,  <_k...@yahoo.com> wrote:
> The cffi-wrapped C code has a good notion of the number and type of
> arguments functions accept, the values needed to initialize a structured C
> data type etc. - and it should even know the names of formal parameters.
>
> I would like to somehow extract this information and ideally have it appear
> as a docstring somewhere further up in my python code. Is there a way to
> acces this information from python?

Good point.  Right now you only have ffi.typeof(c_function), which
gives the signature as a string reconstructed from the internal
representation, without the names of formal parameters.  It would be
nice if these c_function's also had a __doc__ that contains, say, the
original declaration.

Nice indeed...
 
Patches welcome, and bonus points if the
__doc__ also includes the relevant /*comments*/ from the cdef :-)

Gulp... I'm just right inside the innards of the fat C library I'm wrapping. I'm a cffi *user*, really; I haven't even looked into the code (yet). Okay, I'll put it on the to-do-list and once I've recovered from my current project I may give it a shot ;-)

Kay

Danilo Horta

unread,
Apr 23, 2016, 1:05:19 PM4/23/16
to python-cffi, ar...@tunes.org
Hello,

Has anyone look at it? It would be great to be able to define docstrings for C-wrapper functions.

Right now I'm using CFFI + Numba for exposing the Cephes library: https://github.com/Horta/ncephes
But I'm missing this bit.

Best,
Danilo
Reply all
Reply to author
Forward
0 new messages