-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
Description
Hi,
I have a compiler error when i'm trying to call a C foreign function.
This is the error :
error: internal compiler error: type_of with ty_param
leaked memory in rust main loop (1 objects)
rustc: /home/jeremy/Templates/rust-master/rust/src/rt/memory_region.cpp:192: memory_region::~memory_region(): Assertion `false' failed.
And this is the code who produce the error :
mod ffi {
pub extern "C" {
object_create(function : *u8, data : *c_void) -> *c_Object;
}
}
pub trait TestTrait {
pub fn execute(&self);
}
struct Test;
impl Test {
pub fn new() -> Test {
Test
}
}
impl TestTrait for Test {
pub fn execute(&self) -> () {
io::println("Hello world");
}
}
extern fn callback_function<T : TestTrait>(data : &T) -> () {
data.execute();
}
pub struct ObjectWrapped {
priv obj : *ffi::c_Object
}
impl ObjectWrapped {
pub fn new<T : TestTrait>(params : &T) -> ObjectWrapped {
let o = unsafe {ffi::object_create(callback_function, cast::transmute::<*T, *c_void>(params))};
ObjectWrapped {obj : o}
}