Finalizers and FFI

Gracjan Polak gracjan at
Fri Jun 11 10:02:45 EDT 2004

Krasimir Angelov wrote:
> 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.

You are right, I did not think about that. I would expect at least a 
warning from compiler in this case.

Compilation with stub function produced perfect result. It worked.

As far as I know ia32 assembly the only thing that the stub does is 
something like:

      subl <needed_stack_space>, %esp

This could be made automagicaly by GHC... OK, enough ranting :)

Other question: having myPtr :: FunPtr Int, how do I call it from 
Haskell? Is there a way to just invoke function pointer?

>>Warnings in compilation are also strange:
>>$ ghc -package win32  --make interlvIO.hs -o
>>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.

-fvia-C removed warnings but the program crashes anyway without hand 
written stubs. At first I thought that those "stdcall-fixups" were in 
fact "stdcall to ccall" wrappers. OK, nevermind.

Pozdrawiam, Regards,

More information about the Glasgow-haskell-users mailing list