summaryrefslogtreecommitdiff
path: root/testsuite/tests/dcoercion/DCo_Array.hs
diff options
context:
space:
mode:
Diffstat (limited to 'testsuite/tests/dcoercion/DCo_Array.hs')
-rw-r--r--testsuite/tests/dcoercion/DCo_Array.hs31
1 files changed, 31 insertions, 0 deletions
diff --git a/testsuite/tests/dcoercion/DCo_Array.hs b/testsuite/tests/dcoercion/DCo_Array.hs
new file mode 100644
index 0000000000..cf3e389a09
--- /dev/null
+++ b/testsuite/tests/dcoercion/DCo_Array.hs
@@ -0,0 +1,31 @@
+{-# LANGUAGE
+ MagicHash
+ , UnboxedTuples
+ , UnliftedFFITypes
+ #-}
+
+module DCo_Array where
+
+import DCo_Array_aux
+ ( memcpy_thaw )
+
+import GHC.Exts
+ ( Ptr, Int(I#), RealWorld
+ , MutableByteArray#, ByteArray#
+ , newByteArray#
+ )
+import GHC.IO ( IO(..) )
+import GHC.ST ( ST(..) )
+
+data UArray e = UArray !Int ByteArray#
+data STUArray s e = STUArray !Int (MutableByteArray# s)
+
+thawSTUArray :: UArray e -> ST RealWorld (STUArray RealWorld e)
+thawSTUArray (UArray n@(I# n#) arr#) = ST $ \s1# ->
+ case newByteArray# n# s1# of
+ (# s2#, marr# #) ->
+ case memcpy_thaw marr# arr# (fromIntegral n) of
+ IO m ->
+ case m s2# of
+ (# s3#, _ #) ->
+ (# s3#, STUArray n marr# #)