Skip to content

Commit c732fbe

Browse files
committed
Update tests
1 parent 0dd222b commit c732fbe

14 files changed

Lines changed: 791 additions & 860 deletions

‎tests/unit/out/refcount/array_of_noncopy_struct.rs‎

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,16 @@ use std::io::prelude::*;
66
use std::io::{Read, Seek, Write};
77
use std::os::fd::AsFd;
88
use std::rc::{Rc, Weak};
9-
#[repr(C)]
109
#[derive(Default)]
1110
pub struct NonCopy {
12-
pub data: Vec<i32>,
13-
pub tag: i32,
11+
pub data: Value<Vec<i32>>,
12+
pub tag: Value<i32>,
1413
}
1514
impl Clone for NonCopy {
1615
fn clone(&self) -> Self {
1716
let mut this = Self {
18-
data: (self.data).clone(),
19-
tag: self.tag,
17+
data: Rc::new(RefCell::new((*self.data.borrow()).clone())),
18+
tag: Rc::new(RefCell::new((*self.tag.borrow()))),
2019
};
2120
this
2221
}
@@ -26,13 +25,13 @@ impl ByteRepr for NonCopy {
2625
32
2726
}
2827
fn to_bytes(&self, buf: &mut [u8]) {
29-
self.data.to_bytes(&mut buf[0..24]);
30-
self.tag.to_bytes(&mut buf[24..28]);
28+
(*self.data.borrow()).to_bytes(&mut buf[0..24]);
29+
(*self.tag.borrow()).to_bytes(&mut buf[24..28]);
3130
}
3231
fn from_bytes(buf: &[u8]) -> Self {
3332
Self {
34-
data: <Vec<i32>>::from_bytes(&buf[0..24]),
35-
tag: <i32>::from_bytes(&buf[24..28]),
33+
data: Rc::new(RefCell::new(<Vec<i32>>::from_bytes(&buf[0..24]))),
34+
tag: Rc::new(RefCell::new(<i32>::from_bytes(&buf[24..28]))),
3635
}
3736
}
3837
}
@@ -45,21 +44,17 @@ fn main_0() -> i32 {
4544
.map(|_| <NonCopy>::default())
4645
.collect::<Box<[NonCopy]>>(),
4746
));
48-
(*arr.borrow_mut())[(0) as usize].tag = 7;
49-
(*arr.borrow_mut())[(1) as usize].data.push(42);
50-
assert!(((*arr.borrow())[(0) as usize].tag == 7));
51-
assert!(((*arr.borrow())[(1) as usize].data.len() == 1_usize));
47+
(*(*arr.borrow())[(0) as usize].tag.borrow_mut()) = 7;
48+
(*(*arr.borrow())[(1) as usize].data.borrow_mut()).push(42);
49+
assert!(((*(*arr.borrow())[(0) as usize].tag.borrow()) == 7));
50+
assert!(((*(*arr.borrow())[(1) as usize].data.borrow()).len() == 1_usize));
5251
assert!(
53-
((((arr.as_pointer() as Ptr<NonCopy>).offset(1).field_ptr(
54-
0,
55-
|__v: &NonCopy| &__v.data[..],
56-
|__v: &mut NonCopy| &mut __v.data[..]
57-
) as Ptr<i32>)
52+
((((*arr.borrow())[(1) as usize].data.as_pointer() as Ptr<i32>)
5853
.offset(0_usize)
5954
.read())
6055
== 42)
6156
);
62-
assert!(((*arr.borrow())[(2) as usize].tag == 0));
63-
assert!(((*arr.borrow())[(2) as usize].data.len() == 0_usize));
57+
assert!(((*(*arr.borrow())[(2) as usize].tag.borrow()) == 0));
58+
assert!(((*(*arr.borrow())[(2) as usize].data.borrow()).len() == 0_usize));
6459
return 0;
6560
}

‎tests/unit/out/refcount/class_templates.rs‎

Lines changed: 80 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -6,57 +6,38 @@ use std::io::prelude::*;
66
use std::io::{Read, Seek, Write};
77
use std::os::fd::AsFd;
88
use std::rc::{Rc, Weak};
9-
#[repr(C)]
109
#[derive(Default)]
1110
pub struct MyContainer_int_ {
12-
vec_: Vec<i32>,
11+
vec_: Value<Vec<i32>>,
1312
}
14-
pub trait MyContainer_int_Methods {
15-
fn empty(&self) -> bool;
16-
fn size(&self) -> usize;
17-
fn back_const(&self) -> Ptr<i32>;
18-
fn back(&self) -> Ptr<i32>;
19-
fn pop_back(&self);
20-
fn push_back(&self, item: Ptr<i32>);
21-
}
22-
impl MyContainer_int_Methods for Ptr<MyContainer_int_> {
23-
fn empty(&self) -> bool {
24-
return self.with(|__v| (*__v).vec_.clone()).is_empty();
25-
}
26-
fn size(&self) -> usize {
27-
return self.with(|__v| (*__v).vec_.clone()).len();
28-
}
29-
fn back_const(&self) -> Ptr<i32> {
30-
return (self.field_ptr(
31-
0,
32-
|__v: &MyContainer_int_| &__v.vec_[..],
33-
|__v: &mut MyContainer_int_| &mut __v.vec_[..],
34-
) as Ptr<i32>)
35-
.to_last();
36-
}
37-
fn back(&self) -> Ptr<i32> {
38-
return (self.field_ptr(
39-
0,
40-
|__v: &MyContainer_int_| &__v.vec_[..],
41-
|__v: &mut MyContainer_int_| &mut __v.vec_[..],
42-
) as Ptr<i32>)
43-
.to_last();
44-
}
45-
fn pop_back(&self) {
46-
self.with_mut(|__v| __v.vec_.pop());
13+
impl MyContainer_int_ {
14+
pub fn empty(&self) -> bool {
15+
return (*self.vec_.borrow()).is_empty();
16+
}
17+
pub fn size(&self) -> usize {
18+
return (*self.vec_.borrow()).len();
19+
}
20+
pub fn back_const(&self) -> Ptr<i32> {
21+
return (self.vec_.as_pointer() as Ptr<i32>).to_last();
22+
}
23+
pub fn back(&self) -> Ptr<i32> {
24+
return (self.vec_.as_pointer() as Ptr<i32>).to_last();
25+
}
26+
pub fn pop_back(&self) {
27+
(*self.vec_.borrow_mut()).pop();
4728
return;
4829
}
49-
fn push_back(&self, item: Ptr<i32>) {
30+
pub fn push_back(&self, item: Ptr<i32>) {
5031
{
5132
let a0_clone = (item.read()).clone();
52-
self.with_mut(|__v| __v.vec_.push(a0_clone))
33+
(*self.vec_.borrow_mut()).push(a0_clone)
5334
};
5435
}
5536
}
5637
impl Clone for MyContainer_int_ {
5738
fn clone(&self) -> Self {
5839
let mut this = Self {
59-
vec_: (self.vec_).clone(),
40+
vec_: Rc::new(RefCell::new((*self.vec_.borrow()).clone())),
6041
};
6142
this
6243
}
@@ -66,65 +47,46 @@ impl ByteRepr for MyContainer_int_ {
6647
24
6748
}
6849
fn to_bytes(&self, buf: &mut [u8]) {
69-
self.vec_.to_bytes(&mut buf[0..24]);
50+
(*self.vec_.borrow()).to_bytes(&mut buf[0..24]);
7051
}
7152
fn from_bytes(buf: &[u8]) -> Self {
7253
Self {
73-
vec_: <Vec<i32>>::from_bytes(&buf[0..24]),
54+
vec_: Rc::new(RefCell::new(<Vec<i32>>::from_bytes(&buf[0..24]))),
7455
}
7556
}
7657
}
77-
#[repr(C)]
7858
#[derive(Default)]
7959
pub struct MyContainer_char_ {
80-
vec_: Vec<u8>,
81-
}
82-
pub trait MyContainer_char_Methods {
83-
fn empty(&self) -> bool;
84-
fn size(&self) -> usize;
85-
fn back_const(&self) -> Ptr<u8>;
86-
fn back(&self) -> Ptr<u8>;
87-
fn pop_back(&self);
88-
fn push_back(&self, item: Ptr<u8>);
60+
vec_: Value<Vec<u8>>,
8961
}
90-
impl MyContainer_char_Methods for Ptr<MyContainer_char_> {
91-
fn empty(&self) -> bool {
92-
return self.with(|__v| (*__v).vec_.clone()).is_empty();
93-
}
94-
fn size(&self) -> usize {
95-
return self.with(|__v| (*__v).vec_.clone()).len();
96-
}
97-
fn back_const(&self) -> Ptr<u8> {
98-
return (self.field_ptr(
99-
0,
100-
|__v: &MyContainer_char_| &__v.vec_[..],
101-
|__v: &mut MyContainer_char_| &mut __v.vec_[..],
102-
) as Ptr<u8>)
103-
.to_last();
104-
}
105-
fn back(&self) -> Ptr<u8> {
106-
return (self.field_ptr(
107-
0,
108-
|__v: &MyContainer_char_| &__v.vec_[..],
109-
|__v: &mut MyContainer_char_| &mut __v.vec_[..],
110-
) as Ptr<u8>)
111-
.to_last();
112-
}
113-
fn pop_back(&self) {
114-
self.with_mut(|__v| __v.vec_.pop());
62+
impl MyContainer_char_ {
63+
pub fn empty(&self) -> bool {
64+
return (*self.vec_.borrow()).is_empty();
65+
}
66+
pub fn size(&self) -> usize {
67+
return (*self.vec_.borrow()).len();
68+
}
69+
pub fn back_const(&self) -> Ptr<u8> {
70+
return (self.vec_.as_pointer() as Ptr<u8>).to_last();
71+
}
72+
pub fn back(&self) -> Ptr<u8> {
73+
return (self.vec_.as_pointer() as Ptr<u8>).to_last();
74+
}
75+
pub fn pop_back(&self) {
76+
(*self.vec_.borrow_mut()).pop();
11577
return;
11678
}
117-
fn push_back(&self, item: Ptr<u8>) {
79+
pub fn push_back(&self, item: Ptr<u8>) {
11880
{
11981
let a0_clone = (item.read()).clone();
120-
self.with_mut(|__v| __v.vec_.push(a0_clone))
82+
(*self.vec_.borrow_mut()).push(a0_clone)
12183
};
12284
}
12385
}
12486
impl Clone for MyContainer_char_ {
12587
fn clone(&self) -> Self {
12688
let mut this = Self {
127-
vec_: (self.vec_).clone(),
89+
vec_: Rc::new(RefCell::new((*self.vec_.borrow()).clone())),
12890
};
12991
this
13092
}
@@ -134,65 +96,46 @@ impl ByteRepr for MyContainer_char_ {
13496
24
13597
}
13698
fn to_bytes(&self, buf: &mut [u8]) {
137-
self.vec_.to_bytes(&mut buf[0..24]);
99+
(*self.vec_.borrow()).to_bytes(&mut buf[0..24]);
138100
}
139101
fn from_bytes(buf: &[u8]) -> Self {
140102
Self {
141-
vec_: <Vec<u8>>::from_bytes(&buf[0..24]),
103+
vec_: Rc::new(RefCell::new(<Vec<u8>>::from_bytes(&buf[0..24]))),
142104
}
143105
}
144106
}
145-
#[repr(C)]
146107
#[derive(Default)]
147108
pub struct MyContainer_float_ {
148-
vec_: Vec<f32>,
109+
vec_: Value<Vec<f32>>,
149110
}
150-
pub trait MyContainer_float_Methods {
151-
fn empty(&self) -> bool;
152-
fn size(&self) -> usize;
153-
fn back_const(&self) -> Ptr<f32>;
154-
fn back(&self) -> Ptr<f32>;
155-
fn pop_back(&self);
156-
fn push_back(&self, item: Ptr<f32>);
157-
}
158-
impl MyContainer_float_Methods for Ptr<MyContainer_float_> {
159-
fn empty(&self) -> bool {
160-
return self.with(|__v| (*__v).vec_.clone()).is_empty();
161-
}
162-
fn size(&self) -> usize {
163-
return self.with(|__v| (*__v).vec_.clone()).len();
164-
}
165-
fn back_const(&self) -> Ptr<f32> {
166-
return (self.field_ptr(
167-
0,
168-
|__v: &MyContainer_float_| &__v.vec_[..],
169-
|__v: &mut MyContainer_float_| &mut __v.vec_[..],
170-
) as Ptr<f32>)
171-
.to_last();
172-
}
173-
fn back(&self) -> Ptr<f32> {
174-
return (self.field_ptr(
175-
0,
176-
|__v: &MyContainer_float_| &__v.vec_[..],
177-
|__v: &mut MyContainer_float_| &mut __v.vec_[..],
178-
) as Ptr<f32>)
179-
.to_last();
180-
}
181-
fn pop_back(&self) {
182-
self.with_mut(|__v| __v.vec_.pop());
111+
impl MyContainer_float_ {
112+
pub fn empty(&self) -> bool {
113+
return (*self.vec_.borrow()).is_empty();
114+
}
115+
pub fn size(&self) -> usize {
116+
return (*self.vec_.borrow()).len();
117+
}
118+
pub fn back_const(&self) -> Ptr<f32> {
119+
return (self.vec_.as_pointer() as Ptr<f32>).to_last();
120+
}
121+
pub fn back(&self) -> Ptr<f32> {
122+
return (self.vec_.as_pointer() as Ptr<f32>).to_last();
123+
}
124+
pub fn pop_back(&self) {
125+
(*self.vec_.borrow_mut()).pop();
183126
return;
184127
}
185-
fn push_back(&self, item: Ptr<f32>) {
128+
pub fn push_back(&self, item: Ptr<f32>) {
186129
{
187130
let a0_clone = (item.read()).clone();
188-
self.with_mut(|__v| __v.vec_.push(a0_clone))
131+
(*self.vec_.borrow_mut()).push(a0_clone)
189132
};
190133
}
191134
}
192135
impl Clone for MyContainer_float_ {
193136
fn clone(&self) -> Self {
194137
let mut this = Self {
195-
vec_: (self.vec_).clone(),
138+
vec_: Rc::new(RefCell::new((*self.vec_.borrow()).clone())),
196139
};
197140
this
198141
}
@@ -202,11 +145,11 @@ impl ByteRepr for MyContainer_float_ {
202145
24
203146
}
204147
fn to_bytes(&self, buf: &mut [u8]) {
205-
self.vec_.to_bytes(&mut buf[0..24]);
148+
(*self.vec_.borrow()).to_bytes(&mut buf[0..24]);
206149
}
207150
fn from_bytes(buf: &[u8]) -> Self {
208151
Self {
209-
vec_: <Vec<f32>>::from_bytes(&buf[0..24]),
152+
vec_: Rc::new(RefCell::new(<Vec<f32>>::from_bytes(&buf[0..24]))),
210153
}
211154
}
212155
}
@@ -215,39 +158,39 @@ pub fn main() {
215158
}
216159
fn main_0() -> i32 {
217160
let imc: Value<MyContainer_int_> = Rc::new(RefCell::new(<MyContainer_int_>::default()));
218-
assert!(({ imc.as_pointer().empty() }));
161+
assert!(({ (*imc.borrow()).empty() }));
219162
({
220163
let _item: Value<i32> = Rc::new(RefCell::new(1));
221-
imc.as_pointer().push_back(_item.as_pointer())
164+
(*imc.borrow()).push_back(_item.as_pointer())
222165
});
223166
assert!(
224-
(({ imc.as_pointer().size() }) == 1_usize) && ((({ imc.as_pointer().back() }).read()) == 1)
167+
(({ (*imc.borrow()).size() }) == 1_usize) && ((({ (*imc.borrow()).back() }).read()) == 1)
225168
);
226-
({ imc.as_pointer().pop_back() });
227-
assert!(({ imc.as_pointer().empty() }));
169+
({ (*imc.borrow()).pop_back() });
170+
assert!(({ (*imc.borrow()).empty() }));
228171
let cmc: Value<MyContainer_char_> = Rc::new(RefCell::new(<MyContainer_char_>::default()));
229-
assert!(({ cmc.as_pointer().empty() }));
172+
assert!(({ (*cmc.borrow()).empty() }));
230173
({
231174
let _item: Value<u8> = Rc::new(RefCell::new(('a' as u8)));
232-
cmc.as_pointer().push_back(_item.as_pointer())
175+
(*cmc.borrow()).push_back(_item.as_pointer())
233176
});
234177
assert!(
235-
(({ cmc.as_pointer().size() }) == 1_usize)
236-
&& (((({ cmc.as_pointer().back() }).read()) as i32) == (('a' as u8) as i32))
178+
(({ (*cmc.borrow()).size() }) == 1_usize)
179+
&& (((({ (*cmc.borrow()).back() }).read()) as i32) == (('a' as u8) as i32))
237180
);
238-
({ cmc.as_pointer().pop_back() });
239-
assert!(({ cmc.as_pointer().empty() }));
181+
({ (*cmc.borrow()).pop_back() });
182+
assert!(({ (*cmc.borrow()).empty() }));
240183
let fmc: Value<MyContainer_float_> = Rc::new(RefCell::new(<MyContainer_float_>::default()));
241-
assert!(({ fmc.as_pointer().empty() }));
184+
assert!(({ (*fmc.borrow()).empty() }));
242185
({
243186
let _item: Value<f32> = Rc::new(RefCell::new((1.0E+0 as f32)));
244-
fmc.as_pointer().push_back(_item.as_pointer())
187+
(*fmc.borrow()).push_back(_item.as_pointer())
245188
});
246189
assert!(
247-
(({ fmc.as_pointer().size() }) == 1_usize)
248-
&& (((({ fmc.as_pointer().back() }).read()) as f64) == 1.0E+0)
190+
(({ (*fmc.borrow()).size() }) == 1_usize)
191+
&& (((({ (*fmc.borrow()).back() }).read()) as f64) == 1.0E+0)
249192
);
250-
({ fmc.as_pointer().pop_back() });
251-
assert!(({ fmc.as_pointer().empty() }));
193+
({ (*fmc.borrow()).pop_back() });
194+
assert!(({ (*fmc.borrow()).empty() }));
252195
return 0;
253196
}

0 commit comments

Comments
 (0)