@@ -25,6 +25,7 @@ use middle::trans::datum::*;
2525use middle:: trans:: expr:: { Dest , Ignore , SaveIn } ;
2626use middle:: trans:: expr;
2727use middle:: trans:: glue;
28+ use middle:: trans:: machine;
2829use middle:: trans:: machine:: { nonzero_llsize_of, llsize_of_alloc} ;
2930use middle:: trans:: type_:: Type ;
3031use middle:: trans:: type_of;
@@ -59,6 +60,7 @@ pub fn make_drop_glue_unboxed<'a>(
5960 -> & ' a Block < ' a > {
6061 let not_null = IsNotNull ( bcx, vptr) ;
6162 with_cond ( bcx, not_null, |bcx| {
63+ let ccx = bcx. ccx ( ) ;
6264 let tcx = bcx. tcx ( ) ;
6365 let _icx = push_ctxt ( "tvec::make_drop_glue_unboxed" ) ;
6466
@@ -73,8 +75,11 @@ pub fn make_drop_glue_unboxed<'a>(
7375 if should_deallocate {
7476 let not_null = IsNotNull ( bcx, dataptr) ;
7577 with_cond ( bcx, not_null, |bcx| {
76- // FIXME: #13994: the old `Box<[T]>` will not support sized deallocation
77- glue:: trans_exchange_free ( bcx, dataptr, 0 , 8 )
78+ let llty = type_of:: type_of ( ccx, unit_ty) ;
79+ let llsize = machine:: llsize_of ( ccx, llty) ;
80+ let llalign = C_uint ( ccx, machine:: llalign_of_min ( ccx, llty) as uint ) ;
81+ let size = Mul ( bcx, llsize, get_len ( bcx, vptr) ) ;
82+ glue:: trans_exchange_free_dyn ( bcx, dataptr, size, llalign)
7883 } )
7984 } else {
8085 bcx
@@ -281,15 +286,16 @@ pub fn trans_uniq_vec<'a>(bcx: &'a Block<'a>,
281286 debug ! ( " vt={}, count={:?}" , vt. to_string( ccx) , count) ;
282287 let vec_ty = node_id_type ( bcx, uniq_expr. id ) ;
283288
284- let unit_sz = nonzero_llsize_of ( ccx, type_of:: type_of ( ccx, vt. unit_ty ) ) ;
289+ let llty = type_of:: type_of ( ccx, vt. unit_ty ) ;
290+ let unit_sz = nonzero_llsize_of ( ccx, llty) ;
285291 let llcount = if count < 4 u {
286292 C_int ( ccx, 4 )
287293 } else {
288294 C_uint ( ccx, count)
289295 } ;
290296 let alloc = Mul ( bcx, llcount, unit_sz) ;
291- let llty_ptr = type_of :: type_of ( ccx , vt . unit_ty ) . ptr_to ( ) ;
292- let align = C_uint ( ccx, 8 ) ;
297+ let llty_ptr = llty . ptr_to ( ) ;
298+ let align = C_uint ( ccx, machine :: llalign_of_min ( ccx , llty ) as uint ) ;
293299 let Result { bcx : bcx, val : dataptr } = malloc_raw_dyn ( bcx,
294300 llty_ptr,
295301 vec_ty,
@@ -299,16 +305,15 @@ pub fn trans_uniq_vec<'a>(bcx: &'a Block<'a>,
299305 // Create a temporary scope lest execution should fail while
300306 // constructing the vector.
301307 let temp_scope = fcx. push_custom_cleanup_scope ( ) ;
302- // FIXME: #13994: the old `Box<[T]> will not support sized deallocation,
303- // this is a placeholder
304- fcx. schedule_free_value ( cleanup:: CustomScope ( temp_scope) ,
305- dataptr, cleanup:: HeapExchange , vt. unit_ty ) ;
306308
307- debug ! ( " alloc_uniq_vec() returned dataptr={}, len={}" ,
308- bcx . val_to_string ( dataptr) , count ) ;
309+ fcx . schedule_free_slice ( cleanup :: CustomScope ( temp_scope ) ,
310+ dataptr, alloc , align , cleanup :: HeapExchange ) ;
309311
310- let bcx = write_content ( bcx, & vt, uniq_expr,
311- content_expr, SaveIn ( dataptr) ) ;
312+ debug ! ( " alloc_uniq_vec() returned dataptr={}, len={}" ,
313+ bcx. val_to_string( dataptr) , count) ;
314+
315+ let bcx = write_content ( bcx, & vt, uniq_expr,
316+ content_expr, SaveIn ( dataptr) ) ;
312317
313318 fcx. pop_custom_cleanup_scope ( temp_scope) ;
314319
0 commit comments