
Axel Simon
On Wed, Oct 22, 2003 at 02:51:15PM +0100, Duncan Coutts wrote:
All,
So I'm trying to wrap this structure:
struct GtkSourceTagStyle {
/* readonly */ gboolean is_default;
guint mask;
GdkColor foreground; GdkColor background;
gboolean italic; gboolean bold; gboolean underline; gboolean strikethrough;
/* Reserved for future expansion */ guint8 reserved[16]; };
My problem is with the GdkColor members foreground & background. They are themselves structures so c2hs cannot make {#get #} mappings for them. Of course Color has already been wrapped (in gtk2hs/gtk/general/Structs.hsc) and is a member of the Storable class so all we need is to get a pointer to the member to be able to apply peek/poke to it. This is not hard if we manually edit the .hs file produced from the .chs binding file:
I kinda object to use c2hs for marshalling structures. When I wrote the marshalling code for graphics contexts for gtk+hs, I used c2hs only to find out that it calculates the wrong offsets.
That was a bug in c2hs, which has been fixed since then.
Moreover, it is doomed to produce the wrong offsets in some circumstances with bitfields. Windows uses a different layout than Unix, even if you use gcc on both platforms. (gcc behaves differently so that you can use the precompiled Microsoft libraries).
Why do you think that c2hs cannot handle this? If you look at the files "c2hs/toplevel/C2HSConfig.hs.in" and "c2hs/toplevel/c2hs_config.c" in the c2hs source tree, you will see that c2hs actually goes to quite some trouble to find out how to properly access bitfields on the particular OS and architecture it is running on. If you have got any example, where this does not work properly, please submit it as a c2hs bug report. Cheers, Manuel