Skip to content

Commit 14cd48a

Browse files
committed
---
yaml --- r: 13052 b: refs/heads/master c: d89b4c8 h: refs/heads/master v: v3
1 parent 84181d2 commit 14cd48a

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 174f789e0b98cc98d4ba08076c61ef7a4b03a687
2+
refs/heads/master: d89b4c8c61b4995559c2e5b963d58b5dd599fdf3
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf

trunk/src/libstd/arc.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,17 @@ type arc_data<T> = {
1919
data: T
2020
};
2121

22-
resource arc_destruct<T>(data: *arc_data<T>) {
22+
resource arc_destruct<T>(data: *libc::c_void) {
2323
unsafe {
24-
let ptr = &mut (*data).count;
24+
let data: ~arc_data<T> = unsafe::reinterpret_cast(data);
25+
let ref_ptr = &mut data.count;
2526

26-
let new_count = rustrt::rust_atomic_decrement(ptr);
27+
let new_count = rustrt::rust_atomic_decrement(ref_ptr);
2728
assert new_count >= 0;
2829
if new_count == 0 {
29-
let _ptr : ~arc_data<T> = unsafe::reinterpret_cast(data);
3030
// drop glue takes over.
31+
} else {
32+
unsafe::forget(data);
3133
}
3234
}
3335
}
@@ -48,7 +50,11 @@ fn arc<T>(-data: T) -> arc<T> {
4850
wrapper."]
4951
fn get<T>(rc: &a.arc<T>) -> &a.T {
5052
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;
5258
}
5359
}
5460

@@ -58,9 +64,10 @@ The resulting two `arc` objects will point to the same underlying data
5864
object. However, one of the `arc` objects can be sent to another task,
5965
allowing them to share the underlying data."]
6066
fn clone<T>(rc: &arc<T>) -> arc<T> {
61-
let data = **rc;
6267
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);
6471
}
6572
arc_destruct(**rc)
6673
}

0 commit comments

Comments
 (0)