[plt-scheme] silex vs. ffi

From: Neil Van Dyke (neil at neilvandyke.org)
Date: Wed Jan 14 13:38:10 EST 2009

An imprecise parser for arbitrary C header files (which are usually just 
C type and extern declarations, sprinkled with preprocessor gunk) has 
two uses that I see:

1. Starting point for manually-crafted FFI bindings, in most cases.

2. Complete FFI bindings in a small number of cases.

The difficulty is not so much parsing C (which is a nightmare of 
tracking type info and deciding how to interpret the preprocessor pass 
while retaining pre-preprocessing information), but that the header 
files often don't have enough semantic information to derive practical 
FFI bindings.

For a simple example of this, if an argument to a C function is treated 
as an in/out parameter, which is quite common, the header file doesn't 
tell you.  Even if it told you, you might need a human decision on a 
reasonable way to translate that to Scheme.

The header file also doesn't tell you preconditions of C functions, 
whether is returns or passes back allocations that must be freed, 
whether the C code retains allocations passed to it, etc.

You also might have to make human decisions about performance 
considerations.  Naive bindings might do lots more copying than is 
necessary for safety, for example.

-- 
http://www.neilvandyke.org/


Posted on the users mailing list.