From 910fc382e58732745b69540cec575610bbe3ecc6 Mon Sep 17 00:00:00 2001 From: Bodigrim Date: Sun, 18 Aug 2024 14:54:00 +0100 Subject: [PATCH] Fix t_peek_cstring test --- src/Data/Text/Foreign.hs | 3 +++ tests/Tests/Properties/LowLevel.hs | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Data/Text/Foreign.hs b/src/Data/Text/Foreign.hs index ca2b2702..b9fbf393 100644 --- a/src/Data/Text/Foreign.hs +++ b/src/Data/Text/Foreign.hs @@ -158,6 +158,9 @@ asForeignPtr t@(Text _arr _off len) = do -- | Marshal a 'Text' into a C string with a trailing NUL byte, -- encoded as UTF-8 in temporary storage. -- +-- The 'Text' itself must not contain any NUL bytes, this precondition +-- is not checked. Cf. 'withCStringLen'. +-- -- The temporary storage is freed when the subcomputation terminates -- (either normally or via an exception), so the pointer to the -- temporary storage must /not/ be used after this function returns. diff --git a/tests/Tests/Properties/LowLevel.hs b/tests/Tests/Properties/LowLevel.hs index 7d19cc5e..32a1b063 100644 --- a/tests/Tests/Properties/LowLevel.hs +++ b/tests/Tests/Properties/LowLevel.hs @@ -73,7 +73,7 @@ t_use_from0 t = ioProperty $ do let t' = t `T.snoc` '\0' (== T.takeWhile (/= '\0') t') <$> useAsPtr t' (const . fromPtr0) -t_peek_cstring t = ioProperty $ do +t_peek_cstring t = T.all (/= '\0') t ==> ioProperty $ do roundTrip <- T.withCString t T.peekCString assertEqual "cstring" t roundTrip