RFC on plans to implement a c2ffi->cffi generator

Attila Lendvai attila at lendvai.name
Fri Dec 11 18:06:14 UTC 2015


> So if the resulting spec file looked something like
>
>    ;; spec file starts here
>    (cffi-c2ffi:definition foo ...)
>    (cffi-c2ffi:definition bar ...)
>    (cffi-c2ffi:definition baz ...)
>    ;; spec file ends here

ah, ok, this makes sense, thanks!

but it leads up to an issue i'm dealing with now:

the c2ffi output contains offset for each field in a struct, which
enables us to generate partial bindings where not all struct fields
need to have a defined type.

my current idea to deal with undefined types is the following:

  - (cffi:defctype undefined :char
    "Used by cffi-c2ffi to mark types that are used in e.g. structs,
but are not defined in the scope of the generation.")

  - in a first phase collect all defined and referenced types. (this
    may be a PITA because i don't know all the ins and outs of C
    namespaces, e.g. where is it ok to reference a struct by only its
    name, as opposed to by "struct some-struct", and which namespaces
    are looked up in naked type references, etc.)

  - in the emitting phase first emit defctype for each used but not
    defined type before emitting the definitions themselves

  - while emitting definitions simplify them compatibly.  e.g. the
    bindings of functions that take a pointer to an undefined type get
    simplified into a :pointer.

as you can see this needs a multi-phase whole-file processing, but i'm
open for ideas.

the way cl-autowrap deals with this is that its struct framework
doesn't complain for undefined types because it expects :offset for
each field.

maybe defcstruct could be extended in a sane way with something like
this?

-- 
• attila lendvai
• PGP: 963F 5D5F 45C7 DFCD 0A39
--
“Governments want efficient technicians, not human beings, because
human beings become dangerous to governments – and to organized
religions as well. That is why governments and religious organizations
seek to control education.”
	— Jiddu Krishnamurti (1901–1986), 'Education and the Significance of Life'



More information about the cffi-devel mailing list