Skip to content

Compiler error with C foreign function #7529

@jeremyletang

Description

@jeremyletang

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}
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions