[Git][haskell-team/DHG_packages][master] static-bytes: Support big-endian systems
Ilias Tsitsimpis (@iliastsi)
gitlab at salsa.debian.org
Mon Oct 21 12:50:48 BST 2024
Ilias Tsitsimpis pushed to branch master at Debian Haskell Group / DHG_packages
Commits:
2a415d6f by Ilias Tsitsimpis at 2024-10-21T14:44:38+03:00
static-bytes: Support big-endian systems
- - - - -
3 changed files:
- p/haskell-static-bytes/debian/changelog
- + p/haskell-static-bytes/debian/patches/big-endian
- + p/haskell-static-bytes/debian/patches/series
Changes:
=====================================
p/haskell-static-bytes/debian/changelog
=====================================
@@ -1,3 +1,9 @@
+haskell-static-bytes (0.1.0-3) unstable; urgency=medium
+
+ * Apply upstream patch to fix support for big-endian systems
+
+ -- Ilias Tsitsimpis <iliastsi at debian.org> Mon, 21 Oct 2024 14:40:24 +0300
+
haskell-static-bytes (0.1.0-2) unstable; urgency=medium
* Gratuitous post-NEW source upload.
=====================================
p/haskell-static-bytes/debian/patches/big-endian
=====================================
@@ -0,0 +1,92 @@
+From 08d19aaf328fd456960f689fa66e0bfb7eebf28b Mon Sep 17 00:00:00 2001
+From: Mike Pilgrem <mpilgrem at users.noreply.github.com>
+Date: Sun, 20 Oct 2024 20:29:04 +0100
+Subject: [PATCH] Fix #1 Enforce that the Word64 values used are little-endian.
+
+Index: b/src/Data/StaticBytes.hs
+===================================================================
+--- a/src/Data/StaticBytes.hs
++++ b/src/Data/StaticBytes.hs
+@@ -34,6 +34,7 @@ import qualified Data.Vector.Unboxed.Bas
+ import Foreign.ForeignPtr
+ import Foreign.Ptr
+ import Foreign.Storable
++import GHC.ByteOrder ( ByteOrder (..), targetByteOrder )
+ import RIO hiding ( words )
+ import System.IO.Unsafe ( unsafePerformIO )
+
+@@ -75,20 +76,23 @@ class DynamicBytes dbytes where
+ lengthD :: dbytes -> Int
+ -- Yeah, it looks terrible to use a list here, but fusion should kick in
+ withPeekD :: dbytes -> ((Int -> IO Word64) -> IO a) -> IO a
++ -- ^ This assumes that the Word64 values are all little-endian.
+ -- | May throw a runtime exception if invariants are violated!
+ fromWordsD :: Int -> [Word64] -> dbytes
++ -- ^ This assumes that the Word64 values are all little-endian.
+
+ fromWordsForeign ::
+ (ForeignPtr a -> Int -> b)
+ -> Int
+ -> [Word64]
++ -- ^ The Word64 values are assumed to be little-endian.
+ -> b
+ fromWordsForeign wrapper len words0 = unsafePerformIO $ do
+ fptr <- B.mallocByteString len
+ withForeignPtr fptr $ \ptr -> do
+ let loop _ [] = pure ()
+ loop off (w:ws) = do
+- pokeElemOff (castPtr ptr) off w
++ pokeElemOff (castPtr ptr) off (fromLE64 w)
+ loop (off + 1) ws
+ loop 0 words0
+ pure $ wrapper fptr len
+@@ -96,6 +100,7 @@ fromWordsForeign wrapper len words0 = un
+ withPeekForeign ::
+ (ForeignPtr a, Int, Int)
+ -> ((Int -> IO Word64) -> IO b)
++ -- ^ The Word64 values are assumed to be little-endian.
+ -> IO b
+ withPeekForeign (fptr, off, len) inner =
+ withForeignPtr fptr $ \ptr -> do
+@@ -109,7 +114,7 @@ withPeekForeign (fptr, off, len) inner =
+ let w64' = shiftL (fromIntegral w8) (i * 8) .|. w64
+ loop w64' (i + 1)
+ loop 0 0
+- | otherwise = peekByteOff ptr (off + off')
++ | otherwise = toLE64 <$> peekByteOff ptr (off + off')
+ inner f
+
+ instance DynamicBytes B.ByteString where
+@@ -129,7 +134,7 @@ instance word8 ~ Word8 => DynamicBytes (
+ let loop _ [] =
+ VP.Vector 0 len <$> BA.unsafeFreezeByteArray ba
+ loop i (w:ws) = do
+- BA.writeByteArray ba i w
++ BA.writeByteArray ba i (fromLE64 w)
+ loop (i + 1) ws
+ loop 0 words0
+ withPeekD (VP.Vector off len ba) inner = do
+@@ -143,7 +148,8 @@ instance word8 ~ Word8 => DynamicBytes (
+ let w64' = shiftL (fromIntegral w8) (i * 8) .|. w64
+ loop w64' (i + 1)
+ loop 0 0
+- | otherwise = pure $ BA.indexByteArray ba (off + (off' `div` 8))
++ | otherwise = pure $
++ toLE64 $ BA.indexByteArray ba (off + (off' `div` 8))
+ inner f
+
+ instance word8 ~ Word8 => DynamicBytes (VU.Vector word8) where
+@@ -244,3 +250,13 @@ fromStatic ::
+ => sbytes
+ -> dbytes
+ fromStatic = fromWordsD (lengthS (Nothing :: Maybe sbytes)) . ($ []) . toWordsS
++
++-- | Convert a 64 bit value in CPU endianess to little endian.
++toLE64 :: Word64 -> Word64
++toLE64 = case targetByteOrder of
++ BigEndian -> byteSwap64
++ LittleEndian -> id
++
++-- | Convert a little endian 64 bit value to CPU endianess.
++fromLE64 :: Word64 -> Word64
++fromLE64 = toLE64
=====================================
p/haskell-static-bytes/debian/patches/series
=====================================
@@ -0,0 +1 @@
+big-endian
View it on GitLab: https://salsa.debian.org/haskell-team/DHG_packages/-/commit/2a415d6f3e43f5c659aedf8e33af7d0c6c677987
--
View it on GitLab: https://salsa.debian.org/haskell-team/DHG_packages/-/commit/2a415d6f3e43f5c659aedf8e33af7d0c6c677987
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/pkg-haskell-commits/attachments/20241021/84c3d1f9/attachment-0001.htm>
More information about the Pkg-haskell-commits
mailing list