Skip to content

Commit

Permalink
Remove zero-termination on 'useByteStringAsCStringLen'
Browse files Browse the repository at this point in the history
  • Loading branch information
tdammers committed Apr 29, 2024
1 parent f1892f4 commit d1e8df9
Showing 1 changed file with 2 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ import qualified Data.ByteString as BS
import qualified Data.ByteString.Unsafe as BS
import Data.Coerce (coerce)
import Data.Typeable
import Data.Word (Word8)
import Debug.Trace (traceShowM)
import Foreign.C.Error (errnoToIOError, getErrno)
import Foreign.C.String (CStringLen)
Expand All @@ -70,7 +69,7 @@ import Foreign.ForeignPtr (ForeignPtr)
import Foreign.ForeignPtr.Unsafe (unsafeForeignPtrToPtr)
import Foreign.Marshal.Utils (fillBytes)
import Foreign.Ptr (Ptr, nullPtr, castPtr)
import Foreign.Storable (Storable (peek), sizeOf, alignment, pokeByteOff)
import Foreign.Storable (Storable (peek), sizeOf, alignment)
import GHC.IO.Exception (ioException)
import GHC.TypeLits (KnownNat, natVal)
import NoThunks.Class (NoThunks, OnlyCheckWhnfNamed (..))
Expand Down Expand Up @@ -220,10 +219,9 @@ allocaBytes size action = do
unpackByteStringCStringLen :: (MonadThrow m, MonadST m) => ByteString -> (CStringLen -> m a) -> m a
unpackByteStringCStringLen bs f = do
let len = BS.length bs
allocaBytes (len + 1) $ \buf -> do
allocaBytes len $ \buf -> do
unsafeIOToMonadST $ BS.unsafeUseAsCString bs $ \ptr -> do
copyMem buf ptr (fromIntegral len)
pokeByteOff buf len (0 :: Word8)
f (buf, len)

packByteStringCStringLen :: MonadST m => CStringLen -> m ByteString
Expand Down

0 comments on commit d1e8df9

Please sign in to comment.