Skip to content

Commit 238d847

Browse files
committed
Don't add ByteRepr for system header types
1 parent e6a5b18 commit 238d847

13 files changed

Lines changed: 19 additions & 229 deletions

cpp2rust/converter/converter_lib.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,10 @@ bool TypeImplementsByteRepr(clang::QualType qt) {
208208
return TypeImplementsByteRepr(arr->getElementType());
209209
}
210210
if (const auto *rd = qt->getAsRecordDecl()) {
211+
if (rd->getASTContext().getSourceManager().isInSystemHeader(
212+
rd->getLocation())) {
213+
return false;
214+
}
211215
if (rd->isUnion()) {
212216
return true;
213217
}

tests/unit/out/refcount/array_of_noncopy_struct.rs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,7 @@ impl Clone for NonCopy {
2020
this
2121
}
2222
}
23-
impl ByteRepr for NonCopy {
24-
fn byte_size() -> usize {
25-
32
26-
}
27-
fn to_bytes(&self, buf: &mut [u8]) {
28-
(*self.data.borrow()).to_bytes(&mut buf[0..24]);
29-
(*self.tag.borrow()).to_bytes(&mut buf[24..28]);
30-
}
31-
fn from_bytes(buf: &[u8]) -> Self {
32-
Self {
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]))),
35-
}
36-
}
37-
}
23+
impl ByteRepr for NonCopy {}
3824
pub fn main() {
3925
std::process::exit(main_0());
4026
}

tests/unit/out/refcount/class_templates.rs

Lines changed: 3 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,7 @@ impl Clone for MyContainer_int_ {
4242
this
4343
}
4444
}
45-
impl ByteRepr for MyContainer_int_ {
46-
fn byte_size() -> usize {
47-
24
48-
}
49-
fn to_bytes(&self, buf: &mut [u8]) {
50-
(*self.vec_.borrow()).to_bytes(&mut buf[0..24]);
51-
}
52-
fn from_bytes(buf: &[u8]) -> Self {
53-
Self {
54-
vec_: Rc::new(RefCell::new(<Vec<i32>>::from_bytes(&buf[0..24]))),
55-
}
56-
}
57-
}
45+
impl ByteRepr for MyContainer_int_ {}
5846
#[derive(Default)]
5947
pub struct MyContainer_char_ {
6048
vec_: Value<Vec<u8>>,
@@ -91,19 +79,7 @@ impl Clone for MyContainer_char_ {
9179
this
9280
}
9381
}
94-
impl ByteRepr for MyContainer_char_ {
95-
fn byte_size() -> usize {
96-
24
97-
}
98-
fn to_bytes(&self, buf: &mut [u8]) {
99-
(*self.vec_.borrow()).to_bytes(&mut buf[0..24]);
100-
}
101-
fn from_bytes(buf: &[u8]) -> Self {
102-
Self {
103-
vec_: Rc::new(RefCell::new(<Vec<u8>>::from_bytes(&buf[0..24]))),
104-
}
105-
}
106-
}
82+
impl ByteRepr for MyContainer_char_ {}
10783
#[derive(Default)]
10884
pub struct MyContainer_float_ {
10985
vec_: Value<Vec<f32>>,
@@ -140,19 +116,7 @@ impl Clone for MyContainer_float_ {
140116
this
141117
}
142118
}
143-
impl ByteRepr for MyContainer_float_ {
144-
fn byte_size() -> usize {
145-
24
146-
}
147-
fn to_bytes(&self, buf: &mut [u8]) {
148-
(*self.vec_.borrow()).to_bytes(&mut buf[0..24]);
149-
}
150-
fn from_bytes(buf: &[u8]) -> Self {
151-
Self {
152-
vec_: Rc::new(RefCell::new(<Vec<f32>>::from_bytes(&buf[0..24]))),
153-
}
154-
}
155-
}
119+
impl ByteRepr for MyContainer_float_ {}
156120
pub fn main() {
157121
std::process::exit(main_0());
158122
}

tests/unit/out/refcount/foreach_disjoint_field_borrow.rs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,7 @@ impl Clone for S {
2020
this
2121
}
2222
}
23-
impl ByteRepr for S {
24-
fn byte_size() -> usize {
25-
32
26-
}
27-
fn to_bytes(&self, buf: &mut [u8]) {
28-
(*self.v.borrow()).to_bytes(&mut buf[0..24]);
29-
(*self.a.borrow()).to_bytes(&mut buf[24..28]);
30-
}
31-
fn from_bytes(buf: &[u8]) -> Self {
32-
Self {
33-
v: Rc::new(RefCell::new(<Vec<i32>>::from_bytes(&buf[0..24]))),
34-
a: Rc::new(RefCell::new(<i32>::from_bytes(&buf[24..28]))),
35-
}
36-
}
37-
}
23+
impl ByteRepr for S {}
3824
pub fn main() {
3925
std::process::exit(main_0());
4026
}

