Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2471,7 +2471,8 @@ impl TryToRustTy for Type {
TypeKind::Int(ik) => {
match ik {
IntKind::Bool => Ok(aster::ty::TyBuilder::new().bool()),
IntKind::Char => Ok(raw_type(ctx, "c_schar")),
IntKind::Char { .. } => Ok(raw_type(ctx, "c_char")),
IntKind::SChar => Ok(raw_type(ctx, "c_schar")),
IntKind::UChar => Ok(raw_type(ctx, "c_uchar")),
IntKind::Short => Ok(raw_type(ctx, "c_short")),
IntKind::UShort => Ok(raw_type(ctx, "c_ushort")),
Expand Down
34 changes: 32 additions & 2 deletions src/ir/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1090,8 +1090,38 @@ impl<'ctx> BindgenContext<'ctx> {
CXType_Bool => TypeKind::Int(IntKind::Bool),
CXType_Int => TypeKind::Int(IntKind::Int),
CXType_UInt => TypeKind::Int(IntKind::UInt),
CXType_SChar | CXType_Char_S => TypeKind::Int(IntKind::Char),
CXType_UChar | CXType_Char_U => TypeKind::Int(IntKind::UChar),
CXType_SChar | CXType_Char_S |
CXType_UChar | CXType_Char_U => {
let spelling = ty.spelling();

debug_assert!(spelling.contains("char"),
"This is the canonical type, so no aliases or \
typedefs!");

let signed = match ty.kind() {
CXType_SChar | CXType_Char_S => true,
_ => false,
};

// Clang only gives us the signedness of the target platform.
//
// Match the spelling for common cases we can handle
// cross-platform.
match &*spelling {
"char" | "const char" => {
TypeKind::Int(IntKind::Char {
is_signed: signed,
})
},
_ => {
if signed {
TypeKind::Int(IntKind::SChar)
} else {
TypeKind::Int(IntKind::UChar)
}
},
}
}
CXType_Short => TypeKind::Int(IntKind::Short),
CXType_UShort => TypeKind::Int(IntKind::UShort),
CXType_WChar | CXType_Char16 => TypeKind::Int(IntKind::U16),
Expand Down
16 changes: 12 additions & 4 deletions src/ir/int.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@ pub enum IntKind {
/// A `bool`.
Bool,

/// A `char`.
Char,
/// A `signed char`.
SChar,

/// An `unsigned char`.
UChar,

/// A platform-dependent `char` type, with the signedness support.
Char {
/// Whether the char is signed for the target platform.
is_signed: bool,
},

/// A `short`.
Short,

Expand Down Expand Up @@ -84,9 +90,11 @@ impl IntKind {
Bool | UChar | UShort | UInt | ULong | ULongLong | U8 | U16 |
U32 | U64 | U128 => false,

Char | Short | Int | Long | LongLong | I8 | I16 | I32 | I64 |
SChar | Short | Int | Long | LongLong | I8 | I16 | I32 | I64 |
I128 => true,

Char { is_signed } => is_signed,

Custom { is_signed, .. } => is_signed,
}
}
Expand All @@ -97,7 +105,7 @@ impl IntKind {
pub fn known_size(&self) -> Option<usize> {
use self::IntKind::*;
Some(match *self {
Bool | UChar | Char | U8 | I8 => 1,
Bool | UChar | SChar | U8 | I8 | Char { .. } => 1,
U16 | I16 => 2,
U32 | I32 => 4,
U64 | I64 => 8,
Expand Down
6 changes: 3 additions & 3 deletions tests/expectations/tests/anonymous-template-types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ impl <T> Default for Foo<T> {
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct Bar {
pub member: ::std::os::raw::c_schar,
pub member: ::std::os::raw::c_char,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
Expand All @@ -28,6 +28,6 @@ impl <V> Default for Quux<V> {
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct Lobo {
pub also_member: ::std::os::raw::c_schar,
pub also_member: ::std::os::raw::c_char,
}
pub type AliasWithAnonType = ::std::os::raw::c_schar;
pub type AliasWithAnonType = ::std::os::raw::c_char;
2 changes: 1 addition & 1 deletion tests/expectations/tests/arg_keyword.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@

extern "C" {
#[link_name = "_Z3fooPKc"]
pub fn foo(type_: *const ::std::os::raw::c_schar);
pub fn foo(type_: *const ::std::os::raw::c_char);
}
16 changes: 8 additions & 8 deletions tests/expectations/tests/bitfield-method-same-name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,22 @@ fn bindgen_test_layout_Foo() {
}
extern "C" {
#[link_name = "_ZN3Foo4typeEv"]
pub fn Foo_type(this: *mut Foo) -> ::std::os::raw::c_schar;
pub fn Foo_type(this: *mut Foo) -> ::std::os::raw::c_char;
}
extern "C" {
#[link_name = "_ZN3Foo9set_type_Ec"]
pub fn Foo_set_type_(this: *mut Foo, c: ::std::os::raw::c_schar);
pub fn Foo_set_type_(this: *mut Foo, c: ::std::os::raw::c_char);
}
extern "C" {
#[link_name = "_ZN3Foo8set_typeEc"]
pub fn Foo_set_type(this: *mut Foo, c: ::std::os::raw::c_schar);
pub fn Foo_set_type(this: *mut Foo, c: ::std::os::raw::c_char);
}
impl Clone for Foo {
fn clone(&self) -> Self { *self }
}
impl Foo {
#[inline]
pub fn type__bindgen_bitfield(&self) -> ::std::os::raw::c_schar {
pub fn type__bindgen_bitfield(&self) -> ::std::os::raw::c_char {
let mask = 7usize as u8;
let field_val: u8 =
unsafe { ::std::mem::transmute(self._bitfield_1) };
Expand All @@ -43,7 +43,7 @@ impl Foo {
}
#[inline]
pub fn set_type__bindgen_bitfield(&mut self,
val: ::std::os::raw::c_schar) {
val: ::std::os::raw::c_char) {
let mask = 7usize as u8;
let val = val as u8 as u8;
let mut field_val: u8 =
Expand All @@ -53,15 +53,15 @@ impl Foo {
self._bitfield_1 = unsafe { ::std::mem::transmute(field_val) };
}
#[inline]
pub unsafe fn type_(&mut self) -> ::std::os::raw::c_schar {
pub unsafe fn type_(&mut self) -> ::std::os::raw::c_char {
Foo_type(self)
}
#[inline]
pub unsafe fn set_type_(&mut self, c: ::std::os::raw::c_schar) {
pub unsafe fn set_type_(&mut self, c: ::std::os::raw::c_char) {
Foo_set_type_(self, c)
}
#[inline]
pub unsafe fn set_type(&mut self, c: ::std::os::raw::c_schar) {
pub unsafe fn set_type(&mut self, c: ::std::os::raw::c_char) {
Foo_set_type(self, c)
}
}
95 changes: 95 additions & 0 deletions tests/expectations/tests/char.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/* automatically generated by rust-bindgen */


#![allow(non_snake_case)]


pub type Char = ::std::os::raw::c_char;
pub type SChar = ::std::os::raw::c_schar;
pub type UChar = ::std::os::raw::c_uchar;
#[repr(C)]
#[derive(Debug, Default, Copy)]
pub struct Test {
pub ch: ::std::os::raw::c_char,
pub u: ::std::os::raw::c_uchar,
pub d: ::std::os::raw::c_schar,
pub cch: ::std::os::raw::c_char,
pub cu: ::std::os::raw::c_uchar,
pub cd: ::std::os::raw::c_schar,
pub Cch: Char,
pub Cu: UChar,
pub Cd: SChar,
pub Ccch: Char,
pub Ccu: UChar,
pub Ccd: SChar,
}
#[test]
fn bindgen_test_layout_Test() {
assert_eq!(::std::mem::size_of::<Test>() , 12usize , concat ! (
"Size of: " , stringify ! ( Test ) ));
assert_eq! (::std::mem::align_of::<Test>() , 1usize , concat ! (
"Alignment of " , stringify ! ( Test ) ));
assert_eq! (unsafe {
& ( * ( 0 as * const Test ) ) . ch as * const _ as usize } ,
0usize , concat ! (
"Alignment of field: " , stringify ! ( Test ) , "::" ,
stringify ! ( ch ) ));
assert_eq! (unsafe {
& ( * ( 0 as * const Test ) ) . u as * const _ as usize } ,
1usize , concat ! (
"Alignment of field: " , stringify ! ( Test ) , "::" ,
stringify ! ( u ) ));
assert_eq! (unsafe {
& ( * ( 0 as * const Test ) ) . d as * const _ as usize } ,
2usize , concat ! (
"Alignment of field: " , stringify ! ( Test ) , "::" ,
stringify ! ( d ) ));
assert_eq! (unsafe {
& ( * ( 0 as * const Test ) ) . cch as * const _ as usize } ,
3usize , concat ! (
"Alignment of field: " , stringify ! ( Test ) , "::" ,
stringify ! ( cch ) ));
assert_eq! (unsafe {
& ( * ( 0 as * const Test ) ) . cu as * const _ as usize } ,
4usize , concat ! (
"Alignment of field: " , stringify ! ( Test ) , "::" ,
stringify ! ( cu ) ));
assert_eq! (unsafe {
& ( * ( 0 as * const Test ) ) . cd as * const _ as usize } ,
5usize , concat ! (
"Alignment of field: " , stringify ! ( Test ) , "::" ,
stringify ! ( cd ) ));
assert_eq! (unsafe {
& ( * ( 0 as * const Test ) ) . Cch as * const _ as usize } ,
6usize , concat ! (
"Alignment of field: " , stringify ! ( Test ) , "::" ,
stringify ! ( Cch ) ));
assert_eq! (unsafe {
& ( * ( 0 as * const Test ) ) . Cu as * const _ as usize } ,
7usize , concat ! (
"Alignment of field: " , stringify ! ( Test ) , "::" ,
stringify ! ( Cu ) ));
assert_eq! (unsafe {
& ( * ( 0 as * const Test ) ) . Cd as * const _ as usize } ,
8usize , concat ! (
"Alignment of field: " , stringify ! ( Test ) , "::" ,
stringify ! ( Cd ) ));
assert_eq! (unsafe {
& ( * ( 0 as * const Test ) ) . Ccch as * const _ as usize } ,
9usize , concat ! (
"Alignment of field: " , stringify ! ( Test ) , "::" ,
stringify ! ( Ccch ) ));
assert_eq! (unsafe {
& ( * ( 0 as * const Test ) ) . Ccu as * const _ as usize } ,
10usize , concat ! (
"Alignment of field: " , stringify ! ( Test ) , "::" ,
stringify ! ( Ccu ) ));
assert_eq! (unsafe {
& ( * ( 0 as * const Test ) ) . Ccd as * const _ as usize } ,
11usize , concat ! (
"Alignment of field: " , stringify ! ( Test ) , "::" ,
stringify ! ( Ccd ) ));
}
impl Clone for Test {
fn clone(&self) -> Self { *self }
}
16 changes: 8 additions & 8 deletions tests/expectations/tests/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl <T> ::std::fmt::Debug for __BindgenUnionField<T> {
#[repr(C)]
pub struct C {
pub a: ::std::os::raw::c_int,
pub big_array: [::std::os::raw::c_schar; 33usize],
pub big_array: [::std::os::raw::c_char; 33usize],
}
#[test]
fn bindgen_test_layout_C() {
Expand All @@ -88,8 +88,8 @@ impl Default for C {
#[repr(C)]
pub struct C_with_zero_length_array {
pub a: ::std::os::raw::c_int,
pub big_array: [::std::os::raw::c_schar; 33usize],
pub zero_length_array: __IncompleteArrayField<::std::os::raw::c_schar>,
pub big_array: [::std::os::raw::c_char; 33usize],
pub zero_length_array: __IncompleteArrayField<::std::os::raw::c_char>,
}
#[test]
fn bindgen_test_layout_C_with_zero_length_array() {
Expand Down Expand Up @@ -124,8 +124,8 @@ impl Default for C_with_zero_length_array {
#[repr(C)]
pub struct C_with_incomplete_array {
pub a: ::std::os::raw::c_int,
pub big_array: [::std::os::raw::c_schar; 33usize],
pub incomplete_array: __IncompleteArrayField<::std::os::raw::c_schar>,
pub big_array: [::std::os::raw::c_char; 33usize],
pub incomplete_array: __IncompleteArrayField<::std::os::raw::c_char>,
}
#[test]
fn bindgen_test_layout_C_with_incomplete_array() {
Expand All @@ -142,9 +142,9 @@ impl Default for C_with_incomplete_array {
#[repr(C)]
pub struct C_with_zero_length_array_and_incomplete_array {
pub a: ::std::os::raw::c_int,
pub big_array: [::std::os::raw::c_schar; 33usize],
pub zero_length_array: __IncompleteArrayField<::std::os::raw::c_schar>,
pub incomplete_array: __IncompleteArrayField<::std::os::raw::c_schar>,
pub big_array: [::std::os::raw::c_char; 33usize],
pub zero_length_array: __IncompleteArrayField<::std::os::raw::c_char>,
pub incomplete_array: __IncompleteArrayField<::std::os::raw::c_char>,
}
#[test]
fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array() {
Expand Down
2 changes: 1 addition & 1 deletion tests/expectations/tests/class_with_typedef.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub struct C {
pub other_ptr: *mut AnotherInt,
}
pub type C_MyInt = ::std::os::raw::c_int;
pub type C_Lookup = *const ::std::os::raw::c_schar;
pub type C_Lookup = *const ::std::os::raw::c_char;
#[test]
fn bindgen_test_layout_C() {
assert_eq!(::std::mem::size_of::<C>() , 72usize , concat ! (
Expand Down
4 changes: 2 additions & 2 deletions tests/expectations/tests/constant-evaluate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub const k: EasyToOverflow = 2147483648;
pub const k_expr: EasyToOverflow = 0;
pub const BAZ: ::std::os::raw::c_longlong = 24;
pub const fuzz: f64 = 51.;
pub const BAZZ: ::std::os::raw::c_schar = 53;
pub const WAT: ::std::os::raw::c_schar = 0;
pub const BAZZ: ::std::os::raw::c_char = 53;
pub const WAT: ::std::os::raw::c_char = 0;
pub const bytestring: &'static [u8; 4usize] = b"Foo\x00";
pub const NOT_UTF8: [u8; 5usize] = [240, 40, 140, 40, 0];
2 changes: 1 addition & 1 deletion tests/expectations/tests/inline_namespace_whitelist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ pub mod root {
pub mod std {
#[allow(unused_imports)]
use self::super::super::root;
pub type string = *const ::std::os::raw::c_schar;
pub type string = *const ::std::os::raw::c_char;
}
}
2 changes: 1 addition & 1 deletion tests/expectations/tests/issue-493.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub struct basic_string {
pub _address: u8,
}
pub type basic_string_size_type = ::std::os::raw::c_ulonglong;
pub type basic_string_value_type = ::std::os::raw::c_schar;
pub type basic_string_value_type = ::std::os::raw::c_char;
pub type basic_string_pointer = *mut basic_string_value_type;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
Expand Down
2 changes: 1 addition & 1 deletion tests/expectations/tests/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl <T> ::std::marker::Copy for __IncompleteArrayField<T> { }
#[repr(C, packed)]
#[derive(Debug, Default, Copy)]
pub struct header {
pub proto: ::std::os::raw::c_schar,
pub proto: ::std::os::raw::c_char,
pub size: ::std::os::raw::c_uint,
pub data: __IncompleteArrayField<::std::os::raw::c_uchar>,
pub __bindgen_padding_0: [u8; 11usize],
Expand Down
2 changes: 1 addition & 1 deletion tests/expectations/tests/layout_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub type rte_mempool_get_count =
#[derive(Debug, Copy)]
pub struct rte_mempool_ops {
/**< Name of mempool ops struct. */
pub name: [::std::os::raw::c_schar; 32usize],
pub name: [::std::os::raw::c_char; 32usize],
/**< Allocate private data. */
pub alloc: rte_mempool_alloc_t,
/**< Free the external pool. */
Expand Down
6 changes: 3 additions & 3 deletions tests/expectations/tests/layout_cmdline_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub struct cmdline_token_ops {
pub parse: ::std::option::Option<unsafe extern "C" fn(arg1:
*mut cmdline_parse_token_hdr_t,
arg2:
*const ::std::os::raw::c_schar,
*const ::std::os::raw::c_char,
arg3:
*mut ::std::os::raw::c_void,
arg4:
Expand All @@ -80,15 +80,15 @@ pub struct cmdline_token_ops {
arg2:
::std::os::raw::c_int,
arg3:
*mut ::std::os::raw::c_schar,
*mut ::std::os::raw::c_char,
arg4:
::std::os::raw::c_uint)
-> ::std::os::raw::c_int>,
/** get help for this token (token, dstbuf, size) */
pub get_help: ::std::option::Option<unsafe extern "C" fn(arg1:
*mut cmdline_parse_token_hdr_t,
arg2:
*mut ::std::os::raw::c_schar,
*mut ::std::os::raw::c_char,
arg3:
::std::os::raw::c_uint)
-> ::std::os::raw::c_int>,
Expand Down
Loading