Skip to content

[Windows] Wrong ABI when interfacing with C code #28676

Closed
@tomaka

Description

@tomaka

Here is a gist containing the entire source code if you want to reproduce.

When calling the function foo defined like this in C:

typedef struct {
    size_t a;
    size_t b;
    size_t c;
    size_t d;
} Foo;

size_t foo(void* a, void* b, void* c, void* d, Foo f) {
    return f.c;
}

And like this in Rust:

extern {
    fn foo(_: *const libc::c_void, _: *const libc::c_void, _: *const libc::c_void,
           _: *const libc::c_void, _: Foo) -> libc::size_t;
}

You get a crash with the MSVC version of Rust, but the MinGW version works.

This is because apparently the C code expects Foo to actually be a pointer.

If you change the Rust declaration to *const Foo, then it works with the MSVC version and crashes with the MinGW version.

Metadata

Metadata

Assignees

No one assigned

    Labels

    O-windowsOperating system: Windows

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions