pub fn malloc_raw_dyn<'a>(
                      bcx: &'a Block,
                      t: ty::t,
                      heap: heap,
                      size: ValueRef)
                      -> Result<'a> {
    let _icx = push_ctxt("malloc_raw");
    let ccx = bcx.ccx();

    fn require_alloc_fn(bcx: &Block, t: ty::t, it: LangItem) -> ast::DefId {
        let li = &bcx.tcx().lang_items;
        match li.require(it) {
            Ok(id) => id,
            Err(s) => {
                bcx.tcx().sess.fatal(format!("allocation of `{}` {}",
                                          bcx.ty_to_str(t), s));
            }
        }
    }

    if heap == heap_exchange {
        let llty_value = type_of::type_of(ccx, t);


        // Allocate space:
        let r = callee::trans_lang_call(
            bcx,
            require_alloc_fn(bcx, t, ExchangeMallocFnLangItem),
            [size],
            None);
        rslt(r.bcx, PointerCast(r.bcx, r.val, llty_value.ptr_to()))
    } else {
        // we treat ~fn, @fn and @[] as @ here, which isn't ideal
        let langcall = match heap {
            heap_managed => {
                require_alloc_fn(bcx, t, MallocFnLangItem)
            }
            heap_exchange_closure => {
                require_alloc_fn(bcx, t, ClosureExchangeMallocFnLangItem)
            }
            _ => fail!("heap_exchange already handled")
        };

        // Grab the TypeRef type of box_ptr_ty.
        let box_ptr_ty = ty::mk_box(bcx.tcx(), t);
        let llty = type_of(ccx, box_ptr_ty);

        // Get the tydesc for the body:
        let static_ti = get_tydesc(ccx, t);
        glue::lazily_emit_all_tydesc_glue(ccx, static_ti);

        // Allocate space:
        let tydesc = PointerCast(bcx, static_ti.tydesc, Type::i8p());
        let r = callee::trans_lang_call(
            bcx,
            langcall,
            [tydesc, size],
            None);
        rslt(r.bcx, PointerCast(r.bcx, r.val, llty))
    }
}
// malloc_raw_dyn: allocates a box to contain a given type, but with a
// potentially dynamic size.
allocates a box to contain a given type, but with a
potentially dynamic size.
allocates a box to contain a given type but with a potentially dynamic size .
pub fn malloc_raw_dyn<'a>(
                      bcx: &'a Block,
                      t: ty::t,
                      heap: heap,
                      size: ValueRef)
                      -> Result<'a> {
    let _icx = push_ctxt("malloc_raw");
    let ccx = bcx.ccx();
    fn require_alloc_fn(bcx: &Block, t: ty::t, it: LangItem) -> ast::DefId {
        let li = &bcx.tcx().lang_items;
        match li.require(it) {
            Ok(id) => id,
            Err(s) => {
                bcx.tcx().sess.fatal(format!("allocation of `{}` {}",
                                          bcx.ty_to_str(t), s));
            }
        }
    }
    if heap == heap_exchange {
        let llty_value = type_of::type_of(ccx, t);
        // Allocate space:
        let r = callee::trans_lang_call(
            bcx,
            require_alloc_fn(bcx, t, ExchangeMallocFnLangItem),
            [size],
            None);
        rslt(r.bcx, PointerCast(r.bcx, r.val, llty_value.ptr_to()))
    } else {
        // we treat ~fn, @fn and @[] as @ here, which isn't ideal
        let langcall = match heap {
            heap_managed => {
                require_alloc_fn(bcx, t, MallocFnLangItem)
            }
            heap_exchange_closure => {
                require_alloc_fn(bcx, t, ClosureExchangeMallocFnLangItem)
            }
            _ => fail!("heap_exchange already handled")
        };
        // Grab the TypeRef type of box_ptr_ty.
        let box_ptr_ty = ty::mk_box(bcx.tcx(), t);
        let llty = type_of(ccx, box_ptr_ty);
        // Get the tydesc for the body:
        let static_ti = get_tydesc(ccx, t);
        glue::lazily_emit_all_tydesc_glue(ccx, static_ti);
        // Allocate space:
        let tydesc = PointerCast(bcx, static_ti.tydesc, Type::i8p());
        let r = callee::trans_lang_call(
            bcx,
            langcall,
            [tydesc, size],
            None);
        rslt(r.bcx, PointerCast(r.bcx, r.val, llty))
    }
}
pub fn malloc_raw_dyn < ' a > ( bcx : & ' a Block , t : ty :: t , heap : heap , size : ValueRef ) -> Result < ' a > { let _icx = push_ctxt ( " " ) ; let ccx = bcx . ccx ( ) ; fn require_alloc_fn ( bcx : & Block , t : ty :: t , it : LangItem ) -> ast :: DefId { let li = & bcx . tcx ( ) . lang_items ; match li . require ( it ) { Ok ( id ) => id , Err ( s ) => { bcx . tcx ( ) . sess . fatal ( format ! ( " " bcx ty_to_str ( t ) s ) ) ; } } } if heap == heap_exchange { let llty_value = type_of :: type_of ( ccx , t ) ; // Allocate space: let r = callee :: trans_lang_call ( bcx , require_alloc_fn ( bcx , t , ExchangeMallocFnLangItem ) , [ size ] , None ) ; rslt ( r . bcx , PointerCast ( r . bcx , r . val , llty_value . ptr_to ( ) ) ) } else { // we treat ~fn, @fn and @[] as @ here, which isn't ideal let langcall = match heap { heap_managed => { require_alloc_fn ( bcx , t , MallocFnLangItem ) } heap_exchange_closure => { require_alloc_fn ( bcx , t , ClosureExchangeMallocFnLangItem ) } _ => fail ! ( " " ) } ; // Grab the TypeRef type of box_ptr_ty. let box_ptr_ty = ty :: mk_box ( bcx . tcx ( ) , t ) ; let llty = type_of ( ccx , box_ptr_ty ) ; // Get the tydesc for the body: let static_ti = get_tydesc ( ccx , t ) ; glue :: lazily_emit_all_tydesc_glue ( ccx , static_ti ) ; // Allocate space: let tydesc = PointerCast ( bcx , static_ti . tydesc , Type :: i8p ( ) ) ; let r = callee :: trans_lang_call ( bcx , langcall , [ tydesc , size ] , None ) ; rslt ( r . bcx , PointerCast ( r . bcx , r . val , llty ) ) } }
malloc_raw_dyn: allocates a box to contain a given type, but with a
potentially dynamic size.
malloc_raw_dyn : allocates a box to contain a given type but with a potentially dynamic size .
bcx
&'a Block
t
ty::t
heap
heap
size
ValueRef
bcx
&'a Block
t
ty::t
heap
heap
size
ValueRef