I see in Foreign.Ptr documentation that it is good practice to
call freeHaskellFunPtr when a pointer to a Haskell function
(obtained using 'dynamic' stubs) is not going to be used anymore.

Is it possible to do that in a way that is similar to ForeignPtr
behavior, where pointers are finalized when GC knows they're not
going to be used anymore? See this attempt:

In an IO monad:
  a <- giveMeFunPtr
  b <- castFunPtrToPtr a :: IO (Ptr something)
  foreignFunPtr <- newForeignPtr funPtrFinalizer b :: IO (ForeignPtr something)

With funPtrFinalizer a FunPtr to:
  baseFunPtrFinalizer p = freeHaskellFunPtr . castPtrToFunPtr p


Is something like that expected to work, i.e., would I get a
ForeignPtr that I could cast and give to foreign functions, and
still expect that my function pointer would be freed when not
needed anymore?

Thanks,
Maurício

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to