projects
/
ghc-base.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
0df0a6b
)
copyCString* should be in IO. Spotted by Tomasz Zielonka
author
Don Stewart
<dons@cse.unsw.edu.au>
Thu, 18 May 2006 01:21:54 +0000
(
01:21
+0000)
committer
Don Stewart
<dons@cse.unsw.edu.au>
Thu, 18 May 2006 01:21:54 +0000
(
01:21
+0000)
Data/ByteString.hs
patch
|
blob
|
history
diff --git
a/Data/ByteString.hs
b/Data/ByteString.hs
index
06ace6b
..
139609c
100644
(file)
--- 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.
-- | /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.
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)
fp <- mallocForeignPtrArray (len+1)
withForeignPtr fp $ \p -> do
memcpy p (castPtr cstr) (fromIntegral len)