In order to find out more about the missing Garbage Collection, I tried to call at least Main.main from outside:
main.hs:
module Main where
foo :: Int -> IO Int
foo n = return (length (f n))
f :: Int -> [Int]
f 0 = []
f n = n:(f (n-1))
main = foo 2500 >>= \r -> writeFile "output.txt" (show r)
caller_main.c:
#include <Rts.h>
#include <RtsAPI.h>
extern const StgClosure PrelMain_mainIO_closure;
#define mainIO_closure (&PrelMain_mainIO_closure)
void __stdcall caller_main()
{
SchedulerStatus status;
status = rts_evalIO((HaskellObj)mainIO_closure, NULL);
}
dllMain.c:
#include <windows.h>
#include <Rts.h>
static char* args[] = { "ghcDll" };
EXTFUN(__init_PrelMain);
BOOL
STDCALL
DllMain
( HANDLE hModule
, DWORD reason
, void* reserved
)
{
if (reason == DLL_PROCESS_ATTACH) {
/* By now, the RTS DLL should have been hoisted in, but we need to start it up. */
startupHaskell(1, args,__init_PrelMain);
return TRUE;
}
return TRUE;
}
main.def:
EXPORTS
caller_main at 0
Compilation:
ghc -c -static main.hs
ghc -c -static dllMain.c
ghc -c -static caller_main.c
ghc -static --mk-dll -optdll--def=main.def -o main.dll *.o -lHSrts
In this case, the execution of "caller_main" succeeds even when repeating it many times, the initialization of the GC seems to be okay here.
But when increasing the argument of foo in Main.main to e.g. 7500, the first call of "caller_main" leads to an access voilation error ("Access
violation at addr. 69B8A569. Reading from addr. FFFFFFFF."):
main = foo 7500 >>= \r -> writeFile "output.txt" (show r)
So there seem to be two problems:
1) Initialization of the GC also for "standalone functions" - probably an existential question for all tools like HDirect that base on Win-DLLs
(DLL, COM, ...)!
2) Some problem with DLL memory sizes or a bug in GHC?!
For making it possible to reproduce the errors, I attached the files of this and the former example.
Compiling the former example:
ghc -c -static foo.hs -fglasgow-exts
ghc -c -static dllMain.c
ghc -static --mk-dll -optdll--def=foo.def -o foo.dll *.o -lHSrts
-------------- next part --------------
A non-text attachment was scrubbed...
Name: example-main.ZIP
Type: application/x-zip-compressed
Size: 1042 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/glasgow-haskell-bugs/attachments/20001101/33afad9c/example-main.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: example-foo.ZIP
Type: application/x-zip-compressed
Size: 719 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/glasgow-haskell-bugs/attachments/20001101/33afad9c/example-foo.bin