1 Aug 2004 23:55
[ ghc-Bugs-997511 ] Options -no-hs-main -debug cause 'impossible' to happen
SourceForge.net <noreply <at> sourceforge.net>
2004-08-01 21:55:01 GMT
2004-08-01 21:55:01 GMT
Bugs item #997511, was opened at 2004-07-25 05:38 Message generated for change (Comment added) made by nobody You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=108032&aid=997511&group_id=8032 Category: Compiler (FFI) Group: None Status: Open Resolution: None Priority: 5 Submitted By: Nobody/Anonymous (nobody) Assigned to: Nobody/Anonymous (nobody) Summary: Options -no-hs-main -debug cause 'impossible' to happen Initial Comment: Here's the command line: ghc -c ForeignTest.hs -fglasgow-exts -package text -no-hs-main And here's the module: ----------------------- module ForeignTest (reduce) where import Foreign.StablePtr import GensDef import GensCoreIO foreign export ccall "reduce" reduceMain ::(Continue reading)
It involves C code, FFI and optimisations (all seem to be required).
Nice.
The problem shows up as a double value loosing precision when it is sent
to C land and back. It's because ghc generates C code that casts the
value via an unsigned word when it gets it back from C land.
Attached is a small collection of modules which exhibit the problem. If
I make the test case much smaller, the problem goes away. It's not too
complicated code though. Some imports were hacked around and a few bits
commented out to get it out of a larger library. The test program sends
(-1) :: Double to C land and back and gets something rather different
back.
For some context, it's part of the gtk2hs bindings. It deals with a data
type (GValue) on the C side that is a 'variant' type. A big union of
primitive types with an enum field to say what is in the union. The code
implements peek/poke for this type. The peek/poke code does the obvious
thing which is a case expression on the Haskell sum-type value or the
type field of the C value. In each branch of the case we make an FFI
call to do the actual getting / setting:
peek gvPtr = do
gtype <- liftM (toEnum.fromIntegral::Word32 -> TMType) $
(\hsc_ptr -> peekByteOff hsc_ptr 0) gvPtr
RSS Feed