Skip to content

Commit fcb5ed7

Browse files
authored
Merge pull request #8995 from bradcray/localize-default-hash
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.
2 parents 193371b + 5e8f7bd commit fcb5ed7

File tree

4 files changed

+9
-16
lines changed

4 files changed

+9
-16
lines changed

Diff for: modules/internal/String.chpl

+9-4
Original file line numberDiff line numberDiff line change
@@ -1870,10 +1870,15 @@ module String {
18701870

18711871
pragma "no doc"
18721872
inline proc chpl__defaultHash(x : string): uint {
1873-
// Use djb2 (Dan Bernstein in comp.lang.c), XOR version
1874-
var hash: int(64) = 5381;
1875-
for c in 0..#(x.length) {
1876-
hash = ((hash << 5) + hash) ^ x.buff[c];
1873+
var hash: int(64);
1874+
on __primitive("chpl_on_locale_num",
1875+
chpl_buildLocaleID(x.locale_id, c_sublocid_any)) {
1876+
// Use djb2 (Dan Bernstein in comp.lang.c), XOR version
1877+
var locHash: int(64) = 5381;
1878+
for c in 0..#(x.length) {
1879+
locHash = ((locHash << 5) + locHash) ^ x.buff[c];
1880+
}
1881+
hash = locHash;
18771882
}
18781883
return hash;
18791884
}

Diff for: test/multilocale/strings/assocOfString.chpl

100755100644
File mode changed.

Diff for: test/multilocale/strings/assocOfString.future

-11
This file was deleted.

Diff for: test/multilocale/strings/assocOfString.skipif

-1
This file was deleted.

0 commit comments

Comments
 (0)