ffi call works fine in ghci but not as ghc compiledsegfault

Hi, please can you help me with following? I have a call to an external dll (via ffi) which if executed from ghci works fine. If I compile my code with 'ghc -o fm Mycode.hs -L. -lextdll' and run it I get 'Segmentation fault/access violation in generated code'. main = do let param = "FilePath" let value = "C:/dev/misc/haskell/services/FM" result <- liftIO $ FM.setmodulestring param value return "done" setmodulestring :: String -> String -> IO CInt setmodulestring param value = do let cParamLength = fromIntegral $ length param ::CInt cValueLength = fromIntegral $ length value ::CInt setVarInArray = (-1)::CInt alloca $ \cParam -> do alloca $ \cValue -> do result <- c_setmodulestring cParam cParamLength cValue cValueLength setVarInArray return result If I try also with following, the behaviour is the same: setmodulestring2 :: String -> String -> IO CInt setmodulestring2 param value = do cParam <- newCWString param cValue <- newCWString value let cParamLength = fromIntegral $ length param ::CInt cValueLength = fromIntegral $ length value ::CInt setVarInArray = (-1)::CInt result <- c_setmodulestring cParam cParamLength cValue cValueLength setVarInArray free cParam free cValue return res Any comments/ideas more than appreciated. Cheers, Miro

On 03/14/2014 11:24 PM, Miroslav Karpis wrote:
Hi, please can you help me with following?
I have a call to an external dll (via ffi) which if executed from ghci works fine. If I compile my code with 'ghc -o fm Mycode.hs -L. -lextdll' and run it I get 'Segmentation fault/access violation in generated code'.
main = do let param = "FilePath" let value = "C:/dev/misc/haskell/services/FM" result <- liftIO $ FM.setmodulestring param value return "done"
setmodulestring :: String -> String -> IO CInt setmodulestring param value = do let cParamLength = fromIntegral $ length param ::CInt cValueLength = fromIntegral $ length value ::CInt setVarInArray = (-1)::CInt alloca $ \cParam -> do alloca $ \cValue -> do result <- c_setmodulestring cParam cParamLength cValue cValueLength setVarInArray return result
This does not seems correct (or incomplete).
If I try also with following, the behaviour is the same:
setmodulestring2 :: String -> String -> IO CInt setmodulestring2 param value = do cParam <- newCWString param cValue <- newCWString value let cParamLength = fromIntegral $ length param ::CInt cValueLength = fromIntegral $ length value ::CInt setVarInArray = (-1)::CInt result <- c_setmodulestring cParam cParamLength cValue cValueLength setVarInArray free cParam free cValue return res
This one may be correct but without, seeing C code (where it probably segfaults) I cannot say anything further. exact ffi declaration of c_setmodulestring would be usefull, too, to compare with C function.

here comes the c definition: int setmodulestring(char* parameter, int parameterLength, char* value, int valueLength, int setVarInArray); In ghci the main and setmodulestring functions works fine On Sat, Mar 15, 2014 at 12:14 AM, Branimir Maksimovic < branimir.maksimovic@gmail.com> wrote:
On 03/14/2014 11:24 PM, Miroslav Karpis wrote:
Hi, please can you help me with following?
I have a call to an external dll (via ffi) which if executed from ghci works fine. If I compile my code with 'ghc -o fm Mycode.hs -L. -lextdll' and run it I get 'Segmentation fault/access violation in generated code'.
main = do let param = "FilePath" let value = "C:/dev/misc/haskell/services/FM" result <- liftIO $ FM.setmodulestring param value return "done"
setmodulestring :: String -> String -> IO CInt setmodulestring param value = do let cParamLength = fromIntegral $ length param ::CInt cValueLength = fromIntegral $ length value ::CInt setVarInArray = (-1)::CInt alloca $ \cParam -> do alloca $ \cValue -> do result <- c_setmodulestring cParam cParamLength cValue cValueLength setVarInArray return result
This does not seems correct (or incomplete).
If I try also with following, the behaviour is the same:
setmodulestring2 :: String -> String -> IO CInt setmodulestring2 param value = do cParam <- newCWString param cValue <- newCWString value let cParamLength = fromIntegral $ length param ::CInt cValueLength = fromIntegral $ length value ::CInt setVarInArray = (-1)::CInt result <- c_setmodulestring cParam cParamLength cValue cValueLength setVarInArray free cParam free cValue return res
This one may be correct but without, seeing C code (where it probably segfaults) I cannot say anything further. exact ffi declaration of c_setmodulestring would be usefull, too, to compare with C function.
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

