summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2020-10-22 19:18:41 -0400
committerBen Gamari <ben@smart-cactus.org>2020-12-27 11:24:25 -0500
commiteba746567b3a0a86f895369ae5890492bc599125 (patch)
tree90fd1946179916ec8df2e78522f915e0eebee8b5
parent0bb03d25be42121f596662c7e8c299b4d60c887f (diff)
downloadhaskell-eba746567b3a0a86f895369ae5890492bc599125.tar.gz
base: Use unsafeWithForeignPtr in GHC.IO.Buffer
(cherry picked from commit 3d4585fd11f84c8fa5b33fa02469074b187b61cd)
-rw-r--r--libraries/base/GHC/IO/Buffer.hs11
1 files changed, 6 insertions, 5 deletions
diff --git a/libraries/base/GHC/IO/Buffer.hs b/libraries/base/GHC/IO/Buffer.hs
index 167bc2a346..68699d4a74 100644
--- a/libraries/base/GHC/IO/Buffer.hs
+++ b/libraries/base/GHC/IO/Buffer.hs
@@ -72,6 +72,7 @@ import GHC.Word
import GHC.Show
import GHC.Real
import GHC.List
+import GHC.ForeignPtr (unsafeWithForeignPtr)
import Foreign.C.Types
import Foreign.ForeignPtr
import Foreign.Storable
@@ -103,10 +104,10 @@ import Foreign.Storable
type RawBuffer e = ForeignPtr e
readWord8Buf :: RawBuffer Word8 -> Int -> IO Word8
-readWord8Buf arr ix = withForeignPtr arr $ \p -> peekByteOff p ix
+readWord8Buf fp ix = unsafeWithForeignPtr fp $ \p -> peekByteOff p ix
writeWord8Buf :: RawBuffer Word8 -> Int -> Word8 -> IO ()
-writeWord8Buf arr ix w = withForeignPtr arr $ \p -> pokeByteOff p ix w
+writeWord8Buf fp ix w = unsafeWithForeignPtr fp $ \p -> pokeByteOff p ix w
#if defined(CHARBUF_UTF16)
type CharBufElem = Word16
@@ -117,17 +118,17 @@ type CharBufElem = Char
type RawCharBuffer = RawBuffer CharBufElem
peekCharBuf :: RawCharBuffer -> Int -> IO Char
-peekCharBuf arr ix = withForeignPtr arr $ \p -> do
+peekCharBuf arr ix = unsafeWithForeignPtr arr $ \p -> do
(c,_) <- readCharBufPtr p ix
return c
{-# INLINE readCharBuf #-}
readCharBuf :: RawCharBuffer -> Int -> IO (Char, Int)
-readCharBuf arr ix = withForeignPtr arr $ \p -> readCharBufPtr p ix
+readCharBuf arr ix = unsafeWithForeignPtr arr $ \p -> readCharBufPtr p ix
{-# INLINE writeCharBuf #-}
writeCharBuf :: RawCharBuffer -> Int -> Char -> IO Int
-writeCharBuf arr ix c = withForeignPtr arr $ \p -> writeCharBufPtr p ix c
+writeCharBuf arr ix c = unsafeWithForeignPtr arr $ \p -> writeCharBufPtr p ix c
{-# INLINE readCharBufPtr #-}
readCharBufPtr :: Ptr CharBufElem -> Int -> IO (Char, Int)