Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

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

Closed

Description

@pnkfelix

(imported from improperly closed bug #16221)

You cannot pass an array to or return an array from a C function.
The signature f(char x[N]) is equivalent to f(char *x) for every N in C. Therefore it is meaningless to write this in Rust, (or rather, it does not mean what a C programmer and/or FFI generation tool likely thinks it means):

    extern "C" fn f(x: [i32, ..4]); // void f(int x[4])

Option for dealing with this:

  • 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.

Activity

  1. pnkfelix commented on Apr 18, 2015

    @pnkfelix
    ContributorAuthor

    triage: P-low

  2. steveklabnik commented on Jun 6, 2016

    @steveklabnik
    Contributor

    Triage: array syntax has changed, here's the correct syntax:

    extern {
        fn f(x: [i32; 4]);
    }
    
    fn main() {}
    

    no warning or anything.

  3. added
    A-diagnostics
    A-FFI
    C-bug
    on Jul 22, 2017
  4. steveklabnik commented on Oct 31, 2018

    @steveklabnik
    Contributor

    Triage: no change

  5. added
    T-compiler
    A-lints
    on Oct 11, 2019
  6. estebank commented on Oct 11, 2019

    @estebank
    Contributor

    This would have to be implemented as a lint now due to the potential of breaking existing builds. It should be easy enough to implement.

  7. added
    E-easy
    on Oct 11, 2019
  8. added a commit that references this issue on Nov 27, 2019
    2f1a4b3
  9. added
    A-lints
    and removed
    A-lints
    on Dec 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-FFIA-diagnosticsA-lintsC-bugE-easyP-lowT-compiler

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions