|
| 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()] |
| 10 | +pub struct shape_a { |
| 11 | + pub code: Value<u16>, |
| 12 | + pub pad: Value<Box<[u8]>>, |
| 13 | +} |
| 14 | +impl Default for shape_a { |
| 15 | + fn default() -> Self { |
| 16 | + shape_a { |
| 17 | + code: <Value<u16>>::default(), |
| 18 | + pad: Rc::new(RefCell::new( |
| 19 | + (0..14).map(|_| <u8>::default()).collect::<Box<[u8]>>(), |
| 20 | + )), |
| 21 | + } |
| 22 | + } |
| 23 | +} |
| 24 | +impl ByteRepr for shape_a { |
| 25 | + fn byte_size() -> usize { |
| 26 | + 16 |
| 27 | + } |
| 28 | + fn to_bytes(&self, buf: &mut [u8]) { |
| 29 | + (*self.code.borrow()).to_bytes(&mut buf[0..2]); |
| 30 | + (*self.pad.borrow()).to_bytes(&mut buf[2..16]); |
| 31 | + } |
| 32 | + fn from_bytes(buf: &[u8]) -> Self { |
| 33 | + Self { |
| 34 | + code: Rc::new(RefCell::new(<u16>::from_bytes(&buf[0..2]))), |
| 35 | + pad: Rc::new(RefCell::new(<Box<[u8]>>::from_bytes(&buf[2..16]))), |
| 36 | + } |
| 37 | + } |
| 38 | +} |
| 39 | +#[derive()] |
| 40 | +pub struct shape_b { |
| 41 | + pub code: Value<u16>, |
| 42 | + pub lo: Value<u16>, |
| 43 | + pub mid: Value<u32>, |
| 44 | + pub fill: Value<Box<[u8]>>, |
| 45 | + pub tail: Value<u32>, |
| 46 | +} |
| 47 | +impl Default for shape_b { |
| 48 | + fn default() -> Self { |
| 49 | + shape_b { |
| 50 | + code: <Value<u16>>::default(), |
| 51 | + lo: <Value<u16>>::default(), |
| 52 | + mid: <Value<u32>>::default(), |
| 53 | + fill: Rc::new(RefCell::new( |
| 54 | + (0..16).map(|_| <u8>::default()).collect::<Box<[u8]>>(), |
| 55 | + )), |
| 56 | + tail: <Value<u32>>::default(), |
| 57 | + } |
| 58 | + } |
| 59 | +} |
| 60 | +impl ByteRepr for shape_b { |
| 61 | + fn byte_size() -> usize { |
| 62 | + 28 |
| 63 | + } |
| 64 | + fn to_bytes(&self, buf: &mut [u8]) { |
| 65 | + (*self.code.borrow()).to_bytes(&mut buf[0..2]); |
| 66 | + (*self.lo.borrow()).to_bytes(&mut buf[2..4]); |
| 67 | + (*self.mid.borrow()).to_bytes(&mut buf[4..8]); |
| 68 | + (*self.fill.borrow()).to_bytes(&mut buf[8..24]); |
| 69 | + (*self.tail.borrow()).to_bytes(&mut buf[24..28]); |
| 70 | + } |
| 71 | + fn from_bytes(buf: &[u8]) -> Self { |
| 72 | + Self { |
| 73 | + code: Rc::new(RefCell::new(<u16>::from_bytes(&buf[0..2]))), |
| 74 | + lo: Rc::new(RefCell::new(<u16>::from_bytes(&buf[2..4]))), |
| 75 | + mid: Rc::new(RefCell::new(<u32>::from_bytes(&buf[4..8]))), |
| 76 | + fill: Rc::new(RefCell::new(<Box<[u8]>>::from_bytes(&buf[8..24]))), |
| 77 | + tail: Rc::new(RefCell::new(<u32>::from_bytes(&buf[24..28]))), |
| 78 | + } |
| 79 | + } |
| 80 | +} |
| 81 | +pub struct anon_0 { |
| 82 | + __bytes: Value<Box<[u8]>>, |
| 83 | +} |
| 84 | +impl anon_0 { |
| 85 | + pub fn a(&self) -> Ptr<shape_a> { |
| 86 | + (self.__bytes.as_pointer() as Ptr<u8>).reinterpret_cast() |
| 87 | + } |
| 88 | + pub fn b(&self) -> Ptr<shape_b> { |
| 89 | + (self.__bytes.as_pointer() as Ptr<u8>).reinterpret_cast() |
| 90 | + } |
| 91 | + pub fn raw_(&self) -> Ptr<Box<[u8]>> { |
| 92 | + (self.__bytes.as_pointer() as Ptr<u8>).reinterpret_cast() |
| 93 | + } |
| 94 | +} |
| 95 | +impl Clone for anon_0 { |
| 96 | + fn clone(&self) -> Self { |
| 97 | + anon_0 { |
| 98 | + __bytes: Rc::new(RefCell::new(self.__bytes.borrow().clone())), |
| 99 | + } |
| 100 | + } |
| 101 | +} |
| 102 | +impl Default for anon_0 { |
| 103 | + fn default() -> Self { |
| 104 | + anon_0 { |
| 105 | + __bytes: Rc::new(RefCell::new(Box::from([0u8; 64]))), |
| 106 | + } |
| 107 | + } |
| 108 | +} |
| 109 | +impl ByteRepr for anon_0 {} |
| 110 | +#[derive(Default)] |
| 111 | +pub struct Container { |
| 112 | + pub len: Value<u32>, |
| 113 | + pub u: Value<anon_0>, |
| 114 | +} |
| 115 | +impl ByteRepr for Container {} |
| 116 | +pub fn main() { |
| 117 | + std::process::exit(main_0()); |
| 118 | +} |
| 119 | +fn main_0() -> i32 { |
| 120 | + let c: Value<Container> = <Value<Container>>::default(); |
| 121 | + { |
| 122 | + ((c.as_pointer()) as Ptr<Container>) |
| 123 | + .to_any() |
| 124 | + .memset((0) as u8, 68usize as usize); |
| 125 | + ((c.as_pointer()) as Ptr<Container>).to_any().clone() |
| 126 | + }; |
| 127 | + (*(*(*(*c.borrow()).u.borrow()).a().upgrade().deref()) |
| 128 | + .code |
| 129 | + .borrow_mut()) = 10_u16; |
| 130 | + (*(*c.borrow()).len.borrow_mut()) = (28usize as u32); |
| 131 | + (*(*(((*(*c.borrow()).u.borrow()).a()) |
| 132 | + .clone() |
| 133 | + .to_any() |
| 134 | + .cast::<shape_b>() |
| 135 | + .expect("ub:wrong type")) |
| 136 | + .upgrade() |
| 137 | + .deref()) |
| 138 | + .tail |
| 139 | + .borrow_mut()) = 3735928559_u32; |
| 140 | + assert!( |
| 141 | + ((((*(*(*(*c.borrow()).u.borrow()).b().upgrade().deref()) |
| 142 | + .tail |
| 143 | + .borrow()) |
| 144 | + == 3735928559_u32) as i32) |
| 145 | + != 0) |
| 146 | + ); |
| 147 | + assert!( |
| 148 | + (((((*(*(*(*c.borrow()).u.borrow()).b().upgrade().deref()) |
| 149 | + .code |
| 150 | + .borrow()) as i32) |
| 151 | + == 10) as i32) |
| 152 | + != 0) |
| 153 | + ); |
| 154 | + (*(*(*(*c.borrow()).u.borrow()).b().upgrade().deref()) |
| 155 | + .lo |
| 156 | + .borrow_mut()) = 8080_u16; |
| 157 | + assert!( |
| 158 | + ((((((((*(*c.borrow()).u.borrow()).raw_().reinterpret_cast::<u8>()) |
| 159 | + .to_strong() |
| 160 | + .as_pointer() as Ptr::<u8>) |
| 161 | + .offset((2) as isize) |
| 162 | + .read()) as i32) |
| 163 | + == 144) as i32) |
| 164 | + != 0) |
| 165 | + ); |
| 166 | + assert!( |
| 167 | + ((((((((*(*c.borrow()).u.borrow()).raw_().reinterpret_cast::<u8>()) |
| 168 | + .to_strong() |
| 169 | + .as_pointer() as Ptr::<u8>) |
| 170 | + .offset((3) as isize) |
| 171 | + .read()) as i32) |
| 172 | + == 31) as i32) |
| 173 | + != 0) |
| 174 | + ); |
| 175 | + return 0; |
| 176 | +} |
0 commit comments