Need support for import/extend cdef definitions from another library

Issue #37 resolved
Sarvi Shanmugham
created an issue

When libB and libC depend on LibA and structures defined in libA writing CFFI wrappers is trouble some.

Data types and structures have to be redefined in the cdef of libA, libB and libC which is redundant.

The more ugly problem is that if I created an object using libA I cannot pass/use it with libB or libC without typecasting.


 structA ='struct structA *')

 # The following causes an error saying 'struct structA *'

 # is needed but 'struct structA *' is provided.


 # I have to do a typecast to make it work which is ugly and

 # could also be risky coding

 libB.funcB(libB.ffi.cast('struct structA *',structA))

The solution discussed in the mailing list is to implement something like


  import libA


  ffi.cdef(''' libB cdef content ''')

style operation that can import the cdefs from another library. This will address both the above problem as well as eliminate the need for duplicate definition of data types in modular libraries.

Comments (5)

  1. Armin Rigo

    Would it be enough if we have "ffi.include(libA.ffi)" that imports precisely (1) the typedefs and (2) the struct/union/enum declarations? The declaration of functions and global vars can be omitted because you can always refer to them via libA. Am I missing something else?

  2. Sarvi Shanmugham reporter

    I would think so. Infact importing the function definitions may be undesirable. Coz this is only to avoid typecasting of same structures/types across libraries. If we imported functions, it might allow libB.functionfromlibA() which we probably want to disallow, I would think.

  3. Log in to comment