You are passing wchar_t* and function expects char*. On 03/15/2014 12:23 AM, Miro Karpis wrote:
here comes the c definition:
int setmodulestring(char* parameter, int parameterLength, char* value, int valueLength, int setVarInArray);
In ghci the main and setmodulestring functions works fine
On Sat, Mar 15, 2014 at 12:14 AM, Branimir Maksimovic
mailto:branimir.maksimovic@gmail.com> wrote: On 03/14/2014 11:24 PM, Miroslav Karpis wrote:
Hi, please can you help me with following?
I have a call to an external dll (via ffi) which if executed from ghci works fine. If I compile my code with 'ghc -o fm Mycode.hs -L. -lextdll' and run it I get 'Segmentation fault/access violation in generated code'.
main = do let param = "FilePath" let value = "C:/dev/misc/haskell/services/FM" result <- liftIO $ FM.setmodulestring param value return "done"
setmodulestring :: String -> String -> IO CInt setmodulestring param value = do let cParamLength = fromIntegral $ length param ::CInt cValueLength = fromIntegral $ length value ::CInt setVarInArray = (-1)::CInt alloca $ \cParam -> do alloca $ \cValue -> do result <- c_setmodulestring cParam cParamLength cValue cValueLength setVarInArray return result
This does not seems correct (or incomplete).
If I try also with following, the behaviour is the same:
setmodulestring2 :: String -> String -> IO CInt setmodulestring2 param value = do cParam <- newCWString param cValue <- newCWString value let cParamLength = fromIntegral $ length param ::CInt cValueLength = fromIntegral $ length value ::CInt setVarInArray = (-1)::CInt result <- c_setmodulestring cParam cParamLength cValue cValueLength setVarInArray free cParam free cValue return res
This one may be correct but without, seeing C code (where it probably segfaults) I cannot say anything further. exact ffi declaration of c_setmodulestring would be usefull, too, to compare with C function.
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org mailto:Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On Fri, Mar 14, 2014 at 7:29 PM, Branimir Maksimovic < branimir.maksimovic@gmail.com> wrote:
You are passing wchar_t* and function expects char*.
FWIW they asked this before (possibly on a different list) and, absent the C information, I pointed out that Win32 API functions use CWString. This was apparently taken to mean that CWString was the only option.... Some awareness of one's platform conventions tends to be helpful when doing FFI. It seems to be absent here. :/ -- brandon s allbery kf8nh sine nomine associates allbery.b@gmail.com ballbery@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net

On Fri, Mar 14, 2014 at 7:23 PM, Miro Karpis
here comes the c definition:
int setmodulestring(char* parameter, int parameterLength, char* value, int valueLength, int setVarInArray);
If you had included this before (or perhaps noted that I specified Win32 API, not general C function) then I wouldn't have raised the CWString issue. This declaration is not Win32 API and the original CString was correct for it. If you're still having issues... does this by any chance have any association with threads? ghci uses the threaded runtime *and* handles threads slightly differently from compiled code with -threaded (if it core dumps in ghci with -no-ghci-sandbox then this may be the issue)? -- brandon s allbery kf8nh sine nomine associates allbery.b@gmail.com ballbery@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net

I do not think i can help you, but my FFi to functions with similar signature looks like this: C definition: PDFLIB_API int PDFLIB_CALL PDF_begin_document(PDF *p, const char *filename, int len, const char *optlist); haskell FFI: c_beginDocument :: Pdf -> String -> String -> IO Int c_beginDocument pdf a2 a3 = withCString a2 $ \a2' -> withCString a3 $ c_beginDocument'_ pdf a2' 0 foreign import ccall safe "Pdflib.chs.h PDF_begin_document" c_beginDocument'_ :: Pdf -> Ptr CChar -> CInt -> Ptr CChar -> IO Int The difference as you see, i'm using withCString to convert from ahskell to C and i'm passing 0 as the string size. On Friday, March 14, 2014 3:24:23 PM UTC-7, Miroslav Karpis wrote:
Hi, please can you help me with following?
I have a call to an external dll (via ffi) which if executed from ghci works fine. If I compile my code with 'ghc -o fm Mycode.hs -L. -lextdll' and run it I get 'Segmentation fault/access violation in generated code'.
main = do let param = "FilePath" let value = "C:/dev/misc/haskell/services/FM" result <- liftIO $ FM.setmodulestring param value return "done"
setmodulestring :: String -> String -> IO CInt setmodulestring param value = do let cParamLength = fromIntegral $ length param ::CInt cValueLength = fromIntegral $ length value ::CInt setVarInArray = (-1)::CInt alloca $ \cParam -> do alloca $ \cValue -> do result <- c_setmodulestring cParam cParamLength cValue cValueLength setVarInArray return result
If I try also with following, the behaviour is the same:
setmodulestring2 :: String -> String -> IO CInt setmodulestring2 param value = do cParam <- newCWString param cValue <- newCWString value let cParamLength = fromIntegral $ length param ::CInt cValueLength = fromIntegral $ length value ::CInt setVarInArray = (-1)::CInt result <- c_setmodulestring cParam cParamLength cValue cValueLength setVarInArray free cParam free cValue return res
Any comments/ideas more than appreciated.
Cheers, Miro

