Wolfgang Jeltsch pushed to branch wip/jeltsch/portable-bco-byte-array-serialization at Glasgow Haskell Compiler / GHC Commits: 3b17b6f0 by Wolfgang Jeltsch at 2026-09-16T18:14:54+03:00 Change the oder of definition of (de)serialization operations - - - - - 1 changed file: - libraries/ghci/GHCi/ResolvedBCO.hs Changes: ===================================== libraries/ghci/GHCi/ResolvedBCO.hs ===================================== @@ -152,34 +152,6 @@ instance Binary ResolvedBCO where 1 -> ResolvedStaticCon <$> get <*> get <*> get <*> get <*> get <*> get _ -> error "Binary ResolvedBCO: invalid byte" -#if !defined(WORDS_BIGENDIAN) - --- | Serialize a 'BCOByteArray', writing the payload verbatim instead of --- serializing the individual elements. This must only be used when the host --- platform uses little endian and the bitsize of the element type of the --- array is the one that is used for the serialized form of elements. -putBCOByteArrayDirectly :: Storable a => BCOByteArray a -> Put -putBCOByteArrayDirectly @a (BCOByteArray byteArray#) - = putWord64le (fromIntegral size) <> - putBuilder (fromShortByteString (SBS byteArray#)) - where - - size :: Int - size = I# (sizeofByteArray# byteArray#) `div` sizeOf (undefined :: a) - --- | Deserialize a 'BCOByteArray', reading the payload verbatim instead of --- deserializing the individual elements. This must only be used when the host --- platform uses little endian and the bitsize of the element type of the --- array is the one that is used for the serialized form of elements. -getBCOByteArrayDirectly :: Storable a => Get (BCOByteArray a) -getBCOByteArrayDirectly @a = do - size <- fromIntegral <$> getWord64le :: Get Int - SBS byteArray# <- toShort <$> getByteString (size * sizeOf (undefined :: a)) - -- Beware that there is no overflow check for the byte count computation. - return (BCOByteArray byteArray#) - -#endif - #if defined(WORDS_BIGENDIAN) || SIZEOF_HSWORD == 4 -- | Serialize a 'BCOByteArray', not writing the payload verbatim but @@ -215,6 +187,34 @@ getBCOByteArrayPortably getElement = do #endif +#if !defined(WORDS_BIGENDIAN) + +-- | Serialize a 'BCOByteArray', writing the payload verbatim instead of +-- serializing the individual elements. This must only be used when the host +-- platform uses little endian and the bitsize of the element type of the +-- array is the one that is used for the serialized form of elements. +putBCOByteArrayDirectly :: Storable a => BCOByteArray a -> Put +putBCOByteArrayDirectly @a (BCOByteArray byteArray#) + = putWord64le (fromIntegral size) <> + putBuilder (fromShortByteString (SBS byteArray#)) + where + + size :: Int + size = I# (sizeofByteArray# byteArray#) `div` sizeOf (undefined :: a) + +-- | Deserialize a 'BCOByteArray', reading the payload verbatim instead of +-- deserializing the individual elements. This must only be used when the host +-- platform uses little endian and the bitsize of the element type of the +-- array is the one that is used for the serialized form of elements. +getBCOByteArrayDirectly :: Storable a => Get (BCOByteArray a) +getBCOByteArrayDirectly @a = do + size <- fromIntegral <$> getWord64le :: Get Int + SBS byteArray# <- toShort <$> getByteString (size * sizeOf (undefined :: a)) + -- Beware that there is no overflow check for the byte count computation. + return (BCOByteArray byteArray#) + +#endif + -- See [BCOByteArray serialization]. instance Binary (BCOByteArray Word16) where View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/3b17b6f0b709ae21e807b505d873b545... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/3b17b6f0b709ae21e807b505d873b545... You're receiving this email because of your account on gitlab.haskell.org. Manage all notifications: https://gitlab.haskell.org/-/profile/notifications | Help: https://gitlab.haskell.org/help
participants (1)
-
Wolfgang Jeltsch (@jeltsch)