[Haskell-cafe] Writing and testing a Storable instance for a record wrapping ForeignPtrs
Oliver Charles
ollie at ocharles.org.uk
Mon Nov 28 16:14:51 UTC 2022
You are strict in your definition of `sizeOf`. You probably want:
sizeOf ~SignedMessage{messageLength} = ...
On Mon, 28 Nov 2022, at 4:04 PM, Hécate wrote:
> Hi everyone,
>
> In a fit of madness I have found myself writing Haskell code where I
> need to implement a Storable instance. However, by virtue of not being a
> C programmer, I'm fairly lost on some of the details, especially the
> value of the sizeOf and alignment methods.
>
> My Haskell-level record is the following:
>
> data SignedMessage = SignedMessage
> { messageLength :: CSize
> , messageForeignPtr :: ForeignPtr CUChar
> , signatureForeignPtr :: ForeignPtr CUChar
> }
>
>
> Here is the code of the Storable instance:
> https://gist.github.com/Kleidukos/31346d067f309f2a86cbd97a85c0f1e8#file-signing-hs
>
> And so I used `hedgehog-classes` to test the Storable instance. However,
> all the tests fail with the same reason: Prelude.undefined:
>
> https://gist.github.com/Kleidukos/31346d067f309f2a86cbd97a85c0f1e8#file-undefined_error-txt
>
> The main problem (and that's certainly a red herring for me) is that the
> `undefined` call comes frombase:Foreign.Marshal.Array.
> Which shouldn't be a problem, as it is not supposed to be evaluated!
> Yet apparently it is.
>
> If you're interested to see the full code, it's located here:
> https://github.com/haskell-cryptography/libsodium-bindings/blob/add-sel-package/sel/src/Sel/Signing.hs
>
> I'm not sure how to proceed from here. What would be a good angle to
> approach this?
>
> Cheers,
> Hécate
>
> --
> Hécate ✨
> 🐦: @TechnoEmpress
> IRC: Hecate
> WWW: https://glitchbra.in
> RUN: BSD
>
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20221128/127b950b/attachment.html>
More information about the Haskell-Cafe
mailing list