Re: Problem exporting Haskell to C via a DLL in GHC 6.6

2007-02-08 Thread Brian Hulley
Simon Peyton-Jones wrote: I don't think there is any reason in principle why GHC can't generate DLLs that "just work", but plainly it's deficient at the moment. The fundamental reason is that the DLL mechanism itself doesn't allow initialization/ shutdown do be hidden from the user of a DLL, b

Re: Problem exporting Haskell to C via a DLL in GHC 6.6

2007-02-07 Thread Simon Marlow
SevenThunders wrote: Another question I have is, is it possible to create a statically linked Haskell library that can be linked using MS VC tools? Also I must say I am a bit confused about the use of the routine __stginit_Bad. Suppose I had multiple Haskell modules each with their own functio

RE: Problem exporting Haskell to C via a DLL in GHC 6.6

2007-02-07 Thread Simon Peyton-Jones
Brian, Matt | In the final analysis this seems to work fairly well. I export an End() | function to Matlab that calls | shutdownHaskell(). I then create a Matlab script that calls End() prior to | clearing the DLL out of the namespace. | Since it appears that shutdownHaskell() can be called agai

Re: Problem exporting Haskell to C via a DLL in GHC 6.6

2007-02-06 Thread SevenThunders
Brian Hulley wrote: > > > > Since Begin would be a function exported by the DLL, Windows would ensure > that the DLL was loaded when it is first called from your application if > it > was not already loaded so there would be no need for an explicit call to > LoadLibrary. > >> and then End

Re: Problem exporting Haskell to C via a DLL in GHC 6.6

2007-02-06 Thread Brian Hulley
SevenThunders wrote: Brian Hulley wrote: SevenThunders wrote: DllMain if (reason == DLL_PROCESS_DETACH) { shutdownHaskell(); return TRUE; } The above *may* be the problem: it is unsafe to do anything in DllMain that... Instead of trying to start/shutdown Haskell from DllMain,

Re: Problem exporting Haskell to C via a DLL in GHC 6.6

2007-02-06 Thread SevenThunders
Simon Marlow-5 wrote: > > > I wonder if you're hitting this bug: > >http://hackage.haskell.org/trac/ghc/ticket/926 > > if so, it's slightly worrying that the same thing happens if you just link > your > program directly to the DLL, rather than loading it explicitly. > > Cheers, >

Re: Problem exporting Haskell to C via a DLL in GHC 6.6

2007-02-06 Thread SevenThunders
Brian Hulley wrote: > > SevenThunders wrote: >> Before I post this as a bug, I thought I'd check to make sure I'm not >> doing something wrong. >> BOOL >> STDCALL >> DllMain >> ( HANDLE hModule >> , DWORD reason >> , void* reserved >> ) >> { >> if (reason == DLL_PROCESS_ATTACH) { >>

Re: Problem exporting Haskell to C via a DLL in GHC 6.6

2007-02-06 Thread Simon Marlow
SevenThunders wrote: Before I post this as a bug, I thought I'd check to make sure I'm not doing something wrong. For this test case, on my windows XP machine I create a simple Haskell routine that counts the characters in a file, create a DLL for that routine and call it from C. The C code give

Re: Problem exporting Haskell to C via a DLL in GHC 6.6

2007-02-06 Thread Brian Hulley
SevenThunders wrote: Before I post this as a bug, I thought I'd check to make sure I'm not doing something wrong. 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