thank you very much - I have tried also that but got the the same behaviour
(seg fault)
cheers,
m.
On Sun, Mar 16, 2014 at 7:45 AM, Vagif Verdi
I do not think i can help you, but my FFi to functions with similar signature looks like this:
C definition:
PDFLIB_API int PDFLIB_CALL PDF_begin_document(PDF *p, const char *filename, int len, const char *optlist);
haskell FFI:
c_beginDocument :: Pdf -> String -> String -> IO Int c_beginDocument pdf a2 a3 = withCString a2 $ \a2' -> withCString a3 $ c_beginDocument'_ pdf a2' 0
foreign import ccall safe "Pdflib.chs.h PDF_begin_document" c_beginDocument'_ :: Pdf -> Ptr CChar -> CInt -> Ptr CChar -> IO Int
The difference as you see, i'm using withCString to convert from ahskell to C and i'm passing 0 as the string size.
On Friday, March 14, 2014 3:24:23 PM UTC-7, Miroslav Karpis wrote:
Hi, please can you help me with following?
I have a call to an external dll (via ffi) which if executed from ghci works fine. If I compile my code with 'ghc -o fm Mycode.hs -L. -lextdll' and run it I get 'Segmentation fault/access violation in generated code'.
main = do let param = "FilePath" let value = "C:/dev/misc/haskell/services/FM" result <- liftIO $ FM.setmodulestring param value return "done"
setmodulestring :: String -> String -> IO CInt setmodulestring param value = do let cParamLength = fromIntegral $ length param ::CInt cValueLength = fromIntegral $ length value ::CInt setVarInArray = (-1)::CInt alloca $ \cParam -> do alloca $ \cValue -> do result <- c_setmodulestring cParam cParamLength cValue cValueLength setVarInArray return result
If I try also with following, the behaviour is the same:
setmodulestring2 :: String -> String -> IO CInt setmodulestring2 param value = do cParam <- newCWString param cValue <- newCWString value let cParamLength = fromIntegral $ length param ::CInt cValueLength = fromIntegral $ length value ::CInt setVarInArray = (-1)::CInt result <- c_setmodulestring cParam cParamLength cValue cValueLength setVarInArray free cParam free cValue return res
Any comments/ideas more than appreciated.
Cheers, Miro

Notice that i have "safe" in my foreign import ccall. This makes it safe to run in threaded mode. Did you try that? Are you on windows? On Sunday, March 16, 2014 1:40:48 AM UTC-7, Miro Karpis wrote:
thank you very much - I have tried also that but got the the same behaviour (seg fault)
cheers, m.
On Sun, Mar 16, 2014 at 7:45 AM, Vagif Verdi
javascript: wrote:
I do not think i can help you, but my FFi to functions with similar signature looks like this:
C definition:
PDFLIB_API int PDFLIB_CALL PDF_begin_document(PDF *p, const char *filename, int len, const char *optlist);
haskell FFI:
c_beginDocument :: Pdf -> String -> String -> IO Int c_beginDocument pdf a2 a3 = withCString a2 $ \a2' -> withCString a3 $ c_beginDocument'_ pdf a2' 0
foreign import ccall safe "Pdflib.chs.h PDF_begin_document" c_beginDocument'_ :: Pdf -> Ptr CChar -> CInt -> Ptr CChar -> IO Int
The difference as you see, i'm using withCString to convert from ahskell to C and i'm passing 0 as the string size.
On Friday, March 14, 2014 3:24:23 PM UTC-7, Miroslav Karpis wrote:
Hi, please can you help me with following?
I have a call to an external dll (via ffi) which if executed from ghci works fine. If I compile my code with 'ghc -o fm Mycode.hs -L. -lextdll' and run it I get 'Segmentation fault/access violation in generated code'.
main = do let param = "FilePath" let value = "C:/dev/misc/haskell/services/FM" result <- liftIO $ FM.setmodulestring param value return "done"
setmodulestring :: String -> String -> IO CInt setmodulestring param value = do let cParamLength = fromIntegral $ length param ::CInt cValueLength = fromIntegral $ length value ::CInt setVarInArray = (-1)::CInt alloca $ \cParam -> do alloca $ \cValue -> do result <- c_setmodulestring cParam cParamLength cValue cValueLength setVarInArray return result
If I try also with following, the behaviour is the same:
setmodulestring2 :: String -> String -> IO CInt setmodulestring2 param value = do cParam <- newCWString param cValue <- newCWString value let cParamLength = fromIntegral $ length param ::CInt cValueLength = fromIntegral $ length value ::CInt setVarInArray = (-1)::CInt result <- c_setmodulestring cParam cParamLength cValue cValueLength setVarInArray free cParam free cValue return res
Any comments/ideas more than appreciated.
Cheers, Miro

