@@ -786,7 +786,6 @@ impl CodeGenerator for Var {
786
786
& canonical_name,
787
787
link_name,
788
788
None ,
789
- ctx. options ( ) . enable_cxx_namespaces ,
790
789
) {
791
790
canonical_name. as_str ( )
792
791
} else {
@@ -4658,7 +4657,6 @@ impl CodeGenerator for Function {
4658
4657
& canonical_name,
4659
4658
mangled_name,
4660
4659
Some ( abi) ,
4661
- ctx. options ( ) . enable_cxx_namespaces ,
4662
4660
) )
4663
4661
. then ( || mangled_name)
4664
4662
} ) ;
@@ -5853,7 +5851,6 @@ pub(crate) mod utils {
5853
5851
canonical_name : & str ,
5854
5852
mangled_name : & str ,
5855
5853
call_conv : Option < ClangAbi > ,
5856
- enable_cxx_namespaces : bool ,
5857
5854
) -> bool {
5858
5855
// If the mangled name and the canonical name are the same then no
5859
5856
// mangling can have happened between the two versions.
@@ -5862,28 +5859,29 @@ pub(crate) mod utils {
5862
5859
}
5863
5860
5864
5861
// 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 ( "::" , "_" ) ;
5874
5864
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
+ }
5881
5880
} else {
5882
- demangled_name . replace ( "::" , "_" )
5883
- } ;
5881
+ return false ;
5882
+ }
5884
5883
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 ;
5887
5885
}
5888
5886
5889
5887
// Working with &[u8] makes indexing simpler than with &str
0 commit comments