Skip to content

Commit

Permalink
Remove c_ptrTo workarounds in Sort
Browse files Browse the repository at this point in the history
Signed-off-by: Anna Rift <[email protected]>
  • Loading branch information
riftEmber committed Oct 31, 2024
1 parent 067a5ed commit 41805a2
Showing 1 changed file with 7 additions and 22 deletions.
29 changes: 7 additions & 22 deletions modules/standard/Sort.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -1880,21 +1880,6 @@ module ShallowCopy {
private use CTypes;
private use OS.POSIX;

// The shallowCopy / shallowSwap code needs to be able to copy/swap
// _array records. But c_ptrTo on an _array will return a pointer to
// the first element, which messes up the shallowCopy/shallowSwap code
//
// As a workaround, this function just returns a pointer to the argument,
// whether or not it is an array.
//
// TODO: these should be replaced with the appropriate c_addrOf[Const] calls
private inline proc ptrTo(ref x) {
return c_pointer_return(x);
}
private inline proc ptrToConst(const ref x) {
return c_pointer_return_const(x);
}

// These shallow copy functions "move" a record around
// (i.e. they neither swap nor call a copy initializer).
//
Expand All @@ -1907,11 +1892,11 @@ module ShallowCopy {
dst = src;
} else {
var size = c_sizeof(st);
memcpy(ptrTo(dst), ptrTo(src), size);
memcpy(c_addrOf(dst), c_addrOf(src), size);
if boundsChecking {
// The version moved from should never be used again,
// but we clear it out just in case.
memset(ptrTo(src), 0, size);
memset(c_addrOf(src), 0, size);
}
}
}
Expand Down Expand Up @@ -1941,11 +1926,11 @@ module ShallowCopy {
} else {
var size = c_sizeof(st);
// tmp = lhs
memcpy(ptrTo(tmp), ptrTo(lhs), size);
memcpy(c_addrOf(tmp), c_addrOf(lhs), size);
// lhs = rhs
memcpy(ptrTo(lhs), ptrTo(rhs), size);
memcpy(c_addrOf(lhs), c_addrOf(rhs), size);
// rhs = tmp
memcpy(ptrTo(rhs), ptrTo(tmp), size);
memcpy(c_addrOf(rhs), c_addrOf(tmp), size);
}
}

Expand Down Expand Up @@ -1973,7 +1958,7 @@ module ShallowCopy {
if A._instance.isDefaultRectangular() {
type st = __primitive("static field type", A._value, "eltType");
var size = (nElts:c_size_t)*c_sizeof(st);
memcpy(ptrTo(A[dst_idx]), ptrTo(A[src_idx]), size);
memcpy(c_addrOf(A[dst_idx]), c_addrOf(A[src_idx]), size);
} else {
var ok = chpl__bulkTransferArray(/*dst*/ A,
{dst_idx..#nElts_idx},
Expand Down Expand Up @@ -2015,7 +2000,7 @@ module ShallowCopy {
SrcA._instance.isDefaultRectangular() {
type st = __primitive("static field type", DstA._value, "eltType");
var size = (nElts:c_size_t)*c_sizeof(st);
memcpy(ptrTo(DstA[dst_idx]), ptrToConst(SrcA[src_idx]), size);
memcpy(c_addrOf(DstA[dst_idx]), c_addrOfConst(SrcA[src_idx]), size);
} else {
var ok = chpl__bulkTransferArray(/*dst*/ DstA,
{dst_idx..#nElts_dst_idx},
Expand Down

0 comments on commit 41805a2

Please sign in to comment.