|
8 | 8 |
|
9 | 9 | // gdb-command:run
|
10 | 10 |
|
11 |
| -// gdb-command:print r |
12 |
| -// gdb-check:[...]$1 = Rc(strong=2, weak=1) = {value = 42, strong = 2, weak = 1} |
13 |
| -// gdb-command:print a |
14 |
| -// gdb-check:[...]$2 = Arc(strong=2, weak=1) = {value = 42, strong = 2, weak = 1} |
15 |
| - |
| 11 | +// gdb-command:print rc |
| 12 | +// gdb-check:[...]$1 = Rc(strong=11, weak=1) = {value = 111, strong = 11, weak = 1} |
| 13 | +// gdb-command:print arc |
| 14 | +// gdb-check:[...]$2 = Arc(strong=21, weak=1) = {value = 222, strong = 21, weak = 1} |
16 | 15 |
|
17 | 16 | // === LLDB TESTS ==================================================================================
|
18 | 17 |
|
19 | 18 | // lldb-command:run
|
20 | 19 |
|
21 |
| -// lldb-command:print r |
22 |
| -// lldb-check:[...]$0 = strong=2, weak=1 { value = 42 } |
23 |
| -// lldb-command:print a |
24 |
| -// lldb-check:[...]$1 = strong=2, weak=1 { data = 42 } |
| 20 | +// lldb-command:print rc |
| 21 | +// lldb-check:[...]$0 = strong=11, weak=1 { value = 111 } |
| 22 | +// lldb-command:print arc |
| 23 | +// lldb-check:[...]$1 = strong=21, weak=1 { data = 222 } |
25 | 24 |
|
26 | 25 | // === CDB TESTS ==================================================================================
|
27 | 26 |
|
28 | 27 | // cdb-command:g
|
29 | 28 |
|
30 |
| -// cdb-command:dx r,d |
31 |
| -// cdb-check:r,d : 42 [Type: alloc::rc::Rc<i32>] |
32 |
| -// cdb-check: [<Raw View>] [Type: alloc::rc::Rc<i32>] |
33 |
| -// cdb-check: [Reference count] : 2 [Type: core::cell::Cell<usize>] |
| 29 | +// cdb-command:dx rc,d |
| 30 | +// cdb-check:rc,d : 111 [Type: alloc::rc::Rc<i32>] |
| 31 | +// cdb-check: [Reference count] : 11 [Type: core::cell::Cell<usize>] |
| 32 | +// cdb-check: [Weak reference count] : 2 [Type: core::cell::Cell<usize>] |
| 33 | + |
| 34 | +// cdb-command:dx weak_rc,d |
| 35 | +// cdb-check:weak_rc,d : 111 [Type: alloc::rc::Weak<i32>] |
| 36 | +// cdb-check: [Reference count] : 11 [Type: core::cell::Cell<usize>] |
| 37 | +// cdb-check: [Weak reference count] : 2 [Type: core::cell::Cell<usize>] |
| 38 | + |
| 39 | +// cdb-command:dx arc,d |
| 40 | +// cdb-check:arc,d : 222 [Type: alloc::sync::Arc<i32>] |
| 41 | +// cdb-check: [Reference count] : 21 [Type: core::sync::atomic::AtomicUsize] |
| 42 | +// cdb-check: [Weak reference count] : 2 [Type: core::sync::atomic::AtomicUsize] |
| 43 | + |
| 44 | +// cdb-command:dx weak_arc,d |
| 45 | +// cdb-check:weak_arc,d : 222 [Type: alloc::sync::Weak<i32>] |
| 46 | +// cdb-check: [Reference count] : 21 [Type: core::sync::atomic::AtomicUsize] |
| 47 | +// cdb-check: [Weak reference count] : 2 [Type: core::sync::atomic::AtomicUsize] |
| 48 | + |
| 49 | +// cdb-command:dx dyn_rc,d |
| 50 | +// cdb-check:dyn_rc,d [Type: alloc::rc::Rc<dyn$<core::fmt::Debug> >] |
| 51 | +// cdb-check: [Reference count] : 31 [Type: core::cell::Cell<usize>] |
34 | 52 | // cdb-check: [Weak reference count] : 2 [Type: core::cell::Cell<usize>]
|
35 | 53 |
|
36 |
| -// cdb-command:dx r1,d |
37 |
| -// cdb-check:r1,d : 42 [Type: alloc::rc::Rc<i32>] |
38 |
| -// cdb-check: [<Raw View>] [Type: alloc::rc::Rc<i32>] |
39 |
| -// cdb-check: [Reference count] : 2 [Type: core::cell::Cell<usize>] |
| 54 | +// cdb-command:dx dyn_rc_weak,d |
| 55 | +// cdb-check:dyn_rc_weak,d [Type: alloc::rc::Weak<dyn$<core::fmt::Debug> >] |
| 56 | +// cdb-check: [Reference count] : 31 [Type: core::cell::Cell<usize>] |
40 | 57 | // cdb-check: [Weak reference count] : 2 [Type: core::cell::Cell<usize>]
|
41 | 58 |
|
42 |
| -// cdb-command:dx w1,d |
43 |
| -// cdb-check:w1,d : 42 [Type: alloc::rc::Weak<i32>] |
44 |
| -// cdb-check: [<Raw View>] [Type: alloc::rc::Weak<i32>] |
45 |
| -// cdb-check: [Reference count] : 2 [Type: core::cell::Cell<usize>] |
| 59 | +// cdb-command:dx slice_rc,d |
| 60 | +// cdb-check:slice_rc,d : { len=3 } [Type: alloc::rc::Rc<slice$<u32> >] |
| 61 | +// cdb-check: [Length] : 3 [Type: unsigned __int64] |
| 62 | +// cdb-check: [Reference count] : 41 [Type: core::cell::Cell<usize>] |
46 | 63 | // cdb-check: [Weak reference count] : 2 [Type: core::cell::Cell<usize>]
|
| 64 | +// cdb-check: [0] : 1 [Type: u32] |
| 65 | +// cdb-check: [1] : 2 [Type: u32] |
| 66 | +// cdb-check: [2] : 3 [Type: u32] |
| 67 | + |
| 68 | +// cdb-command:dx slice_rc_weak,d |
| 69 | +// cdb-check:slice_rc_weak,d : { len=3 } [Type: alloc::rc::Weak<slice$<u32> >] |
| 70 | +// cdb-check: [Length] : 3 [Type: unsigned __int64] |
| 71 | +// cdb-check: [Reference count] : 41 [Type: core::cell::Cell<usize>] |
| 72 | +// cdb-check: [Weak reference count] : 2 [Type: core::cell::Cell<usize>] |
| 73 | +// cdb-check: [0] : 1 [Type: u32] |
| 74 | +// cdb-check: [1] : 2 [Type: u32] |
| 75 | +// cdb-check: [2] : 3 [Type: u32] |
47 | 76 |
|
48 |
| -// cdb-command:dx a,d |
49 |
| -// cdb-check:a,d : 42 [Type: alloc::sync::Arc<i32>] |
50 |
| -// cdb-check: [<Raw View>] [Type: alloc::sync::Arc<i32>] |
51 |
| -// cdb-check: [Reference count] : 2 [Type: core::sync::atomic::AtomicUsize] |
| 77 | +// cdb-command:dx dyn_arc,d |
| 78 | +// cdb-check:dyn_arc,d [Type: alloc::sync::Arc<dyn$<core::fmt::Debug> >] |
| 79 | +// cdb-check: [Reference count] : 51 [Type: core::sync::atomic::AtomicUsize] |
52 | 80 | // cdb-check: [Weak reference count] : 2 [Type: core::sync::atomic::AtomicUsize]
|
53 | 81 |
|
54 |
| -// cdb-command:dx a1,d |
55 |
| -// cdb-check:a1,d : 42 [Type: alloc::sync::Arc<i32>] |
56 |
| -// cdb-check: [<Raw View>] [Type: alloc::sync::Arc<i32>] |
57 |
| -// cdb-check: [Reference count] : 2 [Type: core::sync::atomic::AtomicUsize] |
| 82 | +// cdb-command:dx dyn_arc_weak,d |
| 83 | +// cdb-check:dyn_arc_weak,d [Type: alloc::sync::Weak<dyn$<core::fmt::Debug> >] |
| 84 | +// cdb-check: [Reference count] : 51 [Type: core::sync::atomic::AtomicUsize] |
58 | 85 | // cdb-check: [Weak reference count] : 2 [Type: core::sync::atomic::AtomicUsize]
|
59 | 86 |
|
60 |
| -// cdb-command:dx w2,d |
61 |
| -// cdb-check:w2,d : 42 [Type: alloc::sync::Weak<i32>] |
62 |
| -// cdb-check: [<Raw View>] [Type: alloc::sync::Weak<i32>] |
63 |
| -// cdb-check: [Reference count] : 2 [Type: core::sync::atomic::AtomicUsize] |
| 87 | +// cdb-command:dx slice_arc,d |
| 88 | +// cdb-check:slice_arc,d : { len=3 } [Type: alloc::sync::Arc<slice$<u32> >] |
| 89 | +// cdb-check: [Length] : 3 [Type: unsigned __int64] |
| 90 | +// cdb-check: [Reference count] : 61 [Type: core::sync::atomic::AtomicUsize] |
| 91 | +// cdb-check: [Weak reference count] : 2 [Type: core::sync::atomic::AtomicUsize] |
| 92 | +// cdb-check: [0] : 4 [Type: u32] |
| 93 | +// cdb-check: [1] : 5 [Type: u32] |
| 94 | +// cdb-check: [2] : 6 [Type: u32] |
| 95 | + |
| 96 | +// cdb-command:dx slice_arc_weak,d |
| 97 | +// cdb-check:slice_arc_weak,d : { len=3 } [Type: alloc::sync::Weak<slice$<u32> >] |
| 98 | +// cdb-check: [Length] : 3 [Type: unsigned __int64] |
| 99 | +// cdb-check: [Reference count] : 61 [Type: core::sync::atomic::AtomicUsize] |
64 | 100 | // cdb-check: [Weak reference count] : 2 [Type: core::sync::atomic::AtomicUsize]
|
| 101 | +// cdb-check: [0] : 4 [Type: u32] |
| 102 | +// cdb-check: [1] : 5 [Type: u32] |
| 103 | +// cdb-check: [2] : 6 [Type: u32] |
65 | 104 |
|
| 105 | +use std::fmt::Debug; |
66 | 106 | use std::rc::Rc;
|
67 | 107 | use std::sync::Arc;
|
68 | 108 |
|
69 | 109 | fn main() {
|
70 |
| - let r = Rc::new(42); |
71 |
| - let r1 = Rc::clone(&r); |
72 |
| - let w1 = Rc::downgrade(&r); |
| 110 | + let rc = Rc::new(111); |
| 111 | + inc_ref_count(&rc, 10); |
| 112 | + let weak_rc = Rc::downgrade(&rc); |
| 113 | + |
| 114 | + let arc = Arc::new(222); |
| 115 | + inc_ref_count(&arc, 20); |
| 116 | + let weak_arc = Arc::downgrade(&arc); |
| 117 | + |
| 118 | + let dyn_rc: Rc<dyn Debug> = Rc::new(333); |
| 119 | + inc_ref_count(&dyn_rc, 30); |
| 120 | + let dyn_rc_weak = Rc::downgrade(&dyn_rc); |
| 121 | + |
| 122 | + let slice_rc: Rc<[u32]> = Rc::from(vec![1, 2, 3]); |
| 123 | + inc_ref_count(&slice_rc, 40); |
| 124 | + let slice_rc_weak = Rc::downgrade(&slice_rc); |
73 | 125 |
|
74 |
| - let a = Arc::new(42); |
75 |
| - let a1 = Arc::clone(&a); |
76 |
| - let w2 = Arc::downgrade(&a); |
| 126 | + let dyn_arc: Arc<dyn Debug> = Arc::new(444); |
| 127 | + inc_ref_count(&dyn_arc, 50); |
| 128 | + let dyn_arc_weak = Arc::downgrade(&dyn_arc); |
| 129 | + |
| 130 | + let slice_arc: Arc<[u32]> = Arc::from(vec![4, 5, 6]); |
| 131 | + inc_ref_count(&slice_arc, 60); |
| 132 | + let slice_arc_weak = Arc::downgrade(&slice_arc); |
77 | 133 |
|
78 | 134 | zzz(); // #break
|
79 | 135 | }
|
80 | 136 |
|
81 |
| -fn zzz() { () } |
| 137 | +fn inc_ref_count<T: Clone>(rc: &T, count: usize) { |
| 138 | + for _ in 0..count { |
| 139 | + std::mem::forget(rc.clone()); |
| 140 | + } |
| 141 | +} |
| 142 | + |
| 143 | +fn zzz() { |
| 144 | + () |
| 145 | +} |
0 commit comments