[C2hs] Re: darcs patch: automagically support stdcall calling convention when ...

Duncan Coutts duncan.coutts at googlemail.com
Sat Jul 3 12:36:06 EDT 2010

On Wed, 2010-06-30 at 01:08 -0500, Jonathan Rockway wrote:
> * On Mon, Jun 14 2010, Duncan Coutts wrote:
> > I've got a follow-on patch, perhaps you could review it?
> Hey Duncan,
> I tested this out on my windows app that uses stdcall calling, and it
> works quite nicely.  I like the changes you made to my original patch
> (C_Call was quite a messy name :).

Ok, great.

> Also, I got to the bottom of my issue where my header files fail to
> parse.  The problem is that the line endings on Windows are \r\n, and \r
> confuses the parser deeply.  It worked in GHC 6.10 because it was being
> "smart" about reading the files, but GHC 6.12 changes that behavior.  I
> poked around in Language.C.Data.InputStream, but didn't find an obvious
> place to call hSetNewlineMode, so instead, I just changed the definition
> of readInputStream to:
>    readInputStream f = liftM (BS.filter (/= '\r')) $ BS.readFile f
> This makes everything work again, but is slightly inelegant.  Anyway,
> the problem is in Language.C, not C2HS.

Yes, this is an "unplanned change" in ghc that affects bytestring text
I/O, which Language.C depends on. We're probably not going to be able to
change the bytestring behaviour back again and just have to redefine the
intended behaviour to the current behaviour. So we'll have to add a fix
in Language.C, probably in the lexer where it detects the end of line.

> > I believe that one can specify attributes after a C function
> > declaration:
> >
> > void foo() __attribute__((__stdcall__));
> >
> > as well as before with the syntax
> >
> > void __attribute__((__stdcall__)) foo();
> >
> >
> > This patch looks at the attributes in both positions.
> Seems sane to me, but I haven't seen the first form before.  But I am no
> expert, I had no idea there were calling conventions until I started
> writing this binding on Windows :) 

Yeah, annoying :-(

> I just reverse-engineered my header files (or rather, the result of
> running cpp on them) and hacked stuff until c2hs worked ;)


> Anyway, thanks for continuing to maintain C2HS.  I like the way it works
> and it has made my life easier.  I owe you a beer sometime :)



More information about the C2hs mailing list