Skip to content

Commit deb6476

Browse files
committed
Use unsafe pointers for recv_packet::header, because the region system is hard and this isn't safe anyway.
1 parent aba665d commit deb6476

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

src/libcore/pipes.rs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ fn try_recv<T: send>(-p: recv_packet<T>) -> option<T> {
169169

170170
/// Returns true if messages are available.
171171
pure fn peek<T: send>(p: recv_packet<T>) -> bool {
172-
alt p.header().state {
172+
alt unsafe {(*p.header()).state} {
173173
empty { false }
174174
blocked { fail "peeking on blocked packet" }
175175
full | terminated { true }
@@ -219,14 +219,16 @@ fn receiver_terminate<T: send>(p: *packet<T>) {
219219
}
220220
}
221221

222-
impl private_methods for packet_header {
222+
impl private_methods for *packet_header {
223223
// Returns the old state.
224-
fn mark_blocked(this: *rust_task) -> state {
224+
unsafe fn mark_blocked(this: *rust_task) -> state {
225+
let self = &*self;
225226
self.blocked_task = some(this);
226227
swap_state_acq(self.state, blocked)
227228
}
228229

229-
fn unblock() {
230+
unsafe fn unblock() {
231+
let self = &*self;
230232
alt swap_state_acq(self.state, empty) {
231233
empty | blocked { }
232234
terminated { self.state = terminated; }
@@ -237,19 +239,19 @@ impl private_methods for packet_header {
237239

238240
#[doc = "Returns when one of the packet headers reports data is
239241
available."]
240-
fn wait_many(pkts: &[&a.packet_header]) -> uint {
242+
fn wait_many(pkts: &[*packet_header]) -> uint {
241243
let this = rustrt::rust_get_task();
242244

243245
rustrt::task_clear_event_reject(this);
244246
let mut data_avail = false;
245247
let mut ready_packet = pkts.len();
246-
for pkts.eachi |i, p| {
248+
for pkts.eachi |i, p| unsafe {
247249
let old = p.mark_blocked(this);
248250
alt old {
249251
full | terminated {
250252
data_avail = true;
251253
ready_packet = i;
252-
p.state = old;
254+
(*p).state = old;
253255
break;
254256
}
255257
blocked { fail "blocking on blocked packet" }
@@ -260,7 +262,7 @@ fn wait_many(pkts: &[&a.packet_header]) -> uint {
260262
while !data_avail {
261263
#debug("sleeping on %? packets", pkts.len());
262264
let event = wait_event(this) as *packet_header;
263-
let pos = vec::position(pkts, |p| ptr::addr_of(*p) == event);
265+
let pos = vec::position(pkts, |p| p == event);
264266

265267
alt pos {
266268
some(i) {
@@ -275,12 +277,14 @@ fn wait_many(pkts: &[&a.packet_header]) -> uint {
275277

276278
#debug("%?", pkts[ready_packet]);
277279

278-
for pkts.each |p| { p.unblock() }
280+
for pkts.each |p| { unsafe{p.unblock()} }
279281

280282
#debug("%?, %?", ready_packet, pkts[ready_packet]);
281283

282-
assert pkts[ready_packet].state == full
283-
|| pkts[ready_packet].state == terminated;
284+
unsafe {
285+
assert (*pkts[ready_packet]).state == full
286+
|| (*pkts[ready_packet]).state == terminated;
287+
}
284288

285289
ready_packet
286290
}
@@ -370,12 +374,12 @@ class recv_packet<T: send> {
370374
option::unwrap(p)
371375
}
372376

373-
pure fn header() -> &self.packet_header {
377+
pure fn header() -> *packet_header {
374378
alt self.p {
375379
some(packet) {
376380
unsafe {
377381
let packet = uniquify(packet);
378-
let header = reinterpret_cast(&packet.header);
382+
let header = ptr::addr_of(packet.header);
379383
forget(packet);
380384
header
381385
}

0 commit comments

Comments
 (0)