Add internal checks
authorRoman Leshchinskiy <rl@cse.unsw.edu.au>
Sat, 6 Oct 2012 21:48:17 +0000 (21:48 +0000)
committerRoman Leshchinskiy <rl@cse.unsw.edu.au>
Sat, 6 Oct 2012 21:48:17 +0000 (21:48 +0000)
Data/Vector/Fusion/Bundle/Monadic.hs
Data/Vector/Generic/Mutable.hs

index 4cbe3af..a487d7f 100644 (file)
@@ -1704,7 +1704,9 @@ fromVectors vs = Bundle (Unf pstep (Left vs))
     vstep :: [v a] -> m (Step [v a] (Chunk v a))
     vstep [] = return Done
     vstep (v:vs) = return $ Yield (Chunk (basicLength v)
-                                         (\mv -> basicUnsafeCopy mv v)) vs
+                                         (\mv -> INTERNAL_CHECK(check) "concatVectors" "length mismatch"
+                                                                       (M.basicLength mv == basicLength v)
+                                                 $ basicUnsafeCopy mv v)) vs
 
 
 concatVectors :: (Monad m, Vector v a) => Bundle m u (v a) -> Bundle m v a
@@ -1732,7 +1734,9 @@ concatVectors Bundle{sElems = Unf step s}
       r <- step s
       case r of
         Yield v s' -> return (Yield (Chunk (basicLength v)
-                                           (\mv -> basicUnsafeCopy mv v)) s')
+                                           (\mv -> INTERNAL_CHECK(check) "concatVectors" "length mismatch"
+                                                                          (M.basicLength mv == basicLength v)
+                                                   $ basicUnsafeCopy mv v)) s')
         Skip    s' -> return (Skip s')
         Done       -> return Done
 
index 6726e64..12d9143 100644 (file)
@@ -413,9 +413,10 @@ vmunstreamMax s n
       v <- INTERNAL_CHECK(checkLength) "munstreamMax" n
            $ unsafeNew n
       let {-# INLINE_INNER copy #-}
-          copy i (Chunk n f) = do
-                                 f (basicUnsafeSlice i n v)
-                                 return (i+n)
+          copy i (Chunk n f) =
+            INTERNAL_CHECK(checkSlice) "munstreamMax.copy" i n (length v) $ do
+              f (basicUnsafeSlice i n v)
+              return (i+n)
 
       n' <- MBundle.vfoldlM' copy 0 s
       return $ INTERNAL_CHECK(checkSlice) "munstreamMax" 0 n' n
@@ -438,7 +439,8 @@ vmunstreamUnknown s
           v' <- if basicLength v < j
                   then unsafeGrow v (delay_inline max (enlarge_delta v) (j - basicLength v))
                   else return v
-          f (basicUnsafeSlice i n v')
+          INTERNAL_CHECK(checkSlice) "munstreamUnknown.copy" i n (length v')
+            $ f (basicUnsafeSlice i n v')
           return (v',j)