From 6d8885a4a77768f51b6cfbde8bb614424c102719 Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Sat, 4 Apr 2020 15:30:48 +0200 Subject: [PATCH] Fix the 32-bit encodeReal and decodeReal in Data.Encoding.GenBinary --- .../OS-Independent/Data/Encoding/GenBinary.icl | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/libraries/OS-Independent/Data/Encoding/GenBinary.icl b/src/libraries/OS-Independent/Data/Encoding/GenBinary.icl index 0319b779..1d3cc735 100644 --- a/src/libraries/OS-Independent/Data/Encoding/GenBinary.icl +++ b/src/libraries/OS-Independent/Data/Encoding/GenBinary.icl @@ -53,7 +53,12 @@ encodeBool True cs=:{es_pos = pos, es_bits = bits} encodeReal :: !Real !*EncodingSt -> *EncodingSt encodeReal real st = IF_INT_64_OR_32 (encodeInt (unsafeCoerce real) st) - (let (i1, i2) = unsafeCoerce real in encodeInt i2 $ encodeInt i1 st) + (let (i1, i2) = realToInts real in encodeInt i2 $ encodeInt i1 st) +where + realToInts :: !Real -> (!Int, !Int) + realToInts _ = code { + no_op + } encodeArray :: !(a *EncodingSt -> *EncodingSt) !(b a) !*EncodingSt -> *EncodingSt | Array b a encodeArray f xs st @@ -161,8 +166,13 @@ where # (mbInt1, st) = decodeInt st # (mbInt2, st) = decodeInt st = case (mbInt1, mbInt2) of - (Just int1, Just int2) = (Just $ unsafeCoerce (int1, int2), st) + (Just int1, Just int2) = (Just $ intsToReal int1 int2, st) _ = (Nothing, st) + where + intsToReal :: !Int !Int -> Real + intsToReal _ _ = code { + no_op + } decodeArray :: !(*EncodingSt -> (Maybe a, *EncodingSt)) !*EncodingSt -> (!Maybe (b a), !*EncodingSt) | Array b a decodeArray f st -- GitLab