X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2Futils%2FStringBuffer.lhs;h=18359456be94d75eadc3b8a79c6e9efc6bbd8452;hb=8a2809c29de9f23eba7ca682b48390033a9d40f6;hp=e52e7e78da9c7792ff9a9b79b747c5ab27888700;hpb=0065d5ab628975892cea1ec7303f968c3338cbe1;p=ghc-hetmet.git diff --git a/compiler/utils/StringBuffer.lhs b/compiler/utils/StringBuffer.lhs index e52e7e7..1835945 100644 --- a/compiler/utils/StringBuffer.lhs +++ b/compiler/utils/StringBuffer.lhs @@ -1,7 +1,7 @@ % +% (c) The University of Glasgow 2006 % (c) The University of Glasgow, 1997-2006 % -\section{String buffers} Buffers for scanning string input stored in external arrays. @@ -33,7 +33,7 @@ module StringBuffer lexemeToFastString, -- * Parsing integers - parseInteger, + parseUnsignedInteger, ) where #include "HsVersions.h" @@ -45,7 +45,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 ) @@ -207,12 +206,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 +223,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}