Skip to content

Commit 32d9d9c

Browse files
committed
Add arrayEndA == objectStartB test
1 parent 3288f90 commit 32d9d9c

3 files changed

Lines changed: 98 additions & 0 deletions

File tree

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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 pair {
11+
pub a: Value<Box<[i32]>>,
12+
pub b: Value<Box<[i32]>>,
13+
}
14+
impl Default for pair {
15+
fn default() -> Self {
16+
pair {
17+
a: Rc::new(RefCell::new(
18+
(0..4).map(|_| <i32>::default()).collect::<Box<[i32]>>(),
19+
)),
20+
b: Rc::new(RefCell::new(
21+
(0..4).map(|_| <i32>::default()).collect::<Box<[i32]>>(),
22+
)),
23+
}
24+
}
25+
}
26+
impl ByteRepr for pair {
27+
fn byte_size() -> usize {
28+
32
29+
}
30+
fn to_bytes(&self, buf: &mut [u8]) {
31+
(*self.a.borrow()).to_bytes(&mut buf[0..16]);
32+
(*self.b.borrow()).to_bytes(&mut buf[16..32]);
33+
}
34+
fn from_bytes(buf: &[u8]) -> Self {
35+
Self {
36+
a: Rc::new(RefCell::new(<Box<[i32]>>::from_bytes(&buf[0..16]))),
37+
b: Rc::new(RefCell::new(<Box<[i32]>>::from_bytes(&buf[16..32]))),
38+
}
39+
}
40+
}
41+
pub fn main() {
42+
std::process::exit(main_0());
43+
}
44+
fn main_0() -> i32 {
45+
let s: Value<pair> = <Value<pair>>::default();
46+
assert!(
47+
(((((*s.borrow()).a.as_pointer() as Ptr::<i32>).offset((4) as isize)
48+
== ((*s.borrow()).b.as_pointer() as Ptr::<i32>)) as i32)
49+
!= 0)
50+
);
51+
return 0;
52+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
extern crate libc;
2+
use libc::*;
3+
extern crate libcc2rs;
4+
use libcc2rs::*;
5+
use std::collections::BTreeMap;
6+
use std::io::{Read, Seek, Write};
7+
use std::os::fd::{AsFd, FromRawFd, IntoRawFd};
8+
use std::rc::Rc;
9+
#[repr(C)]
10+
#[derive(Copy, Clone)]
11+
pub struct pair {
12+
pub a: [i32; 4],
13+
pub b: [i32; 4],
14+
}
15+
impl Default for pair {
16+
fn default() -> Self {
17+
pair {
18+
a: [0_i32; 4],
19+
b: [0_i32; 4],
20+
}
21+
}
22+
}
23+
pub fn main() {
24+
unsafe {
25+
std::process::exit(main_0() as i32);
26+
}
27+
}
28+
unsafe fn main_0() -> i32 {
29+
let mut s: pair = <pair>::default();
30+
assert!(((((s.a.as_mut_ptr().offset((4) as isize)) == (s.b.as_mut_ptr())) as i32) != 0));
31+
return 0;
32+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// panic: refcount
2+
#include <assert.h>
3+
4+
struct pair {
5+
int a[4];
6+
int b[4];
7+
};
8+
9+
int main(void) {
10+
struct pair s;
11+
12+
assert(s.a + 4 == s.b);
13+
return 0;
14+
}

0 commit comments

Comments
 (0)