Skip to content

Commit

Permalink
Move unsafeWithForeignPtr shim into Utils
Browse files Browse the repository at this point in the history
  • Loading branch information
clyring committed Aug 7, 2022
1 parent 6462e4f commit 6df394e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
9 changes: 0 additions & 9 deletions Data/ByteString/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -164,18 +164,9 @@ import GHC.Ptr (Ptr(..))

import GHC.Types (Int (..))

#if MIN_VERSION_base(4,15,0)
import GHC.ForeignPtr (unsafeWithForeignPtr)
#endif

import qualified Language.Haskell.TH.Lib as TH
import qualified Language.Haskell.TH.Syntax as TH

#if !MIN_VERSION_base(4,15,0)
unsafeWithForeignPtr :: ForeignPtr a -> (Ptr a -> IO b) -> IO b
unsafeWithForeignPtr = withForeignPtr
#endif

-- CFILES stuff is Hugs only
{-# CFILES cbits/fpstring.c #-}

Expand Down
7 changes: 7 additions & 0 deletions Data/ByteString/Internal/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module Data.ByteString.Internal.Utils (
plusForeignPtr,
minusForeignPtr,
memcpyf,
unsafeWithForeignPtr,

createf,
createfUptoN,
Expand All @@ -33,7 +34,9 @@ import Foreign.Storable (Storable(..))
import GHC.Exts (Int(I#), minusAddr#)
import GHC.ForeignPtr
( ForeignPtr(ForeignPtr)
#if MIN_VERSION_base(4,15,0)
, unsafeWithForeignPtr
#endif
, mallocPlainForeignPtrBytes
)
import GHC.IO (unsafeDupablePerformIO)
Expand Down Expand Up @@ -84,6 +87,10 @@ pokefpByteOff :: Storable a => ForeignPtr b -> Int -> a -> IO ()
pokefpByteOff fp off val = unsafeWithForeignPtr fp $ \p ->
pokeByteOff p off val

#if !MIN_VERSION_base(4,15,0)
unsafeWithForeignPtr :: ForeignPtr a -> (Ptr a -> IO b) -> IO b
unsafeWithForeignPtr = withForeignPtr
#endif


-- Utilities for ByteString creation
Expand Down

0 comments on commit 6df394e

Please sign in to comment.