Skip to content

Commit b5dd01e

Browse files
committed
Add a bunch more unsafe blocks to prepare for the new semantics of unsafe/closure interactions.
1 parent 2c96a43 commit b5dd01e

File tree

6 files changed

+32
-30
lines changed

6 files changed

+32
-30
lines changed

src/libcore/task.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -2089,7 +2089,7 @@ fn test_child_doesnt_ref_parent() {
20892089
fn test_tls_multitask() unsafe {
20902090
fn my_key(+_x: @~str) { }
20912091
local_data_set(my_key, @~"parent data");
2092-
do task::spawn {
2092+
do task::spawn unsafe {
20932093
assert local_data_get(my_key) == none; // TLS shouldn't carry over.
20942094
local_data_set(my_key, @~"child data");
20952095
assert *(local_data_get(my_key).get()) == ~"child data";
@@ -2155,19 +2155,19 @@ fn test_tls_multiple_types() unsafe {
21552155
fn str_key(+_x: @~str) { }
21562156
fn box_key(+_x: @@()) { }
21572157
fn int_key(+_x: @int) { }
2158-
do task::spawn {
2158+
do task::spawn unsafe {
21592159
local_data_set(str_key, @~"string data");
21602160
local_data_set(box_key, @@());
21612161
local_data_set(int_key, @42);
21622162
}
21632163
}
21642164

21652165
#[test]
2166-
fn test_tls_overwrite_multiple_types() unsafe {
2166+
fn test_tls_overwrite_multiple_types() {
21672167
fn str_key(+_x: @~str) { }
21682168
fn box_key(+_x: @@()) { }
21692169
fn int_key(+_x: @int) { }
2170-
do task::spawn {
2170+
do task::spawn unsafe {
21712171
local_data_set(str_key, @~"string data");
21722172
local_data_set(int_key, @42);
21732173
// This could cause a segfault if overwriting-destruction is done with
@@ -2185,7 +2185,7 @@ fn test_tls_cleanup_on_failure() unsafe {
21852185
fn int_key(+_x: @int) { }
21862186
local_data_set(str_key, @~"parent data");
21872187
local_data_set(box_key, @@());
2188-
do task::spawn { // spawn_linked
2188+
do task::spawn unsafe { // spawn_linked
21892189
local_data_set(str_key, @~"string data");
21902190
local_data_set(box_key, @@());
21912191
local_data_set(int_key, @42);

src/libstd/net_ip.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -85,17 +85,17 @@ enum ip_get_addr_err {
8585
* object in the case of failure
8686
*/
8787
fn get_addr(++node: ~str, iotask: iotask)
88-
-> result::result<~[ip_addr], ip_get_addr_err> unsafe {
88+
-> result::result<~[ip_addr], ip_get_addr_err> {
8989
do core::comm::listen |output_ch| {
90-
do str::as_buf(node) |node_ptr, len| {
90+
do str::as_buf(node) |node_ptr, len| unsafe {
9191
log(debug, fmt!("slice len %?", len));
9292
let handle = create_uv_getaddrinfo_t();
9393
let handle_ptr = ptr::addr_of(handle);
9494
let handle_data: get_addr_data = {
9595
output_ch: output_ch
9696
};
9797
let handle_data_ptr = ptr::addr_of(handle_data);
98-
do interact(iotask) |loop_ptr| {
98+
do interact(iotask) |loop_ptr| unsafe {
9999
let result = uv_getaddrinfo(
100100
loop_ptr,
101101
handle_ptr,

src/libstd/net_tcp.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ fn connect(-input_ip: ip::ip_addr, port: uint,
145145
// we can send into the interact cb to be handled in libuv..
146146
log(debug, fmt!("stream_handle_ptr outside interact %?",
147147
stream_handle_ptr));
148-
do iotask::interact(iotask) |loop_ptr| {
148+
do iotask::interact(iotask) |loop_ptr| unsafe {
149149
log(debug, ~"in interact cb for tcp client connect..");
150150
log(debug, fmt!("stream_handle_ptr in interact %?",
151151
stream_handle_ptr));
@@ -571,7 +571,7 @@ fn listen(-host_ip: ip::ip_addr, port: uint, backlog: uint,
571571
-> result::result<(), tcp_listen_err_data> unsafe {
572572
do listen_common(host_ip, port, backlog, iotask, on_establish_cb)
573573
// on_connect_cb
574-
|handle| {
574+
|handle| unsafe {
575575
let server_data_ptr = uv::ll::get_data_for_uv_handle(handle)
576576
as *tcp_listen_fc_data;
577577
let new_conn = new_tcp_conn(handle);
@@ -608,7 +608,7 @@ fn listen_common(-host_ip: ip::ip_addr, port: uint, backlog: uint,
608608
// tcp::connect (because the iotask::interact cb isn't
609609
// nested within a core::comm::listen block)
610610
let loc_ip = copy(host_ip);
611-
do iotask::interact(iotask) |loop_ptr| {
611+
do iotask::interact(iotask) |loop_ptr| unsafe {
612612
match uv::ll::tcp_init(loop_ptr, server_stream_ptr) {
613613
0i32 => {
614614
uv::ll::set_data_for_uv_handle(
@@ -660,7 +660,7 @@ fn listen_common(-host_ip: ip::ip_addr, port: uint, backlog: uint,
660660
};
661661
match setup_result {
662662
some(err_data) => {
663-
do iotask::interact(iotask) |loop_ptr| {
663+
do iotask::interact(iotask) |loop_ptr| unsafe {
664664
log(debug, fmt!("tcp::listen post-kill recv hl interact %?",
665665
loop_ptr));
666666
(*server_data_ptr).active = false;
@@ -687,7 +687,7 @@ fn listen_common(-host_ip: ip::ip_addr, port: uint, backlog: uint,
687687
none => {
688688
on_establish_cb(kill_ch);
689689
let kill_result = core::comm::recv(kill_po);
690-
do iotask::interact(iotask) |loop_ptr| {
690+
do iotask::interact(iotask) |loop_ptr| unsafe {
691691
log(debug, fmt!("tcp::listen post-kill recv hl interact %?",
692692
loop_ptr));
693693
(*server_data_ptr).active = false;
@@ -844,7 +844,7 @@ fn tear_down_socket_data(socket_data: @tcp_socket_data) unsafe {
844844
};
845845
let close_data_ptr = ptr::addr_of(close_data);
846846
let stream_handle_ptr = (*socket_data).stream_handle_ptr;
847-
do iotask::interact((*socket_data).iotask) |loop_ptr| {
847+
do iotask::interact((*socket_data).iotask) |loop_ptr| unsafe {
848848
log(debug, fmt!("interact dtor for tcp_socket stream %? loop %?",
849849
stream_handle_ptr, loop_ptr));
850850
uv::ll::set_data_for_uv_handle(stream_handle_ptr,
@@ -902,7 +902,7 @@ fn read_stop_common_impl(socket_data: *tcp_socket_data) ->
902902
let stream_handle_ptr = (*socket_data).stream_handle_ptr;
903903
let stop_po = core::comm::port::<option<tcp_err_data>>();
904904
let stop_ch = core::comm::chan(stop_po);
905-
do iotask::interact((*socket_data).iotask) |loop_ptr| {
905+
do iotask::interact((*socket_data).iotask) |loop_ptr| unsafe {
906906
log(debug, ~"in interact cb for tcp::read_stop");
907907
match uv::ll::read_stop(stream_handle_ptr as *uv::ll::uv_stream_t) {
908908
0i32 => {
@@ -930,7 +930,7 @@ fn read_start_common_impl(socket_data: *tcp_socket_data)
930930
let start_po = core::comm::port::<option<uv::ll::uv_err_data>>();
931931
let start_ch = core::comm::chan(start_po);
932932
log(debug, ~"in tcp::read_start before interact loop");
933-
do iotask::interact((*socket_data).iotask) |loop_ptr| {
933+
do iotask::interact((*socket_data).iotask) |loop_ptr| unsafe {
934934
log(debug, fmt!("in tcp::read_start interact cb %?", loop_ptr));
935935
match uv::ll::read_start(stream_handle_ptr as *uv::ll::uv_stream_t,
936936
on_alloc_cb,
@@ -970,7 +970,7 @@ fn write_common_impl(socket_data_ptr: *tcp_socket_data,
970970
result_ch: core::comm::chan(result_po)
971971
};
972972
let write_data_ptr = ptr::addr_of(write_data);
973-
do iotask::interact((*socket_data_ptr).iotask) |loop_ptr| {
973+
do iotask::interact((*socket_data_ptr).iotask) |loop_ptr| unsafe {
974974
log(debug, fmt!("in interact cb for tcp::write %?", loop_ptr));
975975
match uv::ll::write(write_req_ptr,
976976
stream_handle_ptr,

src/libstd/timer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ fn delayed_send<T: copy send>(iotask: iotask,
3131
let timer_done_ch_ptr = ptr::addr_of(timer_done_ch);
3232
let timer = uv::ll::timer_t();
3333
let timer_ptr = ptr::addr_of(timer);
34-
do iotask::interact(iotask) |loop_ptr| {
34+
do iotask::interact(iotask) |loop_ptr| unsafe {
3535
let init_result = uv::ll::timer_init(loop_ptr, timer_ptr);
3636
if (init_result == 0i32) {
3737
let start_result = uv::ll::timer_start(

src/libstd/uv_global_loop.rs

+13-11
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ fn get_monitor_task_gl() -> iotask unsafe {
4949
task::task().sched_mode
5050
(task::SingleThreaded)
5151
.unlinked()
52-
}) |msg_po| {
52+
}) |msg_po| unsafe {
5353
debug!("global monitor task starting");
5454

5555
// As a weak task the runtime will notify us when to exit
@@ -85,20 +85,22 @@ fn get_monitor_task_gl() -> iotask unsafe {
8585
}
8686
}
8787

88-
fn spawn_loop() -> iotask unsafe {
88+
fn spawn_loop() -> iotask {
8989
let builder = do task::task().add_wrapper |task_body| {
9090
fn~(move task_body) {
9191
// The I/O loop task also needs to be weak so it doesn't keep
9292
// the runtime alive
93-
do weaken_task |weak_exit_po| {
94-
debug!("global libuv task is now weak %?", weak_exit_po);
95-
task_body();
93+
unsafe {
94+
do weaken_task |weak_exit_po| {
95+
debug!("global libuv task is now weak %?", weak_exit_po);
96+
task_body();
9697

97-
// We don't wait for the exit message on weak_exit_po
98-
// because the monitor task will tell the uv loop when to
99-
// exit
98+
// We don't wait for the exit message on weak_exit_po
99+
// because the monitor task will tell the uv loop when to
100+
// exit
100101

101-
debug!("global libuv task is leaving weakened state");
102+
debug!("global libuv task is leaving weakened state");
103+
}
102104
}
103105
}
104106
};
@@ -120,7 +122,7 @@ mod test {
120122
log(debug, ~"in simple timer cb");
121123
ll::timer_stop(timer_ptr);
122124
let hl_loop = get_gl();
123-
do iotask::interact(hl_loop) |_loop_ptr| {
125+
do iotask::interact(hl_loop) |_loop_ptr| unsafe {
124126
log(debug, ~"closing timer");
125127
ll::close(timer_ptr, simple_timer_close_cb);
126128
log(debug, ~"about to deref exit_ch_ptr");
@@ -137,7 +139,7 @@ mod test {
137139
exit_ch_ptr));
138140
let timer_handle = ll::timer_t();
139141
let timer_ptr = ptr::addr_of(timer_handle);
140-
do iotask::interact(iotask) |loop_ptr| {
142+
do iotask::interact(iotask) |loop_ptr| unsafe {
141143
log(debug, ~"user code inside interact loop!!!");
142144
let init_status = ll::timer_init(loop_ptr, timer_ptr);
143145
if(init_status == 0i32) {

src/libstd/uv_iotask.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ mod test {
193193
exit_ch: exit_ch
194194
};
195195
let ah_data_ptr = ptr::addr_of(ah_data);
196-
do interact(iotask) |loop_ptr| {
196+
do interact(iotask) |loop_ptr| unsafe {
197197
ll::async_init(loop_ptr, ah_ptr, async_handle_cb);
198198
ll::set_data_for_uv_handle(ah_ptr, ah_data_ptr as *libc::c_void);
199199
ll::async_send(ah_ptr);

0 commit comments

Comments
 (0)