Storable laws

Evan Laforge qdunkan at gmail.com
Wed Mar 7 06:25:42 UTC 2018


On Sun, Dec 17, 2017 at 11:55 PM, Henning Thielemann
<lemming at henning-thielemann.de> wrote:
> On Sun, 17 Dec 2017, Evan Laforge wrote:
>> This is only roughly related, but long ago I completely replaced
>> Storable in my own hsc2hs-using code with CStorable, which is a copy
>> of Storable, except having only the instances that I choose.
>> Specifically, it has instances for CChar but not Char, for CBool but
>> not Bool, etc. because it's too dangerous to silently allow these
>> memory-corrupting instances.  I think reusing Storable for C
>> serialization was a mistake.  Replacing Storable was pretty easy
>> though, just copy-paste the 200-line Foreign module and change the
>> class name.
>
> Would you mind moving this class to a public package?

Done, after much delay: http://hackage.haskell.org/package/c-storable-0.2

That said, from the README:

If you are writing a new C binding, I recommend something higher-level than
hsc2hs, such as c2hs, which I think should sidestep the problem entirely by
verifying your types.  But if you are already using hsc2hs and for whatever
reason don't want subtle memory corruption bugs, you can import ForeignC
instead of Foreign and Foreign.C, and see if you have any.


More information about the Libraries mailing list