Add testcase for getSizeofMutableByteArray#
[ghc.git] / testsuite / tests / primops / should_run / T11296.hs
1 {-# LANGUAGE MagicHash #-}
2 {-# LANGUAGE UnboxedTuples #-}
3
4 import Control.Monad (unless)
5 import GHC.Exts
6 import GHC.Types
7
8 data ByteArray s = BA (MutableByteArray# s)
9
10 main :: IO ()
11 main = do
12 ba# <- IO (\s0 -> case newByteArray# 256# s0 of
13 (# s1, ba# #) -> (# s1, BA ba# #))
14 let go n = do
15 shrink ba# n
16 sz <- getSize ba#
17 unless (sz == n) $ print (sz, n)
18 mapM go [128, 64, 63, 32, 2, 1]
19 return ()
20
21 shrink :: ByteArray RealWorld -> Int -> IO ()
22 shrink (BA ba#) (I# n#) = IO (\s ->
23 case shrinkMutableByteArray# ba# n# s of
24 s' -> (# s', () #))
25
26 getSize :: ByteArray RealWorld -> IO Int
27 getSize (BA ba#) = IO (\s ->
28 case getSizeofMutableByteArray# ba# s of
29 (# s', n# #) -> (# s', I# n# #))
30