Skip to content

Commit 4396ad4

Browse files
committed
Merge remote-tracking branch 'mozilla/incoming' into incoming
2 parents 0a6943d + 6060370 commit 4396ad4

File tree

17 files changed

+219
-83
lines changed

17 files changed

+219
-83
lines changed

src/libcore/comm.rs

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -94,27 +94,31 @@ fn listen<T: send, U>(f: fn(chan<T>) -> U) -> U {
9494
f(po.chan())
9595
}
9696

97-
resource port_ptr<T: send>(po: *rust_port) unsafe {
97+
class port_ptr<T:send> {
98+
let po: *rust_port;
99+
new(po: *rust_port) { self.po = po; }
100+
drop unsafe {
98101
task::unkillable {||
99102
// Once the port is detached it's guaranteed not to receive further
100103
// messages
101104
let yield = 0u;
102105
let yieldp = ptr::addr_of(yield);
103-
rustrt::rust_port_begin_detach(po, yieldp);
106+
rustrt::rust_port_begin_detach(self.po, yieldp);
104107
if yield != 0u {
105108
// Need to wait for the port to be detached
106109
// FIXME: If this fails then we're going to leave our port
107110
// in a bogus state. (Issue #1988)
108111
task::yield();
109112
}
110-
rustrt::rust_port_end_detach(po);
113+
rustrt::rust_port_end_detach(self.po);
111114

112115
// Drain the port so that all the still-enqueued items get dropped
113-
while rustrt::rust_port_size(po) > 0u as size_t {
114-
recv_::<T>(po);
116+
while rustrt::rust_port_size(self.po) > 0u as size_t {
117+
recv_::<T>(self.po);
115118
}
116-
rustrt::del_port(po);
119+
rustrt::del_port(self.po);
117120
}
121+
}
118122
}
119123

120124
#[doc = "
@@ -126,29 +130,34 @@ Fails if the port is detached or dead. Fails if the port
126130
is owned by a different task.
127131
"]
128132
fn as_raw_port<T: send, U>(ch: comm::chan<T>, f: fn(*rust_port) -> U) -> U {
129-
resource portref(p: *rust_port) {
130-
if !ptr::is_null(p) {
131-
rustrt::rust_port_drop(p);
132-
}
133+
134+
class portref {
135+
let p: *rust_port;
136+
new(p: *rust_port) { self.p = p; }
137+
drop {
138+
if !ptr::is_null(self.p) {
139+
rustrt::rust_port_drop(self.p);
140+
}
141+
}
133142
}
134143

135144
let p = portref(rustrt::rust_port_take(*ch));
136145

137-
if ptr::is_null(*p) {
146+
if ptr::is_null(p.p) {
138147
fail "unable to locate port for channel"
139-
} else if rustrt::get_task_id() != rustrt::rust_port_task(*p) {
148+
} else if rustrt::get_task_id() != rustrt::rust_port_task(p.p) {
140149
fail "unable to access unowned port"
141150
}
142151

143-
f(*p)
152+
f(p.p)
144153
}
145154

146155
#[doc = "
147156
Constructs a channel. The channel is bound to the port used to
148157
construct it.
149158
"]
150159
fn chan<T: send>(p: port<T>) -> chan<T> {
151-
chan_t(rustrt::get_port_id(***p))
160+
chan_t(rustrt::get_port_id((**p).po))
152161
}
153162

154163
#[doc = "
@@ -170,10 +179,10 @@ fn send<T: send>(ch: chan<T>, -data: T) {
170179
Receive from a port. If no data is available on the port then the
171180
task will block until data becomes available.
172181
"]
173-
fn recv<T: send>(p: port<T>) -> T { recv_(***p) }
182+
fn recv<T: send>(p: port<T>) -> T { recv_((**p).po) }
174183

175184
#[doc = "Returns true if there are messages available"]
176-
fn peek<T: send>(p: port<T>) -> bool { peek_(***p) }
185+
fn peek<T: send>(p: port<T>) -> bool { peek_((**p).po) }
177186

178187
#[doc(hidden)]
179188
fn recv_chan<T: send>(ch: comm::chan<T>) -> T {
@@ -196,7 +205,7 @@ fn recv_<T: send>(p: *rust_port) -> T {
196205
// Data isn't available yet, so res has not been initialized.
197206
task::yield();
198207
} else {
199-
// In the absense of compiler-generated preemption points
208+
// In the absence of compiler-generated preemption points
200209
// this is a good place to yield
201210
task::yield();
202211
}
@@ -210,7 +219,7 @@ fn peek_(p: *rust_port) -> bool unsafe {
210219
#[doc = "Receive on one of two ports"]
211220
fn select2<A: send, B: send>(p_a: port<A>, p_b: port<B>)
212221
-> either<A, B> unsafe {
213-
let ports = [***p_a, ***p_b];
222+
let ports = [(**p_a).po, (**p_b).po];
214223
let n_ports = 2 as libc::size_t;
215224
let yield = 0u, yieldp = ptr::addr_of(yield);
216225

@@ -233,9 +242,9 @@ fn select2<A: send, B: send>(p_a: port<A>, p_b: port<B>)
233242
// Now we know the port we're supposed to receive from
234243
assert resport != ptr::null();
235244

236-
if resport == ***p_a {
245+
if resport == (**p_a).po {
237246
either::left(recv(p_a))
238-
} else if resport == ***p_b {
247+
} else if resport == (**p_b).po {
239248
either::right(recv(p_b))
240249
} else {
241250
fail "unexpected result from rust_port_select";
@@ -482,4 +491,4 @@ fn test_port_detach_fail() {
482491
}
483492
}
484493
}
485-
}
494+
}

src/libcore/stackwalk.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ fn walk_stack(visit: fn(frame) -> bool) {
2323
reinterpret_cast(frame_pointer)
2424
};
2525
loop {
26-
let frame = frame(frame_address);
26+
let fr = frame(frame_address);
2727

28-
#debug("frame: %x", unsafe { reinterpret_cast(frame.fp) });
29-
visit(frame);
28+
#debug("frame: %x", unsafe { reinterpret_cast(fr.fp) });
29+
visit(fr);
3030

3131
unsafe {
3232
let next_fp: **word = reinterpret_cast(frame_address);
@@ -44,7 +44,7 @@ fn walk_stack(visit: fn(frame) -> bool) {
4444

4545
#[test]
4646
fn test_simple() {
47-
for walk_stack { |frame|
47+
for walk_stack { |_frame|
4848
}
4949
}
5050

@@ -53,7 +53,7 @@ fn test_simple_deep() {
5353
fn run(i: int) {
5454
if i == 0 { ret }
5555

56-
for walk_stack { |frame|
56+
for walk_stack { |_frame|
5757
unsafe {
5858
breakpoint();
5959
}

src/libcore/str.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ pure fn to_upper(s: str/&) -> str {
566566
}
567567

568568
#[doc = "
569-
Replace all occurances of one string with another
569+
Replace all occurrences of one string with another
570570
571571
# Arguments
572572

src/libstd/par.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import future::future;
77
export map, mapi, alli, any, mapi_factory;
88

99
#[doc="The maximum number of tasks this module will spawn for a single
10-
operationg."]
10+
operation."]
1111
const max_tasks : uint = 32u;
1212

1313
#[doc="The minimum number of elements each task will process."]

src/rustc/middle/borrowck/check_loans.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ fn check_loans(bccx: borrowck_ctxt,
4747
mut declared_purity: ast::impure_fn,
4848
mut fn_args: @[]});
4949
let vt = visit::mk_vt(@{visit_expr: check_loans_in_expr,
50+
visit_local: check_loans_in_local,
5051
visit_block: check_loans_in_block,
5152
visit_fn: check_loans_in_fn
5253
with *visit::default_visitor()});
@@ -419,6 +420,9 @@ impl methods for check_loan_ctxt {
419420
// rvalues, I guess.
420421
cat_special(sk_static_item) { }
421422

423+
cat_deref(_, _, unsafe_ptr) {
424+
}
425+
422426
// Nothing else.
423427
_ {
424428
self.bccx.span_err(
@@ -542,6 +546,18 @@ fn check_loans_in_fn(fk: visit::fn_kind, decl: ast::fn_decl, body: ast::blk,
542546
#debug["purity on exit=%?", copy self.declared_purity];
543547
}
544548

549+
fn check_loans_in_local(local: @ast::local,
550+
&&self: check_loan_ctxt,
551+
vt: visit::vt<check_loan_ctxt>) {
552+
alt local.node.init {
553+
some({op: ast::init_move, expr: expr}) {
554+
self.check_move_out(expr);
555+
}
556+
some({op: ast::init_assign, _}) | none {}
557+
}
558+
visit::visit_local(local, self, vt);
559+
}
560+
545561
fn check_loans_in_expr(expr: @ast::expr,
546562
&&self: check_loan_ctxt,
547563
vt: visit::vt<check_loan_ctxt>) {

src/rustc/middle/resolve.rs

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,6 @@ fn visit_item_with_scope(e: @env, i: @ast::item,
573573
}
574574
ast::item_class(tps, ifaces, members, ctor, m_dtor, _) {
575575
v.visit_ty_params(tps, sc, v);
576-
// Can maybe skip this now that we require self on class fields
577576
let class_scope = @cons(scope_item(i), sc);
578577
/* visit the constructor... */
579578
let ctor_scope = @cons(scope_method(ctor.node.self_id, tps),
@@ -1061,7 +1060,7 @@ fn lookup_in_scope(e: env, &&sc: scopes, sp: span, name: ident, ns: namespace,
10611060
}
10621061
ast::item_class(tps, _, members, ctor, _, _) {
10631062
if ns == ns_type {
1064-
ret lookup_in_ty_params(e, name, tps);
1063+
ret lookup_in_ty_params(e, name, tps);
10651064
}
10661065
if ns == ns_val && name == it.ident {
10671066
ret some(ast::def_fn(local_def(ctor.node.id),
@@ -1317,13 +1316,14 @@ fn found_def_item(i: @ast::item, ns: namespace) -> option<def> {
13171316
alt i.node {
13181317
ast::item_const(*) {
13191318
if ns == ns_val {
1320-
ret some(ast::def_const(local_def(i.id))); }
1319+
ret some(ast::def_const(local_def(i.id)));
1320+
}
13211321
}
13221322
ast::item_fn(decl, _, _) {
1323-
if ns == ns_val {
1323+
if ns == ns_val {
13241324
ret some(ast::def_fn(local_def(i.id), decl.purity));
1325-
}
1326-
}
1325+
}
1326+
}
13271327
ast::item_mod(_) {
13281328
if ns == ns_module { ret some(ast::def_mod(local_def(i.id))); }
13291329
}
@@ -1342,9 +1342,16 @@ fn found_def_item(i: @ast::item, ns: namespace) -> option<def> {
13421342
_ { }
13431343
}
13441344
}
1345-
ast::item_class(*) {
1346-
if ns == ns_type {
1347-
ret some(ast::def_class(local_def(i.id)));
1345+
ast::item_class(_, _, _members, ct, _, _) {
1346+
alt ns {
1347+
ns_type {
1348+
ret some(ast::def_class(local_def(i.id)));
1349+
}
1350+
ns_val {
1351+
ret some(ast::def_fn(local_def(ct.node.id),
1352+
ast::impure_fn));
1353+
}
1354+
ns_module { }
13481355
}
13491356
}
13501357
ast::item_impl(*) { /* ??? */ }
@@ -1653,14 +1660,6 @@ fn index_mod(md: ast::_mod) -> mod_index {
16531660
ast::item_class(tps, _, items, ctor, _, _) {
16541661
// add the class name itself
16551662
add_to_index(index, it.ident, mie_item(it));
1656-
// add the constructor decl
1657-
add_to_index(index, it.ident,
1658-
mie_item(@{ident: it.ident, attrs: [],
1659-
id: ctor.node.id,
1660-
node:
1661-
item_fn(ctor.node.dec, tps, ctor.node.body),
1662-
vis: ast::public,
1663-
span: ctor.node.body.span}));
16641663
}
16651664
}
16661665
}

0 commit comments

Comments
 (0)