[racket] FFI - static c arrays inside a struct and libgit2 bindings

From: Joan Arnaldich (jarnaldich at gmail.com)
Date: Fri Sep 2 18:08:45 EDT 2011

Matthew Flatt <mflatt at ...> writes:

> In version 5.1.3 and earlier, you could write
>  (define-cstruct _git_index_entry_unmerged
>    ([mode0 _uint]
>     [mode1 _uint]
>     [mode2 _uint]
>     [oid0 _git_oid] ; assuming _git_oid is defined
>     [oid1 _git_oid]
>     [oid2 _git_oid]
>     [path _string]))
> With the latest development version (or v5.1.3.3 and later), you can
> write
>  (define-cstruct _git_index_entry_unmerged
>    ([mode (_array _uint 3)]
>     [oid (_array _git_oid 3)] ; assuming _git_oid is defined
>     [path _string]))

Thanks a lot!

I think I will work on other parts of the library and then I'll
definitely go for the development version option, which seems to be
just what I was looking for.

In fact, _git_oid was already a struct with a static byte array of
length 40 as its only member. Since every function I had come up with
so far used a (maybe double) pointer to _git_oid, I could just declare
it as (_bytes <mode> 40)... until I found the structs in my first
email. The first solution is probably too ugly when each oid has a
length of 40.

Cheers and thanks again!

Posted on the users mailing list.