Skip to content

Commit de9de85

Browse files
committed
Revert "fix: C++ namespaces mangling"
This reverts commit 2deeabe.
1 parent d0b1344 commit de9de85

File tree

1 file changed

+20
-22
lines changed

1 file changed

+20
-22
lines changed

bindgen/codegen/mod.rs

+20-22
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,6 @@ impl CodeGenerator for Var {
786786
&canonical_name,
787787
link_name,
788788
None,
789-
ctx.options().enable_cxx_namespaces,
790789
) {
791790
canonical_name.as_str()
792791
} else {
@@ -4658,7 +4657,6 @@ impl CodeGenerator for Function {
46584657
&canonical_name,
46594658
mangled_name,
46604659
Some(abi),
4661-
ctx.options().enable_cxx_namespaces,
46624660
))
46634661
.then(|| mangled_name)
46644662
});
@@ -5853,7 +5851,6 @@ pub(crate) mod utils {
58535851
canonical_name: &str,
58545852
mangled_name: &str,
58555853
call_conv: Option<ClangAbi>,
5856-
enable_cxx_namespaces: bool,
58575854
) -> bool {
58585855
// If the mangled name and the canonical name are the same then no
58595856
// mangling can have happened between the two versions.
@@ -5862,28 +5859,29 @@ pub(crate) mod utils {
58625859
}
58635860

58645861
// Check if the mangled name is a valid C++ symbol
5865-
if let Ok(demangled) = ::cpp_demangle::Symbol::new(mangled_name) {
5866-
let demangled_name = match demangled.demangle(
5867-
&::cpp_demangle::DemangleOptions::default()
5868-
.no_params()
5869-
.no_return_type(),
5870-
) {
5871-
Ok(name) => name,
5872-
Err(_) => demangled.to_string(),
5873-
};
5862+
if let Ok(demangled) = cpp_demangle::Symbol::new(mangled_name) {
5863+
let demangled_name = demangled.to_string().replace("::", "_");
58745864

5875-
// Either remove the namespace or replace "::" with "_" if cxx namespaces are enabled
5876-
let demangled_name = if enable_cxx_namespaces {
5877-
demangled_name
5878-
.rsplit_once("::")
5879-
.map(|(_, name)| name.to_string())
5880-
.unwrap_or(demangled_name)
5865+
// Check that the demangled name is longer than the canonical name
5866+
if demangled_name.len() <= canonical_name.len() {
5867+
return false;
5868+
}
5869+
5870+
// Check that the demangled name starts with the canonical name
5871+
if !demangled_name.starts_with(canonical_name) {
5872+
return false;
5873+
}
5874+
5875+
// Check that the suffix is a signature
5876+
if let Some(suffix) = demangled_name.get(canonical_name.len()..) {
5877+
if !suffix.starts_with('(') || !suffix.ends_with(')') {
5878+
return false;
5879+
}
58815880
} else {
5882-
demangled_name.replace("::", "_")
5883-
};
5881+
return false;
5882+
}
58845883

5885-
// Now that we processed the demangled name, we can compare it with the canonical name
5886-
return canonical_name == demangled_name;
5884+
return true;
58875885
}
58885886

58895887
// Working with &[u8] makes indexing simpler than with &str

0 commit comments

Comments
 (0)