@@ -348,17 +348,17 @@ fn opaque_box_body(bcx: block,
348
348
PointerCast ( bcx, bodyptr, T_ptr ( type_of ( ccx, body_t) ) )
349
349
}
350
350
351
- // malloc_raw: expects an unboxed type and returns a pointer to
352
- // enough space for a box of that type. This includes a rust_opaque_box
353
- // header.
354
- fn malloc_raw ( bcx : block , t : ty :: t , heap : heap ) -> ValueRef {
351
+ // malloc_raw_dyn: allocates a box to contain a given type, but with a
352
+ // potentially dynamic size.
353
+ fn malloc_raw_dyn ( bcx : block , t : ty :: t , heap : heap ,
354
+ size : ValueRef ) -> ValueRef {
355
355
let _icx = bcx. insn_ctxt ( "malloc_raw" ) ;
356
356
let ccx = bcx. ccx ( ) ;
357
357
358
358
let ( mk_fn, upcall) = alt heap {
359
- heap_shared { ( ty:: mk_imm_box, ccx. upcalls . malloc ) }
359
+ heap_shared { ( ty:: mk_imm_box, ccx. upcalls . malloc_dyn ) }
360
360
heap_exchange {
361
- ( ty:: mk_imm_uniq, ccx. upcalls . exchange_malloc )
361
+ ( ty:: mk_imm_uniq, ccx. upcalls . exchange_malloc_dyn )
362
362
}
363
363
} ;
364
364
@@ -372,52 +372,40 @@ fn malloc_raw(bcx: block, t: ty::t, heap: heap) -> ValueRef {
372
372
lazily_emit_all_tydesc_glue ( ccx, copy static_ti) ;
373
373
374
374
// Allocate space:
375
- let rval = Call ( bcx, upcall, [ lltydesc] ) ;
375
+ let rval = Call ( bcx, upcall, [ lltydesc, size ] ) ;
376
376
ret PointerCast ( bcx, rval, llty) ;
377
377
}
378
378
379
- // malloc_general: usefully wraps malloc_raw; allocates a box,
379
+ // malloc_raw: expects an unboxed type and returns a pointer to
380
+ // enough space for a box of that type. This includes a rust_opaque_box
381
+ // header.
382
+ fn malloc_raw ( bcx : block , t : ty:: t , heap : heap ) -> ValueRef {
383
+ malloc_raw_dyn ( bcx, t, heap, llsize_of ( bcx. ccx ( ) , type_of ( bcx. ccx ( ) , t) ) )
384
+ }
385
+
386
+ // malloc_general_dyn: usefully wraps malloc_raw_dyn; allocates a box,
380
387
// and pulls out the body
381
- fn malloc_general ( bcx : block , t : ty:: t , heap : heap ) ->
388
+ fn malloc_general_dyn ( bcx : block , t : ty:: t , heap : heap , size : ValueRef ) ->
382
389
{ box : ValueRef , body : ValueRef } {
383
390
let _icx = bcx. insn_ctxt ( "malloc_general" ) ;
384
- let box = malloc_raw ( bcx, t, heap) ;
391
+ let box = malloc_raw_dyn ( bcx, t, heap, size ) ;
385
392
let non_gc_box = non_gc_box_cast ( bcx, box) ;
386
393
let body = GEPi ( bcx, non_gc_box, [ 0 u, abi:: box_field_body] ) ;
387
394
ret { box : box, body : body} ;
388
395
}
389
396
390
397
fn malloc_boxed ( bcx : block , t : ty:: t ) -> { box : ValueRef , body : ValueRef } {
391
- malloc_general ( bcx, t, heap_shared)
398
+ malloc_general_dyn ( bcx, t, heap_shared,
399
+ llsize_of ( bcx. ccx ( ) , type_of ( bcx. ccx ( ) , t) ) )
392
400
}
393
401
fn malloc_unique ( bcx : block , t : ty:: t ) -> { box : ValueRef , body : ValueRef } {
394
- malloc_general ( bcx, t, heap_exchange)
395
- }
396
-
397
- fn malloc_unique_dyn_raw ( bcx : block , t : ty:: t , size : ValueRef ) -> ValueRef {
398
- let _icx = bcx. insn_ctxt ( "malloc_unique_dyn_raw" ) ;
399
- let ccx = bcx. ccx ( ) ;
400
-
401
- // Grab the TypeRef type of box_ptr_ty.
402
- let box_ptr_ty = ty:: mk_imm_uniq ( ccx. tcx , t) ;
403
- let llty = type_of ( ccx, box_ptr_ty) ;
404
-
405
- // Get the tydesc for the body:
406
- let mut static_ti = none;
407
- let lltydesc = get_tydesc ( ccx, t, static_ti) ;
408
- lazily_emit_all_tydesc_glue ( ccx, static_ti) ;
409
-
410
- // Allocate space:
411
- let rval = Call ( bcx, ccx. upcalls . exchange_malloc_dyn , [ lltydesc, size] ) ;
412
- ret PointerCast ( bcx, rval, llty) ;
402
+ malloc_general_dyn ( bcx, t, heap_exchange,
403
+ llsize_of ( bcx. ccx ( ) , type_of ( bcx. ccx ( ) , t) ) )
413
404
}
414
405
415
406
fn malloc_unique_dyn ( bcx : block , t : ty:: t , size : ValueRef
416
407
) -> { box : ValueRef , body : ValueRef } {
417
- let _icx = bcx. insn_ctxt ( "malloc_unique_dyn" ) ;
418
- let box = malloc_unique_dyn_raw ( bcx, t, size) ;
419
- let body = GEPi ( bcx, box, [ 0 u, abi:: box_field_body] ) ;
420
- ret { box : box, body : body} ;
408
+ malloc_general_dyn ( bcx, t, heap_exchange, size)
421
409
}
422
410
423
411
// Type descriptor and type glue stuff
0 commit comments