-
Notifications
You must be signed in to change notification settings - Fork 707
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
Feature 699 constified enum module #741
Changes from 5 commits
5762339
0826846
fb9959a
977ec6f
de155b9
5f4b730
4b10529
465e242
814d28e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
//! Bindgen's core intermediate representation type. | ||
|
||
use super::super::codegen::CONSTIFIED_ENUM_MODULE_REPR_NAME; | ||
use super::annotations::Annotations; | ||
use super::context::{BindgenContext, ItemId, PartialType}; | ||
use super::derive::{CanDeriveCopy, CanDeriveDebug, CanDeriveDefault}; | ||
|
@@ -1443,10 +1444,28 @@ impl ItemCanonicalPath for Item { | |
fn namespace_aware_canonical_path(&self, | ||
ctx: &BindgenContext) | ||
-> Vec<String> { | ||
let path = self.canonical_path(ctx); | ||
let mut path = self.canonical_path(ctx); | ||
let mut is_constified_module_enum = false; | ||
if let ItemKind::Type(ref type_) = self.kind { | ||
if let Some(ref type_) = type_.safe_canonical_type(ctx) { | ||
if let TypeKind::Enum(ref enum_) = *type_.kind() { | ||
if enum_.is_constified_enum_module(ctx, self) { | ||
// Type alias is inside a module | ||
is_constified_module_enum = true; | ||
} | ||
} | ||
} | ||
} | ||
if ctx.options().enable_cxx_namespaces { | ||
if is_constified_module_enum { | ||
path.push(CONSTIFIED_ENUM_MODULE_REPR_NAME.into()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should be in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the check should be in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, I guess, but that relies on |
||
} | ||
return path; | ||
} | ||
if is_constified_module_enum { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To fix the last test-case I commented about, you should remove this early return and let it arrive to the last return. For that to work, you need to add the if is_constified_module_enum {
path.push(CONSTIFIED_ENUM_MODULE_REPR_NAME.into());
}
if ctx.options().enable_cxx_namespaces {
return path;
}
if ctx.options().disable_name_namespacing {
let trailing_segments = if is_constified_module_enum { 2 } else { 1 };
return path[..path.len() - trailing_segments].iter().cloned().collect();
}
return vec![path[1..].join("_")]; |
||
return vec![path.last().unwrap().clone(), | ||
CONSTIFIED_ENUM_MODULE_REPR_NAME.into()]; | ||
} | ||
if ctx.options().disable_name_namespacing { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this branch is correct. |
||
return vec![path.last().unwrap().clone()]; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* automatically generated by rust-bindgen */ | ||
|
||
|
||
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] | ||
|
||
|
||
pub mod foo { | ||
pub type Type = ::std::os::raw::c_uint; | ||
pub const THIS: Type = 0; | ||
pub const SHOULD_BE: Type = 1; | ||
pub const A_CONSTANT: Type = 2; | ||
} | ||
pub use self::foo::Type as foo_alias1; | ||
pub use self::foo_alias1 as foo_alias2; | ||
#[repr(C)] | ||
#[derive(Debug, Copy)] | ||
pub struct bar { | ||
pub this_should_work: foo::Type, | ||
} | ||
#[test] | ||
fn bindgen_test_layout_bar() { | ||
assert_eq!(::std::mem::size_of::<bar>() , 4usize , concat ! ( | ||
"Size of: " , stringify ! ( bar ) )); | ||
assert_eq! (::std::mem::align_of::<bar>() , 4usize , concat ! ( | ||
"Alignment of " , stringify ! ( bar ) )); | ||
assert_eq! (unsafe { | ||
& ( * ( 0 as * const bar ) ) . this_should_work as * const _ | ||
as usize } , 0usize , concat ! ( | ||
"Alignment of field: " , stringify ! ( bar ) , "::" , | ||
stringify ! ( this_should_work ) )); | ||
} | ||
impl Clone for bar { | ||
fn clone(&self) -> Self { *self } | ||
} | ||
impl Default for bar { | ||
fn default() -> Self { unsafe { ::std::mem::zeroed() } } | ||
} | ||
extern "C" { | ||
pub fn func1(arg1: foo::Type, arg2: *mut foo::Type, | ||
arg3: *mut *mut foo::Type) -> *mut foo::Type; | ||
} | ||
extern "C" { | ||
pub fn func2(arg1: foo_alias1, arg2: *mut foo_alias1, | ||
arg3: *mut *mut foo_alias1) -> *mut foo_alias1; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add a helper function that returns this instead.