Popularity
1.4
Declining
Activity
0.0
-
1
1
0

Monthly Downloads: 3
Programming language: Haskell
License: Mozilla Public License 2.0
Tags: Foreign    
Latest version: v0.2.0.0

marshal-contt alternatives and similar packages

Based on the "Foreign" category

Do you think we are missing an alternative of marshal-contt or a related project?

Add another 'Foreign' Package

README

marshal-contt

Hackage Version

A ContT-based wrapper for the bracket-style Haskell-to-C marshalling functions in base and bytestring.

Example:

type Argv = [BS.ByteString]
type Env  = M.Map BS.ByteString BS.ByteString

allocStringArrayWith :: [BS.ByteString] -> ContT r IO (Ptr CString)
allocStringArrayWith = allocaArrayWith0' withCString

allocStringMapWith :: M.Map BS.ByteString BS.ByteString -> (Ptr CString -> IO a) -> IO a
allocStringMapWith = iallocaArrayWith0' (\(k, v) -> withCString $ k <> "=" <> v)

spawn :: FilePath -> [FileActions] -> Argv -> Env -> IO ProcessID
spawn path actions argv env = flip runContT return $ do
    cPath <- withCString path
    cAction <- withFileActions actions
    cArgv <- allocStringArrayWith argv
    cEnv <- marshalEnv env
    pidPtr <- alloca
    liftIO . throwErrnoIf_ (/= 0) path $ 
        posix_spawn pidPtr cPath cActions nullSpawnAttrs cArgv cEnv
    liftIO $ peek pidPtr

spawnp :: String -> [FileActions] -> Argv -> Env -> IO ProcessID
spawnp command actions argv env = flip runContT return $ do
    cPath <- withCString path
    cAction <- withFileActions actions
    cArgv <- allocStringArrayWith argv
    cEnv <- marshalEnv env
    pidPtr <- alloca
    liftIO . throwErrnoIf_ (/= 0) path $ 
        posix_spawnp pidPtr cPath cActions nullSpawnAttrs cArgv cEnv
    liftIO $ peek pidPtr