[Haskell-cafe] Safe/Unsafe calls with the GHC Foreign Function Interface

Stefan O'Rear stefanor at cox.net
Thu May 17 23:36:54 EDT 2007


On Thu, May 17, 2007 at 10:32:11PM -0500, Rob Hoelz wrote:
> More questions from Rob regarding his mysterious bindings...
> 
> So I've been reading the docs for the FFI, and it's my understanding
> that foreign functions imported as "unsafe" are faster, but they've got
> a problem with callbacks.  From what I read, I believe that I should
> just make a foreign function safe if it sets up a callback; is this
> correct?  Normally I wouldn't bother people with questions like this,
> but I'd rather be absolutely certain and avoid tracking down a strange
> bug later.
> 
> Many thanks as always,
> Rob

If it *calls* a callback into haskell.

Also, for unfathomable reasons, safety has been overloaded to include
forking OS threads.  If it could block (like getchar), you must make
it safe. 

Stefan


More information about the Haskell-Cafe mailing list