2017-06-21 08:51:42 -05:00
|
|
|
use std::mem;
|
|
|
|
|
2017-06-22 05:30:02 -05:00
|
|
|
struct Arena(());
|
2017-06-21 08:51:42 -05:00
|
|
|
|
|
|
|
struct Bcx<'a> {
|
2022-06-20 18:00:37 -05:00
|
|
|
fcx: &'a Fcx<'a>,
|
2017-06-21 08:51:42 -05:00
|
|
|
}
|
|
|
|
|
2020-04-16 02:25:12 -05:00
|
|
|
#[allow(dead_code)]
|
2017-06-21 08:51:42 -05:00
|
|
|
struct Fcx<'a> {
|
2017-06-22 05:30:02 -05:00
|
|
|
arena: &'a Arena,
|
2022-06-20 18:00:37 -05:00
|
|
|
ccx: &'a Ccx,
|
2017-06-21 08:51:42 -05:00
|
|
|
}
|
|
|
|
|
2020-04-16 02:25:12 -05:00
|
|
|
#[allow(dead_code)]
|
2017-06-21 08:51:42 -05:00
|
|
|
struct Ccx {
|
2022-06-20 18:00:37 -05:00
|
|
|
x: isize,
|
2017-06-21 08:51:42 -05:00
|
|
|
}
|
|
|
|
|
2022-06-20 18:00:37 -05:00
|
|
|
fn alloc<'a>(_bcx: &'a Arena) -> &'a mut Bcx<'a> {
|
|
|
|
unsafe { mem::transmute(libc::malloc(mem::size_of::<Bcx<'a>>() as libc::size_t)) }
|
2017-06-21 08:51:42 -05:00
|
|
|
}
|
|
|
|
|
2022-06-20 18:00:37 -05:00
|
|
|
fn h<'a>(bcx: &'a Bcx<'a>) -> &'a mut Bcx<'a> {
|
2017-06-21 08:51:42 -05:00
|
|
|
return alloc(bcx.fcx.arena);
|
|
|
|
}
|
|
|
|
|
2022-06-20 18:00:37 -05:00
|
|
|
fn g(fcx: &Fcx) {
|
2017-06-21 08:51:42 -05:00
|
|
|
let bcx = Bcx { fcx: fcx };
|
|
|
|
let bcx2 = h(&bcx);
|
|
|
|
unsafe {
|
|
|
|
libc::free(mem::transmute(bcx2));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-20 18:00:37 -05:00
|
|
|
fn f(ccx: &Ccx) {
|
2017-06-22 05:30:02 -05:00
|
|
|
let a = Arena(());
|
2017-06-21 08:51:42 -05:00
|
|
|
let fcx = Fcx { arena: &a, ccx: ccx };
|
|
|
|
return g(&fcx);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn main() {
|
|
|
|
let ccx = Ccx { x: 0 };
|
|
|
|
f(&ccx);
|
|
|
|
}
|