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

Upstream roll 3 #13

Merged
merged 5 commits into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions bindgen-tests/tests/expectations/tests/char16_t.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions bindgen-tests/tests/headers/char16_t.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// bindgen-flags: --use-distinct-char16-t --raw-line '#[repr(transparent)] pub struct bindgen_cchar16_t(u16);' -- -x c++ -std=c++14

void receive_char16_t(char16_t input) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,9 @@ fn compare_item_info(
expected,
generated,
),
DiscoveredItem::Enum { .. } => compare_enum_info(expected_item, generated_item),
DiscoveredItem::Enum { .. } => {
compare_enum_info(expected_item, generated_item)
}
// DiscoveredItem::Mod { final_name } => todo!(),
// DiscoveredItem::Function { final_name } => todo!(),
// DiscoveredItem::Method { final_name, parent } => todo!(),
Expand Down Expand Up @@ -222,7 +224,6 @@ pub fn compare_union_info(
}
}


pub fn compare_enum_info(
expected_item: &DiscoveredItem,
generated_item: &DiscoveredItem,
Expand Down
7 changes: 6 additions & 1 deletion bindgen/codegen/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,12 @@ pub(crate) mod ast_ty {
match ik {
IntKind::Bool => syn::parse_quote! { bool },
IntKind::Char { .. } => raw_type(ctx, "c_char"),
IntKind::Char16 => raw_type(ctx, "c_char16_t"),
// The following is used only when an unusual command-line
// argument is used. bindgen_cchar16_t is not a real type;
// but this allows downstream postprocessors to distinguish
// this case and do something special for C++ bindings
// containing char16_t.
IntKind::Char16 => syn::parse_quote! { bindgen_cchar16_t },
IntKind::SChar => raw_type(ctx, "c_schar"),
IntKind::UChar => raw_type(ctx, "c_uchar"),
IntKind::Short => raw_type(ctx, "c_short"),
Expand Down
2 changes: 1 addition & 1 deletion bindgen/ir/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,7 @@ impl ClangSubItemParser for Function {
Some(SpecialMemberKind::CopyConstructor)
} else if cursor.is_move_constructor() {
Some(SpecialMemberKind::MoveConstructor)
} else if cursor.kind() == clang_sys::CXCursor_Destructor {
} else if cursor.kind() == CXCursor_Destructor {
Some(SpecialMemberKind::Destructor)
} else {
None
Expand Down
34 changes: 21 additions & 13 deletions bindgen/options/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,19 +182,6 @@ options! {
as_args: "--represent-cxx-operators",
},

/// Whether we should distinguish between 'char16_t' and 'u16'
use_distinct_char16_t: bool {
methods: {
/// If this is true, denote 'char16_t' as a separate type from 'u16'
/// Disabled by default.
pub fn use_distinct_char16_t(mut self, doit: bool) -> Builder {
self.options.use_distinct_char16_t = doit;
self
}
},
as_args: "--use-distinct-char16-t",
},

/// Use a newtype wrapper to clearly denote "opaque" types; that is,
/// types where bindgen has generated a type matching the size and
/// alignment of the C++ type but without any knowledge of what's
Expand Down Expand Up @@ -267,6 +254,27 @@ options! {
as_args: "--use-unused-template-param-newtype-wrapper",
},

/// Whether we should distinguish between 'char16_t' and 'u16'.
/// As standard, bindgen represents `char16_t` as `u16`.
/// Rust does not have a `std::os::raw::c_char16_t` type, and thus
/// we can't use a built-in Rust type in the generated bindings.
/// But for some uses of bindgen, especially when downstream
/// post-processing occurs, it's important to distinguish `char16_t`
/// from normal `uint16_t`. When this option is enabled, bindgen
/// generates a fake type called `bindgen_cchar16_t`. Downstream
/// code post-processors should arrange to replace this with a
/// real type.
use_distinct_char16_t: bool {
methods: {
/// If this is true, denote 'char16_t' as a separate type from 'u16'
/// Disabled by default.
pub fn use_distinct_char16_t(mut self, doit: bool) -> Builder {
self.options.use_distinct_char16_t = doit;
self
}
},
as_args: "--use-distinct-char16-t",
},

/// Types that have been blocklisted and should not appear anywhere in the generated code.
blocklisted_types: RegexSet {
Expand Down
Loading