Skip to content

Commit 38fcdc2

Browse files
committed
remove C++ lib dependent test
1 parent 9c3ffc7 commit 38fcdc2

3 files changed

Lines changed: 11 additions & 79 deletions

File tree

‎tests/unit/container_field_addr.cpp‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,19 @@
66
struct S {
77
int tag;
88
std::vector<int> v;
9-
std::string s;
109
std::map<int, int> m;
1110
};
1211

1312
static void add(std::vector<int> *v, int k) { v->push_back(k); }
1413

15-
static void append(std::string *s, const char *t, std::size_t n) {
16-
s->append(t, n);
17-
}
18-
1914
static void put(std::map<int, int> *m, int k, int v) { (*m)[k] = v; }
2015

2116
static void run(S *h) {
2217
add(&h->v, h->tag);
23-
append(&h->s, "ab", 2);
2418
put(&h->m, h->tag, 2);
2519
std::vector<int> *pv = &h->v;
2620
pv->push_back((int)pv->size());
2721
assert(h->v.size() == 2 && h->v[0] == 7 && h->v[1] == 1);
28-
assert(h->s == "ab");
2922
assert(h->m[7] == 2);
3023
assert(h->tag == 7);
3124
}

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

Lines changed: 6 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,20 @@ pub struct S {
1313
#[offset(8)]
1414
pub v: Value<Vec<i32>>,
1515
#[offset(32)]
16-
pub s: Value<Vec<u8>>,
17-
#[offset(64)]
1816
pub m: BTreeMap<i32, Value<i32>>,
1917
}
2018
impl Clone for S {
2119
fn clone(&self) -> Self {
2220
Self {
2321
tag: self.tag.clone(),
2422
v: Rc::new(RefCell::new((*self.v.borrow()).clone())),
25-
s: Rc::new(RefCell::new((*self.s.borrow()).clone())),
2623
m: self.m.clone(),
2724
}
2825
}
2926
}
3027
impl ByteRepr for S {
3128
fn byte_size() -> usize {
32-
112
29+
80
3330
}
3431
}
3532
pub fn add_0(v: Ptr<Vec<i32>>, k: i32) {
@@ -40,25 +37,7 @@ pub fn add_0(v: Ptr<Vec<i32>>, k: i32) {
4037
(*v.borrow()).with_mut(|__v: &mut Vec<i32>| __v.push(a0_clone))
4138
};
4239
}
43-
pub fn append_1(s: Ptr<Vec<u8>>, t: Ptr<u8>, n: usize) {
44-
let s: Value<Ptr<Vec<u8>>> = Rc::new(RefCell::new(s));
45-
let t: Value<Ptr<u8>> = Rc::new(RefCell::new(t));
46-
let n: Value<usize> = Rc::new(RefCell::new(n));
47-
{
48-
((*s.borrow()).clone() as Ptr<Vec<u8>>).with_mut(|__v: &mut Vec<u8>| {
49-
__v.pop();
50-
__v.extend(
51-
(*t.borrow())
52-
.clone()
53-
.map(|c| c.read())
54-
.take((*n.borrow()) as usize),
55-
);
56-
__v.push(0);
57-
});
58-
((*s.borrow()).clone() as Ptr<Vec<u8>>)
59-
};
60-
}
61-
pub fn put_2(m: Ptr<BTreeMap<i32, Value<i32>>>, k: i32, v: i32) {
40+
pub fn put_1(m: Ptr<BTreeMap<i32, Value<i32>>>, k: i32, v: i32) {
6241
let m: Value<Ptr<BTreeMap<i32, Value<i32>>>> = Rc::new(RefCell::new(m));
6342
let k: Value<i32> = Rc::new(RefCell::new(k));
6443
let v: Value<i32> = Rc::new(RefCell::new(v));
@@ -70,24 +49,17 @@ pub fn put_2(m: Ptr<BTreeMap<i32, Value<i32>>>, k: i32, v: i32) {
7049
})
7150
.write((*v.borrow()));
7251
}
73-
pub fn run_3(h: Ptr<S>) {
52+
pub fn run_2(h: Ptr<S>) {
7453
let h: Value<Ptr<S>> = Rc::new(RefCell::new(h));
7554
({
7655
let _v: Ptr<Vec<i32>> = ((*h.borrow()).with(|__s| __s.v.clone()).as_pointer());
7756
let _k: i32 = (*h.borrow()).with(|__s| __s.tag);
7857
add_0(_v, _k)
7958
});
80-
({
81-
append_1(
82-
((*h.borrow()).with(|__s| __s.s.clone()).as_pointer()),
83-
Ptr::<u8>::from_string_literal(b"ab"),
84-
2_usize,
85-
)
86-
});
8759
({
8860
let _m: Ptr<BTreeMap<i32, Value<i32>>> = (field_ptr!((*h.borrow()), m));
8961
let _k: i32 = (*h.borrow()).with(|__s| __s.tag);
90-
put_2(_m, _k, 2)
62+
put_1(_m, _k, 2)
9163
});
9264
let pv: Value<Ptr<Vec<i32>>> = Rc::new(RefCell::new(
9365
((*h.borrow()).with(|__s| __s.v.clone()).as_pointer()),
@@ -107,17 +79,6 @@ pub fn run_3(h: Ptr<S>) {
10779
.read())
10880
== 1)
10981
);
110-
assert!(
111-
(*(*h.borrow()).with(|__s| __s.s.clone()).borrow())
112-
.iter()
113-
.copied()
114-
.take(
115-
(*(*h.borrow()).with(|__s| __s.s.clone()).borrow())
116-
.len()
117-
.saturating_sub(1)
118-
)
119-
.eq(Ptr::<u8>::from_string_literal(b"ab").to_c_string_iterator())
120-
);
12182
assert!(
12283
(((field_ptr!((*h.borrow()), m) as Ptr<BTreeMap<i32, Value<i32>>>)
12384
.with_mut(|__v: &mut BTreeMap<i32, Value<i32>>| {
@@ -137,10 +98,10 @@ pub fn main() {
13798
fn main_0() -> i32 {
13899
let local: Value<S> = Rc::new(RefCell::new(<S>::default()));
139100
(*local.borrow_mut()).tag = 7;
140-
({ run_3((local.as_pointer())) });
101+
({ run_2((local.as_pointer())) });
141102
let heap: Value<Ptr<S>> = Rc::new(RefCell::new(Ptr::alloc(<S>::default())));
142103
field!((*heap.borrow()), tag).write(7);
143-
({ run_3((*heap.borrow()).clone()) });
104+
({ run_2((*heap.borrow()).clone()) });
144105
(*heap.borrow()).delete();
145106
return 0;
146107
}

‎tests/unit/out/unsafe/container_field_addr.rs‎

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use std::rc::Rc;
1111
pub struct S {
1212
pub tag: i32,
1313
pub v: Vec<i32>,
14-
pub s: Vec<libc::c_char>,
1514
pub m: BTreeMap<i32, Box<i32>>,
1615
}
1716
pub unsafe fn add_0(mut v: *mut Vec<i32>, mut k: i32) {
@@ -20,33 +19,19 @@ pub unsafe fn add_0(mut v: *mut Vec<i32>, mut k: i32) {
2019
(*v).push(a0_clone)
2120
};
2221
}
23-
pub unsafe fn append_1(mut s: *mut Vec<libc::c_char>, mut t: *const libc::c_char, mut n: usize) {
24-
(*s).splice((*s).len().saturating_sub(1)..(*s).len(), {
25-
let mut v = ::std::slice::from_raw_parts(t, n as usize).to_vec();
26-
v.push(0);
27-
v
28-
});
29-
}
30-
pub unsafe fn put_2(mut m: *mut BTreeMap<i32, Box<i32>>, mut k: i32, mut v: i32) {
22+
pub unsafe fn put_1(mut m: *mut BTreeMap<i32, Box<i32>>, mut k: i32, mut v: i32) {
3123
(*(*m).entry(k).or_default().as_mut()) = v;
3224
}
33-
pub unsafe fn run_3(mut h: *mut S) {
25+
pub unsafe fn run_2(mut h: *mut S) {
3426
(unsafe {
3527
let _v: *mut Vec<i32> = (&mut (*h).v as *mut Vec<i32>);
3628
let _k: i32 = (*h).tag;
3729
add_0(_v, _k)
3830
});
39-
(unsafe {
40-
append_1(
41-
(&mut (*h).s as *mut Vec<libc::c_char>),
42-
c"ab".as_ptr(),
43-
2_usize,
44-
)
45-
});
4631
(unsafe {
4732
let _m: *mut BTreeMap<i32, Box<i32>> = (&mut (*h).m as *mut BTreeMap<i32, Box<i32>>);
4833
let _k: i32 = (*h).tag;
49-
put_2(_m, _k, 2)
34+
put_1(_m, _k, 2)
5035
});
5136
let mut pv: *mut Vec<i32> = (&mut (*h).v as *mut Vec<i32>);
5237
{
@@ -57,13 +42,6 @@ pub unsafe fn run_3(mut h: *mut S) {
5742
((((*h).v.len()) == (2_usize)) && (((&mut (*h)).v[(0_usize)]) == (7)))
5843
&& (((&mut (*h)).v[(1_usize)]) == (1))
5944
);
60-
assert!(
61-
(*h).s == {
62-
let s = c"ab".as_ptr();
63-
std::slice::from_raw_parts(s, (0..).take_while(|&i| *s.add(i) != 0).count() + 1)
64-
.to_vec()
65-
}
66-
);
6745
assert!(((*(*h).m.entry(7).or_default().as_mut()) == (2)));
6846
assert!((((*h).tag) == (7)));
6947
}
@@ -76,10 +54,10 @@ pub fn main() {
7654
unsafe fn main_0() -> i32 {
7755
let mut local: S = <S>::default();
7856
local.tag = 7;
79-
(unsafe { run_3((&mut local as *mut S)) });
57+
(unsafe { run_2((&mut local as *mut S)) });
8058
let mut heap: *mut S = (Box::leak(Box::new(<S>::default())) as *mut S);
8159
(*heap).tag = 7;
82-
(unsafe { run_3(heap) });
60+
(unsafe { run_2(heap) });
8361
::std::mem::drop(Box::from_raw(heap));
8462
return 0;
8563
}

0 commit comments

Comments
 (0)