Skip to content

Commit caf4765

Browse files
committed
Merge branch 'main' of https://github.com/rust-lang/rust-bindgen into HEAD
2 parents 32d2e39 + 61603fc commit caf4765

File tree

5 files changed

+41
-16
lines changed

5 files changed

+41
-16
lines changed

bindgen-tests/tests/expectations/tests/char16_t.rs

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// bindgen-flags: --use-distinct-char16-t --raw-line '#[repr(transparent)] pub struct bindgen_cchar16_t(u16);' -- -x c++ -std=c++14
2+
3+
void receive_char16_t(char16_t input) {
4+
}

bindgen-tests/tests/parse_callbacks/item_discovery_callback/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,9 @@ fn compare_item_info(
140140
expected,
141141
generated,
142142
),
143-
DiscoveredItem::Enum { .. } => compare_enum_info(expected_item, generated_item),
143+
DiscoveredItem::Enum { .. } => {
144+
compare_enum_info(expected_item, generated_item)
145+
}
144146
// DiscoveredItem::Mod { final_name } => todo!(),
145147
// DiscoveredItem::Function { final_name } => todo!(),
146148
// DiscoveredItem::Method { final_name, parent } => todo!(),
@@ -222,7 +224,6 @@ pub fn compare_union_info(
222224
}
223225
}
224226

225-
226227
pub fn compare_enum_info(
227228
expected_item: &DiscoveredItem,
228229
generated_item: &DiscoveredItem,

bindgen/codegen/helpers.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,12 @@ pub(crate) mod ast_ty {
200200
match ik {
201201
IntKind::Bool => syn::parse_quote! { bool },
202202
IntKind::Char { .. } => raw_type(ctx, "c_char"),
203-
IntKind::Char16 => raw_type(ctx, "c_char16_t"),
203+
// The following is used only when an unusual command-line
204+
// argument is used. bindgen_cchar16_t is not a real type;
205+
// but this allows downstream postprocessors to distinguish
206+
// this case and do something special for C++ bindings
207+
// containing char16_t.
208+
IntKind::Char16 => syn::parse_quote! { bindgen_cchar16_t },
204209
IntKind::SChar => raw_type(ctx, "c_schar"),
205210
IntKind::UChar => raw_type(ctx, "c_uchar"),
206211
IntKind::Short => raw_type(ctx, "c_short"),

bindgen/options/mod.rs

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -182,19 +182,6 @@ options! {
182182
as_args: "--represent-cxx-operators",
183183
},
184184

185-
/// Whether we should distinguish between 'char16_t' and 'u16'
186-
use_distinct_char16_t: bool {
187-
methods: {
188-
/// If this is true, denote 'char16_t' as a separate type from 'u16'
189-
/// Disabled by default.
190-
pub fn use_distinct_char16_t(mut self, doit: bool) -> Builder {
191-
self.options.use_distinct_char16_t = doit;
192-
self
193-
}
194-
},
195-
as_args: "--use-distinct-char16-t",
196-
},
197-
198185
/// Use a newtype wrapper to clearly denote "opaque" types; that is,
199186
/// types where bindgen has generated a type matching the size and
200187
/// alignment of the C++ type but without any knowledge of what's
@@ -267,6 +254,27 @@ options! {
267254
as_args: "--use-unused-template-param-newtype-wrapper",
268255
},
269256

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

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

0 commit comments

Comments
 (0)