From: qrczak Date: Sat, 14 Apr 2001 22:28:46 +0000 (+0000) Subject: [project @ 2001-04-14 22:28:46 by qrczak] X-Git-Tag: Approximately_9120_patches~2150 X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=7eb00ee308a50c4be6a58c9a76ee491e1bed9ff3;p=ghc-hetmet.git [project @ 2001-04-14 22:28:46 by qrczak] castCCharToChar can be more straightforward and more efficient now. --- diff --git a/ghc/lib/std/PrelCString.lhs b/ghc/lib/std/PrelCString.lhs index 5c00191..2413e30 100644 --- a/ghc/lib/std/PrelCString.lhs +++ b/ghc/lib/std/PrelCString.lhs @@ -1,5 +1,5 @@ % ----------------------------------------------------------------------------- -% $Id: PrelCString.lhs,v 1.2 2001/01/11 19:48:28 qrczak Exp $ +% $Id: PrelCString.lhs,v 1.3 2001/04/14 22:28:46 qrczak Exp $ % % (c) The FFI task force, 2000 % @@ -12,13 +12,10 @@ module PrelCString where import Monad import PrelMarshalArray -import PrelMarshalAlloc -import PrelException import PrelPtr import PrelStorable import PrelCTypes -import PrelCTypesISO -import PrelInt +import PrelWord import PrelByteArr import PrelPack import PrelBase @@ -120,11 +117,7 @@ charsToCChars :: [Char] -> [CChar] charsToCChars = map castCharToCChar castCCharToChar :: CChar -> Char --- castCCharToChar ch = chr (fromIntegral (fromIntegral ch :: Word8)) --- The above produces horrible code. Word and Int modules really --- should be cleaned up... Here is an ugly but fast version: -castCCharToChar ch = case fromIntegral (fromIntegral ch :: Int32) of - I# i# -> C# (chr# (word2Int# (int2Word# i# `and#` int2Word# 0xFF#))) +castCCharToChar ch = unsafeChr (fromIntegral (fromIntegral ch :: Word8)) castCharToCChar :: Char -> CChar castCharToCChar ch = fromIntegral (ord ch) @@ -133,6 +126,7 @@ castCharToCChar ch = fromIntegral (ord ch) -- unsafe CStrings -- --------------- +withUnsafeCString :: String -> (UnsafeCString -> IO a) -> IO a #if __GLASGOW_HASKELL__ newtype UnsafeCString = UnsafeCString (ByteArray Int) withUnsafeCString s f = f (UnsafeCString (packString s))