Skip to content

Commit 21e238d

Browse files
committed
---
yaml --- r: 110295 b: refs/heads/try c: 612e22e h: refs/heads/master i: 110293: 94c40fe 110291: 327f2f2 110287: 6f1ac10 v: v3
1 parent 525520d commit 21e238d

File tree

3 files changed

+40
-6
lines changed

3 files changed

+40
-6
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: e415c25bcd81dc1f9a5a3d25d9b48ed2d545336b
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: c7fac4471201977fdb1c0c0a26c87287e12dc644
5-
refs/heads/try: 9f990f74b3020b2639944add7012e01f22cb135b
5+
refs/heads/try: 612e22e417b41326b2060416892c7b16d921e20b
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/src/etc/vim/syntax/rust.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ syn match rustStringContinuation display contained /\\\n\s*/
135135
syn region rustString start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=rustSpecial,rustSpecialError,rustStringContinuation,@Spell
136136
syn region rustString start='r\z(#*\)"' end='"\z1' contains=@Spell
137137

138-
syn region rustAttribute start="#\[" end="\]" contains=rustString,rustDeriving
138+
syn region rustAttribute start="#!\?\[" end="\]" contains=rustString,rustDeriving
139139
syn region rustDeriving start="deriving(" end=")" contained contains=rustTrait
140140

141141
" Number literals

branches/try/src/libsync/arc.rs

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ impl<T: Share + Send> Drop for Arc<T> {
165165
// Because `fetch_sub` is already atomic, we do not need to synchronize
166166
// with other threads unless we are going to delete the object. This
167167
// same logic applies to the below `fetch_sub` to the `weak` count.
168-
if self.inner().strong.fetch_sub(1, atomics::Release) != 0 { return }
168+
if self.inner().strong.fetch_sub(1, atomics::Release) != 1 { return }
169169

170170
// This fence is needed to prevent reordering of use of the data and
171171
// deletion of the data. Because it is marked `Release`, the
@@ -190,7 +190,7 @@ impl<T: Share + Send> Drop for Arc<T> {
190190
// allocation itself (there may still be weak pointers lying around).
191191
unsafe { drop(ptr::read(&self.inner().data)); }
192192

193-
if self.inner().weak.fetch_sub(1, atomics::Release) == 0 {
193+
if self.inner().weak.fetch_sub(1, atomics::Release) == 1 {
194194
atomics::fence(atomics::Acquire);
195195
unsafe { global_heap::exchange_free(self.x as *u8) }
196196
}
@@ -240,7 +240,7 @@ impl<T: Share + Send> Drop for Weak<T> {
240240
// If we find out that we were the last weak pointer, then its time to
241241
// deallocate the data entirely. See the discussion in Arc::drop() about
242242
// the memory orderings
243-
if self.inner().weak.fetch_sub(1, atomics::Release) == 0 {
243+
if self.inner().weak.fetch_sub(1, atomics::Release) == 1 {
244244
atomics::fence(atomics::Acquire);
245245
unsafe { global_heap::exchange_free(self.x as *u8) }
246246
}
@@ -251,9 +251,24 @@ impl<T: Share + Send> Drop for Weak<T> {
251251
#[allow(experimental)]
252252
mod tests {
253253
use super::{Arc, Weak};
254+
use std::sync::atomics;
255+
use std::task;
254256
use Mutex;
255257

256-
use std::task;
258+
struct Canary(*mut atomics::AtomicUint);
259+
260+
impl Drop for Canary
261+
{
262+
fn drop(&mut self) {
263+
unsafe {
264+
match *self {
265+
Canary(c) => {
266+
(*c).fetch_add(1, atomics::SeqCst);
267+
}
268+
}
269+
}
270+
}
271+
}
257272

258273
#[test]
259274
fn manually_share_arc() {
@@ -349,4 +364,23 @@ mod tests {
349364

350365
// hopefully we don't double-free (or leak)...
351366
}
367+
368+
#[test]
369+
fn drop_arc() {
370+
let mut canary = atomics::AtomicUint::new(0);
371+
let x = Arc::new(Canary(&mut canary as *mut atomics::AtomicUint));
372+
drop(x);
373+
assert!(canary.load(atomics::Acquire) == 1);
374+
}
375+
376+
#[test]
377+
fn drop_arc_weak() {
378+
let mut canary = atomics::AtomicUint::new(0);
379+
let arc = Arc::new(Canary(&mut canary as *mut atomics::AtomicUint));
380+
let arc_weak = arc.downgrade();
381+
assert!(canary.load(atomics::Acquire) == 0);
382+
drop(arc);
383+
assert!(canary.load(atomics::Acquire) == 1);
384+
drop(arc_weak);
385+
}
352386
}

0 commit comments

Comments
 (0)