From: Don Stewart Date: Thu, 18 May 2006 01:21:54 +0000 (+0000) Subject: copyCString* should be in IO. Spotted by Tomasz Zielonka X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=2eb61c24bbe3a2ec1efc8e875f43f7a54f0d0f94;p=ghc-base.git copyCString* should be in IO. Spotted by Tomasz Zielonka --- diff --git a/Data/ByteString.hs b/Data/ByteString.hs index 06ace6b..139609c 100644 --- a/Data/ByteString.hs +++ b/Data/ByteString.hs @@ -1699,12 +1699,12 @@ copy (PS x s l) = create l $ \p -> withForeignPtr x $ \f -> -- | /O(n)/ Duplicate a CString as a ByteString. Useful if you know the -- CString is going to be deallocated from C land. -copyCString :: CString -> ByteString +copyCString :: CString -> IO ByteString copyCString cstr = copyCStringLen (cstr, (fromIntegral $ c_strlen cstr)) -- | /O(n)/ Same as copyCString, but saves a strlen call when the length is known. -copyCStringLen :: CStringLen -> ByteString -copyCStringLen (cstr, len) = inlinePerformIO $ do +copyCStringLen :: CStringLen -> IO ByteString +copyCStringLen (cstr, len) = do fp <- mallocForeignPtrArray (len+1) withForeignPtr fp $ \p -> do memcpy p (castPtr cstr) (fromIntegral len)