Skip to content

Commit 54b2cad

Browse files
committed
libsyntax: Remove fn() unsafe { ... }. r=graydon
1 parent 1d1b811 commit 54b2cad

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+2823
-2441
lines changed

src/compiletest/errors.rs

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -33,34 +33,36 @@ fn load_errors(testfile: &Path) -> ~[expected_error] {
3333
return error_patterns;
3434
}
3535

36-
fn parse_expected(line_num: uint, line: ~str) -> ~[expected_error] unsafe {
37-
let error_tag = ~"//~";
38-
let mut idx;
39-
match str::find_str(line, error_tag) {
40-
None => return ~[],
41-
Some(nn) => { idx = (nn as uint) + str::len(error_tag); }
42-
}
36+
fn parse_expected(line_num: uint, line: ~str) -> ~[expected_error] {
37+
unsafe {
38+
let error_tag = ~"//~";
39+
let mut idx;
40+
match str::find_str(line, error_tag) {
41+
None => return ~[],
42+
Some(nn) => { idx = (nn as uint) + str::len(error_tag); }
43+
}
4344

44-
// "//~^^^ kind msg" denotes a message expected
45-
// three lines above current line:
46-
let mut adjust_line = 0u;
47-
let len = str::len(line);
48-
while idx < len && line[idx] == ('^' as u8) {
49-
adjust_line += 1u;
50-
idx += 1u;
51-
}
45+
// "//~^^^ kind msg" denotes a message expected
46+
// three lines above current line:
47+
let mut adjust_line = 0u;
48+
let len = str::len(line);
49+
while idx < len && line[idx] == ('^' as u8) {
50+
adjust_line += 1u;
51+
idx += 1u;
52+
}
5253

53-
// Extract kind:
54-
while idx < len && line[idx] == (' ' as u8) { idx += 1u; }
55-
let start_kind = idx;
56-
while idx < len && line[idx] != (' ' as u8) { idx += 1u; }
57-
let kind = str::to_lower(str::slice(line, start_kind, idx));
54+
// Extract kind:
55+
while idx < len && line[idx] == (' ' as u8) { idx += 1u; }
56+
let start_kind = idx;
57+
while idx < len && line[idx] != (' ' as u8) { idx += 1u; }
58+
let kind = str::to_lower(str::slice(line, start_kind, idx));
5859

59-
// Extract msg:
60-
while idx < len && line[idx] == (' ' as u8) { idx += 1u; }
61-
let msg = str::slice(line, idx, len);
60+
// Extract msg:
61+
while idx < len && line[idx] == (' ' as u8) { idx += 1u; }
62+
let msg = str::slice(line, idx, len);
6263

63-
debug!("line=%u kind=%s msg=%s", line_num - adjust_line, kind, msg);
64+
debug!("line=%u kind=%s msg=%s", line_num - adjust_line, kind, msg);
6465

65-
return ~[{line: line_num - adjust_line, kind: kind, msg: msg}];
66+
return ~[{line: line_num - adjust_line, kind: kind, msg: msg}];
67+
}
6668
}

src/compiletest/header.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -146,15 +146,17 @@ fn parse_name_directive(line: ~str, directive: ~str) -> bool {
146146
}
147147

148148
fn parse_name_value_directive(line: ~str,
149-
directive: ~str) -> Option<~str> unsafe {
150-
let keycolon = directive + ~":";
151-
match str::find_str(line, keycolon) {
152-
Some(colon) => {
153-
let value = str::slice(line, colon + str::len(keycolon),
154-
str::len(line));
155-
debug!("%s: %s", directive, value);
156-
Some(value)
149+
directive: ~str) -> Option<~str> {
150+
unsafe {
151+
let keycolon = directive + ~":";
152+
match str::find_str(line, keycolon) {
153+
Some(colon) => {
154+
let value = str::slice(line, colon + str::len(keycolon),
155+
str::len(line));
156+
debug!("%s: %s", directive, value);
157+
Some(value)
158+
}
159+
None => None
157160
}
158-
None => None
159161
}
160162
}

src/libcargo/cargo.rc

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,28 +1135,30 @@ fn get_temp_workdir(c: &Cargo) -> Path {
11351135
}
11361136
}
11371137

1138-
fn cmd_install(c: &Cargo) unsafe {
1139-
let wd = get_temp_workdir(c);
1138+
fn cmd_install(c: &Cargo) {
1139+
unsafe {
1140+
let wd = get_temp_workdir(c);
11401141

1141-
if vec::len(c.opts.free) == 2u {
1142-
let cwd = os::getcwd();
1143-
let status = run::run_program(~"cp", ~[~"-R", cwd.to_str(),
1144-
wd.to_str()]);
1142+
if vec::len(c.opts.free) == 2u {
1143+
let cwd = os::getcwd();
1144+
let status = run::run_program(~"cp", ~[~"-R", cwd.to_str(),
1145+
wd.to_str()]);
11451146

1146-
if status != 0 {
1147-
fail fmt!("could not copy directory: %s", cwd.to_str());
1148-
}
1147+
if status != 0 {
1148+
fail fmt!("could not copy directory: %s", cwd.to_str());
1149+
}
11491150

1150-
install_source(c, &wd);
1151-
return;
1152-
}
1151+
install_source(c, &wd);
1152+
return;
1153+
}
11531154

1154-
sync(c);
1155+
sync(c);
11551156

1156-
let query = c.opts.free[2];
1157-
c.current_install = query.to_str();
1157+
let query = c.opts.free[2];
1158+
c.current_install = query.to_str();
11581159

1159-
install_query(c, &wd, query);
1160+
install_query(c, &wd, query);
1161+
}
11601162
}
11611163

11621164
fn sync(c: &Cargo) {

src/libcore/oldcomm.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,9 @@ pub fn listen<T: Owned, U>(f: fn(Chan<T>) -> U) -> U {
121121
}
122122

123123
struct PortPtr<T:Owned> {
124-
po: *rust_port,
125-
drop unsafe {
124+
po: *rust_port,
125+
drop {
126+
unsafe {
126127
do task::unkillable {
127128
// Once the port is detached it's guaranteed not to receive further
128129
// messages
@@ -140,6 +141,7 @@ struct PortPtr<T:Owned> {
140141
recv_::<T>(self.po);
141142
}
142143
rustrt::del_port(self.po);
144+
}
143145
}
144146
}
145147
}
@@ -209,7 +211,7 @@ pub fn send<T: Owned>(ch: Chan<T>, data: T) {
209211
let Chan_(p) = ch;
210212
let data_ptr = ptr::addr_of(&data) as *();
211213
let res = rustrt::rust_port_id_send(p, data_ptr);
212-
if res != 0 unsafe {
214+
if res != 0 {
213215
// Data sent successfully
214216
cast::forget(move data);
215217
}

src/libcore/os.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,10 @@ pub fn fill_charp_buf(f: fn(*mut c_char, size_t) -> bool)
8686
-> Option<~str> {
8787
let buf = vec::cast_to_mut(vec::from_elem(tmpbuf_sz, 0u8 as c_char));
8888
do vec::as_mut_buf(buf) |b, sz| {
89-
if f(b, sz as size_t) unsafe {
90-
Some(str::raw::from_buf(b as *u8))
89+
if f(b, sz as size_t) {
90+
unsafe {
91+
Some(str::raw::from_buf(b as *u8))
92+
}
9193
} else {
9294
None
9395
}

src/libcore/pipes.rs

Lines changed: 50 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,10 @@ impl PacketHeader {
193193
reinterpret_cast(&self.buffer)
194194
}
195195

196-
fn set_buffer<T: Owned>(b: ~Buffer<T>) unsafe {
197-
self.buffer = reinterpret_cast(&b);
196+
fn set_buffer<T: Owned>(b: ~Buffer<T>) {
197+
unsafe {
198+
self.buffer = reinterpret_cast(&b);
199+
}
198200
}
199201
}
200202

@@ -356,19 +358,21 @@ pub unsafe fn get_buffer<T: Owned>(p: *PacketHeader) -> ~Buffer<T> {
356358
struct BufferResource<T: Owned> {
357359
buffer: ~Buffer<T>,
358360

359-
drop unsafe {
360-
let b = move_it!(self.buffer);
361-
//let p = ptr::addr_of(*b);
362-
//error!("drop %?", p);
363-
let old_count = atomic_sub_rel(&mut b.header.ref_count, 1);
364-
//let old_count = atomic_xchng_rel(b.header.ref_count, 0);
365-
if old_count == 1 {
366-
// The new count is 0.
367-
368-
// go go gadget drop glue
369-
}
370-
else {
371-
forget(move b)
361+
drop {
362+
unsafe {
363+
let b = move_it!(self.buffer);
364+
//let p = ptr::addr_of(*b);
365+
//error!("drop %?", p);
366+
let old_count = atomic_sub_rel(&mut b.header.ref_count, 1);
367+
//let old_count = atomic_xchng_rel(b.header.ref_count, 0);
368+
if old_count == 1 {
369+
// The new count is 0.
370+
371+
// go go gadget drop glue
372+
}
373+
else {
374+
forget(move b)
375+
}
372376
}
373377
}
374378
}
@@ -641,18 +645,20 @@ fn wait_many<T: Selectable>(pkts: &[T]) -> uint {
641645

642646
let mut data_avail = false;
643647
let mut ready_packet = pkts.len();
644-
for pkts.eachi |i, p| unsafe {
645-
let p = unsafe { &*p.header() };
646-
let old = p.mark_blocked(this);
647-
match old {
648-
Full | Terminated => {
649-
data_avail = true;
650-
ready_packet = i;
651-
(*p).state = old;
652-
break;
653-
}
654-
Blocked => fail ~"blocking on blocked packet",
655-
Empty => ()
648+
for pkts.eachi |i, p| {
649+
unsafe {
650+
let p = &*p.header();
651+
let old = p.mark_blocked(this);
652+
match old {
653+
Full | Terminated => {
654+
data_avail = true;
655+
ready_packet = i;
656+
(*p).state = old;
657+
break;
658+
}
659+
Blocked => fail ~"blocking on blocked packet",
660+
Empty => ()
661+
}
656662
}
657663
}
658664

@@ -1072,23 +1078,27 @@ impl<T: Owned> Port<T>: GenericPort<T> {
10721078
}
10731079

10741080
impl<T: Owned> Port<T>: Peekable<T> {
1075-
pure fn peek() -> bool unsafe {
1076-
let mut endp = None;
1077-
endp <-> self.endp;
1078-
let peek = match &endp {
1079-
&Some(ref endp) => pipes::peek(endp),
1080-
&None => fail ~"peeking empty stream"
1081-
};
1082-
self.endp <-> endp;
1083-
peek
1081+
pure fn peek() -> bool {
1082+
unsafe {
1083+
let mut endp = None;
1084+
endp <-> self.endp;
1085+
let peek = match &endp {
1086+
&Some(ref endp) => pipes::peek(endp),
1087+
&None => fail ~"peeking empty stream"
1088+
};
1089+
self.endp <-> endp;
1090+
peek
1091+
}
10841092
}
10851093
}
10861094

10871095
impl<T: Owned> Port<T>: Selectable {
1088-
pure fn header() -> *PacketHeader unsafe {
1089-
match self.endp {
1090-
Some(ref endp) => endp.header(),
1091-
None => fail ~"peeking empty stream"
1096+
pure fn header() -> *PacketHeader {
1097+
unsafe {
1098+
match self.endp {
1099+
Some(ref endp) => endp.header(),
1100+
None => fail ~"peeking empty stream"
1101+
}
10921102
}
10931103
}
10941104
}

0 commit comments

Comments
 (0)