Skip to content

Commit e37e151

Browse files
committed
Update output of fn_ptr_stdlib_compare
1 parent 0bd0990 commit e37e151

3 files changed

Lines changed: 86 additions & 18 deletions

File tree

tests/unit/fn_ptr_stdlib_compare.cpp

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,16 @@
33
#include <stdlib.h>
44

55
typedef size_t (*read_fn)(void *, size_t, size_t, FILE *);
6-
typedef void (*free_fn)(void *);
7-
typedef void *(*malloc_fn)(size_t);
6+
7+
typedef size_t (*read_alternative_fn)(char *, size_t, size_t, void *);
88

99
int main() {
1010
read_fn rfn = fread;
1111
assert(rfn == fread);
1212
assert(rfn != nullptr);
1313

14-
free_fn ffn = free;
15-
assert(ffn == free);
16-
assert(ffn != nullptr);
17-
18-
malloc_fn mfn = malloc;
19-
assert(mfn == malloc);
20-
assert(mfn != nullptr);
21-
22-
// Reassign and compare
23-
read_fn rfn2 = fread;
24-
assert(rfn == rfn2);
25-
26-
free_fn ffn2 = nullptr;
27-
assert(ffn != ffn2);
28-
ffn2 = free;
29-
assert(ffn == ffn2);
14+
read_alternative_fn rfn2 = (read_alternative_fn)fread;
15+
assert(rfn == (read_fn)rfn2);
3016

3117
return 0;
3218
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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::Seek;
7+
use std::io::{Read, Write};
8+
use std::os::fd::AsFd;
9+
use std::rc::{Rc, Weak};
10+
pub fn main() {
11+
std::process::exit(main_0());
12+
}
13+
fn main_0() -> i32 {
14+
let rfn: Value<FnPtr<fn(AnyPtr, u64, u64, Ptr<::std::fs::File>) -> u64>> =
15+
Rc::new(RefCell::new(fn_ptr!(
16+
rules::stdio_tgt_refcount::f5,
17+
fn(AnyPtr, u64, u64, Ptr<::std::fs::File>) -> u64
18+
)));
19+
assert!({
20+
let _lhs = (*rfn.borrow()).clone();
21+
_lhs == fn_ptr!(
22+
rules::stdio_tgt_refcount::f5,
23+
fn(AnyPtr, u64, u64, Ptr<::std::fs::File>) -> u64
24+
)
25+
});
26+
assert!(!((*rfn.borrow()).is_null()));
27+
let rfn2: Value<FnPtr<fn(Ptr<u8>, u64, u64, AnyPtr) -> u64>> = Rc::new(RefCell::new(
28+
fn_ptr!(
29+
rules::stdio_tgt_refcount::f5,
30+
fn(AnyPtr, u64, u64, Ptr<::std::fs::File>) -> u64
31+
)
32+
.cast::<fn(Ptr<u8>, u64, u64, AnyPtr) -> u64>(Some(
33+
(|a0: Ptr<u8>, a1: u64, a2: u64, a3: AnyPtr| -> u64 {
34+
rules::stdio_tgt_refcount::f5(
35+
a0.to_any(),
36+
a1,
37+
a2,
38+
a3.cast::<::std::fs::File>().unwrap(),
39+
)
40+
}) as fn(Ptr<u8>, u64, u64, AnyPtr) -> u64,
41+
)),
42+
));
43+
assert!({
44+
let _lhs = (*rfn.borrow()).clone();
45+
_lhs == ((*rfn2.borrow()).cast::<fn(AnyPtr, u64, u64, Ptr<::std::fs::File>) -> u64>(None))
46+
.clone()
47+
});
48+
return 0;
49+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
extern crate libc;
2+
use libc::*;
3+
extern crate libcc2rs;
4+
use libcc2rs::*;
5+
use std::collections::BTreeMap;
6+
use std::io::Seek;
7+
use std::io::{Read, Write};
8+
use std::os::fd::{AsFd, FromRawFd, IntoRawFd};
9+
use std::rc::Rc;
10+
pub fn main() {
11+
unsafe {
12+
std::process::exit(main_0() as i32);
13+
}
14+
}
15+
unsafe fn main_0() -> i32 {
16+
let mut rfn: Option<unsafe fn(*mut ::libc::c_void, u64, u64, *mut ::std::fs::File) -> u64> =
17+
Some(rules::stdio_tgt_unsafe::f5 as _);
18+
assert!(((rfn) == (Some(rules::stdio_tgt_unsafe::f5 as _))));
19+
assert!(!((rfn).is_none()));
20+
let mut rfn2: Option<unsafe fn(*mut u8, u64, u64, *mut ::libc::c_void) -> u64> =
21+
std::mem::transmute::<
22+
Option<unsafe fn(*mut ::libc::c_void, u64, u64, *mut ::std::fs::File) -> u64>,
23+
Option<unsafe fn(*mut u8, u64, u64, *mut ::libc::c_void) -> u64>,
24+
>(Some(rules::stdio_tgt_unsafe::f5 as _));
25+
assert!(
26+
((rfn)
27+
== (std::mem::transmute::<
28+
Option<unsafe fn(*mut u8, u64, u64, *mut ::libc::c_void) -> u64>,
29+
Option<unsafe fn(*mut ::libc::c_void, u64, u64, *mut ::std::fs::File) -> u64>,
30+
>(rfn2)))
31+
);
32+
return 0;
33+
}

0 commit comments

Comments
 (0)