Skip to content

Commit 42cf376

Browse files
committed
---
yaml --- r: 154879 b: refs/heads/try2 c: 5aa2da0 h: refs/heads/master i: 154877: b616d84 154875: b2860cd 154871: be40a11 154863: 2d0e2e0 154847: 5276966 154815: 521c0bf 154751: 9c4ebbf 154623: 960db48 v: v3
1 parent 6dfcbe0 commit 42cf376

File tree

5 files changed

+55
-17
lines changed

5 files changed

+55
-17
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 395e453c06cce045d2e0613a1c6edab2dcfdeceb
8+
refs/heads/try2: 5aa2da013356e814204a0bd5751dbabb71307213
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/liballoc/heap.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
use core::ptr::RawPtr;
1616
#[cfg(not(test))] use core::raw;
17-
#[cfg(not(test))] use util;
17+
#[cfg(stage0, not(test))] use util;
1818

1919
/// Returns a pointer to `size` bytes of memory.
2020
///
@@ -119,7 +119,7 @@ unsafe fn exchange_free(ptr: *mut u8, size: uint, align: uint) {
119119
}
120120

121121
// FIXME: #7496
122-
#[cfg(not(test))]
122+
#[cfg(stage0, not(test))]
123123
#[lang="closure_exchange_malloc"]
124124
#[inline]
125125
#[allow(deprecated)]
@@ -134,6 +134,21 @@ unsafe fn closure_exchange_malloc(drop_glue: fn(*mut u8), size: uint,
134134
alloc as *mut u8
135135
}
136136

137+
// FIXME: #7496
138+
#[cfg(not(stage0), not(test))]
139+
#[lang="closure_exchange_malloc"]
140+
#[inline]
141+
#[allow(deprecated)]
142+
unsafe fn closure_exchange_malloc(drop_glue: fn(*mut u8), size: uint,
143+
align: uint) -> *mut u8 {
144+
let p = allocate(size, align);
145+
146+
let alloc = p as *mut raw::Box<()>;
147+
(*alloc).drop_glue = drop_glue;
148+
149+
alloc as *mut u8
150+
}
151+
137152
#[cfg(jemalloc)]
138153
mod imp {
139154
use core::option::{None, Option};

branches/try2/src/librustc/middle/trans/base.rs

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ use middle::trans::glue;
6666
use middle::trans::inline;
6767
use middle::trans::intrinsic;
6868
use middle::trans::machine;
69-
use middle::trans::machine::{llsize_of, llsize_of_real};
69+
use middle::trans::machine::{llsize_of, llsize_of_real, llalign_of_min};
7070
use middle::trans::meth;
7171
use middle::trans::monomorphize;
7272
use middle::trans::tvec;
@@ -382,13 +382,44 @@ pub fn malloc_raw_dyn<'a>(bcx: &'a Block<'a>,
382382
Result::new(r.bcx, PointerCast(r.bcx, r.val, llty_ptr))
383383
}
384384

385+
pub fn malloc_raw_dyn_proc<'a>(
386+
bcx: &'a Block<'a>,
387+
t: ty::t, alloc_fn: LangItem) -> Result<'a> {
388+
let _icx = push_ctxt("malloc_raw_dyn_proc");
389+
let ccx = bcx.ccx();
390+
391+
let langcall = require_alloc_fn(bcx, t, alloc_fn);
392+
393+
// Grab the TypeRef type of ptr_ty.
394+
let ptr_ty = ty::mk_uniq(bcx.tcx(), t);
395+
let ptr_llty = type_of(ccx, ptr_ty);
396+
397+
let llty = type_of(bcx.ccx(), t);
398+
let size = llsize_of(bcx.ccx(), llty);
399+
let llalign = C_uint(ccx, llalign_of_min(bcx.ccx(), llty) as uint);
400+
401+
// Allocate space:
402+
let drop_glue = glue::get_drop_glue(ccx, ty::mk_uniq(bcx.tcx(), t));
403+
let r = callee::trans_lang_call(
404+
bcx,
405+
langcall,
406+
[
407+
PointerCast(bcx, drop_glue, Type::glue_fn(ccx, Type::i8p(ccx)).ptr_to()),
408+
size,
409+
llalign
410+
],
411+
None);
412+
Result::new(r.bcx, PointerCast(r.bcx, r.val, ptr_llty))
413+
}
414+
415+
385416
pub fn malloc_raw_dyn_managed<'a>(
386417
bcx: &'a Block<'a>,
387418
t: ty::t,
388419
alloc_fn: LangItem,
389420
size: ValueRef)
390421
-> Result<'a> {
391-
let _icx = push_ctxt("malloc_raw_managed");
422+
let _icx = push_ctxt("malloc_raw_dyn_managed");
392423
let ccx = bcx.ccx();
393424

394425
let langcall = require_alloc_fn(bcx, t, alloc_fn);

branches/try2/src/librustc/middle/trans/closure.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ use middle::trans::common::*;
2424
use middle::trans::datum::{Datum, DatumBlock, Expr, Lvalue, rvalue_scratch_datum};
2525
use middle::trans::debuginfo;
2626
use middle::trans::expr;
27-
use middle::trans::machine::llsize_of;
2827
use middle::trans::type_of::*;
2928
use middle::trans::type_::Type;
3029
use middle::ty;
@@ -144,15 +143,12 @@ fn allocate_cbox<'a>(bcx: &'a Block<'a>,
144143
let tcx = bcx.tcx();
145144

146145
// Allocate and initialize the box:
146+
let cbox_ty = tuplify_box_ty(tcx, cdata_ty);
147147
match store {
148148
ty::UniqTraitStore => {
149-
let ty = type_of(bcx.ccx(), cdata_ty);
150-
let size = llsize_of(bcx.ccx(), ty);
151-
// we treat proc as @ here, which isn't ideal
152-
malloc_raw_dyn_managed(bcx, cdata_ty, ClosureExchangeMallocFnLangItem, size)
149+
malloc_raw_dyn_proc(bcx, cbox_ty, ClosureExchangeMallocFnLangItem)
153150
}
154151
ty::RegionTraitStore(..) => {
155-
let cbox_ty = tuplify_box_ty(tcx, cdata_ty);
156152
let llbox = alloc_ty(bcx, cbox_ty, "__closure");
157153
Result::new(bcx, llbox)
158154
}

branches/try2/src/librustc/middle/trans/glue.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -520,12 +520,8 @@ fn make_drop_glue<'a>(bcx: &'a Block<'a>, v0: ValueRef, t: ty::t) -> &'a Block<'
520520
with_cond(bcx, IsNotNull(bcx, env), |bcx| {
521521
let dtor_ptr = GEPi(bcx, env, [0u, abi::box_field_tydesc]);
522522
let dtor = Load(bcx, dtor_ptr);
523-
let cdata = GEPi(bcx, env, [0u, abi::box_field_body]);
524-
Call(bcx, dtor, [PointerCast(bcx, cdata, Type::i8p(bcx.ccx()))], None);
525-
526-
// Free the environment itself
527-
// FIXME: #13994: pass align and size here
528-
trans_exchange_free(bcx, env, 0, 8)
523+
Call(bcx, dtor, [PointerCast(bcx, box_cell_v, Type::i8p(bcx.ccx()))], None);
524+
bcx
529525
})
530526
}
531527
ty::ty_trait(..) => {

0 commit comments

Comments
 (0)