Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions cpp2rust/converter/converter_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,6 @@ bool TypeImplementsByteRepr(clang::QualType qt) {
return TypeImplementsByteRepr(arr->getElementType());
}
if (const auto *rd = qt->getAsRecordDecl()) {
if (rd->getASTContext().getSourceManager().isInSystemHeader(
rd->getLocation())) {
return false;
}
if (rd->isUnion()) {
return true;
}
Expand Down
16 changes: 15 additions & 1 deletion tests/unit/out/refcount/array_of_noncopy_struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,21 @@ impl Clone for NonCopy {
this
}
}
impl ByteRepr for NonCopy {}
impl ByteRepr for NonCopy {
fn byte_size() -> usize {
32
}
fn to_bytes(&self, buf: &mut [u8]) {
(*self.data.borrow()).to_bytes(&mut buf[0..24]);
(*self.tag.borrow()).to_bytes(&mut buf[24..28]);
}
fn from_bytes(buf: &[u8]) -> Self {
Self {
data: Rc::new(RefCell::new(<Vec<i32>>::from_bytes(&buf[0..24]))),
tag: Rc::new(RefCell::new(<i32>::from_bytes(&buf[24..28]))),
}
}
}
pub fn main() {
std::process::exit(main_0());
}
Expand Down
42 changes: 39 additions & 3 deletions tests/unit/out/refcount/class_templates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,19 @@ impl Clone for MyContainer_int_ {
this
}
}
impl ByteRepr for MyContainer_int_ {}
impl ByteRepr for MyContainer_int_ {
fn byte_size() -> usize {
24
}
fn to_bytes(&self, buf: &mut [u8]) {
(*self.vec_.borrow()).to_bytes(&mut buf[0..24]);
}
fn from_bytes(buf: &[u8]) -> Self {
Self {
vec_: Rc::new(RefCell::new(<Vec<i32>>::from_bytes(&buf[0..24]))),
}
}
}
#[derive(Default)]
pub struct MyContainer_char_ {
vec_: Value<Vec<u8>>,
Expand Down Expand Up @@ -79,7 +91,19 @@ impl Clone for MyContainer_char_ {
this
}
}
impl ByteRepr for MyContainer_char_ {}
impl ByteRepr for MyContainer_char_ {
fn byte_size() -> usize {
24
}
fn to_bytes(&self, buf: &mut [u8]) {
(*self.vec_.borrow()).to_bytes(&mut buf[0..24]);
}
fn from_bytes(buf: &[u8]) -> Self {
Self {
vec_: Rc::new(RefCell::new(<Vec<u8>>::from_bytes(&buf[0..24]))),
}
}
}
#[derive(Default)]
pub struct MyContainer_float_ {
vec_: Value<Vec<f32>>,
Expand Down Expand Up @@ -116,7 +140,19 @@ impl Clone for MyContainer_float_ {
this
}
}
impl ByteRepr for MyContainer_float_ {}
impl ByteRepr for MyContainer_float_ {
fn byte_size() -> usize {
24
}
fn to_bytes(&self, buf: &mut [u8]) {
(*self.vec_.borrow()).to_bytes(&mut buf[0..24]);
}
fn from_bytes(buf: &[u8]) -> Self {
Self {
vec_: Rc::new(RefCell::new(<Vec<f32>>::from_bytes(&buf[0..24]))),
}
}
}
pub fn main() {
std::process::exit(main_0());
}
Expand Down
16 changes: 15 additions & 1 deletion tests/unit/out/refcount/foreach_disjoint_field_borrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,21 @@ impl Clone for S {
this
}
}
impl ByteRepr for S {}
impl ByteRepr for S {
fn byte_size() -> usize {
32
}
fn to_bytes(&self, buf: &mut [u8]) {
(*self.v.borrow()).to_bytes(&mut buf[0..24]);
(*self.a.borrow()).to_bytes(&mut buf[24..28]);
}
fn from_bytes(buf: &[u8]) -> Self {
Self {
v: Rc::new(RefCell::new(<Vec<i32>>::from_bytes(&buf[0..24]))),
a: Rc::new(RefCell::new(<i32>::from_bytes(&buf[24..28]))),
}
}
}
pub fn main() {
std::process::exit(main_0());
}
Expand Down
26 changes: 25 additions & 1 deletion tests/unit/out/refcount/huffman.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,31 @@ impl MinHeap {
}
}
}
impl ByteRepr for MinHeap {}
impl ByteRepr for MinHeap {
fn byte_size() -> usize {
32
}
fn to_bytes(&self, buf: &mut [u8]) {
(*self.size.borrow()).to_bytes(&mut buf[0..4]);
(*self.capacity.borrow()).to_bytes(&mut buf[4..8]);
(*self.arr.borrow()).to_bytes(&mut buf[8..16]);
(*self.next.borrow()).to_bytes(&mut buf[16..20]);
(*self.alloc.borrow()).to_bytes(&mut buf[24..32]);
}
fn from_bytes(buf: &[u8]) -> Self {
Self {
size: Rc::new(RefCell::new(<i32>::from_bytes(&buf[0..4]))),
capacity: Rc::new(RefCell::new(<i32>::from_bytes(&buf[4..8]))),
arr: Rc::new(RefCell::new(
<Option<Value<Box<[Ptr<MinHeapNode>]>>>>::from_bytes(&buf[8..16]),
)),
next: Rc::new(RefCell::new(<i32>::from_bytes(&buf[16..20]))),
alloc: Rc::new(RefCell::new(
<Option<Value<Box<[MinHeapNode]>>>>::from_bytes(&buf[24..32]),
)),
}
}
}
pub fn AllocMinHeap_1(capacity: i32) -> Option<Value<MinHeap>> {
let capacity: Value<i32> = Rc::new(RefCell::new(capacity));
let minHeap: Value<Option<Value<MinHeap>>> =
Expand Down
14 changes: 13 additions & 1 deletion tests/unit/out/refcount/implicit_autoref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,19 @@ impl Clone for Holder {
this
}
}
impl ByteRepr for Holder {}
impl ByteRepr for Holder {
fn byte_size() -> usize {
24
}
fn to_bytes(&self, buf: &mut [u8]) {
(*self.v.borrow()).to_bytes(&mut buf[0..24]);
}
fn from_bytes(buf: &[u8]) -> Self {
Self {
v: Rc::new(RefCell::new(<Vec<i32>>::from_bytes(&buf[0..24]))),
}
}
}
pub fn write_through_0(p: Ptr<i32>) {
let p: Value<Ptr<i32>> = Rc::new(RefCell::new(p));
(*p.borrow()).write(42);
Expand Down
42 changes: 40 additions & 2 deletions tests/unit/out/refcount/kruskal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,14 +280,52 @@ impl DisjointSet {
}
}
}
impl ByteRepr for DisjointSet {}
impl ByteRepr for DisjointSet {
fn byte_size() -> usize {
24
}
fn to_bytes(&self, buf: &mut [u8]) {
(*self.rank.borrow()).to_bytes(&mut buf[0..8]);
(*self.parent.borrow()).to_bytes(&mut buf[8..16]);
(*self.n.borrow()).to_bytes(&mut buf[16..20]);
}
fn from_bytes(buf: &[u8]) -> Self {
Self {
rank: Rc::new(RefCell::new(<Option<Value<Box<[i32]>>>>::from_bytes(
&buf[0..8],
))),
parent: Rc::new(RefCell::new(<Option<Value<Box<[i32]>>>>::from_bytes(
&buf[8..16],
))),
n: Rc::new(RefCell::new(<i32>::from_bytes(&buf[16..20]))),
}
}
}
#[derive(Default)]
pub struct Graph {
pub edges: Value<Option<Value<Box<[Edge]>>>>,
pub V: Value<i32>,
pub E: Value<i32>,
}
impl ByteRepr for Graph {}
impl ByteRepr for Graph {
fn byte_size() -> usize {
16
}
fn to_bytes(&self, buf: &mut [u8]) {
(*self.edges.borrow()).to_bytes(&mut buf[0..8]);
(*self.V.borrow()).to_bytes(&mut buf[8..12]);
(*self.E.borrow()).to_bytes(&mut buf[12..16]);
}
fn from_bytes(buf: &[u8]) -> Self {
Self {
edges: Rc::new(RefCell::new(<Option<Value<Box<[Edge]>>>>::from_bytes(
&buf[0..8],
))),
V: Rc::new(RefCell::new(<i32>::from_bytes(&buf[8..12]))),
E: Rc::new(RefCell::new(<i32>::from_bytes(&buf[12..16]))),
}
}
}
pub fn MSTKruskal_2(graph: Ptr<Graph>) -> f64 {
({
let _arr: Ptr<Option<Value<Box<[Edge]>>>> = (*graph.upgrade().deref()).edges.as_pointer();
Expand Down
30 changes: 28 additions & 2 deletions tests/unit/out/refcount/libc_struct_without_default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,21 @@ impl Default for UserDefined {
}
}
}
impl ByteRepr for UserDefined {}
impl ByteRepr for UserDefined {
fn byte_size() -> usize {
32
}
fn to_bytes(&self, buf: &mut [u8]) {
(*self.a.borrow()).to_bytes(&mut buf[0..4]);
(*self.v.borrow()).to_bytes(&mut buf[8..32]);
}
fn from_bytes(buf: &[u8]) -> Self {
Self {
a: Rc::new(RefCell::new(<Vec<i32>>::from_bytes(&buf[0..4]))),
v: Rc::new(RefCell::new(<Vec<i32>>::from_bytes(&buf[8..32]))),
}
}
}
#[derive()]
pub struct FieldIsLibcType {
pub addr: Value<libcc2rs::Sockaddr>,
Expand All @@ -50,7 +64,19 @@ impl Default for FieldIsLibcType {
}
}
}
impl ByteRepr for FieldIsLibcType {}
impl ByteRepr for FieldIsLibcType {
fn byte_size() -> usize {
16
}
fn to_bytes(&self, buf: &mut [u8]) {
(*self.addr.borrow()).to_bytes(&mut buf[0..16]);
}
fn from_bytes(buf: &[u8]) -> Self {
Self {
addr: Rc::new(RefCell::new(<libcc2rs::Sockaddr>::from_bytes(&buf[0..16]))),
}
}
}
pub fn main() {
std::process::exit(main_0());
}
Expand Down
18 changes: 17 additions & 1 deletion tests/unit/out/refcount/push_emplace_back.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,23 @@ impl Clone for JPEGData {
this
}
}
impl ByteRepr for JPEGData {}
impl ByteRepr for JPEGData {
fn byte_size() -> usize {
48
}
fn to_bytes(&self, buf: &mut [u8]) {
(*self.com_data.borrow()).to_bytes(&mut buf[0..24]);
(*self.app_data.borrow()).to_bytes(&mut buf[24..48]);
}
fn from_bytes(buf: &[u8]) -> Self {
Self {
com_data: Rc::new(RefCell::new(<Vec<Value<Vec<u8>>>>::from_bytes(&buf[0..24]))),
app_data: Rc::new(RefCell::new(<Vec<Value<Vec<u8>>>>::from_bytes(
&buf[24..48],
))),
}
}
}
pub fn push_param_0(dest: Ptr<Vec<Value<Vec<u8>>>>) {
let dest: Value<Ptr<Vec<Value<Vec<u8>>>>> = Rc::new(RefCell::new(dest));
((*dest.borrow()).to_strong().as_pointer() as Ptr<Vec<Value<Vec<u8>>>>).with_mut(
Expand Down
18 changes: 17 additions & 1 deletion tests/unit/out/refcount/struct_default_ctor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,23 @@ impl Default for WOFF2Params {
{ WOFF2Params::WOFF2Params() }
}
}
impl ByteRepr for WOFF2Params {}
impl ByteRepr for WOFF2Params {
fn byte_size() -> usize {
40
}
fn to_bytes(&self, buf: &mut [u8]) {
(*self.extended_metadata.borrow()).to_bytes(&mut buf[0..32]);
(*self.brotli_quality.borrow()).to_bytes(&mut buf[32..36]);
(*self.allow_transforms.borrow()).to_bytes(&mut buf[36..37]);
}
fn from_bytes(buf: &[u8]) -> Self {
Self {
extended_metadata: Rc::new(RefCell::new(<Vec<u8>>::from_bytes(&buf[0..32]))),
brotli_quality: Rc::new(RefCell::new(<i32>::from_bytes(&buf[32..36]))),
allow_transforms: Rc::new(RefCell::new(<bool>::from_bytes(&buf[36..37]))),
}
}
}
pub fn main() {
std::process::exit(main_0());
}
Expand Down
14 changes: 13 additions & 1 deletion tests/unit/out/refcount/typedef-anon-struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,19 @@ impl Clone for Outer {
this
}
}
impl ByteRepr for Outer {}
impl ByteRepr for Outer {
fn byte_size() -> usize {
24
}
fn to_bytes(&self, buf: &mut [u8]) {
(*self.runs.borrow()).to_bytes(&mut buf[0..24]);
}
fn from_bytes(buf: &[u8]) -> Self {
Self {
runs: Rc::new(RefCell::new(<Vec<Outer_RunInfo>>::from_bytes(&buf[0..24]))),
}
}
}
pub fn main() {
std::process::exit(main_0());
}
Expand Down
14 changes: 13 additions & 1 deletion tests/unit/out/refcount/unique_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,19 @@ impl SafePointer {
(*(*self.ptr.borrow_mut()).as_ref().unwrap().borrow_mut()).prefix_inc();
}
}
impl ByteRepr for SafePointer {}
impl ByteRepr for SafePointer {
fn byte_size() -> usize {
8
}
fn to_bytes(&self, buf: &mut [u8]) {
(*self.ptr.borrow()).to_bytes(&mut buf[0..8]);
}
fn from_bytes(buf: &[u8]) -> Self {
Self {
ptr: Rc::new(RefCell::new(<Option<Value<i32>>>::from_bytes(&buf[0..8]))),
}
}
}
#[derive(Default)]
pub struct Pair {
pub x: Value<i32>,
Expand Down
14 changes: 13 additions & 1 deletion tests/unit/out/refcount/unique_ptr_const_deref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,19 @@ use std::rc::{Rc, Weak};
pub struct Holder {
pub val: Value<Option<Value<i32>>>,
}
impl ByteRepr for Holder {}
impl ByteRepr for Holder {
fn byte_size() -> usize {
8
}
fn to_bytes(&self, buf: &mut [u8]) {
(*self.val.borrow()).to_bytes(&mut buf[0..8]);
}
fn from_bytes(buf: &[u8]) -> Self {
Self {
val: Rc::new(RefCell::new(<Option<Value<i32>>>::from_bytes(&buf[0..8]))),
}
}
}
pub fn read_val_0(h: Ptr<Holder>) -> i32 {
let h: Value<Ptr<Holder>> = Rc::new(RefCell::new(h));
return (*(*(*(*h.borrow()).upgrade().deref()).val.borrow())
Expand Down
Loading
Loading