Skip to content

Commit 8e200cd

Browse files
committed
Output warnings for non-UTF-8 tokens.
1 parent 61a3319 commit 8e200cd

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

bindgen/ir/context.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2162,7 +2162,14 @@ If you encounter an error missing from this list, please file an issue or a PR!"
21622162
let spelling = token.spelling();
21632163
let name = match spelling.to_str() {
21642164
Ok(name) => Cow::Borrowed(name),
2165-
Err(_) => spelling.to_string_lossy(),
2165+
Err(_) => {
2166+
let name = spelling.to_string_lossy();
2167+
warn!(
2168+
"Lossy conversion of non-UTF8 token {:?} to {:?}.",
2169+
spelling, name
2170+
);
2171+
name
2172+
}
21662173
};
21672174
match name.as_ref() {
21682175
"inline" => {

bindgen/ir/var.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,17 +167,21 @@ fn handle_function_macro(
167167
t.kind == clang_sys::CXToken_Punctuation &&
168168
t.spelling().to_bytes() == b")"
169169
};
170-
let tokens: Vec<_> = cursor.tokens().iter().collect();
171-
if let Some(boundary) = tokens.iter().position(is_closing_paren) {
172-
let tokens: Result<Vec<_>, _> = tokens
170+
let mut raw_tokens: Vec<_> = cursor.tokens().iter().collect();
171+
if let Some(boundary) = raw_tokens.iter().position(is_closing_paren) {
172+
let tokens: Result<Vec<_>, _> = raw_tokens
173173
.iter()
174174
.map(|token| token.spelling().to_str())
175175
.collect();
176176

177177
let mut tokens = if let Ok(tokens) = tokens {
178178
tokens
179179
} else {
180-
// Skip macros containing invalid UTF-8.
180+
let raw_name = raw_tokens.remove(0);
181+
warn!(
182+
"Ignoring macro {:?} containing invalid UTF-8 tokens.",
183+
raw_name.spelling()
184+
);
181185
return;
182186
};
183187

0 commit comments

Comments
 (0)