[Haskell-cafe] Anonymous FFI calls

Simon Peyton Jones simonpj at microsoft.com
Wed Feb 11 23:09:48 UTC 2015


There's a bunch of useful info on this thread.   Does anyone feel able to distill it to our main FFI wiki page:
	https://wiki.haskell.org/GHC/Using_the_FFI
That way, future generations will benefit.

(These user-oriented wiki pages are all linked from GHC's documentation page https://wiki.haskell.org/GHC.)

Thanks!

Simon

| -----Original Message-----
| From: ghc-devs [mailto:ghc-devs-bounces at haskell.org] On Behalf Of adam
| vogt
| Sent: 11 February 2015 19:32
| To: Sylvain Henry
| Cc: ghc-devs at haskell.org; haskell
| Subject: Re: [Haskell-cafe] Anonymous FFI calls
| 
| On Wed, Feb 11, 2015 at 12:26 PM, Sylvain Henry <hsyl20 at gmail.com> wrote:
| > 2015-02-11 16:18 GMT+01:00 Francesco Mazzoli <f at mazzo.li>:
| >>
| >>
| >> Relatedly, if I have some function pointer known at runtime that
| >> addresses a C function that takes some arguments, I have no way to
| >> invoke it from Haskell, since all FFI imports must be declared at
| >> compile-time, and I don't know the address of the symbol I want to
| >> execute at compile time.
| >
| >
| > You can use FunPtr and wrapper imports to convert a FunPtr into a
| Haskell
| > function.
| > https://hackage.haskell.org/package/base-4.7.0.2/docs/Foreign-
| Ptr.html#g:2
| >
| > You may be interested in my dynamic-linker-template package [1] to
| avoid
| > having to write boilerplate wrappers.
| 
| Code using http://hackage.haskell.org/package/libffi looks pretty
| similar, though the specification needs terms (such as argCInt)
| instead of a mandatory type signature. GHC itself includes libffi so
| maybe the foreign import "dynamic" calls end up doing exactly the same
| thing as the hackage libffi does.
| _______________________________________________
| ghc-devs mailing list
| ghc-devs at haskell.org
| http://www.haskell.org/mailman/listinfo/ghc-devs


More information about the ghc-devs mailing list