X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=blobdiff_plain;f=compiler%2Futils%2FStringBuffer.lhs;h=d7135353a171568cc418ea8d0479b8d2de0aeda6;hp=8eb6fc2bc4627a82229ea4a3deb985362dd90eae;hb=7fc749a43b4b6b85d234fa95d4928648259584f4;hpb=046ee54f048ddd721dcee41916d6a6f68db3b15b diff --git a/compiler/utils/StringBuffer.lhs b/compiler/utils/StringBuffer.lhs index 8eb6fc2..d713535 100644 --- a/compiler/utils/StringBuffer.lhs +++ b/compiler/utils/StringBuffer.lhs @@ -6,6 +6,13 @@ Buffers for scanning string input stored in external arrays. \begin{code} +{-# OPTIONS -w #-} +-- The above warning supression flag is a temporary kludge. +-- While working on this module you are encouraged to remove it and fix +-- any warnings in the module. See +-- http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#Warnings +-- for details + module StringBuffer ( StringBuffer(..), @@ -33,7 +40,7 @@ module StringBuffer lexemeToFastString, -- * Parsing integers - parseInteger, + parseUnsignedInteger, ) where #include "HsVersions.h" @@ -45,7 +52,6 @@ import Foreign import System.IO ( hGetBuf, hFileSize,IOMode(ReadMode), hClose , Handle, hTell ) -import GHC.Ptr ( Ptr(..) ) import GHC.Exts import GHC.IOBase ( IO(..) ) import GHC.Base ( unsafeChr ) @@ -114,7 +120,7 @@ hGetStringBufferBlock handle wanted withForeignPtr buf $ \ptr -> do r <- if size == 0 then return 0 else hGetBuf handle ptr size if r /= size - then ioError (userError $ "short read of file: "++show(r,size,fromIntegral size_i,handle)) + then ioError (userError $ "short read of file: "++show(r,size,size_i,handle)) else do pokeArray (ptr `plusPtr` size :: Ptr Word8) [0,0,0] return (StringBuffer buf size 0) @@ -207,12 +213,14 @@ byteOff (StringBuffer buf _ cur) i = w <- peek (ptr `plusPtr` (cur+i)) return (unsafeChr (fromIntegral (w::Word8))) --- | XXX assumes ASCII digits only -parseInteger :: StringBuffer -> Int -> Integer -> (Char->Int) -> Integer -parseInteger buf len radix to_int +-- | XXX assumes ASCII digits only (by using byteOff) +parseUnsignedInteger :: StringBuffer -> Int -> Integer -> (Char->Int) -> Integer +parseUnsignedInteger buf len radix char_to_int = go 0 0 - where go i x | i == len = x - | otherwise = go (i+1) (x * radix + toInteger (to_int (byteOff buf i))) + where + go i x | i == len = x + | otherwise = go (i+1) + (x * radix + toInteger (char_to_int (byteOff buf i))) -- ----------------------------------------------------------------------------- -- under the carpet @@ -222,19 +230,4 @@ parseInteger buf len radix to_int inlinePerformIO :: IO a -> a inlinePerformIO (IO m) = case m realWorld# of (# _, r #) -> r -#if __GLASGOW_HASKELL__ < 600 -mallocForeignPtrArray :: Storable a => Int -> IO (ForeignPtr a) -mallocForeignPtrArray = doMalloc undefined - where - doMalloc :: Storable b => b -> Int -> IO (ForeignPtr b) - doMalloc dummy size = mallocForeignPtrBytes (size * sizeOf dummy) - -mallocForeignPtrBytes :: Int -> IO (ForeignPtr a) -mallocForeignPtrBytes n = do - r <- mallocBytes n - newForeignPtr r (finalizerFree r) - -foreign import ccall unsafe "stdlib.h free" - finalizerFree :: Ptr a -> IO () -#endif \end{code}