summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSven Tennie <sven.tennie@gmail.com>2023-01-21 20:27:03 +0000
committerSven Tennie <sven.tennie@gmail.com>2023-01-21 20:27:03 +0000
commit66b456027815af00e40bd20a08769a880ce5fbc5 (patch)
tree01aaca92e4c35b9eb1ce1c71715b6e1959c2ec3f
parent2fc29feb84e6a1b5e2dfaa7a2bedaaf9eb41afea (diff)
downloadhaskell-66b456027815af00e40bd20a08769a880ce5fbc5.tar.gz
Get rid of static word size in test
-rw-r--r--libraries/ghc-heap/tests/TestUtils.hs9
-rw-r--r--libraries/ghc-heap/tests/stack_lib.c4
2 files changed, 9 insertions, 4 deletions
diff --git a/libraries/ghc-heap/tests/TestUtils.hs b/libraries/ghc-heap/tests/TestUtils.hs
index 85b5dbd077..d2447fda0a 100644
--- a/libraries/ghc-heap/tests/TestUtils.hs
+++ b/libraries/ghc-heap/tests/TestUtils.hs
@@ -9,7 +9,7 @@ module TestUtils
( assertEqual,
assertThat,
assertStackInvariants,
- unbox
+ unbox,
)
where
@@ -61,19 +61,20 @@ foreign import ccall "foldStackToArrayClosure" foldStackToArrayClosure# :: Stack
foldStackToArrayClosure :: StackSnapshot -> ByteArray
foldStackToArrayClosure (StackSnapshot s#) = ByteArray (foldStackToArrayClosure# s#)
+foreign import ccall "bytesInWord" bytesInWord# :: Word
+
stackSnapshotToClosureTypes :: ByteArray -> [ClosureType]
stackSnapshotToClosureTypes = wordsToClosureTypes . toWords
where
toWords :: ByteArray -> [Word]
toWords ba@(ByteArray b#) =
let s = I# (sizeofByteArray# b#)
- in -- TODO: Adjust 8 to machine word size
- [W# (indexWordArray# b# (toInt# i)) | i <- [0 .. maxWordIndex (ba)]]
+ in [W# (indexWordArray# b# (toInt# i)) | i <- [0 .. maxWordIndex (ba)]]
where
maxWordIndex :: ByteArray -> Int
maxWordIndex (ByteArray ba#) =
let s = I# (sizeofByteArray# ba#)
- words = s `div` 8
+ words = s `div` fromIntegral bytesInWord#
in case words of
w | w == 0 -> error "ByteArray contains no content!"
w -> w - 1
diff --git a/libraries/ghc-heap/tests/stack_lib.c b/libraries/ghc-heap/tests/stack_lib.c
index 7e2644d16d..fee05753a3 100644
--- a/libraries/ghc-heap/tests/stack_lib.c
+++ b/libraries/ghc-heap/tests/stack_lib.c
@@ -240,3 +240,7 @@ StgArrBytes *foldStackToArrayClosure(StgStack *stack) {
freeList(cl);
return arrayClosure;
}
+
+StgWord bytesInWord() {
+ return SIZEOF_W;
+}