2012-03-23 17:28:47 -05:00
|
|
|
import libc, sys, unsafe;
|
|
|
|
|
|
|
|
enum arena = ();
|
|
|
|
|
2012-07-11 12:28:30 -05:00
|
|
|
type bcx = {
|
2012-03-23 17:28:47 -05:00
|
|
|
fcx: &fcx
|
|
|
|
};
|
|
|
|
|
2012-07-11 12:28:30 -05:00
|
|
|
type fcx = {
|
2012-03-23 17:28:47 -05:00
|
|
|
arena: &arena,
|
|
|
|
ccx: &ccx
|
|
|
|
};
|
|
|
|
|
|
|
|
type ccx = {
|
|
|
|
x: int
|
|
|
|
};
|
|
|
|
|
|
|
|
impl arena for arena {
|
2012-07-09 19:23:13 -05:00
|
|
|
fn alloc_inner(sz: uint, _align: uint) -> *() unsafe {
|
2012-08-01 19:30:05 -05:00
|
|
|
return unsafe::reinterpret_cast(libc::malloc(sz as libc::size_t));
|
2012-03-23 17:28:47 -05:00
|
|
|
}
|
2012-07-09 19:23:13 -05:00
|
|
|
fn alloc(tydesc: *()) -> *() {
|
|
|
|
unsafe {
|
|
|
|
let tydesc = tydesc as *sys::type_desc;
|
|
|
|
self.alloc_inner((*tydesc).size, (*tydesc).align)
|
|
|
|
}
|
|
|
|
}
|
2012-03-23 17:28:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn h(bcx : &bcx) -> &bcx {
|
2012-08-01 19:30:05 -05:00
|
|
|
return new(*bcx.fcx.arena) { fcx: bcx.fcx };
|
2012-03-23 17:28:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn g(fcx : &fcx) {
|
|
|
|
let bcx = { fcx: fcx };
|
|
|
|
let bcx2 = h(&bcx);
|
|
|
|
unsafe {
|
|
|
|
libc::free(unsafe::reinterpret_cast(bcx2));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn f(ccx : &ccx) {
|
|
|
|
let a = arena(());
|
|
|
|
let fcx = { arena: &a, ccx: ccx };
|
2012-08-01 19:30:05 -05:00
|
|
|
return g(&fcx);
|
2012-03-23 17:28:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let ccx = { x: 0 };
|
|
|
|
f(&ccx);
|
|
|
|
}
|
|
|
|
|