shithub: MicroHs

Download patch

ref: fb93ec6ffc3b33a143d6be326fe07adbc8d370c7
parent: c1f43436df7047dcf4b1b628f17e7765d02e993a
author: Lennart Augustsson <lennart.augustsson@epicgames.com>
date: Tue Jan 2 08:44:34 EST 2024

Fix serious size bug.

--- a/lib/Foreign/Storable.hs
+++ b/lib/Foreign/Storable.hs
@@ -26,9 +26,12 @@
 foreign import ccall "peekWord" c_peekWord :: Ptr Word -> IO Word
 foreign import ccall "pokeWord" c_pokeWord :: Ptr Word -> Word -> IO ()
 
+wordSizeInBytes :: Int
+wordSizeInBytes = _wordSize `primIntQuot` 8
+
 instance Storable Word where
-  sizeOf    _ = _wordSize
-  alignment _ = _wordSize
+  sizeOf    _ = wordSizeInBytes
+  alignment _ = wordSizeInBytes
   peek p      = c_peekWord p
   poke p w    = c_pokeWord p w
 
@@ -36,8 +39,8 @@
 foreign import ccall "pokePtr" c_pokePtr :: forall a . Ptr (Ptr a) -> Ptr a -> IO ()
 
 instance forall a . Storable (Ptr a) where
-  sizeOf    _ = _wordSize
-  alignment _ = _wordSize
+  sizeOf    _ = wordSizeInBytes
+  alignment _ = wordSizeInBytes
   peek p      = c_peekPtr p
   poke p w    = c_pokePtr p w
 
@@ -45,7 +48,7 @@
 foreign import ccall "pokeByte" c_pokeByte :: Ptr Word8 -> Word8 -> IO ()
 
 instance Storable Word8 where
-  sizeOf    _ = 8
-  alignment _ = 8
+  sizeOf    _ = 1
+  alignment _ = 1
   peek p      = c_peekByte p
   poke p w    = c_pokeByte p w
--