@@ -1060,22 +1060,26 @@ fn GEP_tup_like(@block_ctxt cx, @ty.t t,
1060
1060
}
1061
1061
1062
1062
1063
- fn trans_malloc_inner ( @block_ctxt cx , TypeRef llptr_ty ) -> result {
1064
- auto llbody_ty = lib . llvm . llvm . LLVMGetElementType ( llptr_ty ) ;
1063
+ fn trans_raw_malloc ( @block_ctxt cx , TypeRef llptr_ty , ValueRef llsize )
1064
+ -> result {
1065
1065
// FIXME: need a table to collect tydesc globals.
1066
1066
auto tydesc = C_int ( 0 ) ;
1067
- auto sz = llsize_of ( llbody_ty) ;
1068
- auto sub = trans_upcall ( cx, "upcall_malloc" , vec ( sz, tydesc) ) ;
1069
- sub. val = vi2p ( sub. bcx , sub. val , llptr_ty) ;
1070
- ret sub;
1067
+ auto rslt = trans_upcall ( cx, "upcall_malloc" , vec ( llsize, tydesc) ) ;
1068
+ rslt = res ( rslt. bcx , vi2p ( cx, rslt. val , llptr_ty) ) ;
1069
+ ret rslt;
1070
+ }
1071
+
1072
+ fn trans_malloc_without_cleanup ( @block_ctxt cx , @ty. t t ) -> result {
1073
+ auto llty = type_of ( cx. fcx . ccx , t) ;
1074
+ auto rslt = size_of ( cx, t) ;
1075
+ ret trans_raw_malloc ( rslt. bcx , llty, rslt. val ) ;
1071
1076
}
1072
1077
1073
1078
fn trans_malloc ( @block_ctxt cx , @ty. t t ) -> result {
1074
1079
auto scope_cx = find_scope_cx ( cx) ;
1075
- auto llptr_ty = type_of ( cx. fcx . ccx , t) ;
1076
- auto sub = trans_malloc_inner ( cx, llptr_ty) ;
1077
- scope_cx. cleanups += clean ( bind drop_ty ( _, sub. val , t) ) ;
1078
- ret sub;
1080
+ auto rslt = trans_malloc_without_cleanup ( cx, t) ;
1081
+ scope_cx. cleanups += clean ( bind drop_ty ( _, rslt. val , t) ) ;
1082
+ ret rslt;
1079
1083
}
1080
1084
1081
1085
@@ -3216,7 +3220,9 @@ fn trans_bind(@block_ctxt cx, @ast.expr f,
3216
3220
ty_param_count) ;
3217
3221
3218
3222
// Malloc a box for the body.
3219
- auto r = trans_malloc_inner( bcx, llclosure_ty) ;
3223
+ // FIXME: this isn't generic-safe
3224
+ auto r = trans_raw_malloc( bcx, llclosure_ty,
3225
+ llsize_of( llvm. LLVMGetElementType ( llclosure_ty) ) ) ;
3220
3226
auto box = r. val;
3221
3227
bcx = r. bcx;
3222
3228
auto rc = bcx. build. GEP ( box,
@@ -4453,7 +4459,8 @@ fn trans_obj(@crate_ctxt cx, &ast._obj ob, ast.def_id oid,
4453
4459
let TypeRef llboxed_body_ty = type_of( cx, boxed_body_ty) ;
4454
4460
4455
4461
// Malloc a box for the body.
4456
- auto box = trans_malloc_inner( bcx, llboxed_body_ty) ;
4462
+ auto box = trans_raw_malloc( bcx, llboxed_body_ty,
4463
+ llsize_of( llvm. LLVMGetElementType ( llboxed_body_ty) ) ) ;
4457
4464
bcx = box. bcx;
4458
4465
auto rc = GEP_tup_like ( bcx, boxed_body_ty, box. val,
4459
4466
vec( 0 , abi. box_rc_field_refcnt) ) ;
0 commit comments