Skip to content

Commit 70a986d

Browse files
committed
Revert "Remove c_ptrTo workarounds in Sort"
This reverts commit f390c61. Reverted as it seems these workarounds have been removed from Sort on main in the meantime.
1 parent 536fb2f commit 70a986d

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

modules/standard/Sort.chpl

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1859,6 +1859,21 @@ module ShallowCopy {
18591859
private use CTypes;
18601860
private use OS.POSIX;
18611861

1862+
// The shallowCopy / shallowSwap code needs to be able to copy/swap
1863+
// _array records. But c_ptrTo on an _array will return a pointer to
1864+
// the first element, which messes up the shallowCopy/shallowSwap code
1865+
//
1866+
// As a workaround, this function just returns a pointer to the argument,
1867+
// whether or not it is an array.
1868+
//
1869+
// TODO: these should be replaced with the appropriate c_addrOf[Const] calls
1870+
private inline proc ptrTo(ref x) {
1871+
return c_pointer_return(x);
1872+
}
1873+
private inline proc ptrToConst(const ref x) {
1874+
return c_pointer_return_const(x);
1875+
}
1876+
18621877
// These shallow copy functions "move" a record around
18631878
// (i.e. they neither swap nor call a copy initializer).
18641879
//
@@ -1871,11 +1886,11 @@ module ShallowCopy {
18711886
dst = src;
18721887
} else {
18731888
var size = c_sizeof(st);
1874-
memcpy(c_addrOf(dst), c_addrOf(src), size);
1889+
memcpy(ptrTo(dst), ptrTo(src), size);
18751890
if boundsChecking {
18761891
// The version moved from should never be used again,
18771892
// but we clear it out just in case.
1878-
memset(c_addrOf(src), 0, size);
1893+
memset(ptrTo(src), 0, size);
18791894
}
18801895
}
18811896
}
@@ -1905,11 +1920,11 @@ module ShallowCopy {
19051920
} else {
19061921
var size = c_sizeof(st);
19071922
// tmp = lhs
1908-
memcpy(c_addrOf(tmp), c_addrOf(lhs), size);
1923+
memcpy(ptrTo(tmp), ptrTo(lhs), size);
19091924
// lhs = rhs
1910-
memcpy(c_addrOf(lhs), c_addrOf(rhs), size);
1925+
memcpy(ptrTo(lhs), ptrTo(rhs), size);
19111926
// rhs = tmp
1912-
memcpy(c_addrOf(rhs), c_addrOf(tmp), size);
1927+
memcpy(ptrTo(rhs), ptrTo(tmp), size);
19131928
}
19141929
}
19151930

@@ -1937,7 +1952,7 @@ module ShallowCopy {
19371952
if A._instance.isDefaultRectangular() {
19381953
type st = __primitive("static field type", A._value, "eltType");
19391954
var size = (nElts:c_size_t)*c_sizeof(st);
1940-
memcpy(c_addrOf(A[dst_idx]), c_addrOf(A[src_idx]), size);
1955+
memcpy(ptrTo(A[dst_idx]), ptrTo(A[src_idx]), size);
19411956
} else {
19421957
var ok = chpl__bulkTransferArray(/*dst*/ A,
19431958
{dst_idx..#nElts_idx},
@@ -1979,7 +1994,7 @@ module ShallowCopy {
19791994
SrcA._instance.isDefaultRectangular() {
19801995
type st = __primitive("static field type", DstA._value, "eltType");
19811996
var size = (nElts:c_size_t)*c_sizeof(st);
1982-
memcpy(c_addrOf(DstA[dst_idx]), c_addrOfConst(SrcA[src_idx]), size);
1997+
memcpy(ptrTo(DstA[dst_idx]), ptrToConst(SrcA[src_idx]), size);
19831998
} else {
19841999
var ok = chpl__bulkTransferArray(/*dst*/ DstA,
19852000
{dst_idx..#nElts_dst_idx},

0 commit comments

Comments
 (0)