Skip to content

Commit 76295b1

Browse files
authored
Initialize tuple length fields (#1992)
Thanks to @ggreif and @crusso for helping debugging this.
1 parent 81962fc commit 76295b1

File tree

5 files changed

+137
-0
lines changed

5 files changed

+137
-0
lines changed

rts/blob.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ typedef as_ptr blob_iter_t; // the data structure used to iterate a text value
1717
export blob_iter_t blob_iter(blob_t s) {
1818
as_ptr i = alloc_words(TUPLE_HEADER_SIZE + 2);
1919
TAG(i) = TAG_ARRAY;
20+
TUPLE_LEN(i) = 2;
2021
BLOB_ITER_BLOB(i) = s;
2122
BLOB_ITER_POS(i) = 0;
2223
return i;

rts/text.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ static blob_t find_leaf(text_t s, text_iter_cont_t *todo) {
297297
while (TAG(s) == TAG_CONCAT) {
298298
as_ptr c = alloc_words(TUPLE_HEADER_SIZE + 2);
299299
TAG(c) = TAG_ARRAY;
300+
TUPLE_LEN(c) = 2;
300301
TEXT_CONT_TEXT(c) = CONCAT_ARG2(s);
301302
TEXT_CONT_NEXT(c) = *todo;
302303
*todo = c;
@@ -308,6 +309,7 @@ static blob_t find_leaf(text_t s, text_iter_cont_t *todo) {
308309
export text_iter_t text_iter(text_t s) {
309310
as_ptr i = alloc_words(TUPLE_HEADER_SIZE + 3);
310311
TAG(i) = TAG_ARRAY;
312+
TUPLE_LEN(i) = 3;
311313
TEXT_ITER_POS(i) = 0;
312314
TEXT_ITER_TODO(i) = 0;
313315
TEXT_ITER_BLOB(i) = find_leaf(s, &TEXT_ITER_TODO(i));

test/run-drun/gc.mo

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import Prim "mo:prim";
2+
// check blob and text iterator objects survive gc correctly
3+
actor {
4+
public shared func testBytes() : async () {
5+
let blob = "\00\01\02\03" : Blob;
6+
for (b in blob.bytes()) {
7+
await async {};
8+
Prim.debugPrint(debug_show b);
9+
};
10+
};
11+
12+
public shared func testChars() : async () {
13+
let text = "abcd" # "efgh" # "hijklmnopqrstuvwxyz";
14+
for (c in text.chars()) {
15+
await async {};
16+
Prim.debugPrint(debug_show c);
17+
};
18+
};
19+
20+
public shared func testArray() : async () {
21+
let is = ["0","1","2"];
22+
for (i in is.vals()) {
23+
await async {};
24+
Prim.debugPrint(debug_show i);
25+
};
26+
};
27+
28+
29+
public shared func testArrayMut() : async () {
30+
let is = [var "0","1","2"];
31+
for (i in is.vals()) {
32+
await async {};
33+
Prim.debugPrint(debug_show i);
34+
};
35+
};
36+
}
37+
38+
//CALL ingress testBytes "DIDL\x00\x00"
39+
//CALL ingress testChars "DIDL\x00\x00"
40+
//CALL ingress testArray "DIDL\x00\x00"
41+
//CALL ingress testArrayMut "DIDL\x00\x00"
42+

test/run-drun/ok/gc.drun-run.ok

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
ingress Completed: Reply: 0x4449444c016c01b3c4b1f2046801000112010000000000000000000000000000000001
2+
ingress Completed: Reply: 0x4449444c0000
3+
debug.print: 0x0
4+
debug.print: 0x1
5+
debug.print: 0x2
6+
debug.print: 0x3
7+
ingress Completed: Reply: 0x4449444c0000
8+
debug.print: 'a'
9+
debug.print: 'b'
10+
debug.print: 'c'
11+
debug.print: 'd'
12+
debug.print: 'e'
13+
debug.print: 'f'
14+
debug.print: 'g'
15+
debug.print: 'h'
16+
debug.print: 'h'
17+
debug.print: 'i'
18+
debug.print: 'j'
19+
debug.print: 'k'
20+
debug.print: 'l'
21+
debug.print: 'm'
22+
debug.print: 'n'
23+
debug.print: 'o'
24+
debug.print: 'p'
25+
debug.print: 'q'
26+
debug.print: 'r'
27+
debug.print: 's'
28+
debug.print: 't'
29+
debug.print: 'u'
30+
debug.print: 'v'
31+
debug.print: 'w'
32+
debug.print: 'x'
33+
debug.print: 'y'
34+
debug.print: 'z'
35+
ingress Completed: Reply: 0x4449444c0000
36+
debug.print: "0"
37+
debug.print: "1"
38+
debug.print: "2"
39+
ingress Completed: Reply: 0x4449444c0000
40+
debug.print: "0"
41+
debug.print: "1"
42+
debug.print: "2"
43+
ingress Completed: Reply: 0x4449444c0000

test/run-drun/ok/gc.ic-ref-run.ok

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
→ update create_canister()
2+
← completed: (record {1313628723 = service "cvccv-qqaaq-aaaaa-aaaaa-c"})
3+
→ update install_code(record {4849238 = blob ""; 265441191 = blob "\00asm\01\00\0…
4+
← completed: ()
5+
→ update testBytes()
6+
debug.print: 0x0
7+
debug.print: 0x1
8+
debug.print: 0x2
9+
debug.print: 0x3
10+
← completed: ()
11+
→ update testChars()
12+
debug.print: 'a'
13+
debug.print: 'b'
14+
debug.print: 'c'
15+
debug.print: 'd'
16+
debug.print: 'e'
17+
debug.print: 'f'
18+
debug.print: 'g'
19+
debug.print: 'h'
20+
debug.print: 'h'
21+
debug.print: 'i'
22+
debug.print: 'j'
23+
debug.print: 'k'
24+
debug.print: 'l'
25+
debug.print: 'm'
26+
debug.print: 'n'
27+
debug.print: 'o'
28+
debug.print: 'p'
29+
debug.print: 'q'
30+
debug.print: 'r'
31+
debug.print: 's'
32+
debug.print: 't'
33+
debug.print: 'u'
34+
debug.print: 'v'
35+
debug.print: 'w'
36+
debug.print: 'x'
37+
debug.print: 'y'
38+
debug.print: 'z'
39+
← completed: ()
40+
→ update testArray()
41+
debug.print: "0"
42+
debug.print: "1"
43+
debug.print: "2"
44+
← completed: ()
45+
→ update testArrayMut()
46+
debug.print: "0"
47+
debug.print: "1"
48+
debug.print: "2"
49+
← completed: ()

0 commit comments

Comments
 (0)