--- Allocate a mutable array of characters with no indices.
-
-allocChars :: Int -> IO (MutableByteArray RealWorld ())
-allocChars (I# size#) = IO $ \ s# ->
- case newCharArray# size# s# of
- StateAndMutableByteArray# s2# barr# ->
- IOok s2# (MutableByteArray bot barr#)
- where
- bot = error "PosixUtil.allocChars"
-
--- Allocate a mutable array of words with no indices
-
-allocWords :: Int -> IO (MutableByteArray RealWorld ())
-allocWords (I# size#) = IO $ \ s# ->
- case newIntArray# size# s# of
- StateAndMutableByteArray# s2# barr# ->
- IOok s2# (MutableByteArray bot barr#)
- where
- bot = error "PosixUtil.allocWords"
-
--- Freeze these index-free mutable arrays
-
-freeze :: MutableByteArray RealWorld () -> IO (ByteArray ())
-freeze (MutableByteArray ixs arr#) = IO $ \ s# ->
- case unsafeFreezeByteArray# arr# s# of
- StateAndByteArray# s2# frozen# ->
- IOok s2# (ByteArray ixs frozen#)
-
--- Copy a null-terminated string from outside the heap to
--- Haskellized nonsense inside the heap
-
-strcpy :: Addr -> IO String
-strcpy str = unpackCStringIO str
-
--- Turn a string list into a NULL-terminated vector of null-terminated
--- strings No indices...I hate indices. Death to Ix.
-
-vectorize :: [String] -> IO (ByteArray ())
-vectorize xs = do
- arr <- allocWords (len + 1)
- fill arr 0 xs
- freeze arr
- where
- len :: Int
- len = length xs
-
- fill :: MutableByteArray RealWorld () -> Int -> [String] -> IO ()
- fill arr n [] =
- _casm_ ``((PP_)%0)[%1] = NULL;'' arr n
- fill arr n (x:xs) =
- stToIO (psToByteArrayST x) >>= \ barr ->
- _casm_ ``((PP_)%0)[%1] = (P_)%2;'' arr n barr
- >>= \ () ->
- fill arr (n+1) xs
-
--- Turn a NULL-terminated vector of null-terminated strings into a string list
--- unvectorize ... (now in misc/Util.lhs)
-