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

pointer constness is applied to pointee #511

Closed
bsteinb opened this issue Feb 13, 2017 · 6 comments
Closed

pointer constness is applied to pointee #511

bsteinb opened this issue Feb 13, 2017 · 6 comments

Comments

@bsteinb
Copy link
Contributor

bsteinb commented Feb 13, 2017

C header:

char * a;
const char * b;
char * const c;
const char * const d;

I run:

$ bindgen const_pointer.h

I expect:

/* automatically generated by rust-bindgen */

extern "C" {
    #[link_name = "a"]
    pub static mut a: *mut ::std::os::raw::c_char;
}
extern "C" {
    #[link_name = "b"]
    pub static mut b: *const ::std::os::raw::c_char;
}
extern "C" {
    #[link_name = "c"]
    pub static c: *mut ::std::os::raw::c_char;
}
extern "C" {
    #[link_name = "d"]
    pub static d: *const ::std::os::raw::c_char;
}

I get (c is *const instead of *mut):

/* automatically generated by rust-bindgen */

extern "C" {
    #[link_name = "a"]
    pub static mut a: *mut ::std::os::raw::c_char;
}
extern "C" {
    #[link_name = "b"]
    pub static mut b: *const ::std::os::raw::c_char;
}
extern "C" {
    #[link_name = "c"]
    pub static c: *const ::std::os::raw::c_char;
}
extern "C" {
    #[link_name = "d"]
    pub static d: *const ::std::os::raw::c_char;
}

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::context: builtin_or_resolved_ty: Type(char *, kind: Pointer, decl: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None), canon: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None)), Some(Cursor(a kind: VarDecl, loc: const_pointer.h:1:8, usr: Some("c:@a"))), None
DEBUG:bindgen::ir::context: Not resolved, maybe builtin?
DEBUG:bindgen::ir::context: builtin_or_resolved_ty: Type(char *, kind: Pointer, decl: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None), canon: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None)), Some(Cursor(a kind: VarDecl, loc: const_pointer.h:1:8, usr: Some("c:@a"))), None
DEBUG:bindgen::ir::context: Not resolved, maybe builtin?
DEBUG:bindgen::ir::ty: from_clang_ty: ItemId(1), ty: Type(char *, kind: Pointer, decl: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None), canon: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None)), loc: Some(Cursor(a kind: VarDecl, loc: const_pointer.h:1:8, usr: Some("c:@a")))
DEBUG:bindgen::ir::ty: currently_parsed_types: []
DEBUG:bindgen::ir::item: from_ty_or_ref_with_id: ItemId(2) Type(char, kind: Char_S, decl: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None), canon: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None)), Some(Cursor(a kind: VarDecl, loc: const_pointer.h:1:8, usr: Some("c:@a"))), None
DEBUG:bindgen::ir::context: builtin_or_resolved_ty: Type(char, kind: Char_S, decl: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None), canon: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None)), Some(Cursor(a kind: VarDecl, loc: const_pointer.h:1:8, usr: Some("c:@a"))), None
DEBUG:bindgen::ir::context: Not resolved, maybe builtin?
DEBUG:bindgen::ir::context: add_builtin_item: item = Item { id: ItemId(3), 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("char"), layout: Some(Layout { size: 1, align: 1, packed: false }), kind: Int(Char), is_const: false }) }
DEBUG:bindgen::ir::item: ItemId(3) already resolved: Some(Cursor(a kind: VarDecl, loc: const_pointer.h:1:8, usr: Some("c:@a")))
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: 8, align: 8, packed: false }), kind: Pointer(ItemId(3)), is_const: false }) }, declaration: Some(Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None)), loc: Some(Cursor(a kind: VarDecl, loc: const_pointer.h:1:8, usr: Some("c:@a")))
DEBUG:bindgen::ir::context: Invalid declaration Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None) found for type Type { name: None, layout: Some(Layout { size: 8, align: 8, packed: false }), kind: Pointer(ItemId(3)), is_const: false }
DEBUG:bindgen::ir::context: BindgenContext::add_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: Var(Var { name: "a", mangled_name: Some("a"), ty: ItemId(1), val: None, is_const: false }) }, declaration: Some(Cursor(a kind: VarDecl, loc: const_pointer.h:1:8, usr: Some("c:@a"))), loc: Some(Cursor(a kind: VarDecl, loc: const_pointer.h:1:8, usr: Some("c:@a")))
DEBUG:bindgen::ir::context: builtin_or_resolved_ty: Type(const char *, kind: Pointer, decl: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None), canon: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None)), Some(Cursor(b kind: VarDecl, loc: const_pointer.h:2:14, usr: Some("c:@b"))), None
DEBUG:bindgen::ir::context: Not resolved, maybe builtin?
DEBUG:bindgen::ir::context: builtin_or_resolved_ty: Type(const char *, kind: Pointer, decl: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None), canon: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None)), Some(Cursor(b kind: VarDecl, loc: const_pointer.h:2:14, usr: Some("c:@b"))), None
DEBUG:bindgen::ir::context: Not resolved, maybe builtin?
DEBUG:bindgen::ir::ty: from_clang_ty: ItemId(5), ty: Type(const char *, kind: Pointer, decl: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None), canon: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None)), loc: Some(Cursor(b kind: VarDecl, loc: const_pointer.h:2:14, usr: Some("c:@b")))
DEBUG:bindgen::ir::ty: currently_parsed_types: []
DEBUG:bindgen::ir::item: from_ty_or_ref_with_id: ItemId(6) Type(const char, kind: Char_S, decl: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None), canon: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None)), Some(Cursor(b kind: VarDecl, loc: const_pointer.h:2:14, usr: Some("c:@b"))), None
DEBUG:bindgen::ir::context: builtin_or_resolved_ty: Type(const char, kind: Char_S, decl: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None), canon: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None)), Some(Cursor(b kind: VarDecl, loc: const_pointer.h:2:14, usr: Some("c:@b"))), None
DEBUG:bindgen::ir::context: Not resolved, maybe builtin?
DEBUG:bindgen::ir::context: add_builtin_item: item = Item { id: ItemId(7), 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 char"), layout: Some(Layout { size: 1, align: 1, packed: false }), kind: Int(Char), is_const: true }) }
DEBUG:bindgen::ir::item: ItemId(7) already resolved: Some(Cursor(b kind: VarDecl, loc: const_pointer.h:2:14, usr: Some("c:@b")))
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: Type(Type { name: None, layout: Some(Layout { size: 8, align: 8, packed: false }), kind: Pointer(ItemId(7)), is_const: false }) }, declaration: Some(Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None)), loc: Some(Cursor(b kind: VarDecl, loc: const_pointer.h:2:14, usr: Some("c:@b")))
DEBUG:bindgen::ir::context: Invalid declaration Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None) found for type Type { name: None, layout: Some(Layout { size: 8, align: 8, packed: false }), kind: Pointer(ItemId(7)), is_const: false }
DEBUG:bindgen::ir::context: BindgenContext::add_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: Var(Var { name: "b", mangled_name: Some("b"), ty: ItemId(5), val: None, is_const: false }) }, declaration: Some(Cursor(b kind: VarDecl, loc: const_pointer.h:2:14, usr: Some("c:@b"))), loc: Some(Cursor(b kind: VarDecl, loc: const_pointer.h:2:14, usr: Some("c:@b")))
DEBUG:bindgen::ir::context: builtin_or_resolved_ty: Type(char *const, kind: Pointer, decl: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None), canon: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None)), Some(Cursor(c kind: VarDecl, loc: const_pointer.h:3:14, usr: Some("c:@c"))), None
DEBUG:bindgen::ir::context: Not resolved, maybe builtin?
DEBUG:bindgen::ir::context: builtin_or_resolved_ty: Type(char *const, kind: Pointer, decl: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None), canon: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None)), Some(Cursor(c kind: VarDecl, loc: const_pointer.h:3:14, usr: Some("c:@c"))), None
DEBUG:bindgen::ir::context: Not resolved, maybe builtin?
DEBUG:bindgen::ir::ty: from_clang_ty: ItemId(9), ty: Type(char *const, kind: Pointer, decl: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None), canon: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None)), loc: Some(Cursor(c kind: VarDecl, loc: const_pointer.h:3:14, usr: Some("c:@c")))
DEBUG:bindgen::ir::ty: currently_parsed_types: []
DEBUG:bindgen::ir::item: from_ty_or_ref_with_id: ItemId(10) Type(char, kind: Char_S, decl: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None), canon: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None)), Some(Cursor(c kind: VarDecl, loc: const_pointer.h:3:14, usr: Some("c:@c"))), None
DEBUG:bindgen::ir::context: builtin_or_resolved_ty: Type(char, kind: Char_S, decl: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None), canon: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None)), Some(Cursor(c kind: VarDecl, loc: const_pointer.h:3:14, usr: Some("c:@c"))), None
DEBUG:bindgen::ir::context: Not resolved, maybe builtin?
DEBUG:bindgen::ir::context: add_builtin_item: item = Item { id: ItemId(11), 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("char"), layout: Some(Layout { size: 1, align: 1, packed: false }), kind: Int(Char), is_const: false }) }
DEBUG:bindgen::ir::item: ItemId(11) already resolved: Some(Cursor(c kind: VarDecl, loc: const_pointer.h:3:14, usr: Some("c:@c")))
DEBUG:bindgen::ir::context: BindgenContext::add_item(Item { id: ItemId(9), 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: 8, align: 8, packed: false }), kind: Pointer(ItemId(11)), is_const: true }) }, declaration: Some(Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None)), loc: Some(Cursor(c kind: VarDecl, loc: const_pointer.h:3:14, usr: Some("c:@c")))
DEBUG:bindgen::ir::context: Invalid declaration Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None) found for type Type { name: None, layout: Some(Layout { size: 8, align: 8, packed: false }), kind: Pointer(ItemId(11)), is_const: true }
DEBUG:bindgen::ir::context: BindgenContext::add_item(Item { id: ItemId(12), 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: Var(Var { name: "c", mangled_name: Some("c"), ty: ItemId(9), val: None, is_const: true }) }, declaration: Some(Cursor(c kind: VarDecl, loc: const_pointer.h:3:14, usr: Some("c:@c"))), loc: Some(Cursor(c kind: VarDecl, loc: const_pointer.h:3:14, usr: Some("c:@c")))
DEBUG:bindgen::ir::context: builtin_or_resolved_ty: Type(const char *const, kind: Pointer, decl: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None), canon: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None)), Some(Cursor(d kind: VarDecl, loc: const_pointer.h:4:20, usr: Some("c:@d"))), None
DEBUG:bindgen::ir::context: Not resolved, maybe builtin?
DEBUG:bindgen::ir::context: builtin_or_resolved_ty: Type(const char *const, kind: Pointer, decl: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None), canon: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None)), Some(Cursor(d kind: VarDecl, loc: const_pointer.h:4:20, usr: Some("c:@d"))), None
DEBUG:bindgen::ir::context: Not resolved, maybe builtin?
DEBUG:bindgen::ir::ty: from_clang_ty: ItemId(13), ty: Type(const char *const, kind: Pointer, decl: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None), canon: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None)), loc: Some(Cursor(d kind: VarDecl, loc: const_pointer.h:4:20, usr: Some("c:@d")))
DEBUG:bindgen::ir::ty: currently_parsed_types: []
DEBUG:bindgen::ir::item: from_ty_or_ref_with_id: ItemId(14) Type(const char, kind: Char_S, decl: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None), canon: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None)), Some(Cursor(d kind: VarDecl, loc: const_pointer.h:4:20, usr: Some("c:@d"))), None
DEBUG:bindgen::ir::context: builtin_or_resolved_ty: Type(const char, kind: Char_S, decl: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None), canon: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None)), Some(Cursor(d kind: VarDecl, loc: const_pointer.h:4:20, usr: Some("c:@d"))), None
DEBUG:bindgen::ir::context: Not resolved, maybe builtin?
DEBUG:bindgen::ir::context: add_builtin_item: item = Item { id: ItemId(15), 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 char"), layout: Some(Layout { size: 1, align: 1, packed: false }), kind: Int(Char), is_const: true }) }
DEBUG:bindgen::ir::item: ItemId(15) already resolved: Some(Cursor(d kind: VarDecl, loc: const_pointer.h:4:20, usr: Some("c:@d")))
DEBUG:bindgen::ir::context: BindgenContext::add_item(Item { id: ItemId(13), 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: 8, align: 8, packed: false }), kind: Pointer(ItemId(15)), is_const: true }) }, declaration: Some(Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None)), loc: Some(Cursor(d kind: VarDecl, loc: const_pointer.h:4:20, usr: Some("c:@d")))
DEBUG:bindgen::ir::context: Invalid declaration Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None) found for type Type { name: None, layout: Some(Layout { size: 8, align: 8, packed: false }), kind: Pointer(ItemId(15)), is_const: true }
DEBUG:bindgen::ir::context: BindgenContext::add_item(Item { id: ItemId(16), 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: Var(Var { name: "d", mangled_name: Some("d"), ty: ItemId(13), val: None, is_const: true }) }, declaration: Some(Cursor(d kind: VarDecl, loc: const_pointer.h:4:20, usr: Some("c:@d"))), loc: Some(Cursor(d kind: VarDecl, loc: const_pointer.h:4:20, usr: Some("c:@d")))
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_pointer.h"], input_header: Some("const_pointer.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(1), ItemId(4), ItemId(5), ItemId(8), ItemId(9), ItemId(12), ItemId(13), ItemId(16)] }) }
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(1), ItemId(4), ItemId(5), ItemId(8), ItemId(9), ItemId(12), ItemId(13), ItemId(16)] }) }
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: 8, align: 8, packed: false }), kind: Pointer(ItemId(3)), 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: 8, align: 8, packed: false }), kind: Pointer(ItemId(3)), is_const: false }) }
DEBUG:bindgen::codegen: <Item as CodeGenerator>::codegen: self = 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: Var(Var { name: "a", mangled_name: Some("a"), ty: ItemId(1), val: None, is_const: false }) }
DEBUG:bindgen::codegen: <Var as CodeGenerator>::codegen: 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: Var(Var { name: "a", mangled_name: Some("a"), ty: ItemId(1), val: None, 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: Type(Type { name: None, layout: Some(Layout { size: 8, align: 8, packed: false }), kind: Pointer(ItemId(7)), is_const: false }) }
DEBUG:bindgen::codegen: <Type 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: Type(Type { name: None, layout: Some(Layout { size: 8, align: 8, packed: false }), kind: Pointer(ItemId(7)), is_const: false }) }
DEBUG:bindgen::codegen: <Item as CodeGenerator>::codegen: self = 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: Var(Var { name: "b", mangled_name: Some("b"), ty: ItemId(5), val: None, is_const: false }) }
DEBUG:bindgen::codegen: <Var as CodeGenerator>::codegen: 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: Var(Var { name: "b", mangled_name: Some("b"), ty: ItemId(5), val: None, is_const: false }) }
DEBUG:bindgen::codegen: <Item as CodeGenerator>::codegen: self = Item { id: ItemId(9), 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: 8, align: 8, packed: false }), kind: Pointer(ItemId(11)), is_const: true }) }
DEBUG:bindgen::codegen: <Type as CodeGenerator>::codegen: item = Item { id: ItemId(9), 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: 8, align: 8, packed: false }), kind: Pointer(ItemId(11)), is_const: true }) }
DEBUG:bindgen::codegen: <Item as CodeGenerator>::codegen: self = Item { id: ItemId(12), 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: Var(Var { name: "c", mangled_name: Some("c"), ty: ItemId(9), val: None, is_const: true }) }
DEBUG:bindgen::codegen: <Var as CodeGenerator>::codegen: item = Item { id: ItemId(12), 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: Var(Var { name: "c", mangled_name: Some("c"), ty: ItemId(9), val: None, is_const: true }) }
DEBUG:bindgen::codegen: <Item as CodeGenerator>::codegen: self = Item { id: ItemId(13), 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: 8, align: 8, packed: false }), kind: Pointer(ItemId(15)), is_const: true }) }
DEBUG:bindgen::codegen: <Type as CodeGenerator>::codegen: item = Item { id: ItemId(13), 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: 8, align: 8, packed: false }), kind: Pointer(ItemId(15)), is_const: true }) }
DEBUG:bindgen::codegen: <Item as CodeGenerator>::codegen: self = Item { id: ItemId(16), 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: Var(Var { name: "d", mangled_name: Some("d"), ty: ItemId(13), val: None, is_const: true }) }
DEBUG:bindgen::codegen: <Var as CodeGenerator>::codegen: item = Item { id: ItemId(16), 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: Var(Var { name: "d", mangled_name: Some("d"), ty: ItemId(13), val: None, is_const: true }) }
@fitzgen fitzgen added the bug label Feb 13, 2017
@fitzgen
Copy link
Member

fitzgen commented Feb 13, 2017

Thanks for the bug report!

@emilio
Copy link
Contributor

emilio commented Feb 14, 2017

Note to whoever tackles this (including potentially myself): The fix for this seems straight-forward but isn't (removing self.is_const() || from this line should in theory do it).

The reason why it's not so trivial is that we lose constness info when finding an already resolved type, and the proper way to fix this is a proper QualifiedType abstraction.

@lilianmoraru
Copy link

I ported some code and was checking with bindgen if it produced the same result, and I hit the same issue.
Here is another code example:

int func(char ** const a, a_set * const b);

the code I wrote looks like this:

fn func(a: *mut *mut c_char, b: *mut a_set) -> c_int;

bindgen code:

fn func(a: *const *mut c_char, b: *const a_set) -> c_int

Note that in both cases(a and b) only the address is immutable.

@emilio
Copy link
Contributor

emilio commented Feb 27, 2017

Yeah, there's more ongoing discussion to fix this in #534.

@Jascha-N
Copy link

It seems to be even worse for (externally defined?) arrays.

extern RduinoSerial * const RDUINO_SERIAL_PORTS[6];

turns into:

extern "C" {
    #[link_name = "RDUINO_SERIAL_PORTS"]
    pub static mut RDUINO_SERIAL_PORTS: [*const RduinoSerial; 6usize];
}

The elements of the array should obviously not be mutable, but the objects that those elements point to, should be mutable. The constness on these bindings is completely in reverse.

@emilio
Copy link
Contributor

emilio commented May 16, 2018

Fixed in #1311 and #1312

@emilio emilio closed this as completed May 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants