Skip to content

Commit

Permalink
Remove encoding_rs again.
Browse files Browse the repository at this point in the history
  • Loading branch information
reitermarkus committed Feb 21, 2024
1 parent aba0479 commit d4984df
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 35 deletions.
10 changes: 0 additions & 10 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion bindgen-integration/cpp/Test.h
Expand Up @@ -20,7 +20,7 @@
a
//#define TESTMACRO_INVALID("string") // A conforming preprocessor rejects this
#define TESTMACRO_STRING_EXPR ("string")
#define TESTMACRO_STRING_FUNC_NON_UTF8(x) (x "ÿÿ") /* invalid UTF-8 on purpose */
#define TESTMACRO_STRING_FUNC_NON_UTF8(x) (x "ÿÿ") /* invalid UTF-8 on purpose */

enum {
MY_ANNOYING_MACRO =
Expand Down
1 change: 0 additions & 1 deletion bindgen/Cargo.toml
Expand Up @@ -29,7 +29,6 @@ annotate-snippets = { version = "0.9.1", features = ["color"], optional = true }
bitflags = "2.2.1"
cexpr = "0.6"
clang-sys = { version = "1", features = ["clang_6_0"] }
encoding_rs = "0.8.33"
itertools = { version = ">=0.10,<0.13", default-features = false }
lazy_static = "1"
lazycell = "1"
Expand Down
9 changes: 3 additions & 6 deletions bindgen/clang.rs
Expand Up @@ -1038,12 +1038,9 @@ pub(crate) struct ClangToken {
}

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

/// Converts a ClangToken to a `cexpr` token if possible.
Expand Down
14 changes: 6 additions & 8 deletions bindgen/ir/context.rs
Expand Up @@ -2159,8 +2159,8 @@ If you encounter an error missing from this list, please file an issue or a PR!"
let mut kind = ModuleKind::Normal;
let mut looking_for_name = false;
for token in cursor.tokens().iter() {
match token.spelling() {
b"inline" => {
match token.spelling().to_str().unwrap() {
"inline" => {
debug_assert!(
kind != ModuleKind::Inline,
"Multiple inline keywords?"
Expand All @@ -2177,20 +2177,18 @@ If you encounter an error missing from this list, please file an issue or a PR!"
// but the tokenization of the second begins with the double
// colon. That's ok, so we only need to handle the weird
// tokenization here.
b"namespace" | b"::" => {
"namespace" | b"::" => {

Check failure on line 2180 in bindgen/ir/context.rs

View workflow job for this annotation

GitHub Actions / rustfmt-clippy

mismatched types
looking_for_name = true;
}
b"{" => {
"{" => {
// This should be an anonymous namespace.
assert!(looking_for_name);
break;
}
name => {
if looking_for_name {
if module_name.is_none() {
module_name = Some(
String::from_utf8_lossy(name).into_owned(),
);
module_name = Some(name.into_owned());

Check failure on line 2191 in bindgen/ir/context.rs

View workflow job for this annotation

GitHub Actions / rustfmt-clippy

no method named `into_owned` found for reference `&str` in the current scope
}
break;
} else {
Expand All @@ -2205,7 +2203,7 @@ If you encounter an error missing from this list, please file an issue or a PR!"
// See also https://github.com/rust-lang/rust-bindgen/issues/1676.
warn!(
"Ignored unknown namespace prefix '{}' at {:?} in {:?}",
String::from_utf8_lossy(name),
name,
token,
cursor
);
Expand Down
13 changes: 4 additions & 9 deletions bindgen/ir/var.rs
Expand Up @@ -164,16 +164,14 @@ fn handle_function_macro(
) {
let is_closing_paren = |t: &ClangToken| {
// Test cheap token kind before comparing exact spellings.
t.kind == clang_sys::CXToken_Punctuation && t.spelling() == b")"
t.kind == clang_sys::CXToken_Punctuation &&
t.spelling().to_bytes() == b")"
};
let tokens: Vec<_> = cursor.tokens().iter().collect();
if let Some(boundary) = tokens.iter().position(is_closing_paren) {
let mut tokens = tokens
.iter()
.map(|token| {
let s = token.spelling();
encoding_rs::mem::decode_latin1(s)
})
.map(|token| token.spelling().to_str().unwrap())
.collect::<Vec<_>>();

let name = tokens.remove(0);
Expand All @@ -185,11 +183,8 @@ fn handle_function_macro(
.collect();
let body = tokens;

let args = args.iter().map(|s| s.as_ref()).collect::<Vec<_>>();
let body = body.iter().map(|s| s.as_ref()).collect::<Vec<_>>();

let info = FnMacroInfo {
name: &name,
name: name,

Check warning on line 187 in bindgen/ir/var.rs

View workflow job for this annotation

GitHub Actions / rustfmt-clippy

redundant field names in struct initialization
args: &args,
body: &body,
};
Expand Down

0 comments on commit d4984df

Please sign in to comment.