[GHC] #2594: Wrong size for Int in arguments to functions
wrapped to FunPtr by FFI wrappers (on 64-bit machine)
GHC
trac at galois.com
Sat Sep 13 19:52:10 EDT 2008
#2594: Wrong size for Int in arguments to functions wrapped to FunPtr by FFI
wrappers (on 64-bit machine)
-------------------------------+--------------------------------------------
Reporter: shahn | Owner:
Type: bug | Status: closed
Priority: normal | Milestone:
Component: Compiler | Version: 6.8.3
Severity: normal | Resolution: invalid
Keywords: | Testcase:
Architecture: x86_64 (amd64) | Os: Linux
-------------------------------+--------------------------------------------
Changes (by duncan):
* status: new => closed
* resolution: => invalid
Comment:
I think this is an incorrect use of the FFI. The example uses Haskell
`Int` and passes it to C code which uses it at C's type `int`. These are
not the same types, though they do happen to coincide on x86 32bit. The
example should be using `CInt` on the Haskell side. Alternatively, if the
intention really is to use the Haskell `Int` type then the C side code
must use `HsInt` (which is defined in `HsFFI.h`).
The reason we get the observed result is because on x86-64, GHC uses a
64-bit `Int` while C's `int` remains 32bit so `-1` in a 32bit int is all
`1` bits but that bit pattern as a larger int is `2^32-1`.
So I'm closing the ticket as invalid. If anyone thinks this is incorrect
then please do re-open it.
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/2594#comment:1>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the Glasgow-haskell-bugs
mailing list