fix sized deallocation for proc
This commit is contained in:
parent
395e453c06
commit
5aa2da0133
|
@ -14,7 +14,7 @@
|
|||
|
||||
use core::ptr::RawPtr;
|
||||
#[cfg(not(test))] use core::raw;
|
||||
#[cfg(not(test))] use util;
|
||||
#[cfg(stage0, not(test))] use util;
|
||||
|
||||
/// Returns a pointer to `size` bytes of memory.
|
||||
///
|
||||
|
@ -119,7 +119,7 @@ unsafe fn exchange_free(ptr: *mut u8, size: uint, align: uint) {
|
|||
}
|
||||
|
||||
// FIXME: #7496
|
||||
#[cfg(not(test))]
|
||||
#[cfg(stage0, not(test))]
|
||||
#[lang="closure_exchange_malloc"]
|
||||
#[inline]
|
||||
#[allow(deprecated)]
|
||||
|
@ -134,6 +134,21 @@ unsafe fn closure_exchange_malloc(drop_glue: fn(*mut u8), size: uint,
|
|||
alloc as *mut u8
|
||||
}
|
||||
|
||||
// FIXME: #7496
|
||||
#[cfg(not(stage0), not(test))]
|
||||
#[lang="closure_exchange_malloc"]
|
||||
#[inline]
|
||||
#[allow(deprecated)]
|
||||
unsafe fn closure_exchange_malloc(drop_glue: fn(*mut u8), size: uint,
|
||||
align: uint) -> *mut u8 {
|
||||
let p = allocate(size, align);
|
||||
|
||||
let alloc = p as *mut raw::Box<()>;
|
||||
(*alloc).drop_glue = drop_glue;
|
||||
|
||||
alloc as *mut u8
|
||||
}
|
||||
|
||||
#[cfg(jemalloc)]
|
||||
mod imp {
|
||||
use core::option::{None, Option};
|
||||
|
|
|
@ -66,7 +66,7 @@ use middle::trans::glue;
|
|||
use middle::trans::inline;
|
||||
use middle::trans::intrinsic;
|
||||
use middle::trans::machine;
|
||||
use middle::trans::machine::{llsize_of, llsize_of_real};
|
||||
use middle::trans::machine::{llsize_of, llsize_of_real, llalign_of_min};
|
||||
use middle::trans::meth;
|
||||
use middle::trans::monomorphize;
|
||||
use middle::trans::tvec;
|
||||
|
@ -382,13 +382,44 @@ pub fn malloc_raw_dyn<'a>(bcx: &'a Block<'a>,
|
|||
Result::new(r.bcx, PointerCast(r.bcx, r.val, llty_ptr))
|
||||
}
|
||||
|
||||
pub fn malloc_raw_dyn_proc<'a>(
|
||||
bcx: &'a Block<'a>,
|
||||
t: ty::t, alloc_fn: LangItem) -> Result<'a> {
|
||||
let _icx = push_ctxt("malloc_raw_dyn_proc");
|
||||
let ccx = bcx.ccx();
|
||||
|
||||
let langcall = require_alloc_fn(bcx, t, alloc_fn);
|
||||
|
||||
// Grab the TypeRef type of ptr_ty.
|
||||
let ptr_ty = ty::mk_uniq(bcx.tcx(), t);
|
||||
let ptr_llty = type_of(ccx, ptr_ty);
|
||||
|
||||
let llty = type_of(bcx.ccx(), t);
|
||||
let size = llsize_of(bcx.ccx(), llty);
|
||||
let llalign = C_uint(ccx, llalign_of_min(bcx.ccx(), llty) as uint);
|
||||
|
||||
// Allocate space:
|
||||
let drop_glue = glue::get_drop_glue(ccx, ty::mk_uniq(bcx.tcx(), t));
|
||||
let r = callee::trans_lang_call(
|
||||
bcx,
|
||||
langcall,
|
||||
[
|
||||
PointerCast(bcx, drop_glue, Type::glue_fn(ccx, Type::i8p(ccx)).ptr_to()),
|
||||
size,
|
||||
llalign
|
||||
],
|
||||
None);
|
||||
Result::new(r.bcx, PointerCast(r.bcx, r.val, ptr_llty))
|
||||
}
|
||||
|
||||
|
||||
pub fn malloc_raw_dyn_managed<'a>(
|
||||
bcx: &'a Block<'a>,
|
||||
t: ty::t,
|
||||
alloc_fn: LangItem,
|
||||
size: ValueRef)
|
||||
-> Result<'a> {
|
||||
let _icx = push_ctxt("malloc_raw_managed");
|
||||
let _icx = push_ctxt("malloc_raw_dyn_managed");
|
||||
let ccx = bcx.ccx();
|
||||
|
||||
let langcall = require_alloc_fn(bcx, t, alloc_fn);
|
||||
|
|
|
@ -24,7 +24,6 @@ use middle::trans::common::*;
|
|||
use middle::trans::datum::{Datum, DatumBlock, Expr, Lvalue, rvalue_scratch_datum};
|
||||
use middle::trans::debuginfo;
|
||||
use middle::trans::expr;
|
||||
use middle::trans::machine::llsize_of;
|
||||
use middle::trans::type_of::*;
|
||||
use middle::trans::type_::Type;
|
||||
use middle::ty;
|
||||
|
@ -144,15 +143,12 @@ fn allocate_cbox<'a>(bcx: &'a Block<'a>,
|
|||
let tcx = bcx.tcx();
|
||||
|
||||
// Allocate and initialize the box:
|
||||
let cbox_ty = tuplify_box_ty(tcx, cdata_ty);
|
||||
match store {
|
||||
ty::UniqTraitStore => {
|
||||
let ty = type_of(bcx.ccx(), cdata_ty);
|
||||
let size = llsize_of(bcx.ccx(), ty);
|
||||
// we treat proc as @ here, which isn't ideal
|
||||
malloc_raw_dyn_managed(bcx, cdata_ty, ClosureExchangeMallocFnLangItem, size)
|
||||
malloc_raw_dyn_proc(bcx, cbox_ty, ClosureExchangeMallocFnLangItem)
|
||||
}
|
||||
ty::RegionTraitStore(..) => {
|
||||
let cbox_ty = tuplify_box_ty(tcx, cdata_ty);
|
||||
let llbox = alloc_ty(bcx, cbox_ty, "__closure");
|
||||
Result::new(bcx, llbox)
|
||||
}
|
||||
|
|
|
@ -520,12 +520,8 @@ fn make_drop_glue<'a>(bcx: &'a Block<'a>, v0: ValueRef, t: ty::t) -> &'a Block<'
|
|||
with_cond(bcx, IsNotNull(bcx, env), |bcx| {
|
||||
let dtor_ptr = GEPi(bcx, env, [0u, abi::box_field_tydesc]);
|
||||
let dtor = Load(bcx, dtor_ptr);
|
||||
let cdata = GEPi(bcx, env, [0u, abi::box_field_body]);
|
||||
Call(bcx, dtor, [PointerCast(bcx, cdata, Type::i8p(bcx.ccx()))], None);
|
||||
|
||||
// Free the environment itself
|
||||
// FIXME: #13994: pass align and size here
|
||||
trans_exchange_free(bcx, env, 0, 8)
|
||||
Call(bcx, dtor, [PointerCast(bcx, box_cell_v, Type::i8p(bcx.ccx()))], None);
|
||||
bcx
|
||||
})
|
||||
}
|
||||
ty::ty_trait(..) => {
|
||||
|
|
Loading…
Reference in New Issue