Make sure resources always have their drop glue called

Even when their content does not contain pointers
This commit is contained in:
Marijn Haverbeke 2011-07-29 12:53:58 +02:00
parent 0ba34d873d
commit ae46c154f0
2 changed files with 9 additions and 1 deletions

View file

@ -2403,7 +2403,7 @@ fn drop_slot(cx: &@block_ctxt, slot: ValueRef, t: &ty::t) -> result {
}
fn drop_ty(cx: &@block_ctxt, v: ValueRef, t: ty::t) -> result {
if ty::type_has_pointers(bcx_tcx(cx), t) {
if ty::type_needs_drop(bcx_tcx(cx), t) {
ret call_tydesc_glue(cx, v, t, abi::tydesc_field_drop_glue);
}
ret rslt(cx, C_nil());

View file

@ -157,6 +157,7 @@ export type_err;
export type_err_to_str;
export type_has_dynamic_size;
export type_has_pointers;
export type_needs_drop;
export type_is_bool;
export type_is_bot;
export type_is_box;
@ -1022,6 +1023,13 @@ fn type_has_pointers(cx: &ctxt, ty: &t) -> bool {
ret result;
}
fn type_needs_drop(cx: &ctxt, ty: &t) -> bool {
ret alt struct(cx, ty) {
ty_res(_, _, _) { true }
_ { type_has_pointers(cx, ty) }
};
}
fn type_kind(cx: &ctxt, ty: &t) -> ast::kind {
alt cx.kind_cache.find(ty) {
some(result) { ret result; }