Skip to content

Commit

Permalink
Merge pull request #8995 from bradcray/localize-default-hash
Browse files Browse the repository at this point in the history
Use on-clause to compute defaultHash on locale owning string

[reviewed by @mppf and @ronawho ]

This simple change seems to address the problem in issue #8990
by using an on-clause to ensure that defaultHash is computed on
the same locale where a string is allocated.

This leads me to wonder what we could do to guard against such
accidental "remote meddling in string buffer data" mistakes
in the future (e.g., use a getter/setter for the internal data
that contains locality assertions when --checks are on?)

Fixes #8990.
  • Loading branch information
bradcray authored Mar 28, 2018
2 parents 193371b + 5e8f7bd commit fcb5ed7
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 16 deletions.
13 changes: 9 additions & 4 deletions modules/internal/String.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -1870,10 +1870,15 @@ module String {

pragma "no doc"
inline proc chpl__defaultHash(x : string): uint {
// Use djb2 (Dan Bernstein in comp.lang.c), XOR version
var hash: int(64) = 5381;
for c in 0..#(x.length) {
hash = ((hash << 5) + hash) ^ x.buff[c];
var hash: int(64);
on __primitive("chpl_on_locale_num",
chpl_buildLocaleID(x.locale_id, c_sublocid_any)) {
// Use djb2 (Dan Bernstein in comp.lang.c), XOR version
var locHash: int(64) = 5381;
for c in 0..#(x.length) {
locHash = ((locHash << 5) + locHash) ^ x.buff[c];
}
hash = locHash;
}
return hash;
}
Expand Down
Empty file modified test/multilocale/strings/assocOfString.chpl
100755 → 100644
Empty file.
11 changes: 0 additions & 11 deletions test/multilocale/strings/assocOfString.future

This file was deleted.

1 change: 0 additions & 1 deletion test/multilocale/strings/assocOfString.skipif

This file was deleted.

0 comments on commit fcb5ed7

Please sign in to comment.