scotty + ffi segfault

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

On Fri, Mar 14, 2014 at 4:46 PM, Miro Karpis
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
The path you show earlier looks like Windows; you probably want CWString for Win32 API functions (so newCWString etc.). -- brandon s allbery kf8nh sine nomine associates allbery.b@gmail.com ballbery@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net

thanks, but also after changing my CString/newCString to
CWString/newCWString I'm getting the segfault. As I mentioned if I run
the setmodulestring
function from ghci everyting works fine (I get proper return value). The
problem only comes if I call setmodulestring from the main.
I have simplified the main here:
main = do
let param = "FilePath"
let value = "C:/dev/misc/haskell/services/FM"
result <- liftIO $ FM.setmodulestring param value
return "done"
Another strange thing is that I can call another external function from the
'main' function without problem.
On Fri, Mar 14, 2014 at 9:52 PM, Brandon Allbery
On Fri, Mar 14, 2014 at 4:46 PM, Miro Karpis
wrote: 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
The path you show earlier looks like Windows; you probably want CWString for Win32 API functions (so newCWString etc.).
-- brandon s allbery kf8nh sine nomine associates allbery.b@gmail.com ballbery@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net
participants (2)
-
Brandon Allbery
-
Miro Karpis