Skip to content

Commit e5731d9

Browse files
committed
Update tests
1 parent 0aa2387 commit e5731d9

3 files changed

Lines changed: 96 additions & 0 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include <cassert>
2+
3+
static int total = 0;
4+
5+
struct S {
6+
S(int x) { total += x; }
7+
};
8+
9+
static S a(1);
10+
static S b(10);
11+
12+
int main() {
13+
assert(total == 11);
14+
return 0;
15+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
thread_local!(
10+
pub static total_0: Value<i32> = Rc::new(RefCell::new(0));
11+
);
12+
#[derive(Default)]
13+
pub struct S {}
14+
impl S {
15+
pub fn S(x: i32) -> Self {
16+
let x: Value<i32> = Rc::new(RefCell::new(x));
17+
let __this: Value<S> = Rc::new(RefCell::new(Self {}));
18+
let this: Ptr<S> = __this.as_pointer();
19+
(*total_0.with(Value::clone).borrow_mut()) += (*x.borrow());
20+
Rc::try_unwrap(__this).ok().unwrap().into_inner()
21+
}
22+
}
23+
impl Clone for S {
24+
fn clone(&self) -> Self {
25+
let __this: Value<S> = Rc::new(RefCell::new(Self {}));
26+
let this: Ptr<S> = __this.as_pointer();
27+
Rc::try_unwrap(__this).ok().unwrap().into_inner()
28+
}
29+
}
30+
impl ByteRepr for S {
31+
fn byte_size() -> usize {
32+
1
33+
}
34+
fn to_bytes(&self, buf: &mut [u8]) {}
35+
fn from_bytes(buf: &[u8]) -> Self {
36+
Self {}
37+
}
38+
}
39+
thread_local!(
40+
pub static a_1: Value<S> = Rc::new(RefCell::new(S::S({ 1 })));
41+
);
42+
thread_local!(
43+
pub static b_2: Value<S> = Rc::new(RefCell::new(S::S({ 10 })));
44+
);
45+
pub fn main() {
46+
std::process::exit(main_0());
47+
}
48+
fn main_0() -> i32 {
49+
assert!(((*total_0.with(Value::clone).borrow()) == 11));
50+
return 0;
51+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
pub static mut total_0: std::cell::LazyCell<i32> = std::cell::LazyCell::new(|| unsafe { 0 });
10+
#[repr(C)]
11+
#[derive(Copy, Clone, Default)]
12+
pub struct S {}
13+
impl S {
14+
pub unsafe fn S(mut x: i32) -> Self {
15+
let mut this = Self {};
16+
(*std::cell::LazyCell::force_mut(&mut *&raw mut total_0)) += x;
17+
this
18+
}
19+
}
20+
pub static mut a_1: std::cell::LazyCell<S> = std::cell::LazyCell::new(|| unsafe { S::S({ 1 }) });
21+
pub static mut b_2: std::cell::LazyCell<S> = std::cell::LazyCell::new(|| unsafe { S::S({ 10 }) });
22+
pub fn main() {
23+
unsafe {
24+
std::process::exit(main_0() as i32);
25+
}
26+
}
27+
unsafe fn main_0() -> i32 {
28+
assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut total_0)) == (11)));
29+
return 0;
30+
}

0 commit comments

Comments
 (0)