Skip to content

Commit 32d05c1

Browse files
committed
Clarify documentation of Data.Text.Foreign
- `fromPtr` and `fromPtr0` are unsafe - Merge the "Unsafe conversion code" and "Low-level manipulation" sections
1 parent b807cd9 commit 32d05c1

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

src/Data/Text/Foreign.hs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ module Data.Text.Foreign
1515
-- * Interoperability with native code
1616
-- $interop
1717
I8
18-
-- * Safe conversion functions
18+
-- * Pointer conversion functions
1919
, fromPtr
2020
, fromPtr0
2121
, useAsPtr
@@ -25,13 +25,12 @@ module Data.Text.Foreign
2525
, withCString
2626
, peekCStringLen
2727
, withCStringLen
28-
-- * Unsafe conversion code
29-
, lengthWord8
30-
, unsafeCopyToPtr
3128
-- * Low-level manipulation
3229
-- $lowlevel
3330
, dropWord8
3431
, takeWord8
32+
, lengthWord8
33+
, unsafeCopyToPtr
3534
) where
3635

3736
import Control.Monad.ST.Unsafe (unsafeSTToIO)
@@ -69,6 +68,10 @@ newtype I8 = I8 Int
6968

7069
-- | /O(n)/ Create a new 'Text' from a 'Ptr' 'Word8' by copying the
7170
-- contents of the array.
71+
--
72+
-- __This function is unsafe.__ The source array must contain a valid
73+
-- UTF-8 string of the given length. There are no guarantees about what
74+
-- happens otherwise.
7275
fromPtr :: Ptr Word8 -- ^ source array
7376
-> I8 -- ^ length of source array (in 'Word8' units)
7477
-> IO Text
@@ -82,6 +85,9 @@ fromPtr ptr (I8 len) = unsafeSTToIO $ do
8285
-- | /O(n)/ Create a new 'Text' from a 'Ptr' 'Word8' by copying the
8386
-- contents of the NUL-terminated array.
8487
--
88+
-- __This function is unsafe.__ The source array must contain a NULL-terminated
89+
-- valid UTF-8 string. There are no guarantees about what happens otherwise.
90+
--
8591
-- @since 2.0.1
8692
fromPtr0 :: Ptr Word8 -- ^ source array
8793
-> IO Text

0 commit comments

Comments
 (0)