cdata-structuresstructpython-cfficffi

Clarification sought on validity and reason for "empty" C struct definition in Python CFFI definition file


I am reading some code, and came across this rather odd C struct definition:

typedef struct dataObject
  {
      ...;
  } DATA_OBJECT;

Can anyone explain (with references if possible):

  1. If this is a valid struct definition.
  2. What would be the purpose of such a definition (where no fields/members are defined).

Solution

  • If this is a valid struct definition

    No.

    What would be the purpose of such a definition (where no fields/members are defined)?

    The file purpose is to provide the python CFFI parser with type and function declarations to use.

    The purpose of this file is to preprocessed by python CFFI ffibuilder.cdef(). From letting C compiler fill the gaps:

    Moreover, you can use “...” (literally, dot-dot-dot) in the cdef() at various places, in order to ask the C compiler to fill in the details. These places are:

    • structure declarations: any struct { } or union { } that ends with “...;” as the last “field” is partial: it may be missing fields, have them declared out of order, use non-standard alignment, etc. Precisely, the field offsets, total struct size, and total struct alignment deduced by looking at the cdef are not relied upon and will instead be corrected by the compiler. (But note that you can only access fields that you declared, not others.) Any struct declaration which doesn’t use “...” is assumed to be exact, but this is checked: you get an error if it is not correct.
    • [...]
    • unknown types: [....] In some cases you need to say that foo_t is not opaque, but just a struct where you don’t know any field; then you would use typedef struct { ...; } foo_t;.

    I suspect it means to the CFFI that struct dataObject and DATA_OBJECT are opaque types meant to be used only as pointers and the CFFI parser does not support struct declarations.

    The file is used here in clips_build.py as I understand to build clipspy python interface to C.