[Haskell-cafe] [ANN] Haskell FFI Tutorial

Donn Cave donn at avvanta.com
Mon Nov 10 19:46:05 UTC 2014


quoth Evan Laforge <qdunkan at gmail.com>
> 
> Just from personal experience, the fact that haskell types like Bool
> and Char are Storable combined with hsc's low level nature makes it
> easy to create memory corruption bugs by writing `(#poke Struct field)
> flag` instead of `(#poke Struct field) (toBool flag)`.  The former
> will compile and likely work most of the time, but will corrupt
> memory, which will eventually result in a nondeterministic GC crash
> some time after the actual corruption.  In my case, it took over a
> year to find the bug.

Could you explain this problem a little further?  I looked in my code
and found lots of stuff like `(#poke termios, c_iflag) a iflag', so was
alarmed for a moment, but naturally I've declared iflag Word32, via the
hsc #type macro.  And I'd expect the targets of poking to be like that -
full of CChar and Word32 etc. - foreign types of the appropriate size.
The idea that there'd be anything else in there changes the perspective
somewhat, and if that's common, indeed the tutorial should account for it.

(Or maybe I completely misunderstand what's going on here!)

	Donn


More information about the Haskell-Cafe mailing list