Finalizers and FFI

Krasimir Angelov ka2_mail at yahoo.com
Fri Jun 11 03:44:05 EDT 2004


--- Gracjan Polak <gracjan at student.uci.agh.edu.pl>
wrote:
> foreign import stdcall "windows.h &UnmapViewOfFile"
>                funptrUnmapViewOfFile :: FunPtr (Ptr
> a -> IO ())
> 
> 
> Basically I'd love to do (in Windows world):
> 
> mapTheFileToMemory = do
>     handle  <- winOpenFile(...)
>     mapping <- winCreateFileMapping(...)
>     view    <- winMapViewOfFile(...)
>     finview <- newForeignPtr funptrUnmapViewOfFile
> view
>     return finview
> 
> Strangely enough my finalizer run always this time,
> no need to say 
> performGC or yield'ing at the end of main. But it
> crashes my program :(

The problem here is that the external functions
(instances of type FunPtr) are always executed with
ccall convention regardless of stdcall declaration in
the foreign import. The workaround is to write simple
stub function in C with ccall convention.

> 
> Warnings in compilation are also strange:
> 
> $ ghc -package win32  --make interlvIO.hs -o
> interlvIO.exe
> Chasing modules from: interlvIO.hs
> Compiling Main             ( interlvIO.hs,
> interlvIO.o )
> Linking ...
> Warning: resolving _UnmapViewOfFile by linking to
> _UnmapViewOfFile at 4
> Use --enable-stdcall-fixup to disable these warnings
> Use --disable-stdcall-fixup to disable these fixups

Try to use -fvia-C to avoid the warnings. When the
program is compiled via the native code generator then
windows.h isn't included and this causes the problem.



	
		
__________________________________
Do you Yahoo!?
Friends.  Fun.  Try the all-new Yahoo! Messenger.
http://messenger.yahoo.com/ 


More information about the Glasgow-haskell-users mailing list