Hi Hendrik,
On Mon, 17 May 2021 at 17:17, Hendrik Dorn <
dorn.h...@gmail.com> wrote:
> is there a native cffi way of binding function arguments to keywords? In pybind11 this was pybind::arg("my_function_argument"). I would like to avoid python-wrapping my cffi-wrapped c-function.
No, there is no other way. I might be willing to accept a patch to
cffi, though. It would need to be clear when it works and when it
doesn't. In C, the function argument names are ignored and don't need
to be written in headers, so this is valid syntax: ``int foo(int x,
long);``. You can't really call such a function from Python using the
name ``x`` because the second argument is missing a name. But you
could call ``int foo(long, int x);`` as ``foo(42, x=5)`` is OK.
And also, would it apply only to functions declared directly in the
cdef, or also to function pointer types? The latter requires touching
the ``ctype`` of function pointers and might break things, like giving
an error when trying to convert a ``int (*foo_t)(int);`` to a ``int
(*bar_t)(int mystuff);``, so I guess it shouldn't be done. But then,
keyword arguments can only be supported in the API mode (with
set_source()), because in ABI mode (with dlopen()) all exposed C
functions are just regular function pointers.
A bientôt,
Armin