Skip to content

Commit 47e86a0

Browse files
committed
Fix rust_vec constructor assertion failure caused by slow path of upcall_vec_grow. Add testcase.
1 parent 11e747f commit 47e86a0

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

src/rt/rust_upcall.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ upcall_vec_grow(rust_task *task, rust_vec *v, size_t n_bytes, uintptr_t is_gc)
381381
LOG_UPCALL_ENTRY(task);
382382
rust_dom *dom = task->dom;
383383
task->log(rust_log::UPCALL|rust_log::MEM,
384-
"upcall vec_grow(%" PRIxPTR ", %" PRIdPTR
384+
"upcall vec_grow(0x%" PRIxPTR ", %" PRIdPTR
385385
"), alloc=%" PRIdPTR ", fill=%" PRIdPTR,
386386
v, n_bytes, v->alloc, v->fill);
387387
size_t alloc = next_power_of_two(sizeof(rust_vec) + v->fill + n_bytes);
@@ -411,7 +411,8 @@ upcall_vec_grow(rust_task *task, rust_vec *v, size_t n_bytes, uintptr_t is_gc)
411411
return NULL;
412412
}
413413
v->deref();
414-
v = new (mem) rust_vec(dom, alloc, v->fill, &v->data[0]);
414+
v = new (mem) rust_vec(dom, alloc, v->fill,
415+
v->fill ? &v->data[0] : NULL);
415416
}
416417
I(dom, sizeof(rust_vec) + v->fill <= v->alloc);
417418
return v;

src/test/run-pass/vec-append.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,25 @@
11
// -*- rust -*-
22

3-
fn main() {
3+
fn fast_growth() {
44
let vec[int] v = vec(1,2,3,4,5);
55
v += vec(6,7,8,9,0);
6+
67
log v.(9);
78
check(v.(0) == 1);
89
check(v.(7) == 8);
910
check(v.(9) == 0);
1011
}
12+
13+
fn slow_growth() {
14+
let vec[int] v = vec();
15+
let vec[int] u = v;
16+
v += vec(17);
17+
18+
log v.(0);
19+
check (v.(0) == 17);
20+
}
21+
22+
fn main() {
23+
fast_growth();
24+
slow_growth();
25+
}

0 commit comments

Comments
 (0)