Skip to content

Commit 37c6e53

Browse files
author
bors-servo
authored
Auto merge of #1217 - emilio:variadic, r=pepyakin
codegen: Be consistent about variadic signatures. Fixes #1216.
2 parents b59b169 + ac3faac commit 37c6e53

File tree

3 files changed

+54
-10
lines changed

3 files changed

+54
-10
lines changed

src/codegen/mod.rs

+8-10
Original file line numberDiff line numberDiff line change
@@ -3249,21 +3249,13 @@ impl CodeGenerator for Function {
32493249
abi => abi,
32503250
};
32513251

3252-
let variadic = if signature.is_variadic() {
3253-
quote! { ... }
3254-
} else {
3255-
quote! {}
3256-
};
3257-
32583252
let ident = ctx.rust_ident(canonical_name);
32593253
let mut tokens = quote! { extern #abi };
32603254
tokens.append("{\n");
32613255
if !attributes.is_empty() {
32623256
tokens.append_separated(attributes, "\n");
32633257
tokens.append("\n");
32643258
}
3265-
let mut args = args;
3266-
args.push(variadic);
32673259
tokens.append(quote! {
32683260
pub fn #ident ( #( #args ),* ) #ret;
32693261
});
@@ -3719,7 +3711,7 @@ mod utils {
37193711
use super::ToPtr;
37203712

37213713
let mut unnamed_arguments = 0;
3722-
sig.argument_types().iter().map(|&(ref name, ty)| {
3714+
let mut args = sig.argument_types().iter().map(|&(ref name, ty)| {
37233715
let arg_item = ctx.resolve_item(ty);
37243716
let arg_ty = arg_item.kind().expect_type();
37253717

@@ -3766,6 +3758,12 @@ mod utils {
37663758
quote! {
37673759
#arg_name : #arg_ty
37683760
}
3769-
}).collect()
3761+
}).collect::<Vec<_>>();
3762+
3763+
if sig.is_variadic() {
3764+
args.push(quote! { ... })
3765+
}
3766+
3767+
args
37703768
}
37713769
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/* automatically generated by rust-bindgen */
2+
3+
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
4+
5+
extern "C" {
6+
pub fn f(a: ::std::os::raw::c_int, ...);
7+
}
8+
#[repr(C)]
9+
#[derive(Debug, Copy, Clone)]
10+
pub struct Foo {
11+
pub f: ::std::option::Option<
12+
unsafe extern "C" fn(
13+
p: *mut ::std::os::raw::c_void,
14+
obj: *mut ::std::os::raw::c_void,
15+
a: ::std::os::raw::c_int,
16+
...
17+
),
18+
>,
19+
}
20+
#[test]
21+
fn bindgen_test_layout_Foo() {
22+
assert_eq!(
23+
::std::mem::size_of::<Foo>(),
24+
8usize,
25+
concat!("Size of: ", stringify!(Foo))
26+
);
27+
assert_eq!(
28+
::std::mem::align_of::<Foo>(),
29+
8usize,
30+
concat!("Alignment of ", stringify!(Foo))
31+
);
32+
assert_eq!(
33+
unsafe { &(*(::std::ptr::null::<Foo>())).f as *const _ as usize },
34+
0usize,
35+
concat!("Offset of field: ", stringify!(Foo), "::", stringify!(f))
36+
);
37+
}
38+
impl Default for Foo {
39+
fn default() -> Self {
40+
unsafe { ::std::mem::zeroed() }
41+
}
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
void f(int a, ...);
2+
struct Foo {
3+
void (*f)(void *p, void *obj, int a, ...);
4+
};

0 commit comments

Comments
 (0)