[plt-scheme] ANN: c.plt (C manipulation and FFI utilities)

From: Dave Herman (dherman at ccs.neu.edu)
Date: Mon Feb 2 17:34:21 EST 2009

I've just posted a new PLaneT package called c.plt:


This may be of interest to anyone working with the FFI. You can use it 
to parse header info and query a system C compiler to get exact data 
structure sizes and byte offsets for struct fields etc. Example:

 > (define time.h
       #reader (planet dherman/c/reader) {
           struct tm {
               int tm_sec;
               int tm_min;
               int tm_hour;
               int tm_mday;
               int tm_mon;
               int tm_year;
               int tm_wday;
               int tm_yday;
               int tm_isdst;
 > (define time-abi
     (compile-header time.h
       (system-compiler #:include<> '("time.h") gcc)))
 > (layout-size (time-abi 'tm))
 > (layout-offset (time-abi 'tm) 'tm_sec)
 > (layout-offset (time-abi 'tm) 'tm_year)

The first version is available but pretty rough. There's lots of missing 
functionality. I'm happy to accept requests and bug reports.


Posted on the users mailing list.