on master help sign in
Add debug code for utf8 decoding
commitb1c1b1880a8b5c9269b1a0d4624444f595836de0 authorHarendra Kumar <harendra.kumar@gmail.com> dateFri 8 Nov 2019, 22:14 (7 years ago) parentbea83e9
2 files changed+17−2
src/Streamly/Streams/StreamD.hs+8−1 streamly.cabal+9−1
src/Streamly/Streams/StreamD.hs+8−1
@@ -3483,7 +3483,14 @@ decode0 table byte =
34833483 let !t = table `unsafePeekElemOff` fromIntegral byte
34843484 !codep' = (0xff `shiftR` (fromIntegral t)) .&. fromIntegral byte
34853485 !state' = table `unsafePeekElemOff` (256 + fromIntegral t)
3486− in (Tuple' state' codep')
3486+ in assert ((byte > 0x7f || error showByte)
3487+ && (state' /= 0 || error (showByte ++ showState state')))
3488+ (Tuple' state' codep')
3489+
3490+ where
3491+
3492+ showByte = "decode0: Invalid byte: " ++ show byte
3493+ showState st = " state: " ++ show st ++ " table: " ++ show table
34873494
34883495-- When the state is not 0
34893496{-# INLINE decode1 #-}
streamly.cabal+9−1
@@ -132,6 +132,11 @@ flag inspection
132132 manual: True
133133 default: False
134134
135+flag debug
136+ description: Debug build with asserts enabled
137+ manual: True
138+ default: False
139+
135140flag dev
136141 description: Development build
137142 manual: True
@@ -193,7 +198,10 @@ common compile-options
193198 if flag(dev)
194199 ghc-options: -Wmissed-specialisations
195200 -Wall-missed-specialisations
196− -fno-ignore-asserts
201+
202+ if flag(dev) || flag(debug)
203+ ghc-options: -fno-ignore-asserts
204+
197205 if impl(ghc >= 8.0)
198206 ghc-options: -Wcompat
199207 -Wunrecognised-warning-flags