Skip to content

Commit 89e2725

Browse files
author
bors-servo
authored
Auto merge of #52 - servo:dedup-virtual-overloaded-names, r=emilio
Deduplicate names of virtual overloaded methods. Fix #48 r? @emilio
2 parents 1e26a8a + 5210a9f commit 89e2725

File tree

4 files changed

+47
-1
lines changed

4 files changed

+47
-1
lines changed

src/gen.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -968,6 +968,7 @@ fn cstruct_to_rs(ctx: &mut GenCtx, name: &str, ci: CompInfo,
968968
vffields.push(field);
969969
}
970970

971+
let mut counts: HashMap<String, isize> = HashMap::new();
971972
for vm in ci.vmethods.iter() {
972973
let ty = match vm.ty {
973974
TFuncPtr(ref sig) => {
@@ -977,7 +978,19 @@ fn cstruct_to_rs(ctx: &mut GenCtx, name: &str, ci: CompInfo,
977978
_ => unreachable!()
978979
};
979980

980-
let name = first(rust_id(ctx, &vm.name));
981+
let mut name = vm.name.clone();
982+
let mut count = 0;
983+
match counts.get(&vm.name) {
984+
Some(x) => {
985+
count = *x;
986+
name.push_str(&x.to_string());
987+
},
988+
None => ()
989+
}
990+
count += 1;
991+
counts.insert(vm.name.clone(), count);
992+
993+
let name = first(rust_id(ctx, &name));
981994

982995
vffields.push(ast::StructField {
983996
span: ctx.span,

src/parser.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1490,6 +1490,7 @@ pub fn parse(options: ClangParserOptions, logger: &Logger) -> Result<ModuleMap,
14901490
}
14911491

14921492
if ctx.err_count > 0 {
1493+
logger.error(&format!("{} errors after diagnostics", ctx.err_count));
14931494
return Err(())
14941495
}
14951496

@@ -1510,6 +1511,7 @@ pub fn parse(options: ClangParserOptions, logger: &Logger) -> Result<ModuleMap,
15101511
ix.dispose();
15111512

15121513
if ctx.err_count > 0 {
1514+
logger.error(&format!("{} errors after translation", ctx.err_count));
15131515
return Err(())
15141516
}
15151517

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/* automatically generated by rust-bindgen */
2+
3+
4+
#![allow(non_snake_case)]
5+
6+
7+
#[repr(C)]
8+
#[derive(Debug, Copy)]
9+
pub struct Struct_C {
10+
pub _vftable: *const _vftable_Struct_C,
11+
}
12+
#[repr(C)]
13+
pub struct _vftable_Struct_C {
14+
pub do_thing: unsafe extern "C" fn(this: *mut ::std::os::raw::c_void,
15+
arg1: ::std::os::raw::c_char),
16+
pub do_thing1: unsafe extern "C" fn(this: *mut ::std::os::raw::c_void,
17+
arg1: ::std::os::raw::c_int),
18+
}
19+
impl ::std::clone::Clone for Struct_C {
20+
fn clone(&self) -> Self { *self }
21+
}
22+
#[test]
23+
fn bindgen_test_layout_Struct_C() {
24+
assert_eq!(::std::mem::size_of::<Struct_C>() , 8usize);
25+
assert_eq!(::std::mem::align_of::<Struct_C>() , 8usize);
26+
}

tests/headers/virtual_overloaded.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class C {
2+
public:
3+
virtual void do_thing(char) { };
4+
virtual void do_thing(int) { };
5+
};

0 commit comments

Comments
 (0)