Storable laws

David Feuer david.feuer at gmail.com
Sat Dec 16 05:33:36 UTC 2017


The documentation for pokeByteOff indicates that the following equality
holds:

  pokeElemOff addr idx x =
    poke (addr `plusPtr` (idx * sizeOf x)) x

Notably, this ignores alignment. It thus seems to imply that sizeOf must
always be a multiple of alignment; otherwise, non-zero indices could access
non-aligned addresses.

Was this intentional? If so, I believe sizeOf and alignment should document
the law. If not, then I believe the {poke,peek}ElemOff laws need to change
to something like

  pokeElemOff addr idx x =
     poke (addr `plusPtr` (idx * lcm (sizeOf x) (alignment x))) x
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/libraries/attachments/20171216/723caa23/attachment.html>


More information about the Libraries mailing list