forked from reitermarkus/rust-bindgen
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a C naming option (rust-lang#2045)
Closes rust-lang#2045. Fixes rust-lang#1252.
- Loading branch information
1 parent
7ff354b
commit 060b665
Showing
5 changed files
with
158 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
#![allow( | ||
dead_code, | ||
non_snake_case, | ||
non_camel_case_types, | ||
non_upper_case_globals | ||
)] | ||
|
||
#[repr(C)] | ||
#[derive(Debug, Default, Copy, Clone)] | ||
pub struct struct_a { | ||
pub a: ::std::os::raw::c_int, | ||
} | ||
#[test] | ||
fn bindgen_test_layout_struct_a() { | ||
assert_eq!( | ||
::std::mem::size_of::<struct_a>(), | ||
4usize, | ||
concat!("Size of: ", stringify!(struct_a)) | ||
); | ||
assert_eq!( | ||
::std::mem::align_of::<struct_a>(), | ||
4usize, | ||
concat!("Alignment of ", stringify!(struct_a)) | ||
); | ||
assert_eq!( | ||
unsafe { &(*(::std::ptr::null::<struct_a>())).a as *const _ as usize }, | ||
0usize, | ||
concat!( | ||
"Offset of field: ", | ||
stringify!(struct_a), | ||
"::", | ||
stringify!(a) | ||
) | ||
); | ||
} | ||
pub type a = *const struct_a; | ||
#[repr(C)] | ||
#[derive(Copy, Clone)] | ||
pub union union_b { | ||
pub a: ::std::os::raw::c_int, | ||
pub b: ::std::os::raw::c_int, | ||
} | ||
#[test] | ||
fn bindgen_test_layout_union_b() { | ||
assert_eq!( | ||
::std::mem::size_of::<union_b>(), | ||
4usize, | ||
concat!("Size of: ", stringify!(union_b)) | ||
); | ||
assert_eq!( | ||
::std::mem::align_of::<union_b>(), | ||
4usize, | ||
concat!("Alignment of ", stringify!(union_b)) | ||
); | ||
assert_eq!( | ||
unsafe { &(*(::std::ptr::null::<union_b>())).a as *const _ as usize }, | ||
0usize, | ||
concat!( | ||
"Offset of field: ", | ||
stringify!(union_b), | ||
"::", | ||
stringify!(a) | ||
) | ||
); | ||
assert_eq!( | ||
unsafe { &(*(::std::ptr::null::<union_b>())).b as *const _ as usize }, | ||
0usize, | ||
concat!( | ||
"Offset of field: ", | ||
stringify!(union_b), | ||
"::", | ||
stringify!(b) | ||
) | ||
); | ||
} | ||
impl Default for union_b { | ||
fn default() -> Self { | ||
unsafe { ::std::mem::zeroed() } | ||
} | ||
} | ||
pub type b = union_b; | ||
pub const enum_c_A: enum_c = 0; | ||
pub type enum_c = ::std::os::raw::c_uint; | ||
extern "C" { | ||
pub fn takes_a(arg: a); | ||
} | ||
extern "C" { | ||
pub fn takes_b(arg: b); | ||
} | ||
extern "C" { | ||
pub fn takes_c(arg: enum_c); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// bindgen-flags: --c-naming | ||
|
||
typedef const struct a { | ||
int a; | ||
} *a; | ||
|
||
union b { | ||
int a; | ||
int b; | ||
}; | ||
typedef union b b; | ||
|
||
enum c { | ||
A, | ||
}; | ||
|
||
void takes_a(a arg) {} | ||
void takes_b(b arg) {} | ||
void takes_c(enum c arg) {} |