Skip to content

Commit 2f1095d

Browse files
committed
---
yaml --- r: 10478 b: refs/heads/snap-stage3 c: 591b280 h: refs/heads/master v: v3
1 parent 23d5023 commit 2f1095d

File tree

5 files changed

+27
-44
lines changed

5 files changed

+27
-44
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
refs/heads/master: 2898dcc5d97da9427ac367542382b6239d9c0bbf
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 4c0d41cffae78725c20a40302e81ef1246c3e4c7
4+
refs/heads/snap-stage3: 591b2802ffd32d805ba70dba33452e5a4d42ed9e
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

branches/snap-stage3/src/rt/rust_upcall.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ exchange_malloc(rust_task *task, type_desc *td, uintptr_t size) {
156156
return (uintptr_t)header;
157157
}
158158

159+
// FIXME: remove after snapshot (6/13/12)
159160
struct s_exchange_malloc_args {
160161
uintptr_t retval;
161162
type_desc *td;
@@ -238,6 +239,7 @@ shared_malloc(rust_task *task, type_desc *td, uintptr_t size) {
238239
return (uintptr_t)box;
239240
}
240241

242+
// FIXME: remove after snapshot (6/13/12)
241243
struct s_malloc_args {
242244
uintptr_t retval;
243245
type_desc *td;

branches/snap-stage3/src/rustc/back/upcall.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@ import lib::llvm::{type_names, ModuleRef, ValueRef, TypeRef};
1010
type upcalls =
1111
{_fail: ValueRef,
1212
trace: ValueRef,
13-
malloc: ValueRef,
1413
malloc_dyn: ValueRef,
1514
free: ValueRef,
16-
exchange_malloc: ValueRef,
1715
exchange_malloc_dyn: ValueRef,
1816
exchange_free: ValueRef,
1917
validate_box: ValueRef,
@@ -57,17 +55,12 @@ fn declare_upcalls(targ_cfg: @session::config,
5755
trace: dv("trace", [T_ptr(T_i8()),
5856
T_ptr(T_i8()),
5957
int_t]),
60-
malloc:
61-
nothrow(d("malloc", [T_ptr(tydesc_type)],
6258
malloc_dyn:
6359
nothrow(d("malloc_dyn",
6460
[T_ptr(tydesc_type), int_t],
6561
T_ptr(T_i8()))),
6662
free:
6763
nothrow(dv("free", [T_ptr(T_i8())])),
68-
exchange_malloc:
69-
nothrow(d("exchange_malloc", [T_ptr(tydesc_type)],
70-
T_ptr(T_i8()))),
7164
exchange_malloc_dyn:
7265
nothrow(d("exchange_malloc_dyn",
7366
[T_ptr(tydesc_type), int_t],

branches/snap-stage3/src/rustc/middle/trans/base.rs

Lines changed: 22 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -348,17 +348,17 @@ fn opaque_box_body(bcx: block,
348348
PointerCast(bcx, bodyptr, T_ptr(type_of(ccx, body_t)))
349349
}
350350

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 {
355355
let _icx = bcx.insn_ctxt("malloc_raw");
356356
let ccx = bcx.ccx();
357357

358358
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) }
360360
heap_exchange {
361-
(ty::mk_imm_uniq, ccx.upcalls.exchange_malloc )
361+
(ty::mk_imm_uniq, ccx.upcalls.exchange_malloc_dyn )
362362
}
363363
};
364364

@@ -372,52 +372,40 @@ fn malloc_raw(bcx: block, t: ty::t, heap: heap) -> ValueRef {
372372
lazily_emit_all_tydesc_glue(ccx, copy static_ti);
373373

374374
// Allocate space:
375-
let rval = Call(bcx, upcall, [lltydesc]);
375+
let rval = Call(bcx, upcall, [lltydesc, size]);
376376
ret PointerCast(bcx, rval, llty);
377377
}
378378

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,
380387
// 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) ->
382389
{box: ValueRef, body: ValueRef} {
383390
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);
385392
let non_gc_box = non_gc_box_cast(bcx, box);
386393
let body = GEPi(bcx, non_gc_box, [0u, abi::box_field_body]);
387394
ret {box: box, body: body};
388395
}
389396

390397
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)))
392400
}
393401
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)))
413404
}
414405

415406
fn malloc_unique_dyn(bcx: block, t: ty::t, size: ValueRef
416407
) -> {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, [0u, abi::box_field_body]);
420-
ret {box: box, body: body};
408+
malloc_general_dyn(bcx, t, heap_exchange, size)
421409
}
422410

423411
// Type descriptor and type glue stuff

branches/snap-stage3/src/rustc/middle/trans/closure.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -553,8 +553,8 @@ fn make_opaque_cbox_take_glue(
553553
let sz = Add(bcx, sz, shape::llsize_of(ccx, T_box_header(ccx)));
554554

555555
// Allocate memory, update original ptr, and copy existing data
556-
let malloc = ccx.upcalls.exchange_malloc;
557-
let cbox_out = Call(bcx, malloc, [tydesc]);
556+
let malloc = ccx.upcalls.exchange_malloc_dyn;
557+
let cbox_out = Call(bcx, malloc, [tydesc, sz]);
558558
let cbox_out = PointerCast(bcx, cbox_out, llopaquecboxty);
559559
call_memmove(bcx, cbox_out, cbox_in, sz);
560560
Store(bcx, cbox_out, cboxptr);

0 commit comments

Comments
 (0)