Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the API more suitable for use with newForeignPtr #17

Open
ion1 opened this issue Sep 2, 2024 · 0 comments
Open

Make the API more suitable for use with newForeignPtr #17

ion1 opened this issue Sep 2, 2024 · 0 comments

Comments

@ion1
Copy link

ion1 commented Sep 2, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant