// FIXME: #13996: mark the `allocate` and `reallocate` return value as `noalias`
-#[cfg(not(test))] use core::raw;
+#[cfg(stage0, not(test))] use core::raw;
#[cfg(stage0, not(test))] use util;
/// Returns a pointer to `size` bytes of memory.
deallocate(ptr, size, align);
}
-// FIXME: #7496
#[cfg(stage0, not(test))]
#[lang="closure_exchange_malloc"]
#[inline]
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
-}
-
// The minimum alignment guaranteed by the architecture. This value is used to
// add fast paths for low alignment values. In practice, the alignment is a
// constant at the call site and the branch will be optimized out.
BeginUnwindLangItem, "begin_unwind", begin_unwind;
ExchangeMallocFnLangItem, "exchange_malloc", exchange_malloc_fn;
- ClosureExchangeMallocFnLangItem, "closure_exchange_malloc", closure_exchange_malloc_fn;
ExchangeFreeFnLangItem, "exchange_free", exchange_free_fn;
MallocFnLangItem, "malloc", malloc_fn;
FreeFnLangItem, "free", free_fn;
Result::new(r.bcx, PointerCast(r.bcx, r.val, llty_ptr))
}
-pub fn malloc_raw_dyn_proc<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
- t: ty::t, alloc_fn: LangItem)
- -> Result<'blk, 'tcx> {
+pub fn malloc_raw_dyn_proc<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, t: ty::t) -> Result<'blk, 'tcx> {
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 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))
+ // Allocate space and store the destructor pointer:
+ let Result {bcx: bcx, val: llbox} = malloc_raw_dyn(bcx, ptr_llty, t, size, llalign);
+ let dtor_ptr = GEPi(bcx, llbox, [0u, abi::box_field_drop_glue]);
+ let drop_glue_field_ty = type_of(ccx, ty::mk_nil_ptr(bcx.tcx()));
+ let drop_glue = PointerCast(bcx, glue::get_drop_glue(ccx, ty::mk_uniq(bcx.tcx(), t)),
+ drop_glue_field_ty);
+ Store(bcx, drop_glue, dtor_ptr);
+
+ Result::new(bcx, llbox)
}
use llvm::ValueRef;
use middle::def;
use middle::freevars;
-use middle::lang_items::ClosureExchangeMallocFnLangItem;
use middle::trans::adt;
use middle::trans::base::*;
use middle::trans::build::*;
let cbox_ty = tuplify_box_ty(tcx, cdata_ty);
match store {
ty::UniqTraitStore => {
- malloc_raw_dyn_proc(bcx, cbox_ty, ClosureExchangeMallocFnLangItem)
+ malloc_raw_dyn_proc(bcx, cbox_ty)
}
ty::RegionTraitStore(..) => {
let llbox = alloc_ty(bcx, cbox_ty, "__closure");
let env_ptr_ty = Type::at_box(bcx.ccx(), Type::i8(bcx.ccx())).ptr_to();
let env = PointerCast(bcx, env, env_ptr_ty);
with_cond(bcx, IsNotNull(bcx, env), |bcx| {
- let dtor_ptr = GEPi(bcx, env, [0u, abi::box_field_tydesc]);
+ let dtor_ptr = GEPi(bcx, env, [0u, abi::box_field_drop_glue]);
let dtor = Load(bcx, dtor_ptr);
Call(bcx, dtor, [PointerCast(bcx, box_cell_v, Type::i8p(bcx.ccx()))], None);
bcx
// except according to those terms.
pub static box_field_refcnt: uint = 0u;
-pub static box_field_tydesc: uint = 1u;
+pub static box_field_drop_glue: uint = 1u;
pub static box_field_body: uint = 4u;
pub static tydesc_field_visit_glue: uint = 3u;