|
| 1 | +extern crate libcc2rs; |
| 2 | +use libcc2rs::*; |
| 3 | +use std::cell::RefCell; |
| 4 | +use std::collections::BTreeMap; |
| 5 | +use std::io::prelude::*; |
| 6 | +use std::io::{Read, Seek, Write}; |
| 7 | +use std::os::fd::AsFd; |
| 8 | +use std::rc::{Rc, Weak}; |
| 9 | +#[derive(DeepClone, Record, ByteRepr, VaArg, FnPtrArg)] |
| 10 | +#[byte_size(4)] |
| 11 | +pub struct F { |
| 12 | + #[offset(0)] |
| 13 | + pub n: i32, |
| 14 | + #[offset(4)] |
| 15 | + #[byte_size(0)] |
| 16 | + pub tail: Value<Box<[i8]>>, |
| 17 | +} |
| 18 | +impl Default for F { |
| 19 | + fn default() -> Self { |
| 20 | + F { |
| 21 | + n: 0_i32, |
| 22 | + tail: Rc::new(RefCell::new(Box::<[i8]>::default())), |
| 23 | + } |
| 24 | + } |
| 25 | +} |
| 26 | +pub fn main() { |
| 27 | + __cpp2rust_init_globals(); |
| 28 | + std::process::exit(main_0()); |
| 29 | +} |
| 30 | +fn main_0() -> i32 { |
| 31 | + assert!((((4usize == ::std::mem::size_of::<i32>()) as i32) != 0)); |
| 32 | + let mut f: Ptr<F> = |
| 33 | + libcc2rs::malloc_refcount((4usize as usize).wrapping_add(4_usize)).reinterpret_cast::<F>(); |
| 34 | + assert!((((!((f).is_null())) as i32) != 0)); |
| 35 | + field!(f, n).write(4); |
| 36 | + { |
| 37 | + ((array_field_ptr!(f, tail) as Ptr<i8>) as Ptr<i8>) |
| 38 | + .to_any() |
| 39 | + .memcpy( |
| 40 | + &Ptr::<i8>::from_string_literal(b"xyz").to_any(), |
| 41 | + 4_usize as usize, |
| 42 | + ); |
| 43 | + ((array_field_ptr!(f, tail) as Ptr<i8>) as Ptr<i8>).to_any() |
| 44 | + }; |
| 45 | + assert!((((f.with(|__s| __s.n) == 4) as i32) != 0)); |
| 46 | + assert!( |
| 47 | + ((({ |
| 48 | + let mut __it1 = (array_field_ptr!(f, tail) as Ptr<i8>).to_c_string_iterator(); |
| 49 | + let mut __it2 = Ptr::<i8>::from_string_literal(b"xyz").to_c_string_iterator(); |
| 50 | + loop { |
| 51 | + let __c1 = __it1.next(); |
| 52 | + let __c2 = __it2.next(); |
| 53 | + if __c1 != __c2 { |
| 54 | + break (__c1.unwrap_or(0) as u8 as i32) - (__c2.unwrap_or(0) as u8 as i32); |
| 55 | + } |
| 56 | + if __c1.is_none() { |
| 57 | + break 0; |
| 58 | + } |
| 59 | + } |
| 60 | + } == 0) as i32) |
| 61 | + != 0) |
| 62 | + ); |
| 63 | + assert!( |
| 64 | + (((((elem!((array_field_ptr!(f, tail) as Ptr::<i8>), 1).read()) as i32) == ('y' as i32)) |
| 65 | + as i32) |
| 66 | + != 0) |
| 67 | + ); |
| 68 | + libcc2rs::free_refcount((f).to_any()); |
| 69 | + let mut g: Ptr<F> = |
| 70 | + libcc2rs::malloc_refcount((4usize as usize).wrapping_add(8_usize)).reinterpret_cast::<F>(); |
| 71 | + assert!((((!((g).is_null())) as i32) != 0)); |
| 72 | + field!(g, n).write(8); |
| 73 | + { |
| 74 | + ((array_field_ptr!(g, tail) as Ptr<i8>) as Ptr<i8>) |
| 75 | + .to_any() |
| 76 | + .memcpy( |
| 77 | + &Ptr::<i8>::from_string_literal(b"abcdefg").to_any(), |
| 78 | + 8_usize as usize, |
| 79 | + ); |
| 80 | + ((array_field_ptr!(g, tail) as Ptr<i8>) as Ptr<i8>).to_any() |
| 81 | + }; |
| 82 | + assert!( |
| 83 | + (((((elem!((array_field_ptr!(g, tail) as Ptr::<i8>), 6).read()) as i32) == ('g' as i32)) |
| 84 | + as i32) |
| 85 | + != 0) |
| 86 | + ); |
| 87 | + assert!( |
| 88 | + (((((elem!((array_field_ptr!(g, tail) as Ptr::<i8>), 7).read()) as i32) == ('\0' as i32)) |
| 89 | + as i32) |
| 90 | + != 0) |
| 91 | + ); |
| 92 | + libcc2rs::free_refcount((g).to_any()); |
| 93 | + return 0; |
| 94 | +} |
| 95 | +pub fn __cpp2rust_init_globals() {} |
0 commit comments