Skip to content

Should externfn! include an abi? #10074

Closed
@erickt

Description

@erickt

It's now recommended to use externfn!(...) to bind to a C library function, but those external functions are being declared with the implicit Rust abi. For example, this script errors out:

externfn!(fn foo())
//extern "C" { fn foo(); }

fn bar(_f: extern "C" unsafe fn()) { }

fn main() {
    bar(foo)
}

It errors with:

foo.rs:8:8: 8:11 error: mismatched types: expected `extern "C" unsafe fn()` but found `extern "Rust" unsafe fn()` (expected "C" fn but found "Rust" fn)
foo.rs:8     bar(foo)
                 ^~~
error: aborting due to previous error

Swapping the comments gets it to compile fine. Is this safe? Given that #10052 says the Rust ABI is not precisely defined as the C ABI, should we change externfn! to include an ABI argument to future proof our bindings?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions