on master help sign in
Add debug code for utf8 decoding
b1c1b18Harendra Kumar
src/Streamly/Streams/StreamD.hs+8−1
@@ -3483,7 +3483,14 @@ decode0 table byte =
3483 let !t = table `unsafePeekElemOff` fromIntegral byte
3483 let !t = table `unsafePeekElemOff` fromIntegral byte
3484 !codep' = (0xff `shiftR` (fromIntegral t)) .&. fromIntegral byte
3484 !codep' = (0xff `shiftR` (fromIntegral t)) .&. fromIntegral byte
3485 !state' = table `unsafePeekElemOff` (256 + fromIntegral t)
3485 !state' = table `unsafePeekElemOff` (256 + fromIntegral t)
3486+ in assert ((byte > 0x7f || error showByte)
3487+ && (state' /= 0 || error (showByte ++ showState state')))
3486− in (Tuple' state' codep')
3488+ (Tuple' state' codep')
3489+
3490+ where
3491+
3492+ showByte = "decode0: Invalid byte: " ++ show byte
3493+ showState st = " state: " ++ show st ++ " table: " ++ show table
3487
3494
3488-- When the state is not 0
3495-- When the state is not 0
3489{-# INLINE decode1 #-}
3496{-# INLINE decode1 #-}
streamly.cabal+9−1
@@ -132,6 +132,11 @@ flag inspection
132 manual: True
132 manual: True
133 default: False
133 default: False
134
134
135+flag debug
136+ description: Debug build with asserts enabled
137+ manual: True
138+ default: False
139+
135flag dev
140flag dev
136 description: Development build
141 description: Development build
137 manual: True
142 manual: True
@@ -193,7 +198,10 @@ common compile-options
193 if flag(dev)
198 if flag(dev)
194 ghc-options: -Wmissed-specialisations
199 ghc-options: -Wmissed-specialisations
195 -Wall-missed-specialisations
200 -Wall-missed-specialisations
201+
202+ if flag(dev) || flag(debug)
196− -fno-ignore-asserts
203+ ghc-options: -fno-ignore-asserts
204+
197 if impl(ghc >= 8.0)
205 if impl(ghc >= 8.0)
198 ghc-options: -Wcompat
206 ghc-options: -Wcompat
199 -Wunrecognised-warning-flags
207 -Wunrecognised-warning-flags