mirror of
https://github.com/openharmony/third_party_rust_bindgen.git
synced 2026-07-18 17:34:33 -04:00
Fix duplicated function names (#2341)
Even though this change does name deduplication in a slower way, it avoids name collisions without any breaking changes in the test suite. Fixes #2202
This commit is contained in:
committed by
GitHub
parent
935202b30f
commit
ab2d1c2e8b
@@ -0,0 +1,67 @@
|
||||
#![allow(
|
||||
dead_code,
|
||||
non_snake_case,
|
||||
non_camel_case_types,
|
||||
non_upper_case_globals
|
||||
)]
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone)]
|
||||
pub struct BitStream {
|
||||
pub _address: u8,
|
||||
}
|
||||
#[test]
|
||||
fn bindgen_test_layout_BitStream() {
|
||||
assert_eq!(
|
||||
::std::mem::size_of::<BitStream>(),
|
||||
1usize,
|
||||
concat!("Size of: ", stringify!(BitStream))
|
||||
);
|
||||
assert_eq!(
|
||||
::std::mem::align_of::<BitStream>(),
|
||||
1usize,
|
||||
concat!("Alignment of ", stringify!(BitStream))
|
||||
);
|
||||
}
|
||||
extern "C" {
|
||||
#[link_name = "\u{1}_ZN9BitStream5WriteEPKcj"]
|
||||
pub fn BitStream_Write(
|
||||
this: *mut BitStream,
|
||||
inputByteArray: *const ::std::os::raw::c_char,
|
||||
numberOfBytes: ::std::os::raw::c_uint,
|
||||
);
|
||||
}
|
||||
extern "C" {
|
||||
#[link_name = "\u{1}_ZN9BitStream5WriteEPS_j"]
|
||||
pub fn BitStream_Write1(
|
||||
this: *mut BitStream,
|
||||
bitStream: *mut BitStream,
|
||||
numberOfBits: ::std::os::raw::c_uint,
|
||||
);
|
||||
}
|
||||
extern "C" {
|
||||
#[link_name = "\u{1}_ZN9BitStream6Write1Ev"]
|
||||
pub fn BitStream_Write11(this: *mut BitStream);
|
||||
}
|
||||
impl BitStream {
|
||||
#[inline]
|
||||
pub unsafe fn Write(
|
||||
&mut self,
|
||||
inputByteArray: *const ::std::os::raw::c_char,
|
||||
numberOfBytes: ::std::os::raw::c_uint,
|
||||
) {
|
||||
unsafe { BitStream_Write(self, inputByteArray, numberOfBytes) }
|
||||
}
|
||||
#[inline]
|
||||
pub unsafe fn Write1(
|
||||
&mut self,
|
||||
bitStream: *mut BitStream,
|
||||
numberOfBits: ::std::os::raw::c_uint,
|
||||
) {
|
||||
unsafe { BitStream_Write1(self, bitStream, numberOfBits) }
|
||||
}
|
||||
#[inline]
|
||||
pub unsafe fn Write11(&mut self) {
|
||||
unsafe { BitStream_Write11(self) }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
class BitStream {
|
||||
public:
|
||||
void Write(const char *inputByteArray, unsigned int numberOfBytes);
|
||||
void Write(BitStream *bitStream, unsigned numberOfBits);
|
||||
void Write1();
|
||||
};
|
||||
+15
-9
@@ -2421,7 +2421,7 @@ trait MethodCodegen {
|
||||
&self,
|
||||
ctx: &BindgenContext,
|
||||
methods: &mut Vec<proc_macro2::TokenStream>,
|
||||
method_names: &mut HashMap<String, usize>,
|
||||
method_names: &mut HashSet<String>,
|
||||
result: &mut CodegenResult<'a>,
|
||||
parent: &CompInfo,
|
||||
);
|
||||
@@ -2432,7 +2432,7 @@ impl MethodCodegen for Method {
|
||||
&self,
|
||||
ctx: &BindgenContext,
|
||||
methods: &mut Vec<proc_macro2::TokenStream>,
|
||||
method_names: &mut HashMap<String, usize>,
|
||||
method_names: &mut HashSet<String>,
|
||||
result: &mut CodegenResult<'a>,
|
||||
_parent: &CompInfo,
|
||||
) {
|
||||
@@ -2499,16 +2499,22 @@ impl MethodCodegen for Method {
|
||||
return;
|
||||
}
|
||||
|
||||
let count = {
|
||||
let count = method_names.entry(name.clone()).or_insert(0);
|
||||
*count += 1;
|
||||
*count - 1
|
||||
};
|
||||
if method_names.contains(&name) {
|
||||
let mut count = 1;
|
||||
let mut new_name;
|
||||
|
||||
if count != 0 {
|
||||
name.push_str(&count.to_string());
|
||||
while {
|
||||
new_name = format!("{}{}", name, count);
|
||||
method_names.contains(&new_name)
|
||||
} {
|
||||
count += 1;
|
||||
}
|
||||
|
||||
name = new_name;
|
||||
}
|
||||
|
||||
method_names.insert(name.clone());
|
||||
|
||||
let mut function_name = function_item.canonical_name(ctx);
|
||||
if times_seen > 0 {
|
||||
write!(&mut function_name, "{}", times_seen).unwrap();
|
||||
|
||||
Reference in New Issue
Block a user