> > We're groping around in the dark here
> 
> Sorry, yes we are.  It is a bit cheeky of me to always punt and say
> "I'll bet it is a GHC problem" when I haven't even seen the bug myself
> on a machine whose configuration I know.  Sorry about that.  

No problem :)

> In fact, it turns out that you've uncovered a bug in the ffi backend
> of GreenCard.  The ghc backend (and GHC itself) is fine though so I'd
> guess that Sigbjorn tested this release with the ghc backend but since
> then the Makefile (or something in the hslibs Makefile hierarchy)
> switched to using the ffi backend.
> 
> I'll set about fixing this right away.
> 
> In the meantime, adding this line:
> 
> SRC_GC_OPTS    += --target ghc

Actually the win32 library is pre-compiled into .hs files in the
repository (I can't remember why we did this, but I suspect it was to
remove the dependency on GreenCard when building GHC on Windows).

> to hslibs/win32/Makefile may fix the problem (but I haven't been able
> to test this myself).
> 
> I'm attaching details for those who want them.
> 
> --
> Alastair Reid
> 
> 
> [Explanation of how word8 is currently marshalled by 
> GreenCard deleted]
> 
> > On a big-endian machine I'd expect this to break.  Does it?
> 
> Digging deeper into my memory of GreenCard, the answer should be no
> and the could should be perfectly safe (the word "should" is 
> key here).
> 
> Greencard is supposed to turn each %fun into a pair of functions - one
> Haskell, one C.  They are supposed to comminucate with each other
> through a common set of types which includes Word32 but excludes
> Word8.  To send a Word8 from one to the other we:
> 
>   Convert the word8 to word32.
>   Hand the word32 across the border.
>   Convert the word32 back into a word8.

Ok, this makes sense now.

> This is what happens in the Hugs backend
> 
>   primFun(prim_foo_rgb)
>   { BYTE arg1; BYTE arg2; BYTE arg3;DWORD res1;;
>     arg1 = (BYTE)(hugs->getWord());              // THESE 3 LINES
>     arg2 = (BYTE)(hugs->getWord());              // THESE 3 LINES
>     arg3 = (BYTE)(hugs->getWord());              // THESE 3 LINES
>     { res1 = RGB(arg1,arg2,arg3);
>      hugs->putWord((DWORD)(res1));
>      hugs_returnIO(1);
>      }
>   }
>   
> and, through the magic of _casm_, in the ghc backend
>   
>   rgb :: BYTE -> BYTE -> BYTE -> COLORREF
>   rgb gc_arg1 gc_arg2 gc_arg3 =
>     unsafePerformIO(
>       case ( word8ToWord32   gc_arg1) of { arg1 ->
>       case ( word8ToWord32   gc_arg2) of { arg2 ->
>       case ( word8ToWord32   gc_arg3) of { arg3 ->
>       _casm_ ``do {BYTE arg1; BYTE arg2; BYTE arg3;DWORD res1;
>                    arg1 = (BYTE)%0; arg2 = (BYTE)%1; arg3 = (BYTE)%2;
>                    do { res1 = RGB(arg1,arg2,arg3);
>                        
>                        %r = (DWORD)(res1);} while(0);} 
> while(0);'' arg1 arg2 arg3
>       >>= \  res1  ->
>       (return (res1))}}})
> 
> but not in the ffi backend  
>   
>   DWORD prim_rgb(BYTE arg1,BYTE arg2,BYTE arg3)
>   { DWORD res1;
>     do { res1 = RGB(arg1,arg2,arg3);
>         
>         return((DWORD)(res1));} while(0);
>   }

Right, I see the problem now.  Thanks for looking into it.

Cheers,
        Simon
_______________________________________________
Glasgow-haskell-bugs mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to