thanks. Have tried with safe - still seg-fault.
On Sun, Mar 16, 2014 at 5:09 PM, Vagif Verdi
Notice that i have "safe" in my foreign import ccall. This makes it safe to run in threaded mode. Did you try that?
Are you on windows?
On Sunday, March 16, 2014 1:40:48 AM UTC-7, Miro Karpis wrote:
thank you very much - I have tried also that but got the the same behaviour (seg fault)
cheers, m.
On Sun, Mar 16, 2014 at 7:45 AM, Vagif Verdi
wrote: I do not think i can help you, but my FFi to functions with similar signature looks like this:
C definition:
PDFLIB_API int PDFLIB_CALL PDF_begin_document(PDF *p, const char *filename, int len, const char *optlist);
haskell FFI:
c_beginDocument :: Pdf -> String -> String -> IO Int c_beginDocument pdf a2 a3 = withCString a2 $ \a2' -> withCString a3 $ c_beginDocument'_ pdf a2' 0
foreign import ccall safe "Pdflib.chs.h PDF_begin_document" c_beginDocument'_ :: Pdf -> Ptr CChar -> CInt -> Ptr CChar -> IO Int
The difference as you see, i'm using withCString to convert from ahskell to C and i'm passing 0 as the string size.
On Friday, March 14, 2014 3:24:23 PM UTC-7, Miroslav Karpis wrote:
Hi, please can you help me with following?
I have a call to an external dll (via ffi) which if executed from ghci works fine. If I compile my code with 'ghc -o fm Mycode.hs -L. -lextdll' and run it I get 'Segmentation fault/access violation in generated code'.
main = do let param = "FilePath" let value = "C:/dev/misc/haskell/services/FM" result <- liftIO $ FM.setmodulestring param value return "done"
setmodulestring :: String -> String -> IO CInt setmodulestring param value = do let cParamLength = fromIntegral $ length param ::CInt cValueLength = fromIntegral $ length value ::CInt setVarInArray = (-1)::CInt alloca $ \cParam -> do alloca $ \cValue -> do result <- c_setmodulestring cParam cParamLength cValue cValueLength setVarInArray return result
If I try also with following, the behaviour is the same:
setmodulestring2 :: String -> String -> IO CInt setmodulestring2 param value = do cParam <- newCWString param cValue <- newCWString value let cParamLength = fromIntegral $ length param ::CInt cValueLength = fromIntegral $ length value ::CInt setVarInArray = (-1)::CInt result <- c_setmodulestring cParam cParamLength cValue cValueLength setVarInArray free cParam free cValue return res
Any comments/ideas more than appreciated.
Cheers, Miro

what version of ghc and cabal?
have you tried cabalizing the code and seeing what flags its passing? is it
possible you're passing the wrong flags?
On Sun, Mar 16, 2014 at 5:21 PM, Miro Karpis
thanks. Have tried with safe - still seg-fault.
On Sun, Mar 16, 2014 at 5:09 PM, Vagif Verdi
wrote: Notice that i have "safe" in my foreign import ccall. This makes it safe to run in threaded mode. Did you try that?
Are you on windows?
On Sunday, March 16, 2014 1:40:48 AM UTC-7, Miro Karpis wrote:
thank you very much - I have tried also that but got the the same behaviour (seg fault)
cheers, m.
On Sun, Mar 16, 2014 at 7:45 AM, Vagif Verdi
wrote: I do not think i can help you, but my FFi to functions with similar signature looks like this:
C definition:
PDFLIB_API int PDFLIB_CALL PDF_begin_document(PDF *p, const char *filename, int len, const char *optlist);
haskell FFI:
c_beginDocument :: Pdf -> String -> String -> IO Int c_beginDocument pdf a2 a3 = withCString a2 $ \a2' -> withCString a3 $ c_beginDocument'_ pdf a2' 0
foreign import ccall safe "Pdflib.chs.h PDF_begin_document" c_beginDocument'_ :: Pdf -> Ptr CChar -> CInt -> Ptr CChar -> IO Int
The difference as you see, i'm using withCString to convert from ahskell to C and i'm passing 0 as the string size.
On Friday, March 14, 2014 3:24:23 PM UTC-7, Miroslav Karpis wrote:
Hi, please can you help me with following?
I have a call to an external dll (via ffi) which if executed from ghci works fine. If I compile my code with 'ghc -o fm Mycode.hs -L. -lextdll' and run it I get 'Segmentation fault/access violation in generated code'.
main = do let param = "FilePath" let value = "C:/dev/misc/haskell/services/FM" result <- liftIO $ FM.setmodulestring param value return "done"
setmodulestring :: String -> String -> IO CInt setmodulestring param value = do let cParamLength = fromIntegral $ length param ::CInt cValueLength = fromIntegral $ length value ::CInt setVarInArray = (-1)::CInt alloca $ \cParam -> do alloca $ \cValue -> do result <- c_setmodulestring cParam cParamLength cValue cValueLength setVarInArray return result
If I try also with following, the behaviour is the same:
setmodulestring2 :: String -> String -> IO CInt setmodulestring2 param value = do cParam <- newCWString param cValue <- newCWString value let cParamLength = fromIntegral $ length param ::CInt cValueLength = fromIntegral $ length value ::CInt setVarInArray = (-1)::CInt result <- c_setmodulestring cParam cParamLength cValue cValueLength setVarInArray free cParam free cValue return res
Any comments/ideas more than appreciated.
Cheers, Miro
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Hi, sorry, but not sure what you mean with 'cabalizing the code and seeing the flags its passing'. cabal-install version 1.16.0.2 using version 1.16.0 of the Cabal library ghc: version 7.6.3 after looking a bit more I can see that the ffi call does what it should do, but it crashes right after that. As mentioned before in ghci everything runs fine. On Sun, Mar 16, 2014 at 11:20 PM, Carter Schonwald < carter.schonwald@gmail.com> wrote:
what version of ghc and cabal?
have you tried cabalizing the code and seeing what flags its passing? is it possible you're passing the wrong flags?
On Sun, Mar 16, 2014 at 5:21 PM, Miro Karpis
wrote: thanks. Have tried with safe - still seg-fault.
On Sun, Mar 16, 2014 at 5:09 PM, Vagif Verdi
wrote: Notice that i have "safe" in my foreign import ccall. This makes it safe to run in threaded mode. Did you try that?
Are you on windows?
On Sunday, March 16, 2014 1:40:48 AM UTC-7, Miro Karpis wrote:
thank you very much - I have tried also that but got the the same behaviour (seg fault)
cheers, m.
On Sun, Mar 16, 2014 at 7:45 AM, Vagif Verdi
wrote: I do not think i can help you, but my FFi to functions with similar signature looks like this:
C definition:
PDFLIB_API int PDFLIB_CALL PDF_begin_document(PDF *p, const char *filename, int len, const char *optlist);
haskell FFI:
c_beginDocument :: Pdf -> String -> String -> IO Int c_beginDocument pdf a2 a3 = withCString a2 $ \a2' -> withCString a3 $ c_beginDocument'_ pdf a2' 0
foreign import ccall safe "Pdflib.chs.h PDF_begin_document" c_beginDocument'_ :: Pdf -> Ptr CChar -> CInt -> Ptr CChar -> IO Int
The difference as you see, i'm using withCString to convert from ahskell to C and i'm passing 0 as the string size.
On Friday, March 14, 2014 3:24:23 PM UTC-7, Miroslav Karpis wrote:
Hi, please can you help me with following?
I have a call to an external dll (via ffi) which if executed from ghci works fine. If I compile my code with 'ghc -o fm Mycode.hs -L. -lextdll' and run it I get 'Segmentation fault/access violation in generated code'.
main = do let param = "FilePath" let value = "C:/dev/misc/haskell/services/FM" result <- liftIO $ FM.setmodulestring param value return "done"
setmodulestring :: String -> String -> IO CInt setmodulestring param value = do let cParamLength = fromIntegral $ length param ::CInt cValueLength = fromIntegral $ length value ::CInt setVarInArray = (-1)::CInt alloca $ \cParam -> do alloca $ \cValue -> do result <- c_setmodulestring cParam cParamLength cValue cValueLength setVarInArray return result
If I try also with following, the behaviour is the same:
setmodulestring2 :: String -> String -> IO CInt setmodulestring2 param value = do cParam <- newCWString param cValue <- newCWString value let cParamLength = fromIntegral $ length param ::CInt cValueLength = fromIntegral $ length value ::CInt setVarInArray = (-1)::CInt result <- c_setmodulestring cParam cParamLength cValue cValueLength setVarInArray free cParam free cValue return res
Any comments/ideas more than appreciated.
Cheers, Miro
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On Sun, Mar 16, 2014 at 6:38 PM, Miro Karpis
after looking a bit more I can see that the ffi call does what it should do, but it crashes right after that. As mentioned before in ghci everything runs fine.
I don't think I got an answer to this before: does it still work in ghci if you run it with ghci -fno-ghci-sandbox ? -- brandon s allbery kf8nh sine nomine associates allbery.b@gmail.com ballbery@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net

