[C2hs] Questions

Manuel M T Chakravarty chak at cse.unsw.edu.au
Mon Aug 15 02:24:00 EDT 2005


Paolo Martini:
> Why doesn't {#enum ..#} hooks define the default marshallers to be
> cFromEnum/cToEnum? 

This would certainly be a useful feature.  (In fact, a FIXME comment at
GenBind.lookupDftMarshIn suggests just that.)  I'll implement it when I
find the time; otherwise, feel free to give it a try yourself if you
like.

> Furthermore, is it possible to define the
> marshallers functions for a give type? (IMO it would make the .chs files
> more readable) 

Not at the moment.  The internal functionality needed to support this is
similar to that for default marshaller from enum hooks.  Basically, the
default marshaller table is currently static.  It cannot be extended at
runtime.  As soon as there is a dynamic table, much of what you want
should be easy to realise.

> If not, would it be possible to extend the syntax, maybe
> adding "... inmarsh outmarsh#}" at the end of the hooks?

Which hooks do you want this for?

> For example I'm using "id" as the marshaller for {#pointer ..#} hooks,
> (in {#fun name {id `pointer'} -> `pointer' id#}) is it correct, or am I
> missing something?
> 
> I can't find an example of a C struct type which isn't defined as a
> pointer.  How should one go to bind structures like this?
> 
>      typedef struct {
>        unsigned long        index;
>        double               x;
>        double               y;
>      } cairo_glyph_t;
> 
> And then, how to pass them to functions getting a *cairo_glyph_t?
> Moreover, what if they are getting an array of them? (e.g.
> 
>      void cairo_show_glyphs (cairo_t *cr,
>                              cairo_glyph_t *glyphs,
>                              int num_glyphs);

I don't quite understand this.  You are using a pointer to cairo_glyph_t
here.  Look at 

  http://www.cse.unsw.edu.au/~chak/repos/c2hs/c2hs/tests/pointer.h
  http://www.cse.unsw.edu.au/~chak/repos/c2hs/c2hs/tests/Pointer.chs

the struct Point is used in the same way in this example.  (Well, only
one point is passed in the example, where as you pass a whole lot of
glyhs, but the C type still has the same structure.)

Or are you asking how to do the same with fun hooks?

Arrays are generally best marshalled with the functions from

  http://haskell.org/ghc/docs/latest/html/libraries/base/Foreign.Marshal.Array.html

Manuel




More information about the C2hs mailing list