Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiler error with C foreign function #7529

Closed
jeremyletang opened this issue Jul 1, 2013 · 3 comments
Closed

Compiler error with C foreign function #7529

jeremyletang opened this issue Jul 1, 2013 · 3 comments
Labels
A-codegen Area: Code generation A-type-system Area: Type system

Comments

@jeremyletang
Copy link
Contributor

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}
    }
@brson
Copy link
Contributor

brson commented Jul 10, 2013

Presumably related to the generic callback.

@klutzy
Copy link
Contributor

klutzy commented Mar 21, 2014

Fixed by #10353. (See #12502 for supporting generic foreign functions.)

@alexcrichton
Copy link
Member

Thanks @klutzy, closed by 8f3f666

flip1995 pushed a commit to flip1995/rust that referenced this issue Aug 12, 2021
…995,llogiq

Use node v12.x in CI

In rust-lang/rust-clippy#7528 (comment), remark-cli version has been updated recently and it requires to use ESM module: https://github.com/remarkjs/remark/releases/tag/14.0.0. Node version in CI was v10.24.1, it seems to be old.

changelog: none
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-codegen Area: Code generation A-type-system Area: Type system
Projects
None yet
Development

No branches or pull requests

4 participants