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

const array arguments are translated into *mut #509

Closed
bsteinb opened this issue Feb 13, 2017 · 1 comment
Closed

const array arguments are translated into *mut #509

bsteinb opened this issue Feb 13, 2017 · 1 comment
Labels

Comments

@bsteinb
Copy link
Contributor

bsteinb commented Feb 13, 2017

This used to work with libbindgen 0.1.7. Tried it again tonight, now it does not.

C header:

void f(const int a[]);

I run:

$ bindgen const_array.h

I expect:

/* automatically generated by rust-bindgen */

extern "C" {
    pub fn f(a: *const ::std::os::raw::c_int);
}

I get:

/* automatically generated by rust-bindgen */

extern "C" {
    pub fn f(a: *mut ::std::os::raw::c_int);
}

Debug log:

INFO:bindgen: Clang Version: clang version 3.9.1 (tags/RELEASE_391/final)
DEBUG:bindgen::ir::context: BindgenContext::add_item(Item { id: ItemId(0), local_id: Cell { value: None }, next_child_local_id: Cell { value: 1 }, canonical_name_cache: RefCell { value: None }, comment: None, annotations: Annotations { opaque: false, hide: false, use_instead_of: None, disallow_copy: false, private_fields: None, accessor_kind: None, constify_enum_variant: false }, parent_id: ItemId(0), kind: Module(Module { name: Some("root"), kind: Normal, children_ids: [] }) }, declaration: None, loc: None
DEBUG:bindgen::ir::function: Function::parse(Cursor(f kind: FunctionDecl, loc: const_array.h:1:6, usr: Some("c:@F@f")), Type(void (const int *), kind: FunctionProto, decl: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None), canon: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None)))
DEBUG:bindgen::ir::context: builtin_or_resolved_ty: Type(void (const int *), kind: FunctionProto, decl: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None), canon: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None)), Some(Cursor(f kind: FunctionDecl, loc: const_array.h:1:6, usr: Some("c:@F@f"))), None
DEBUG:bindgen::ir::context: Not resolved, maybe builtin?
DEBUG:bindgen::ir::context: builtin_or_resolved_ty: Type(void (const int *), kind: FunctionProto, decl: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None), canon: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None)), Some(Cursor(f kind: FunctionDecl, loc: const_array.h:1:6, usr: Some("c:@F@f"))), None
DEBUG:bindgen::ir::context: Not resolved, maybe builtin?
DEBUG:bindgen::ir::ty: from_clang_ty: ItemId(1), ty: Type(void (const int *), kind: FunctionProto, decl: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None), canon: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None)), loc: Some(Cursor(f kind: FunctionDecl, loc: const_array.h:1:6, usr: Some("c:@F@f")))
DEBUG:bindgen::ir::ty: currently_parsed_types: []
DEBUG:bindgen::ir::function: FunctionSig::from_ty Type(void (const int *), kind: FunctionProto, decl: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None), canon: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None)) Cursor(f kind: FunctionDecl, loc: const_array.h:1:6, usr: Some("c:@F@f"))
DEBUG:bindgen::ir::item: from_ty_or_ref_with_id: ItemId(2) Type(const int [], kind: IncompleteArray, decl: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None), canon: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None)), Some(Cursor(a kind: ParmDecl, loc: const_array.h:1:18, usr: Some("c:const_array.h@7@F@f@a"))), None
DEBUG:bindgen::ir::context: builtin_or_resolved_ty: Type(const int [], kind: IncompleteArray, decl: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None), canon: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None)), Some(Cursor(a kind: ParmDecl, loc: const_array.h:1:18, usr: Some("c:const_array.h@7@F@f@a"))), None
DEBUG:bindgen::ir::context: Not resolved, maybe builtin?
DEBUG:bindgen::ir::item: New unresolved type reference: Type(const int [], kind: IncompleteArray, decl: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None), canon: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None)), Some(Cursor(a kind: ParmDecl, loc: const_array.h:1:18, usr: Some("c:const_array.h@7@F@f@a")))
DEBUG:bindgen::ir::context: BindgenContext::add_item(Item { id: ItemId(2), local_id: Cell { value: None }, next_child_local_id: Cell { value: 1 }, canonical_name_cache: RefCell { value: None }, comment: None, annotations: Annotations { opaque: false, hide: false, use_instead_of: None, disallow_copy: false, private_fields: None, accessor_kind: None, constify_enum_variant: false }, parent_id: ItemId(0), kind: Type(Type { name: None, layout: None, kind: UnresolvedTypeRef(Type(const int [], kind: IncompleteArray, decl: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None), canon: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None)), Some(Cursor(a kind: ParmDecl, loc: const_array.h:1:18, usr: Some("c:const_array.h@7@F@f@a"))), None), is_const: false }) }, declaration: Some(Cursor( kind: InvalidFile, loc: builtin definitions, usr: None)), loc: None
DEBUG:bindgen::ir::context: Invalid declaration Cursor( kind: InvalidFile, loc: builtin definitions, usr: None) found for type Type { name: None, layout: None, kind: UnresolvedTypeRef(Type(const int [], kind: IncompleteArray, decl: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None), canon: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None)), Some(Cursor(a kind: ParmDecl, loc: const_array.h:1:18, usr: Some("c:const_array.h@7@F@f@a"))), None), is_const: false }
DEBUG:bindgen::ir::item: from_ty_or_ref_with_id: ItemId(3) Type(void, kind: Void, decl: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None), canon: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None)), None, None
DEBUG:bindgen::ir::context: builtin_or_resolved_ty: Type(void, kind: Void, decl: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None), canon: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None)), None, None
DEBUG:bindgen::ir::context: Not resolved, maybe builtin?
DEBUG:bindgen::ir::context: add_builtin_item: item = Item { id: ItemId(4), local_id: Cell { value: None }, next_child_local_id: Cell { value: 1 }, canonical_name_cache: RefCell { value: None }, comment: None, annotations: Annotations { opaque: false, hide: false, use_instead_of: None, disallow_copy: false, private_fields: None, accessor_kind: None, constify_enum_variant: false }, parent_id: ItemId(0), kind: Type(Type { name: Some("void"), layout: None, kind: Void, is_const: false }) }
DEBUG:bindgen::ir::item: ItemId(4) already resolved: None
DEBUG:bindgen::ir::context: BindgenContext::add_item(Item { id: ItemId(1), local_id: Cell { value: None }, next_child_local_id: Cell { value: 1 }, canonical_name_cache: RefCell { value: None }, comment: None, annotations: Annotations { opaque: false, hide: false, use_instead_of: None, disallow_copy: false, private_fields: None, accessor_kind: None, constify_enum_variant: false }, parent_id: ItemId(0), kind: Type(Type { name: None, layout: Some(Layout { size: 1, align: 4, packed: false }), kind: Function(FunctionSig { return_type: ItemId(4), argument_types: [(Some("a"), ItemId(2))], is_variadic: false, abi: C }), is_const: false }) }, declaration: Some(Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None)), loc: Some(Cursor(f kind: FunctionDecl, loc: const_array.h:1:6, usr: Some("c:@F@f")))
DEBUG:bindgen::ir::context: Invalid declaration Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None) found for type Type { name: None, layout: Some(Layout { size: 1, align: 4, packed: false }), kind: Function(FunctionSig { return_type: ItemId(4), argument_types: [(Some("a"), ItemId(2))], is_variadic: false, abi: C }), is_const: false }
DEBUG:bindgen::ir::context: BindgenContext::add_item(Item { id: ItemId(5), local_id: Cell { value: None }, next_child_local_id: Cell { value: 1 }, canonical_name_cache: RefCell { value: None }, comment: None, annotations: Annotations { opaque: false, hide: false, use_instead_of: None, disallow_copy: false, private_fields: None, accessor_kind: None, constify_enum_variant: false }, parent_id: ItemId(0), kind: Function(Function { name: "f", mangled_name: None, signature: ItemId(1), comment: None }) }, declaration: Some(Cursor(f kind: FunctionDecl, loc: const_array.h:1:6, usr: Some("c:@F@f"))), loc: Some(Cursor(f kind: FunctionDecl, loc: const_array.h:1:6, usr: Some("c:@F@f")))
DEBUG:bindgen::ir::context: builtin_or_resolved_ty: Type(const int [], kind: IncompleteArray, decl: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None), canon: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None)), Some(Cursor(a kind: ParmDecl, loc: const_array.h:1:18, usr: Some("c:const_array.h@7@F@f@a"))), None
DEBUG:bindgen::ir::context: Not resolved, maybe builtin?
DEBUG:bindgen::ir::context: builtin_or_resolved_ty: Type(const int [], kind: IncompleteArray, decl: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None), canon: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None)), Some(Cursor(a kind: ParmDecl, loc: const_array.h:1:18, usr: Some("c:const_array.h@7@F@f@a"))), None
DEBUG:bindgen::ir::context: Not resolved, maybe builtin?
DEBUG:bindgen::ir::ty: from_clang_ty: ItemId(6), ty: Type(const int [], kind: IncompleteArray, decl: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None), canon: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None)), loc: Some(Cursor(a kind: ParmDecl, loc: const_array.h:1:18, usr: Some("c:const_array.h@7@F@f@a")))
DEBUG:bindgen::ir::ty: currently_parsed_types: []
DEBUG:bindgen::ir::context: builtin_or_resolved_ty: Type(const int, kind: Int, decl: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None), canon: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None)), Some(Cursor(a kind: ParmDecl, loc: const_array.h:1:18, usr: Some("c:const_array.h@7@F@f@a"))), None
DEBUG:bindgen::ir::context: Not resolved, maybe builtin?
DEBUG:bindgen::ir::context: add_builtin_item: item = Item { id: ItemId(8), local_id: Cell { value: None }, next_child_local_id: Cell { value: 1 }, canonical_name_cache: RefCell { value: None }, comment: None, annotations: Annotations { opaque: false, hide: false, use_instead_of: None, disallow_copy: false, private_fields: None, accessor_kind: None, constify_enum_variant: false }, parent_id: ItemId(0), kind: Type(Type { name: Some("const int"), layout: Some(Layout { size: 4, align: 4, packed: false }), kind: Int(Int), is_const: true }) }
DEBUG:bindgen::ir::context: BindgenContext::add_item(Item { id: ItemId(6), local_id: Cell { value: None }, next_child_local_id: Cell { value: 1 }, canonical_name_cache: RefCell { value: None }, comment: None, annotations: Annotations { opaque: false, hide: false, use_instead_of: None, disallow_copy: false, private_fields: None, accessor_kind: None, constify_enum_variant: false }, parent_id: ItemId(0), kind: Type(Type { name: None, layout: None, kind: Array(ItemId(8), 0), is_const: false }) }, declaration: Some(Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None)), loc: Some(Cursor(a kind: ParmDecl, loc: const_array.h:1:18, usr: Some("c:const_array.h@7@F@f@a")))
DEBUG:bindgen::ir::context: Invalid declaration Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None) found for type Type { name: None, layout: None, kind: Array(ItemId(8), 0), is_const: false }
DEBUG:bindgen::ir::context: No replacements to process
DEBUG:bindgen::codegen: codegen: BindgenOptions { hidden_types: RegexSet { items: [], set: Some(RegexSet([])) }, opaque_types: RegexSet { items: [], set: Some(RegexSet([])) }, whitelisted_types: RegexSet { items: [], set: Some(RegexSet([])) }, whitelisted_functions: RegexSet { items: [], set: Some(RegexSet([])) }, whitelisted_vars: RegexSet { items: [], set: Some(RegexSet([])) }, bitfield_enums: RegexSet { items: [], set: Some(RegexSet([])) }, constified_enums: RegexSet { items: [], set: Some(RegexSet([])) }, builtins: false, links: [], emit_ast: false, emit_ir: false, enable_cxx_namespaces: false, disable_name_namespacing: false, derive_debug: true, unstable_rust: true, use_core: false, ctypes_prefix: None, namespaced_constants: true, msvc_mangling: false, convert_floats: true, raw_lines: [], clang_args: ["-isystem", "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1", "-isystem", "/usr/local/include", "-isystem", "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/8.0.0/include", "-isystem", "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include", "-isystem", "/usr/include", "-isystem", "/System/Library/Frameworks", "-isystem", "/Library/Frameworks", "const_array.h"], input_header: Some("const_array.h"), dummy_uses: None, type_chooser: None, codegen_config: CodegenConfig { functions: true, types: true, vars: true, methods: true, constructors: true }, conservative_inline_namespaces: false, generate_comments: true, whitelist_recursively: true, objc_extern_crate: false }
DEBUG:bindgen::codegen: <Item as CodeGenerator>::codegen: self = Item { id: ItemId(0), local_id: Cell { value: None }, next_child_local_id: Cell { value: 1 }, canonical_name_cache: RefCell { value: None }, comment: None, annotations: Annotations { opaque: false, hide: false, use_instead_of: None, disallow_copy: false, private_fields: None, accessor_kind: None, constify_enum_variant: false }, parent_id: ItemId(0), kind: Module(Module { name: Some("root"), kind: Normal, children_ids: [ItemId(2), ItemId(1), ItemId(5), ItemId(6)] }) }
DEBUG:bindgen::codegen: <Module as CodeGenerator>::codegen: item = Item { id: ItemId(0), local_id: Cell { value: None }, next_child_local_id: Cell { value: 1 }, canonical_name_cache: RefCell { value: None }, comment: None, annotations: Annotations { opaque: false, hide: false, use_instead_of: None, disallow_copy: false, private_fields: None, accessor_kind: None, constify_enum_variant: false }, parent_id: ItemId(0), kind: Module(Module { name: Some("root"), kind: Normal, children_ids: [ItemId(2), ItemId(1), ItemId(5), ItemId(6)] }) }
DEBUG:bindgen::codegen: <Item as CodeGenerator>::codegen: self = Item { id: ItemId(2), local_id: Cell { value: None }, next_child_local_id: Cell { value: 1 }, canonical_name_cache: RefCell { value: None }, comment: None, annotations: Annotations { opaque: false, hide: false, use_instead_of: None, disallow_copy: false, private_fields: None, accessor_kind: None, constify_enum_variant: false }, parent_id: ItemId(0), kind: Type(Type { name: None, layout: None, kind: ResolvedTypeRef(ItemId(6)), is_const: false }) }
DEBUG:bindgen::codegen: <Type as CodeGenerator>::codegen: item = Item { id: ItemId(2), local_id: Cell { value: None }, next_child_local_id: Cell { value: 1 }, canonical_name_cache: RefCell { value: None }, comment: None, annotations: Annotations { opaque: false, hide: false, use_instead_of: None, disallow_copy: false, private_fields: None, accessor_kind: None, constify_enum_variant: false }, parent_id: ItemId(0), kind: Type(Type { name: None, layout: None, kind: ResolvedTypeRef(ItemId(6)), is_const: false }) }
DEBUG:bindgen::codegen: <Item as CodeGenerator>::codegen: self = Item { id: ItemId(1), local_id: Cell { value: None }, next_child_local_id: Cell { value: 1 }, canonical_name_cache: RefCell { value: None }, comment: None, annotations: Annotations { opaque: false, hide: false, use_instead_of: None, disallow_copy: false, private_fields: None, accessor_kind: None, constify_enum_variant: false }, parent_id: ItemId(0), kind: Type(Type { name: None, layout: Some(Layout { size: 1, align: 4, packed: false }), kind: Function(FunctionSig { return_type: ItemId(4), argument_types: [(Some("a"), ItemId(2))], is_variadic: false, abi: C }), is_const: false }) }
DEBUG:bindgen::codegen: <Type as CodeGenerator>::codegen: item = Item { id: ItemId(1), local_id: Cell { value: None }, next_child_local_id: Cell { value: 1 }, canonical_name_cache: RefCell { value: None }, comment: None, annotations: Annotations { opaque: false, hide: false, use_instead_of: None, disallow_copy: false, private_fields: None, accessor_kind: None, constify_enum_variant: false }, parent_id: ItemId(0), kind: Type(Type { name: None, layout: Some(Layout { size: 1, align: 4, packed: false }), kind: Function(FunctionSig { return_type: ItemId(4), argument_types: [(Some("a"), ItemId(2))], is_variadic: false, abi: C }), is_const: false }) }
DEBUG:bindgen::codegen: <Item as CodeGenerator>::codegen: self = Item { id: ItemId(5), local_id: Cell { value: None }, next_child_local_id: Cell { value: 1 }, canonical_name_cache: RefCell { value: None }, comment: None, annotations: Annotations { opaque: false, hide: false, use_instead_of: None, disallow_copy: false, private_fields: None, accessor_kind: None, constify_enum_variant: false }, parent_id: ItemId(0), kind: Function(Function { name: "f", mangled_name: None, signature: ItemId(1), comment: None }) }
DEBUG:bindgen::codegen: <Function as CodeGenerator>::codegen: item = Item { id: ItemId(5), local_id: Cell { value: None }, next_child_local_id: Cell { value: 1 }, canonical_name_cache: RefCell { value: None }, comment: None, annotations: Annotations { opaque: false, hide: false, use_instead_of: None, disallow_copy: false, private_fields: None, accessor_kind: None, constify_enum_variant: false }, parent_id: ItemId(0), kind: Function(Function { name: "f", mangled_name: None, signature: ItemId(1), comment: None }) }
DEBUG:bindgen::codegen: <Item as CodeGenerator>::codegen: self = Item { id: ItemId(6), local_id: Cell { value: None }, next_child_local_id: Cell { value: 1 }, canonical_name_cache: RefCell { value: None }, comment: None, annotations: Annotations { opaque: false, hide: false, use_instead_of: None, disallow_copy: false, private_fields: None, accessor_kind: None, constify_enum_variant: false }, parent_id: ItemId(0), kind: Type(Type { name: None, layout: None, kind: Array(ItemId(8), 0), is_const: false }) }
DEBUG:bindgen::codegen: <Type as CodeGenerator>::codegen: item = Item { id: ItemId(6), local_id: Cell { value: None }, next_child_local_id: Cell { value: 1 }, canonical_name_cache: RefCell { value: None }, comment: None, annotations: Annotations { opaque: false, hide: false, use_instead_of: None, disallow_copy: false, private_fields: None, accessor_kind: None, constify_enum_variant: false }, parent_id: ItemId(0), kind: Type(Type { name: None, layout: None, kind: Array(ItemId(8), 0), is_const: false }) }
@fitzgen
Copy link
Member

fitzgen commented Feb 13, 2017

Thanks for the bug report!

emilio added a commit to emilio/rust-bindgen that referenced this issue Feb 14, 2017
…guments.

Fixes rust-lang#509

I'm actually surprised we had no tests for this.

Signed-off-by: Emilio Cobos Álvarez <emilio@crisal.io>
emilio added a commit to emilio/rust-bindgen that referenced this issue Feb 14, 2017
…nction arguments.

Fixes rust-lang#509

I'm actually surprised we had no tests for this.

Signed-off-by: Emilio Cobos Álvarez <emilio@crisal.io>
bors-servo pushed a commit that referenced this issue Feb 14, 2017
Use the constness of the inner type when converting array function args.

Fixes #509

I'm actually surprised we had no tests for this.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants