From eba746567b3a0a86f895369ae5890492bc599125 Mon Sep 17 00:00:00 2001 From: Ben Gamari Date: Thu, 22 Oct 2020 19:18:41 -0400 Subject: base: Use unsafeWithForeignPtr in GHC.IO.Buffer (cherry picked from commit 3d4585fd11f84c8fa5b33fa02469074b187b61cd) --- libraries/base/GHC/IO/Buffer.hs | 11 ++++++----- 1 file 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) -- cgit v1.2.1