File tree Expand file tree Collapse file tree 3 files changed +30
-10
lines changed Expand file tree Collapse file tree 3 files changed +30
-10
lines changed Original file line number Diff line number Diff line change 1
1
---
2
- refs/heads/master: 0aeddb3673459969fdbb32018f9c59f603607cf5
2
+ refs/heads/master: 86babab2fe92223511042e9cb4b233841cffa054
Original file line number Diff line number Diff line change @@ -6,14 +6,15 @@ export _chan;
6
6
export _port;
7
7
8
8
export mk_port;
9
+ export chan_from_unsafe_ptr;
9
10
10
11
native "rust" mod rustrt {
11
12
type void ;
12
13
type rust_chan ;
13
14
type rust_port ;
14
15
15
16
fn new_chan ( po : * rust_port ) -> * rust_chan ;
16
- fn del_chan ( ch : * rust_chan ) ;
17
+ fn take_chan ( ch : * rust_chan ) ;
17
18
fn drop_chan ( ch : * rust_chan ) ;
18
19
fn chan_send ( ch : * rust_chan , v : * void ) ;
19
20
@@ -42,6 +43,16 @@ obj _chan[T](raw_chan : @chan_ptr) {
42
43
rustrt:: chan_send ( * * raw_chan,
43
44
unsafe :: reinterpret_cast ( ptr:: addr_of ( v) ) ) ;
44
45
}
46
+
47
+ // Use this to get something we can send over a channel.
48
+ fn unsafe_ptr ( ) -> * u8 {
49
+ rustrt:: take_chan ( * * raw_chan) ;
50
+ ret unsafe:: reinterpret_cast ( * * raw_chan) ;
51
+ }
52
+ }
53
+
54
+ fn chan_from_unsafe_ptr[ T ] ( ch : * u8) -> _chan[ T ] {
55
+ _chan ( @chan_ptr ( unsafe :: reinterpret_cast ( ch) ) )
45
56
}
46
57
47
58
obj _port[ T ] ( raw_port : @port_ptr) {
Original file line number Diff line number Diff line change
1
+ use std;
2
+
3
+ import std:: comm;
4
+
1
5
fn main ( ) { test05 ( ) ; }
2
6
3
- fn test05_start ( ch : chan[ int ] ) { ch <| 10 ; ch <| 20 ; ch <| 30 ; }
7
+ fn test05_start ( pch : * u8 ) {
8
+ let ch = comm:: chan_from_unsafe_ptr ( pch) ;
9
+
10
+ ch. send ( 10 ) ;
11
+ ch. send ( 20 ) ;
12
+ ch. send ( 30 ) ;
13
+ }
4
14
5
15
fn test05 ( ) {
6
- let po: port[ int ] = port ( ) ;
7
- let ch: chan[ int ] = chan ( po) ;
8
- spawn test05_start ( chan ( po) ) ;
9
- let value: int ;
10
- po |> value;
11
- po |> value;
12
- po |> value;
16
+ let po = comm:: mk_port[ int] ( ) ;
17
+ let ch = po. mk_chan ( ) ;
18
+ spawn test05_start ( ch. unsafe_ptr ( ) ) ;
19
+ let value = po. recv ( ) ;
20
+ value = po. recv ( ) ;
21
+ value = po. recv ( ) ;
13
22
assert ( value == 30 ) ;
14
23
}
You can’t perform that action at this time.
0 commit comments