@@ -1641,6 +1641,8 @@ fn GEP_tag(@block_ctxt cx,
1641
1641
}
1642
1642
1643
1643
1644
+ // trans_raw_malloc: expects a type indicating which pointer type we want and
1645
+ // a size indicating how much space we want malloc'd.
1644
1646
fn trans_raw_malloc ( & @block_ctxt cx , TypeRef llptr_ty , ValueRef llsize)
1645
1647
-> result {
1646
1648
// FIXME: need a table to collect tydesc globals.
@@ -1650,14 +1652,29 @@ fn trans_raw_malloc(&@block_ctxt cx, TypeRef llptr_ty, ValueRef llsize)
1650
1652
ret res ( cx, cx. build . PointerCast ( rval, llptr_ty) ) ;
1651
1653
}
1652
1654
1655
+
1656
+ // trans_malloc_boxed: expects an unboxed type and returns a pointer to enough
1657
+ // space for something of that type, along with space for a reference count;
1658
+ // in other words, it allocates a box for something of that type.
1653
1659
fn trans_malloc_boxed ( & @block_ctxt cx , ty:: t t) -> result {
1654
1660
// Synthesize a fake box type structurally so we have something
1655
1661
// to measure the size of.
1662
+
1663
+ // We synthesize two types here because we want both the type of the
1664
+ // pointer and the pointee. boxed_body is the type that we measure the
1665
+ // size of; box_ptr is the type that's converted to a TypeRef and used as
1666
+ // the pointer cast target in trans_raw_malloc.
1656
1667
auto boxed_body = ty:: mk_imm_tup ( cx. fcx . lcx . ccx . tcx ,
1668
+ // The mk_int here is the space being
1669
+ // reserved for the refcount.
1657
1670
[ ty:: mk_int ( cx. fcx . lcx . ccx . tcx ) , t] ) ;
1658
1671
auto box_ptr = ty:: mk_imm_box ( cx. fcx . lcx . ccx . tcx , t) ;
1659
1672
auto sz = size_of ( cx, boxed_body) ;
1673
+
1674
+ // Grab the TypeRef type of box_ptr, because that's what trans_raw_malloc
1675
+ // wants.
1660
1676
auto llty = type_of ( cx. fcx . lcx . ccx , cx. sp , box_ptr) ;
1677
+
1661
1678
ret trans_raw_malloc ( sz. bcx , llty, sz. val ) ;
1662
1679
}
1663
1680
0 commit comments