Bug in GHC's Garbage Collection?
Christian Lescher
christian at lescher.de
Sat Oct 28 09:35:36 EDT 2000
Trying to build a Win DLL with Haskell functions, I recognized some
strange things, which look to me like a bug in GHC's garbage collection.
Here's what I did:
1) First Trial:
* Define a module "Foo" (foo.hs):
module Foo where
foreign export stdcall foo :: Int -> IO Int
foo :: Int -> IO Int
foo n = return (length (f n))
f :: Int -> [Int]
f 0 = []
f n = n:(f (n-1))
* Write a def-File (foo.def):
EXPORTS
foo at 4
* Define the DllMain function in C (dllMain.c):
#include <windows.h>
#include <Rts.h>
static char* args[] = { "ghcDll" };
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,NULL);
return TRUE;
}
return TRUE;
}
* Compile it up:
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
* Call "foo" from outside 3 times with the argument 2500:
The first two times the execution succeeds; but the third call ends with
an access violation error ("Zugriffsverletzung bei Adresse 69B89B99.
Lesen von Adresse FFFFFFFF.")
2) Second Trial:
* Write an addional caller-function in C (foo_caller.c), that
start/shuts down the RTS every time calling "foo".
#include "foo_stub.h"
#include "RtsAPI.h"
static char* args[] = { "ghcDll" };
StgInt __stdcall call_foo(StgInt a0)
{
StgInt res;
startupHaskell(1, args,NULL);
res = foo(a0);
shutdownHaskell();
return res;
}
* Adjust the def file:
EXPORTS
foo at 4
call_foo at 4
* Compile it up:
ghc -c -static foo_caller.c
ghc -static --mk-dll -optdll--def=foo.def -o foo.dll *.o -lHSrts
* Call "call_foo" from outside with the argument 2500:
Now everything seems to be okay, the call can be repeated again and
again without any error.
I use GHC 4.08.1 with cygwin 1.1. - I recognized this kind of error also
when compiling with GHC4.05.
What to do about this?
Christian
-------------- next part --------------
A non-text attachment was scrubbed...
Name: foo.hs
Type: application/x-unknown-content-type-hs_auto_file
Size: 171 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/glasgow-haskell-bugs/attachments/20001028/1de0ffd4/foo.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: foo_caller.c
Type: application/x-unknown-content-type-c_auto_file
Size: 230 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/glasgow-haskell-bugs/attachments/20001028/1de0ffd4/foo_caller.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: foo.def
Type: application/x-unknown-content-type-def_auto_file
Size: 35 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/glasgow-haskell-bugs/attachments/20001028/1de0ffd4/foo-0001.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: dllMain.c
Type: application/x-unknown-content-type-c_auto_file
Size: 388 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/glasgow-haskell-bugs/attachments/20001028/1de0ffd4/dllMain.bin
More information about the Glasgow-haskell-bugs
mailing list