on master help sign in
Get array bounds checking working again

--HG-- extra : convert_revision : ccc0b4ed03d958671fc3fefda51970e3e4e8799f

commit423564dea636e8837542e4602c32395402acfcb0 authorBryan O'Sullivan <bos@serpentine.com> dateSun 29 Aug 2010, 06:05 (16 years ago) parentb475569
1 file changed+6−6
Data/Text/Array.hs+6−6
Data/Text/Array.hs+6−6
@@ -123,7 +123,7 @@ bytesInArray n = n `shiftL` 1
123123-- crash on an out-of-bounds access.
124124unsafeIndex :: Array -> Int -> Word16
125125unsafeIndex Array{..} i@(I# i#) =
126− CHECK_BOUNDS("unsafeIndex",len,i)
126+ CHECK_BOUNDS("unsafeIndex",aLen,i)
127127 case indexWord16Array# aBA i# of r# -> (W16# r#)
128128{-# INLINE unsafeIndex #-}
129129
@@ -131,7 +131,7 @@ unsafeIndex Array{..} i@(I# i#) =
131131-- crash on an out-of-bounds access.
132132unsafeIndexWord :: Array -> Int -> Word
133133unsafeIndexWord Array{..} i@(I# i#) =
134− CHECK_BOUNDS("unsafeIndexWord",len,i)
134+ CHECK_BOUNDS("unsafeIndexWord",aLen`div`wordFactor,i)
135135 case indexWordArray# aBA i# of r# -> (W# r#)
136136{-# INLINE unsafeIndexWord #-}
137137
@@ -139,7 +139,7 @@ unsafeIndexWord Array{..} i@(I# i#) =
139139-- crash on an out-of-bounds access.
140140unsafeRead :: MArray s -> Int -> ST s Word16
141141unsafeRead MArray{..} i@(I# i#) = ST $ \s# ->
142− CHECK_BOUNDS("unsafeRead",len,i)
142+ CHECK_BOUNDS("unsafeRead",maLen,i)
143143 case readWord16Array# maBA i# s# of
144144 (# s2#, r# #) -> (# s2#, W16# r# #)
145145{-# INLINE unsafeRead #-}
@@ -148,7 +148,7 @@ unsafeRead MArray{..} i@(I# i#) = ST $ \s# ->
148148-- on an out-of-bounds access.
149149unsafeWrite :: MArray s -> Int -> Word16 -> ST s ()
150150unsafeWrite MArray{..} i@(I# i#) (W16# e#) = ST $ \s1# ->
151− CHECK_BOUNDS("unsafeWrite",len,i)
151+ CHECK_BOUNDS("unsafeWrite",maLen,i)
152152 case writeWord16Array# maBA i# e# s1# of
153153 s2# -> (# s2#, () #)
154154{-# INLINE unsafeWrite #-}
@@ -157,7 +157,7 @@ unsafeWrite MArray{..} i@(I# i#) (W16# e#) = ST $ \s1# ->
157157-- crash on an out-of-bounds access.
158158unsafeReadWord :: MArray s -> Int -> ST s Word
159159unsafeReadWord MArray{..} i@(I# i#) = ST $ \s# ->
160− CHECK_BOUNDS("unsafeRead64",len,i)
160+ CHECK_BOUNDS("unsafeRead64",maLen`div`wordFactor,i)
161161 case readWordArray# maBA i# s# of
162162 (# s2#, r# #) -> (# s2#, W# r# #)
163163{-# INLINE unsafeReadWord #-}
@@ -166,7 +166,7 @@ unsafeReadWord MArray{..} i@(I# i#) = ST $ \s# ->
166166-- on an out-of-bounds access.
167167unsafeWriteWord :: MArray s -> Int -> Word -> ST s ()
168168unsafeWriteWord MArray{..} i@(I# i#) (W# e#) = ST $ \s1# ->
169− CHECK_BOUNDS("unsafeWriteWord",len,i)
169+ CHECK_BOUNDS("unsafeWriteWord",maLen`div`wordFactor,i)
170170 case writeWordArray# maBA i# e# s1# of
171171 s2# -> (# s2#, () #)
172172{-# INLINE unsafeWriteWord #-}