Stack overflow when using unpackCStringIO on strings > 65 KB
Christian Lescher
christian at lescher.de
Sun Apr 22 12:36:49 EDT 2001
Recently, I was trying out again some Win DLLs built with GHC4.08.2 and
Cygwin.
I discovered that unpackCStringIO (module CStrings, package lang)
produces a stack overflow when applied to strings > 65 KB, which seems a
little strange to me. Is this a bug - or at least a too stack-intensive
implementation of unpackCStringIO?
I attached some sample code for reproducing the problem. It is a small
Win DLL with a "revstring" function that reverses a given string.
module RevStringDll where
import CString
import Addr
import ByteArray
foreign export stdcall revstring :: Addr -> IO Addr
revstring :: Addr -> IO Addr
revstring cstr = do
s <- unpackCStringIO cstr
r <- packStringIO (reverse s)
res <- mallocAndStrCpy r
return res
foreign import ccall unsafe mallocAndStrCpy :: ByteArray Int -> IO
Addr
I compile it like this:
ghc -c dllMain.c
ghc -c mallocAndStrCpy.c
ghc -c RevStringDll.hs -package lang -fglasgow-exts
ghc --mk-dll -optdll--def=revstr.def -o revstr.dll *.o -lHSrts
-package lang
What can I do about this problem? Is this maybe already fixed in GHC5.0?
BTW: For passing back the string result, I use an addional C function
"mallocAndStrCpy". Can I do without by replacing it with some Haskell
code?
Christian
-------------- next part --------------
A non-text attachment was scrubbed...
Name: revstr.def
Type: application/x-unknown-content-type-def_auto_file
Size: 65 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/glasgow-haskell-bugs/attachments/20010422/202636e4/revstr.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mallocAndStrCpy.c
Type: application/x-unknown-content-type-c_auto_file
Size: 260 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/glasgow-haskell-bugs/attachments/20010422/202636e4/mallocAndStrCpy.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: dllMain.c
Type: application/x-unknown-content-type-c_auto_file
Size: 518 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/glasgow-haskell-bugs/attachments/20010422/202636e4/dllMain.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: RevStringDll.hs
Type: application/x-unknown-content-type-hs_auto_file
Size: 365 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/glasgow-haskell-bugs/attachments/20010422/202636e4/RevStringDll.bin
More information about the Glasgow-haskell-bugs
mailing list