tests/unit/out/refcount/huffman.rs

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -200,31 +200,7 @@ impl MinHeap {
200200
}
201201
}
202202
}
203-
impl ByteRepr for MinHeap {
204-
fn byte_size() -> usize {
205-
32
206-
}
207-
fn to_bytes(&self, buf: &mut [u8]) {
208-
(*self.size.borrow()).to_bytes(&mut buf[0..4]);
209-
(*self.capacity.borrow()).to_bytes(&mut buf[4..8]);
210-
(*self.arr.borrow()).to_bytes(&mut buf[8..16]);
211-
(*self.next.borrow()).to_bytes(&mut buf[16..20]);
212-
(*self.alloc.borrow()).to_bytes(&mut buf[24..32]);
213-
}
214-
fn from_bytes(buf: &[u8]) -> Self {
215-
Self {
216-
size: Rc::new(RefCell::new(<i32>::from_bytes(&buf[0..4]))),
217-
capacity: Rc::new(RefCell::new(<i32>::from_bytes(&buf[4..8]))),
218-
arr: Rc::new(RefCell::new(
219-
<Option<Value<Box<[Ptr<MinHeapNode>]>>>>::from_bytes(&buf[8..16]),
220-
)),
221-
next: Rc::new(RefCell::new(<i32>::from_bytes(&buf[16..20]))),
222-
alloc: Rc::new(RefCell::new(
223-
<Option<Value<Box<[MinHeapNode]>>>>::from_bytes(&buf[24..32]),
224-
)),
225-
}
226-
}
227-
}
203+
impl ByteRepr for MinHeap {}
228204
pub fn AllocMinHeap_1(capacity: i32) -> Option<Value<MinHeap>> {
229205
let capacity: Value<i32> = Rc::new(RefCell::new(capacity));
230206
let minHeap: Value<Option<Value<MinHeap>>> =

tests/unit/out/refcount/implicit_autoref.rs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,7 @@ impl Clone for Holder {
1818
this
1919
}
2020
}
21-
impl ByteRepr for Holder {
22-
fn byte_size() -> usize {
23-
24
24-
}
25-
fn to_bytes(&self, buf: &mut [u8]) {
26-
(*self.v.borrow()).to_bytes(&mut buf[0..24]);
27-
}
28-
fn from_bytes(buf: &[u8]) -> Self {
29-
Self {
30-
v: Rc::new(RefCell::new(<Vec<i32>>::from_bytes(&buf[0..24]))),
31-
}
32-
}
33-
}
21+
impl ByteRepr for Holder {}
3422
pub fn write_through_0(p: Ptr<i32>) {
3523
let p: Value<Ptr<i32>> = Rc::new(RefCell::new(p));
3624
(*p.borrow()).write(42);

tests/unit/out/refcount/kruskal.rs

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -280,52 +280,14 @@ impl DisjointSet {
280280
}
281281
}
282282
}
283-
impl ByteRepr for DisjointSet {
284-
fn byte_size() -> usize {
285-
24
286-
}
287-
fn to_bytes(&self, buf: &mut [u8]) {
288-
(*self.rank.borrow()).to_bytes(&mut buf[0..8]);
289-
(*self.parent.borrow()).to_bytes(&mut buf[8..16]);
290-
(*self.n.borrow()).to_bytes(&mut buf[16..20]);
291-
}
292-
fn from_bytes(buf: &[u8]) -> Self {
293-
Self {
294-
rank: Rc::new(RefCell::new(<Option<Value<Box<[i32]>>>>::from_bytes(
295-
&buf[0..8],
296-
))),
297-
parent: Rc::new(RefCell::new(<Option<Value<Box<[i32]>>>>::from_bytes(
298-
&buf[8..16],
299-
))),
300-
n: Rc::new(RefCell::new(<i32>::from_bytes(&buf[16..20]))),
301-
}
302-
}
303-
}
283+
impl ByteRepr for DisjointSet {}
304284
#[derive(Default)]
305285
pub struct Graph {
306286
pub edges: Value<Option<Value<Box<[Edge]>>>>,
307287
pub V: Value<i32>,
308288
pub E: Value<i32>,
309289
}
310-
impl ByteRepr for Graph {
311-
fn byte_size() -> usize {
312-
16
313-
}
314-
fn to_bytes(&self, buf: &mut [u8]) {
315-
(*self.edges.borrow()).to_bytes(&mut buf[0..8]);
316-
(*self.V.borrow()).to_bytes(&mut buf[8..12]);
317-
(*self.E.borrow()).to_bytes(&mut buf[12..16]);
318-
}
319-
fn from_bytes(buf: &[u8]) -> Self {
320-
Self {
321-
edges: Rc::new(RefCell::new(<Option<Value<Box<[Edge]>>>>::from_bytes(
322-
&buf[0..8],
323-
))),
324-
V: Rc::new(RefCell::new(<i32>::from_bytes(&buf[8..12]))),
325-
E: Rc::new(RefCell::new(<i32>::from_bytes(&buf[12..16]))),
326-
}
327-
}
328-
}
290+
impl ByteRepr for Graph {}
329291
pub fn MSTKruskal_2(graph: Ptr<Graph>) -> f64 {
330292
({
331293
let _arr: Ptr<Option<Value<Box<[Edge]>>>> = (*graph.upgrade().deref()).edges.as_pointer();

tests/unit/out/refcount/push_emplace_back.rs

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -70,23 +70,7 @@ impl Clone for JPEGData {
7070
this
7171
}
7272
}
73-
impl ByteRepr for JPEGData {
74-
fn byte_size() -> usize {
75-
48
76-
}
77-
fn to_bytes(&self, buf: &mut [u8]) {
78-
(*self.com_data.borrow()).to_bytes(&mut buf[0..24]);
79-
(*self.app_data.borrow()).to_bytes(&mut buf[24..48]);
80-
}
81-
fn from_bytes(buf: &[u8]) -> Self {
82-
Self {
83-
com_data: Rc::new(RefCell::new(<Vec<Value<Vec<u8>>>>::from_bytes(&buf[0..24]))),
84-
app_data: Rc::new(RefCell::new(<Vec<Value<Vec<u8>>>>::from_bytes(
85-
&buf[24..48],
86-
))),
87-
}
88-
}
89-
}
73+
impl ByteRepr for JPEGData {}
9074
pub fn push_param_0(dest: Ptr<Vec<Value<Vec<u8>>>>) {
9175
let dest: Value<Ptr<Vec<Value<Vec<u8>>>>> = Rc::new(RefCell::new(dest));
9276
((*dest.borrow()).to_strong().as_pointer() as Ptr<Vec<Value<Vec<u8>>>>).with_mut(

tests/unit/out/refcount/typedef-anon-struct.rs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,7 @@ impl Clone for Outer {
4747
this
4848
}
4949
}
50-
impl ByteRepr for Outer {
51-
fn byte_size() -> usize {
52-
24
53-
}
54-
fn to_bytes(&self, buf: &mut [u8]) {
55-
(*self.runs.borrow()).to_bytes(&mut buf[0..24]);
56-
}
57-
fn from_bytes(buf: &[u8]) -> Self {
58-
Self {
59-
runs: Rc::new(RefCell::new(<Vec<Outer_RunInfo>>::from_bytes(&buf[0..24]))),
60-
}
61-
}
62-
}
50+
impl ByteRepr for Outer {}
6351
pub fn main() {
6452
std::process::exit(main_0());
6553
}

tests/unit/out/refcount/unique_ptr.rs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,7 @@ impl SafePointer {
1515
(*(*self.ptr.borrow_mut()).as_ref().unwrap().borrow_mut()).prefix_inc();
1616
}
1717
}
18-
impl ByteRepr for SafePointer {
19-
fn byte_size() -> usize {
20-
8
21-
}
22-
fn to_bytes(&self, buf: &mut [u8]) {
23-
(*self.ptr.borrow()).to_bytes(&mut buf[0..8]);
24-
}
25-
fn from_bytes(buf: &[u8]) -> Self {
26-
Self {
27-
ptr: Rc::new(RefCell::new(<Option<Value<i32>>>::from_bytes(&buf[0..8]))),
28-
}
29-
}
30-
}
18+
impl ByteRepr for SafePointer {}
3119
#[derive(Default)]
3220
pub struct Pair {
3321
pub x: Value<i32>,

0 commit comments

Comments
 (0)