mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-08 04:56:58 +00:00
When copying function values, null out the destination's binding iff the source's binding is null.
This commit is contained in:
parent
ee04c0236c
commit
8559a85cca
@ -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
|
||||
|
||||
| _ ->
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user