summaryrefslogtreecommitdiff
path: root/libraries/base/System/Posix/Internals.hs
diff options
context:
space:
mode:
authorIan Lynagh <igloo@earth.li>2012-05-20 13:48:20 +0100
committerIan Lynagh <igloo@earth.li>2012-05-20 19:55:32 +0100
commitcf14ed623f97eaf238dd9a9232c01479b177a40b (patch)
treea27ba708fc0f6de76cece33aa1e2d20e59aa13d7 /libraries/base/System/Posix/Internals.hs
parent5176c1f825c43fb357a41eb9acf5143f5bc897d5 (diff)
downloadhaskell-cf14ed623f97eaf238dd9a9232c01479b177a40b.tar.gz
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).
Diffstat (limited to 'libraries/base/System/Posix/Internals.hs')
-rw-r--r--libraries/base/System/Posix/Internals.hs24
1 files changed, 20 insertions, 4 deletions
diff --git a/libraries/base/System/Posix/Internals.hs b/libraries/base/System/Posix/Internals.hs
index d2bd0e62a7..5583c3b5ed 100644
--- a/libraries/base/System/Posix/Internals.hs
+++ b/libraries/base/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).
+-}
+