Here’s my situation:
I would like to call ffmpeg’s av_free_packet function:
// avformat.h
static inline void av_free_packet(AVPacket *pkt)
{
if (pkt && pkt->destruct)
pkt->destruct(pkt);
}
But unfortunately this function is static inline, and so doesn’t really appear in the linked library.
However, it is a very simple function, which I could reimplement in Haskell. And that’s what I can’t figure out how to do. Here’s a partial attempt (.hsc):
av_free_packet :: Ptr AVPacket -> IO ()
av_free_packet pkt =
when (nullPtr /= pkt) $ do
destruct <- (#peek AVPacket, destruct) pkt :: IO (FunPtr (Ptr AVPacket -> IO ()))
when (nullFunPtr /= destruct) $ funPtrToFun destruct pkt
funPtrToFun :: FunPtr a -> a
funPtrToFun = ?
For now I could resort to implementing this function in C (by just calling the original), but it seems to me that calling function pointers should be possible somehow..
From The Haskell 98 Foreign Function Interface 1.0,
In your case, the usage would look something like the following.