Skip to content

Commit 5a5ae74

Browse files
committed
FIX: problem with externally modified keys of map!
fixes: Oldes/Rebol-issues#2220
1 parent a95ce75 commit 5a5ae74

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

src/core/t-map.c

+15-2
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@
221221
REBCNT *hashes;
222222
REBCNT hash;
223223
REBCNT n;
224+
REBVAL *set;
224225

225226
if (IS_NONE(key) || hser == NULL) return 0;
226227

@@ -248,14 +249,26 @@
248249
// append key
249250
if(ANY_WORD(key) && VAL_TYPE(key) != REB_SET_WORD) {
250251
// Normalize the KEY (word) to be a SET-WORD
251-
REBVAL *set = Append_Value(series);
252+
set = Append_Value(series);
252253
*set = *key;
253254
VAL_SET(set, REB_SET_WORD);
255+
} else if (ANY_BINSTR(key) && !IS_LOCK_SERIES(VAL_SERIES(key))) {
256+
// copy the key if it is any-series (except when it is permanently locked)
257+
set = Append_Value(series);
258+
VAL_SERIES(set) = Copy_String(VAL_SERIES(key), VAL_INDEX(key), VAL_LEN(key));
259+
VAL_TYPE(set) = VAL_TYPE(key);
254260
} else {
255261
Append_Val(series, key);
256262
}
257263
#else
258-
Append_Val(series, key);
264+
if (ANY_BINSTR(key) && !IS_LOCK_SERIES(VAL_SERIES(key))) {
265+
// copy the key if it is any-series (except when it is permanently locked)
266+
set = Append_Value(series);
267+
VAL_SERIES(set) = Copy_String(VAL_SERIES(key), VAL_INDEX(key), VAL_LEN(key));
268+
VAL_TYPE(set) = VAL_TYPE(key);
269+
} else {
270+
Append_Val(series, key);
271+
}
259272
#endif
260273
// append value
261274
Append_Val(series, val); // no Copy_Series_Value(val) on strings

src/tests/units/map-test.r3

+12
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,18 @@ Rebol [
5858
n: copy/deep m
5959
--assert not same? n/b m/b
6060

61+
;@@ https://github.com/Oldes/Rebol-issues/issues/2220
62+
--test-- "map-issue-2220"
63+
; using at least 8 keys (initial map implemention was using internally block for small maps)
64+
keys: ["a" #{} #{00} a@b http://a http://b %file1 %file2]
65+
m: map collect [repeat i 8 [keep keys/:i keep i]]
66+
--assert keys = keys-of m
67+
repeat i 8 [
68+
--assert i = select m keys/:i
69+
append keys/:i #"X"
70+
--assert none? select m keys/:i
71+
]
72+
6173
===end-group===
6274

6375

0 commit comments

Comments
 (0)