[C2hs] Pointers to structs without typedef

Jelmer Vernooij jelmer at samba.org
Mon Nov 14 17:58:19 EST 2005


On Tue, Nov 15, 2005 at 01:20:13AM +1100, Manuel M T Chakravarty wrote about 'Re: [C2hs] Pointers to structs without typedef':
> Ok, I see what you mean.  This does look like a bug.  Is this a show
> stopper for you?
Pretty much, as it means I can't just use the original headers. Is there 
anything I can do to help fix it? I'd be happy to spend some hours on 
fixing it, if you can point me in the right direction.

Cheers,

Jelmer

> Jelmer Vernooij:
> > On Thu, Nov 10, 2005 at 12:29:02AM +1100, Manuel M T Chakravarty wrote about 'Re: [C2hs] Pointers to structs without typedef':
> > > Jelmer Vernooij:
> > > > c2hs appears to have trouble with pointers to structs when not using
> > > > typedefs. A simple that shows this behaviour:

> > > > module Foo
> > > > where

> > > > #c

> > > > struct foo { char x; };

> > > > void bar(struct foo *x);

> > > > #endc

> > > > {#pointer *'struct foo' as Foo newtype#}

> > > I think you meant

> > >   {#pointer *foo as Foo newtype#}

> > That's what I tried initially, but that doesn't appear to work; c2hs will
> > generate "Ptr ()" as the first argument of bar. It does work correctly 
> > if I make foo a typdef.

> > If I try this:

> > module Foo
> > where

> > #c

> > typedef struct foo {
> > 	char x;
> > } foo_typedef;

> > void bar1(struct foo *x);
> > void bar2(foo_typedef *x);

> > #endc

> > {#pointer *foo as Foo newtype#}
> > {#pointer *foo_typedef as FooTypedef newtype#}

> > test1 = {#call bar1#}
> > test2 = {#call bar2#}

> > c2hs generates the following stub for `bar1':

> > foreign import ccall safe "c2hstest.h bar1"
> >   bar1 :: ((Ptr ()) -> (IO ()))

> > whereas I would expect the `Ptr ()' to be `Foo' instead.

> > the stub for `bar2' is correct:

> > foreign import ccall safe "c2hstest.h bar2"
> >   bar2 :: ((FooTypedef) -> (IO ()))

> > Cheers,

> > 	Jelmer

-- 
Jelmer Vernooij <jelmer at samba.org> - http://jelmer.vernstok.nl/
Currently playing: Counting Crows - I Wish I Was A girl
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://www.haskell.org//pipermail/c2hs/attachments/20051114/f4af6bb7/attachment.bin


More information about the C2hs mailing list