Skip to content

Support implict casts from void* when compiling C code. #249

Description

@jrmuizel

e.g.

struct Foo {
        int y;
        int x;
};

void f() {
        struct Foo* f = malloc(sizeof(struct Foo));
}

compiles to:

pub fn f_0() {
    let f: Value<Ptr<Foo>> = Rc::new(RefCell::new(libcc2rs::malloc_refcount(8usize)));
}

which gives:

error[E0308]: mismatched types
   --> src/main.rs:38:51
    |
 38 |     let f: Value<Ptr<Foo>> = Rc::new(RefCell::new(libcc2rs::malloc_refcount(8usize)));
    |                                      ------------ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Ptr<Foo>`, found `AnyPtr`
    |                                      |
    |                                      arguments to this function are incorrect
    |
    = note: expected struct `libcc2rs::Ptr<Foo>`
               found struct `AnyPtr`

It should instead compile to:

pub fn f_0() {
    let f: Value<Ptr<Foo>> = Rc::new(RefCell::new(
        libcc2rs::malloc_refcount(8usize).reinterpret_cast::<Foo>(),
    ));
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions