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

revstr.def

mallocAndStrCpy.c

dllMain.c

RevStringDll.hs

Reply via email to