RFC on plans to implement a c2ffi->cffi generator

Attila Lendvai attila at lendvai.name
Thu Dec 17 00:49:52 UTC 2015


i've pushed a v0.1 here:

https://github.com/attila-lendvai/cffi

i know that it's pretty useless without an extensive example, but
that's all for now.

it tracks type dependencies and only emits definitions that have their
type dependencies already emitted. e.g. defcstruct will skip slots
whose type has not been defined already.

it can compile the following in its entirety into valid cffi (with
only filtering out "va_list", and a small patch to cffi):

bluez.h:
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <sys/ioctl.h>
#include <bluetooth/bluetooth.h>
#include <bluetooth/hci.h>
#include <bluetooth/hci_lib.h>

and this is an example usage of the ASDF component:

(:cffi-c2ffi-file "bluez.h"
  :package #:hu.dwim.bluez
  :spec-path (system-relative-pathname :hu.dwim.bluez2 "autospec/")
  :exclude-archs ("i386-unknown-freebsd"
                  "x86_64-unknown-freebsd"
                  "i686-apple-darwin9"
                  "x86_64-apple-darwin9"
                  "i686-pc-windows-msvc"
                  "x86_64-pc-windows-msvc")
  :sys-include-paths ( ;; my llvm is not installed; or is it a c2ffi bug?
                      "/path/llvm-3.6/lib/clang/3.6.2/include/"
                      )
  :include-sources :all #+nil("bluetooth/bluetooth.h"
                              "bluetooth/hci.h"
                              "bluetooth/hci_lib.h")
  :exclude-sources () #+nil :all
  :include-definitions :all #+nil("memset"
                        "size_t"
                        "ssize_t"
                        "socklen_t"
                        ...
                        )
  :exclude-definitions ("va_list"))

an open question is that cl-ppcre (or equivalent) would be handy for
filtering definitions, but it's a rather heavy dependency. i'll
probably keep it optional, and redefine some defun's if someone loads
cffi-c2ffi+cl-ppcre.asd

but i'm open for suggestions.

more later,

-- 
• attila lendvai
• PGP: 963F 5D5F 45C7 DFCD 0A39
--
“As I began to love myself I freed myself of anything that is no good
for my health – food, people, things, situations, and everything that
drew me down and away from myself. At first I called this attitude a
healthy egoism. Today I know it is "LOVE OF ONESELF".”
	— Charles Chaplin (1889–1977)



More information about the cffi-devel mailing list