Skip to content

Commit d4984df

Browse files
committed
Remove encoding_rs again.
1 parent aba0479 commit d4984df

File tree

6 files changed

+14
-35
lines changed

6 files changed

+14
-35
lines changed

Cargo.lock

Lines changed: 0 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bindgen-integration/cpp/Test.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
a
2121
//#define TESTMACRO_INVALID("string") // A conforming preprocessor rejects this
2222
#define TESTMACRO_STRING_EXPR ("string")
23-
#define TESTMACRO_STRING_FUNC_NON_UTF8(x) (x "ÿÿ") /* invalid UTF-8 on purpose */
23+
#define TESTMACRO_STRING_FUNC_NON_UTF8(x) (x "ÿÿ") /* invalid UTF-8 on purpose */
2424

2525
enum {
2626
MY_ANNOYING_MACRO =

bindgen/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ annotate-snippets = { version = "0.9.1", features = ["color"], optional = true }
2929
bitflags = "2.2.1"
3030
cexpr = "0.6"
3131
clang-sys = { version = "1", features = ["clang_6_0"] }
32-
encoding_rs = "0.8.33"
3332
itertools = { version = ">=0.10,<0.13", default-features = false }
3433
lazy_static = "1"
3534
lazycell = "1"

bindgen/clang.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,12 +1038,9 @@ pub(crate) struct ClangToken {
10381038
}
10391039

10401040
impl ClangToken {
1041-
/// Get the token spelling, without being converted to utf-8.
1042-
pub(crate) fn spelling(&self) -> &[u8] {
1043-
let c_str = unsafe {
1044-
CStr::from_ptr(clang_getCString(self.spelling) as *const _)
1045-
};
1046-
c_str.to_bytes()
1041+
/// Returns the token spelling.
1042+
pub(crate) fn spelling(&self) -> &CStr {
1043+
unsafe { CStr::from_ptr(clang_getCString(self.spelling) as *const _) }
10471044
}
10481045

10491046
/// Converts a ClangToken to a `cexpr` token if possible.

bindgen/ir/context.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2159,8 +2159,8 @@ If you encounter an error missing from this list, please file an issue or a PR!"
21592159
let mut kind = ModuleKind::Normal;
21602160
let mut looking_for_name = false;
21612161
for token in cursor.tokens().iter() {
2162-
match token.spelling() {
2163-
b"inline" => {
2162+
match token.spelling().to_str().unwrap() {
2163+
"inline" => {
21642164
debug_assert!(
21652165
kind != ModuleKind::Inline,
21662166
"Multiple inline keywords?"
@@ -2177,20 +2177,18 @@ If you encounter an error missing from this list, please file an issue or a PR!"
21772177
// but the tokenization of the second begins with the double
21782178
// colon. That's ok, so we only need to handle the weird
21792179
// tokenization here.
2180-
b"namespace" | b"::" => {
2180+
"namespace" | b"::" => {
21812181
looking_for_name = true;
21822182
}
2183-
b"{" => {
2183+
"{" => {
21842184
// This should be an anonymous namespace.
21852185
assert!(looking_for_name);
21862186
break;
21872187
}
21882188
name => {
21892189
if looking_for_name {
21902190
if module_name.is_none() {
2191-
module_name = Some(
2192-
String::from_utf8_lossy(name).into_owned(),
2193-
);
2191+
module_name = Some(name.into_owned());
21942192
}
21952193
break;
21962194
} else {
@@ -2205,7 +2203,7 @@ If you encounter an error missing from this list, please file an issue or a PR!"
22052203
// See also https://github.com/rust-lang/rust-bindgen/issues/1676.
22062204
warn!(
22072205
"Ignored unknown namespace prefix '{}' at {:?} in {:?}",
2208-
String::from_utf8_lossy(name),
2206+
name,
22092207
token,
22102208
cursor
22112209
);

bindgen/ir/var.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -164,16 +164,14 @@ fn handle_function_macro(
164164
) {
165165
let is_closing_paren = |t: &ClangToken| {
166166
// Test cheap token kind before comparing exact spellings.
167-
t.kind == clang_sys::CXToken_Punctuation && t.spelling() == b")"
167+
t.kind == clang_sys::CXToken_Punctuation &&
168+
t.spelling().to_bytes() == b")"
168169
};
169170
let tokens: Vec<_> = cursor.tokens().iter().collect();
170171
if let Some(boundary) = tokens.iter().position(is_closing_paren) {
171172
let mut tokens = tokens
172173
.iter()
173-
.map(|token| {
174-
let s = token.spelling();
175-
encoding_rs::mem::decode_latin1(s)
176-
})
174+
.map(|token| token.spelling().to_str().unwrap())
177175
.collect::<Vec<_>>();
178176

179177
let name = tokens.remove(0);
@@ -185,11 +183,8 @@ fn handle_function_macro(
185183
.collect();
186184
let body = tokens;
187185

188-
let args = args.iter().map(|s| s.as_ref()).collect::<Vec<_>>();
189-
let body = body.iter().map(|s| s.as_ref()).collect::<Vec<_>>();
190-
191186
let info = FnMacroInfo {
192-
name: &name,
187+
name: name,
193188
args: &args,
194189
body: &body,
195190
};

0 commit comments

Comments
 (0)