File tree Expand file tree Collapse file tree 1 file changed +14
-7
lines changed Expand file tree Collapse file tree 1 file changed +14
-7
lines changed Original file line number Diff line number Diff line change @@ -19,15 +19,17 @@ type arc_data<T> = {
19
19
data : T
20
20
} ;
21
21
22
- resource arc_destruct<T >( data: * arc_data< T > ) {
22
+ resource arc_destruct<T >( data: * libc :: c_void ) {
23
23
unsafe {
24
- let ptr = & mut ( * data) . count ;
24
+ let data: ~arc_data < T > = unsafe :: reinterpret_cast ( data) ;
25
+ let ref_ptr = & mut data. count ;
25
26
26
- let new_count = rustrt:: rust_atomic_decrement ( ptr ) ;
27
+ let new_count = rustrt:: rust_atomic_decrement ( ref_ptr ) ;
27
28
assert new_count >= 0 ;
28
29
if new_count == 0 {
29
- let _ptr : ~arc_data < T > = unsafe :: reinterpret_cast ( data) ;
30
30
// drop glue takes over.
31
+ } else {
32
+ unsafe :: forget ( data) ;
31
33
}
32
34
}
33
35
}
@@ -48,7 +50,11 @@ fn arc<T>(-data: T) -> arc<T> {
48
50
wrapper." ]
49
51
fn get < T > ( rc : & a. arc < T > ) -> & a . T {
50
52
unsafe {
51
- & ( * * * rc) . data
53
+ let ptr: ~arc_data < T > = unsafe :: reinterpret_cast ( * * rc) ;
54
+ // Cast us back into the correct region
55
+ let r = unsafe :: reinterpret_cast ( & ptr. data ) ;
56
+ unsafe :: forget ( ptr) ;
57
+ ret r;
52
58
}
53
59
}
54
60
@@ -58,9 +64,10 @@ The resulting two `arc` objects will point to the same underlying data
58
64
object. However, one of the `arc` objects can be sent to another task,
59
65
allowing them to share the underlying data." ]
60
66
fn clone < T > ( rc : & arc < T > ) -> arc < T > {
61
- let data = * * rc;
62
67
unsafe {
63
- rustrt:: rust_atomic_increment ( & mut ( * data) . count ) ;
68
+ let ptr: ~arc_data < T > = unsafe :: reinterpret_cast ( * * rc) ;
69
+ rustrt:: rust_atomic_increment ( & mut ptr. count ) ;
70
+ unsafe :: forget ( ptr) ;
64
71
}
65
72
arc_destruct ( * * rc)
66
73
}
You can’t perform that action at this time.
0 commit comments