summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2021-08-04 10:28:11 -0400
committerMarge Bot <ben+marge-bot@smart-cactus.org>2021-08-09 08:10:11 -0400
commit080ffd4b78fe8b60f9eb4490b39f971d76ebb46e (patch)
tree23440336d3fc63e60375e8387f0ea7f1be28d238
parentcf7e6c8d3492fdfbbbf0bf853feed4743e04e75e (diff)
downloadhaskell-080ffd4b78fe8b60f9eb4490b39f971d76ebb46e.tar.gz
rts: Fix use of sized array in Heap.h
Sized arrays cannot be used in headers that might be imported from C++. Fixes #20199.
-rw-r--r--includes/rts/storage/Heap.h8
-rw-r--r--libraries/ghc-heap/tests/create_tso.c2
-rw-r--r--rts/Heap.c4
3 files changed, 9 insertions, 5 deletions
diff --git a/includes/rts/storage/Heap.h b/includes/rts/storage/Heap.h
index b950df76e5..b3b1efaf9f 100644
--- a/includes/rts/storage/Heap.h
+++ b/includes/rts/storage/Heap.h
@@ -18,10 +18,14 @@ void heap_view_closure_ptrs_in_pap_payload(StgClosure *ptrs[], StgWord *nptrs
StgWord heap_view_closureSize(StgClosure *closure);
/*
- * Collect the pointers of a closure into the given array. `size` should be
+ * Collect the pointers of a closure into the given array. The given array should be
* large enough to hold all collected pointers e.g.
* `heap_view_closureSize(closure)`. Returns the number of pointers collected.
* The caller must ensure that `closure` is not modified (or moved by the GC)
* for the duration of the call to `collect_pointers`.
+ *
+ * In principle this is
+ * StgWord collect_pointers(StgClosure *closure, StgWord size, StgClosure *ptrs[size]);
+ * but we cannot write this and retain C++ compatibility.
*/
-StgWord collect_pointers(StgClosure *closure, StgWord size, StgClosure *ptrs[size]);
+StgWord collect_pointers(StgClosure *closure, StgClosure *ptrs[]);
diff --git a/libraries/ghc-heap/tests/create_tso.c b/libraries/ghc-heap/tests/create_tso.c
index 4b00333197..064a88d47b 100644
--- a/libraries/ghc-heap/tests/create_tso.c
+++ b/libraries/ghc-heap/tests/create_tso.c
@@ -17,7 +17,7 @@ void unpack_closure
StgWord closureSizeW = heap_view_closureSize(inClosure);
int closureSizeB = sizeof(StgWord) * closureSizeW;
StgClosure ** pointers = malloc(closureSizeB);
- *outPointersSize = collect_pointers(inClosure, closureSizeW, pointers);
+ *outPointersSize = collect_pointers(inClosure, pointers);
*outPointers = pointers;
// Copy the heap rep.
diff --git a/rts/Heap.c b/rts/Heap.c
index 627b91d5db..9f9154de27 100644
--- a/rts/Heap.c
+++ b/rts/Heap.c
@@ -77,7 +77,7 @@ void heap_view_closure_ptrs_in_pap_payload(StgClosure *ptrs[], StgWord *nptrs
}
// See Heap.h
-StgWord collect_pointers(StgClosure *closure, StgWord size, StgClosure *ptrs[size]) {
+StgWord collect_pointers(StgClosure *closure, StgClosure *ptrs[]) {
StgClosure **end;
const StgInfoTable *info = get_itbl(closure);
StgWord nptrs = 0;
@@ -250,7 +250,7 @@ StgMutArrPtrs *heap_view_closurePtrs(Capability *cap, StgClosure *closure) {
// the closure and then we can allocate space on the heap and copy them
// there
StgClosure *ptrs[size];
- StgWord nptrs = collect_pointers(closure, size, ptrs);
+ StgWord nptrs = collect_pointers(closure, ptrs);
size = nptrs + mutArrPtrsCardTableSize(nptrs);
StgMutArrPtrs *arr =