I am trying to dynamically load a shared haskell module - and it almost
works... however as
soon as the grabage collector thread runs it frees/moves something and the
program falls over.
Presumably this means I need to use a StablePtr - however I have as yet been
unable to work out
what exactly is the cause. I was hoping somebody with some knowledge of th
einternals of GHC could
help me out...

The summary of what happens is:

        using FFI to call libdl on linux:

                - load module using dlopen (the library is compiled with -optl -shared 
and
the
                        loader is compiled with -rdynamic, so after loading all static 
symbols
                        should be resolved.)

                - using dlsym to get a FunPtr to a module initialiser.

                - passing a StablePtr to a (FiniteMap String (SomeFunction)) as well 
as a
dynamically exported
                        continuation function (ie a "main-loop") which takes the 
FiniteMap as an
argument to the
                        initialiser.

                (now in the loaded module)

                - de-reference FiniteMap StablePtr, and add a handler function and
string-identifier
                        using addToFM, then create a newStablePtr to the modified 
FiniteMap and
call the
                        dynamic imported main-loop fn with FiniteMap as argument.

                - main loop calls back to module at a later time - dependant on string
identifier.

when I run this with +RTS -B it successfully loads, links and calls back 3
or 4 times, then goes 'beep'
and dies - I think in the garbage collector thread itself, or as soon as the
GC finishes. Any info that
would shed light on what is happening would be useful.

        Regards,
        Keean Schupke.

_______________________________________________
Glasgow-haskell-users mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users

Reply via email to