Cairo Deimos bindings

James Miller james at aatch.net
Thu Apr 26 16:05:25 PDT 2012


On Thursday, 26 April 2012 at 22:45:01 UTC, Trass3r wrote:
>> I'd say that usable htod generated headers still are a welcome 
>> addition to Deimos.
>>
>> David
>
> Even using some regex's is better than htod. It drops const, 
> removes or messes up the comments etc.

There are also many things that should be changed in a binding to 
make it more D compatible, without affecting the C binding. Many 
C libraries define their own bool type, but D has a bool type 
that can be used just as easily, also making it easier to write D 
using native types.

Lots of C code has extraneous typedefs that are only there to 
strip out struct and union keywords, so they can be rewritten. 
enums cause issues because the C enum:

    enum Status {
       STATUS_SUCCESS
    }

has type enum Status and the members are access like 
STATUS_SUCCESS. The same enum in D is

    enum Status {
       STATUS_SUCCESS
    }

has type Status and the members are accessed using 
Status.STATUS_SUCCESS, which can be very bloated when converting 
heavily-namespaced code into D, because accessing the member 
CAIRO_STATUS_NO_MEMORY from the enum cario_status_t is fine in C, 
and neccessary because of the lack of modules, but the same in D 
is cario_status_t.CAIRO_STATUS_NO_MEMORY, which is very verbose. 
Consider that this is one of the shorter enums in cairo, then it 
becomes a problem.

Sometimes code will rely on specific, extra, headers to determine 
what to do, further complicating bindings, especially when you 
need to check for certain functionality.

htod is not a useful tool, especially if you want to do any sort 
of cross-platform, robust binding, manual binding is really the 
only way to do it properly and properly reflect the original 
binding and api of the library.

It doesn't take that long, I did the binding for the 3000 line 
cairo.h file in about 3 hours, through judicious use of regex 
replaces and macros (I love Vim).

--
James Miller


More information about the Digitalmars-d mailing list