I would expect that field to translate to type [Ptr CChar], which correctly happens, woohoo!
The problem is that I expect a list of length 8, where each Ptr CChar points to a character array with length 255. Instead I get a list of length 255, where the pointers are all invalid.
In the final haskell code, the deserialization looks like
instance Storable C'MyCoolStruct where
peek p = do
v0 <- peekArray (2040 `div` (sizeOf (undefined :: Ptr CChar)) (plusPtr p 0)
return (C'MyCoolStruct v0)
which translates to
instance Storable C'MyCoolStruct where
peek p = do
v0 <- peekArray 255 p :: IO [Ptr CChar]
return (C'MyCoolStruct v0)
This gives corrupt output. The pointers aren't valid pointers, they are strings cast to pointers.
I think the correct implementation would be:
instance Storable C'MyCoolStruct where
peek p = do
let v0 = [plusPtr (plusPtr p 0) (255 * k) | k <- [0..8]]
return (C'MyCoolStruct v0)
I looked through the source code but didn't make much progress. I'll be happy to try again if you can give me a few pointers to relevant sections.
I have a struct like:
I would expect that field to translate to type
[Ptr CChar]
, which correctly happens, woohoo!The problem is that I expect a list of length 8, where each
Ptr CChar
points to a character array with length 255. Instead I get a list of length 255, where the pointers are all invalid.In the final haskell code, the deserialization looks like
which translates to
This gives corrupt output. The pointers aren't valid pointers, they are strings cast to pointers. I think the correct implementation would be:
I looked through the source code but didn't make much progress. I'll be happy to try again if you can give me a few pointers to relevant sections.