[commit: base] master: Change a few FFI imports to use CAPI (3581ef2)
Ian Lynagh
igloo at earth.li
Sun May 20 20:55:59 CEST 2012
Repository : ssh://darcs.haskell.org//srv/darcs/packages/base
On branch : master
http://hackage.haskell.org/trac/ghc/changeset/3581ef278ff57ecd8630482cac93d88813e72263
>---------------------------------------------------------------
commit 3581ef278ff57ecd8630482cac93d88813e72263
Author: Ian Lynagh <igloo at earth.li>
Date: Sun May 20 13:48:20 2012 +0100
Change a few FFI imports to use CAPI
On Win64, ssize_t is 64 bit, but functions like read return 32 bit
ints. The CAPI wrapper means the C compiler takes care of doing all
the necessary casting.
Technically we should instead be making the types of the FFI imports
different on different platforms, but I think this will work out
simpler overall.
Before this fix, when the functions failed with -1, we thought they
were returning with 4294967295, and so didn't throw an exception.
This lead to a segfault in echo001(ghci).
>---------------------------------------------------------------
System/Posix/Internals.hs | 24 ++++++++++++++++++++----
1 files changed, 20 insertions(+), 4 deletions(-)
diff --git a/System/Posix/Internals.hs b/System/Posix/Internals.hs
index d2bd0e6..5583c3b 100644
--- a/System/Posix/Internals.hs
+++ b/System/Posix/Internals.hs
@@ -435,10 +435,12 @@ foreign import ccall unsafe "HsBase.h __hscore_open"
foreign import ccall safe "HsBase.h __hscore_open"
c_safe_open :: CFilePath -> CInt -> CMode -> IO CInt
-foreign import ccall unsafe "HsBase.h read"
+-- See Note: CSsize
+foreign import capi unsafe "HsBase.h read"
c_read :: CInt -> Ptr Word8 -> CSize -> IO CSsize
-foreign import ccall safe "HsBase.h read"
+-- See Note: CSsize
+foreign import capi safe "HsBase.h read"
c_safe_read :: CInt -> Ptr Word8 -> CSize -> IO CSsize
foreign import ccall unsafe "HsBase.h __hscore_stat"
@@ -447,10 +449,12 @@ foreign import ccall unsafe "HsBase.h __hscore_stat"
foreign import ccall unsafe "HsBase.h umask"
c_umask :: CMode -> IO CMode
-foreign import ccall unsafe "HsBase.h write"
+-- See Note: CSsize
+foreign import capi unsafe "HsBase.h write"
c_write :: CInt -> Ptr Word8 -> CSize -> IO CSsize
-foreign import ccall safe "HsBase.h write"
+-- See Note: CSsize
+foreign import capi safe "HsBase.h write"
c_safe_write :: CInt -> Ptr Word8 -> CSize -> IO CSsize
foreign import ccall unsafe "HsBase.h __hscore_ftruncate"
@@ -583,3 +587,15 @@ foreign import capi unsafe "stdio.h value SEEK_CUR" sEEK_CUR :: CInt
foreign import capi unsafe "stdio.h value SEEK_SET" sEEK_SET :: CInt
foreign import capi unsafe "stdio.h value SEEK_END" sEEK_END :: CInt
+{-
+Note: CSsize
+
+On Win64, ssize_t is 64 bit, but functions like read return 32 bit
+ints. The CAPI wrapper means the C compiler takes care of doing all
+the necessary casting.
+
+When using ccall instead, when the functions failed with -1, we thought
+they were returning with 4294967295, and so didn't throw an exception.
+This lead to a segfault in echo001(ghci).
+-}
+
More information about the Cvs-libraries
mailing list