Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions modules/internal/ChapelArray.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -3693,7 +3693,7 @@ module ChapelArray {
chpl_arrayToPtrErrorHelper(arr);

use CTypes;
const ptr = c_pointer_return(arr[arr.domain.low]);
const ptr = c_addrOf(arr[arr.domain.low]);
if castToVoidStar then
return ptr: c_ptr(void);
else
Expand All @@ -3703,7 +3703,7 @@ module ChapelArray {
chpl_arrayToPtrErrorHelper(arr);

use CTypes;
const ptr = c_pointer_return_const(arr[arr.domain.low]);
const ptr = c_addrOfConst(arr[arr.domain.low]);
if castToVoidStar then
return ptr: c_ptrConst(void);
else
Expand Down
16 changes: 3 additions & 13 deletions modules/internal/ChapelHashtable.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -62,37 +62,27 @@ module ChapelHashtable {

const sizeofElement = _ddata_sizeof_element(ret);

// The memset call below needs to be able to set _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.
inline proc ptrTo(ref x) {
return c_pointer_return(x);
}

select initMethod {
when ArrayInit.noInit {
// do nothing
}
when ArrayInit.serialInit {
for slot in _allSlots(size) {
memset(ptrTo(ret[slot]), 0:uint(8), sizeofElement.safeCast(c_size_t));
memset(c_addrOf(ret[slot]), 0:uint(8), sizeofElement.safeCast(c_size_t));
}
}
when ArrayInit.parallelInit {
// This should match the 'these' iterator in terms of idx->task
forall slot in _allSlots(size) {
memset(ptrTo(ret[slot]), 0:uint(8), sizeofElement.safeCast(c_size_t));
memset(c_addrOf(ret[slot]), 0:uint(8), sizeofElement.safeCast(c_size_t));
}
}
when ArrayInit.gpuInit {
use ChplConfig;
if CHPL_LOCALE_MODEL=="gpu" {
extern proc chpl_gpu_memset(addr, byte, numBytes);
foreach slot in _allSlots(size) {
chpl_gpu_memset(ptrTo(ret[slot]), 0:uint(8), sizeofElement);
chpl_gpu_memset(c_addrOf(ret[slot]), 0:uint(8), sizeofElement);
}
}
else {
Expand Down
47 changes: 10 additions & 37 deletions modules/standard/CTypes.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -953,43 +953,6 @@ module CTypes {

// Begin c_addrOf[Const] definitions

/*
Returns a :type:`c_ptr` to the address of an array.

This is distinct from :func:`c_ptrTo` in that it returns a pointer to
the array object itself, rather than to the first element of the array's
buffer.

Note that the existence of this :type:`c_ptr` has no impact on the lifetime
of the array. The returned pointer will be invalid if the array is freed.
*/
@chpldoc.nodoc
inline proc c_addrOf(ref arr: []) {
if (boundsChecking && arr._value.locale != here) then
// Changed from error to unstable warning in 2.4. Warning can be removed
// once we're confident it's not causing problems.
if chpl_warnUnstable then
compilerWarning(
"calling c_addrOf on an array from another locale is unstable");

return c_pointer_return(arr);
}

/*
Like :proc:`c_addrOf` for arrays, but returns a :type:`c_ptrConst` which
disallows direct modification of the pointee.
*/
@chpldoc.nodoc
inline proc c_addrOfConst(const arr: []) {
if (boundsChecking && arr._value.locale != here) then
// See note on corresponding c_addrOf overload
if chpl_warnUnstable then
compilerWarning(
"calling c_addrOfConst on an array from another locale is unstable");

return c_pointer_return_const(arr);
}

/*
Returns a :type:`c_ptr` to the address of any Chapel object.

Expand All @@ -1001,6 +964,11 @@ module CTypes {
inline proc c_addrOf(ref x: ?t): c_ptr(t) {
if isDomainType(t) then
compilerError("c_addrOf domain type not supported");
if (isArrayType(t) && boundsChecking && x._value.locale != here) then
// See note on corresponding c_addrOf overload
if chpl_warnUnstable then
compilerWarning(
"calling c_addrOf on an array from another locale is unstable");
return c_pointer_return(x);
}

Expand All @@ -1019,6 +987,11 @@ module CTypes {
inline proc c_addrOfConst(const ref x: ?t): c_ptrConst(t) {
if isDomainType(t) then
compilerError("c_addrOfConst domain type not supported");
if (isArrayType(t) && boundsChecking && x._value.locale != here) then
// See note on corresponding c_addrOf overload
if chpl_warnUnstable then
compilerWarning(
"calling c_addrOfConst on an array from another locale is unstable");
return c_pointer_return_const(x);
}

Expand Down