mkFreeClosure :: FunPtr a -> IO (FreeClosure a)
mkFreeClosure callback = do
  freef <- wrapFreeFunction freeFunction
  return $ FreeClosure callback freef
  where
    freeFunction :: FreeFunction a
    freeFunction sptr = do
      (FreeClosure cb freef) <- deRefStablePtr sptr
      freeStablePtr sptr
      freeHaskellFunPtr cb
      freeHaskellFunPtr freef  -- XXX we are freeing ourselves.
                               -- XXX this is officially not ok,
                               -- XXX but it seems like it'll do.
mkFreeClosure :: FunPtr a -> IO (FreeClosure a)
mkFreeClosure callback = do
  freef <- wrapFreeFunction freeFunction
  return $ FreeClosure callback freef
  where
    freeFunction :: FreeFunction a
    freeFunction sptr = do
      (FreeClosure cb freef) <- deRefStablePtr sptr
      freeStablePtr sptr
      freeHaskellFunPtr cb
      freeHaskellFunPtr freef  -- XXX we are freeing ourselves.
                               -- XXX this is officially not ok,
                               -- XXX but it seems like it'll do.
mkFreeClosure callback = do
  freef <- wrapFreeFunction freeFunction
  return $ FreeClosure callback freef
  where
    freeFunction :: FreeFunction a
    freeFunction sptr = do
      (FreeClosure cb freef) <- deRefStablePtr sptr
      freeStablePtr sptr
      freeHaskellFunPtr cb
      freeHaskellFunPtr freef  -- XXX we are freeing ourselves.
                               -- XXX this is officially not ok,
                               -- XXX but it seems like it'll do.