Skip to content
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

Don't allow array types in extern "C" functions. #16221

Closed
mahkoh opened this issue Aug 3, 2014 · 3 comments
Closed

Don't allow array types in extern "C" functions. #16221

mahkoh opened this issue Aug 3, 2014 · 3 comments
Labels
P-low Low priority

Comments

@mahkoh
Copy link
Contributor

mahkoh commented Aug 3, 2014

You cannot pass an array to or return an array from a C function. f(char x[N]) is equivalent to f(char *x) for every N. On x86_64 linux, the following two extern "C" functions produce the same assembly:

extern "C" {
    fn f(x: [i32, ..4]); // void f(int x[4])
    fn g(x: i64, y: i64);
}

This will segfault.

@alexcrichton
Copy link
Member

Nominating.

@pnkfelix
Copy link
Member

pnkfelix commented Aug 7, 2014

There are a couple of things here

  • We can extend our existing lint to detect cases like this and warn about them.
  • We could make the extern "C" fn form reject this signature, since the expected correspondence between Rust and C does not hold here.
  • If the Rust FFI binding generation scripts/programs out there are generating this sort of code, they need to be fixed.

@pnkfelix
Copy link
Member

pnkfelix commented Aug 7, 2014

Assigning P-low, not 1.0 milestone.

@pnkfelix pnkfelix added P-low and removed I-nominated labels Aug 7, 2014
@mahkoh mahkoh closed this as completed Apr 11, 2015
@rust-lang rust-lang locked and limited conversation to collaborators Apr 11, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
P-low Low priority
Projects
None yet
Development

No branches or pull requests

3 participants