CFFI for interfacing C functions

CFFI has been a great success so far in Python. Did you consider using it for interfacing C code?

There are many benefits of CFFI, just to mention few:

  • Abstract the Python version (CPython2, CPython3, PyPy).
  • Better control over when and why the C compilation occurs, and more standard ways to write setuptools-based files.
  • Keep all the Python-related logic in Python so that you don’t need to write much C code.

Are you asking about our library (TH, THC, etc.) wrappers or about the extensions?

Our FFI extension utils actually depend on cffi. You can check extension-ffi repo for examples.

Thanks for response.
I was asking about wrappers at PyTorch (TH, THC…) - looking at the sources I saw that you are using CPython C API.
With CFFI you could get support for PyPy for free (and probably some other runtimes as well).

we could not use CFFI for that part because we wanted a lot of additional stuff for our core bindings.
For example, multiple dispatch – with CFFI, we have to build a multiple dispatch in python, which we did not want.
Also, a few other things like autogeneration of good errors etc.
See this code pointer for an example:

A very quick question.
I am trying to write a small cffi extension for pytorch (it will only be a small util function not an entire layer).
My question is that the argument for the c function in the example, use THFloatTensor*.
Does it means it also support Variable ?