sorry,...yes it works with -fno-ghci-sandbox (no seg.fault)
On Sun, Mar 16, 2014 at 11:47 PM, Brandon Allbery
On Sun, Mar 16, 2014 at 6:38 PM, Miro Karpis
wrote: after looking a bit more I can see that the ffi call does what it should do, but it crashes right after that. As mentioned before in ghci everything runs fine.
I don't think I got an answer to this before: does it still work in ghci if you run it with
ghci -fno-ghci-sandbox
?
-- brandon s allbery kf8nh sine nomine associates allbery.b@gmail.com ballbery@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net

I finally managed to fix the seg-fault. Brandon and Branimir you were as
always right ;-) . Problem was in the external function definition. After
changing it to 'stdcall' everything works fine.
for further reference working code below:
foreign import stdcall safe "setmodulestring" c_setmodulestring :: CString
-> CUInt -> CString -> CUInt -> CInt -> IO CInt
--all 3 versions work fine:
setmodulestring param value = do
cParam <- newCString param
cValue <- newCString value
let cParamLength = fromIntegral $ length param ::CUInt
cValueLength = fromIntegral $ length value ::CUInt
setVarInArray = (-1)::CInt
result <- c_setmodulestring cParam cParamLength cValue cValueLength
setVarInArray
free cParam
free cValue
return result
setmodulestring2 param value = do
let cParamLength = fromIntegral $ length param ::CUInt
cValueLength = fromIntegral $ length value ::CUInt
setVarInArray = (-1)::CInt
B.useAsCString (B.pack param) $ \cParam -> do
B.useAsCString (B.pack value) $ \cValue -> do
result <- c_setmodulestring cParam cParamLength cValue cValueLength
setVarInArray
return result
setmodulestring3 param value =
withCString param $ \cParam -> do
withCString value $ \cValue -> do
result <- c_setmodulestring cParam cParamLength cValue cValueLength
setVarInArray
return result
where
cParamLength = fromIntegral $ length param ::CUInt
cValueLength = fromIntegral $ length value ::CUInt
setVarInArray = (-1)::CInt
thank you cafe, for helping me along this ;-)
On Sun, Mar 16, 2014 at 11:57 PM, Miro Karpis
sorry,...yes it works with -fno-ghci-sandbox (no seg.fault)
On Sun, Mar 16, 2014 at 11:47 PM, Brandon Allbery
wrote: On Sun, Mar 16, 2014 at 6:38 PM, Miro Karpis
wrote: after looking a bit more I can see that the ffi call does what it should do, but it crashes right after that. As mentioned before in ghci everything runs fine.
I don't think I got an answer to this before: does it still work in ghci if you run it with
ghci -fno-ghci-sandbox
?
-- brandon s allbery kf8nh sine nomine associates allbery.b@gmail.com ballbery@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net
participants (6)
-
Brandon Allbery
-
Branimir Maksimovic
-
Carter Schonwald
-
Miro Karpis
-
Miroslav Karpis
-
Vagif Verdi