[Haskell-beginners] scotty + ffi segfault

Miro Karpis miroslav.karpis at gmail.com
Fri Mar 14 20:46:48 UTC 2014


Hi, please can you help me with following?

I'm trying to combine scotty + ffi but it returns 'Segmentation
fault/access violation in generated code'.

The thing is, that when I run only the ffi setmodulestring function,
everything works fine. When I call it from scotty I get the segfault. I
have hardcoded the 'param' and 'value' parameters in setmodulestring
function just to be sure that the input is correct.

scotty code:

main = scotty 3000 $ do
middleware logStdoutDev

post "/setstringtest" $ do
let param = "FilePath"
let value = "C:/dev/misc/haskell/services/FM"
result <- liftIO $ FM.setmodulestring param value
text "done"

ffi code:

setmodulestring :: String -> String -> IO CInt
setmodulestring param value = do
cParam <- newCString param
cValue <- newCString value
let cParamLength = fromIntegral $ length param ::CInt
    cValueLength = fromIntegral $ length value ::CInt
    setVarInArray = (-1)::CInt
result <- c_setmodulestring cParam cParamLength cValue cValueLength
setVarInArray
return result


Any comments/ideas more than appreciated.

Cheers,
Miro
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20140314/d806ec4c/attachment.html>


More information about the Beginners mailing list