Skip to content

Wrong ABI for fixed-size array parameters #171

Open
@Luthaf

Description

@Luthaf

It looks like rust uses pass by value for fixed-size array ([f64;3]), but C uses pass by reference (pointer to the first element).

Which means a functions like

pub unsafe extern fn with_array(foo: [f64; 3]) {
    // code
}

will be translated as

void with_array(double foo[3]);

which is incorrect, as rust will look for 3 values in the parameters, and not a single pointer.

If I correct the rust function to match the C prototype as

pub unsafe extern fn with_array(foo: &[f64; 3])

cbindgen will emit the wrong declaration:

void with_array(double (*foo)[3]);

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions