| 1 |
{-# LANGUAGE CPP #-} |
| 2 |
-- | |
| 3 |
-- Module : Test.Tasty.KAT.Internal |
| 4 |
-- License : MIT |
| 5 |
-- Maintainer : Vincent Hanquez <[email protected]> |
| 6 |
-- Stability : experimental |
| 7 |
-- Portability : Good |
| 8 |
-- |
| 9 |
-- compat |
| 10 |
-- |
| 11 |
module Test.Tasty.KAT.Internal |
| 12 |
( unsafeCreateUptoN |
| 13 |
) where |
| 14 |
|
| 15 |
import qualified Data.ByteString.Internal as B |
| 16 |
import Data.ByteString (ByteString) |
| 17 |
import Foreign.Ptr |
| 18 |
import Data.Word |
| 19 |
|
| 20 |
#if !(MIN_VERSION_bytestring(0,10,4)) |
| 21 |
import Foreign.ForeignPtr |
| 22 |
import System.IO.Unsafe (unsafePerformIO) |
| 23 |
#endif |
| 24 |
|
| 25 |
unsafeCreateUptoN :: Int -> (Ptr Word8 -> IO Int) -> ByteString |
| 26 |
#if MIN_VERSION_bytestring(0,10,4) |
| 27 |
unsafeCreateUptoN = B.unsafeCreateUptoN |
| 28 |
#else |
| 29 |
unsafeCreateUptoN len f = unsafePerformIO $ do |
| 30 |
fp <- B.mallocByteString len |
| 31 |
l' <- withForeignPtr fp f |
| 32 |
return $! B.PS fp 0 l' |
| 33 |
#endif |