aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRoy Frostig <[email protected]>2010-08-26 14:44:03 -0700
committerRoy Frostig <[email protected]>2010-08-26 14:44:11 -0700
commit8559a85ccacf70c51d93759b47a3880ae818b247 (patch)
treea876043c326e22a467f644c4bdd3994aaa8fb083 /src
parentAdd check to catch bug underlying issue #152. Fix will take longer. (diff)
downloadrust-8559a85ccacf70c51d93759b47a3880ae818b247.tar.xz
rust-8559a85ccacf70c51d93759b47a3880ae818b247.zip
When copying function values, null out the destination's binding iff the source's binding is null.
Diffstat (limited to 'src')
-rw-r--r--src/boot/me/trans.ml15
-rw-r--r--src/test/run-pass/lib-map.rs24
2 files changed, 24 insertions, 15 deletions
diff --git a/src/boot/me/trans.ml b/src/boot/me/trans.ml
index 8deda627..d83f6c52 100644
--- a/src/boot/me/trans.ml
+++ b/src/boot/me/trans.ml
@@ -2933,12 +2933,18 @@ let trans_visitor
: unit =
drop_ty (get_ty_params_of_current_frame()) cell ty None
+ (* Returns a mark for a jmp that must be patched to the continuation of
+ * the null case (i.e. fall-through means not null).
+ *)
and null_check (cell:Il.cell) : quad_idx =
emit (Il.cmp (Il.Cell cell) zero);
let j = mark() in
emit (Il.jmp Il.JE Il.CodeNone);
j
+ (* Returns a mark for a jmp that must be patched to the continuation of
+ * the non-zero refcount case (i.e. fall-through means zero refcount).
+ *)
and drop_refcount_and_cmp (boxed:Il.cell) : quad_idx =
iflog (fun _ -> annotate "drop refcount and maybe free");
let rc = box_rc_cell boxed in
@@ -3268,7 +3274,14 @@ let trans_visitor
dst_binding (Ast.TY_box Ast.TY_int)
src_binding (Ast.TY_box Ast.TY_int)
curr_iso;
- patch null_jmp
+ let end_jmp = mark() in
+ emit (Il.jmp Il.JMP Il.CodeNone);
+ patch null_jmp;
+ (* The src had a null binding, so make sure the dst
+ * does now too.
+ *)
+ mov dst_binding zero;
+ patch end_jmp
end
| _ ->
diff --git a/src/test/run-pass/lib-map.rs b/src/test/run-pass/lib-map.rs
index bc70e51c..51285c06 100644
--- a/src/test/run-pass/lib-map.rs
+++ b/src/test/run-pass/lib-map.rs
@@ -13,11 +13,8 @@ fn test_simple() {
ret u;
}
- // FIXME we don't really want to bind here but if we don't then the
- // hashmap's drop glue UMRs when trying to drop these functions, which
- // it stores internally.
- let map.hashfn[uint] hasher = bind hash(_);
- let map.eqfn[uint] eqer = bind eq(_, _);
+ let map.hashfn[uint] hasher = hash;
+ let map.eqfn[uint] eqer = eq;
let map.hashmap[uint, uint] hm = map.mk_hashmap[uint, uint](hasher, eqer);
hm.insert(10u, 12u);
@@ -43,7 +40,7 @@ fn test_simple() {
fn test_growth() {
log "*** starting test_growth";
- let uint map_capacity = 64u; // Keep in sync with map.mk_hashmap
+ let uint num_to_insert = 64u;
fn eq(&uint x, &uint y) -> bool { ret x == y; }
fn hash(&uint u) -> uint {
@@ -52,13 +49,12 @@ fn test_growth() {
ret u;
}
- // FIXME: as in test_simple(), don't really want to bind.
- let map.hashfn[uint] hasher = bind hash(_);
- let map.eqfn[uint] eqer = bind eq(_, _);
+ let map.hashfn[uint] hasher = hash;
+ let map.eqfn[uint] eqer = eq;
let map.hashmap[uint, uint] hm = map.mk_hashmap[uint, uint](hasher, eqer);
let uint i = 0u;
- while (i < map_capacity) {
+ while (i < num_to_insert) {
hm.insert(i, i * i);
log "inserting " + std._uint.to_str(i, 10u)
+ " -> " + std._uint.to_str(i * i, 10u);
@@ -68,22 +64,22 @@ fn test_growth() {
log "-----";
i = 0u;
- while (i < map_capacity) {
+ while (i < num_to_insert) {
log "get(" + std._uint.to_str(i, 10u) + ") = "
+ std._uint.to_str(hm.get(i), 10u);
check (hm.get(i) == i * i);
i += 1u;
}
- hm.insert(map_capacity, 17u);
- check (hm.get(map_capacity) == 17u);
+ hm.insert(num_to_insert, 17u);
+ check (hm.get(num_to_insert) == 17u);
log "-----";
hm.rehash();
i = 0u;
- while (i < map_capacity) {
+ while (i < num_to_insert) {
log "get(" + std._uint.to_str(i, 10u) + ") = "
+ std._uint.to_str(hm.get(i), 10u);
check (hm.get(i) == i * i);