Skip to content

Should externfn! include an abi? #10074

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

Closed
erickt opened this issue Oct 26, 2013 · 3 comments
Closed

Should externfn! include an abi? #10074

erickt opened this issue Oct 26, 2013 · 3 comments

Comments

@erickt
Copy link
Contributor

erickt commented Oct 26, 2013

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?

@nikomatsakis
Copy link
Contributor

I'm not really opposed to this, but I'm not sure I'd say it's "recommended" to use externfn!. The role of externfn! is to bridge from extern to Rust (though I guess it could be generalized to "bridge from ABI to ABI"). However, if we opt to remove segmented stacks, we wouldn't need externfn! at all (it's not clear to me we need it now...)

@erickt
Copy link
Contributor Author

erickt commented Oct 28, 2013

@nikomatsakis: I figured it was recommended because of the tutorial-ffi document. It talks about how externfn! can save some of the tedium of writing ffi functions. It doesn't mention that externfn! does not specify the ABI.

@nikomatsakis
Copy link
Contributor

Likely a non-issue, since we are removing segmented stacks and thus (hopefully) the need for externfn!

flip1995 pushed a commit to flip1995/rust that referenced this issue Apr 3, 2025
Closes rust-lang#10074

changelog: [`redundant_clone`]: fix FP on enum cast
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants