Is your feature request related to a problem? Please describe.
I would like to use ForeignPtr to deal with the disposal of a Module. Currently, I can't pass Binaryen.Module.dispose as a finalizer to newForeignPtr as it's not a FunPtr.
Additionally, newForeignPtr and withForeignPtr want to deal with Ptr Module values rather than Module ones.
Describe the solution you'd like + Describe alternatives you've considered
To enable using Binaryen.Module.dispose as a finalizer, I believe the import would need to look like:
foreign import ccall unsafe "&BinaryenModuleDispose"
dispose ::
FunPtr (Module -> IO ())
However, to make using the API with withForeignPtr nice, I can think of three options:
- Have the user of haskell-binaryen implement wrappers such as
newModuleForeignPtr :: FunPtr (Module -> IO ()) -> Module -> IO (ForeignPtr Module) and withModuleForeignPtr :: ForeignPtr Module -> (Module -> IO a) -> IO a.
- Change haskell-binaryen to make all the FFI imports return or take a
Ptr Module rather than a Module.
- Change haskell-binaryen to export a
Module type which wraps a ForeignPtr, have Module.create/Module.allocateAndWriteText set up finalizers, and have the exposed API use withForeignPtr internally.
I'm okay with any solution.
Additional context
I might be able to make a pull request once I know if/how you would like this to be done.