Skip to content

Commit 72059ec

Browse files
committed
ir: consider all nested definitions inside structs to be inner types.
Fixes rust-lang#643
1 parent 5b74655 commit 72059ec

File tree

3 files changed

+228
-10
lines changed

3 files changed

+228
-10
lines changed

src/ir/comp.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -588,21 +588,19 @@ impl CompInfo {
588588
CXCursor_ClassTemplate |
589589
CXCursor_ClassDecl => {
590590
// We can find non-semantic children here, clang uses a
591-
// StructDecl to note incomplete structs that hasn't been
592-
// forward-declared before, see:
591+
// StructDecl to note incomplete structs that haven't been
592+
// forward-declared before, see [1].
593593
//
594594
// Also, clang seems to scope struct definitions inside
595-
// unions to the whole translation unit. Since those are
596-
// anonymous, let's just assume that if the cursor we've
597-
// found is a definition it's a valid inner type.
595+
// unions, and other named struct definitions inside other
596+
// structs to the whole translation unit.
598597
//
599-
// Note that doing this could be always ok, but let's just
600-
// keep the union check for now.
598+
// Let's just assume that if the cursor we've found is a
599+
// definition, it's a valid inner type.
601600
//
602-
// https://github.com/servo/rust-bindgen/issues/482
601+
// [1]: https://github.com/servo/rust-bindgen/issues/482
603602
let is_inner_struct = cur.semantic_parent() == cursor ||
604-
(kind == CompKind::Union &&
605-
cur.is_definition());
603+
cur.is_definition();
606604
if !is_inner_struct {
607605
return CXChildVisit_Continue;
608606
}
Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
/* automatically generated by rust-bindgen */
2+
3+
4+
#![allow(non_snake_case)]
5+
6+
7+
#[repr(C)]
8+
#[derive(Default)]
9+
pub struct __IncompleteArrayField<T>(::std::marker::PhantomData<T>);
10+
impl <T> __IncompleteArrayField<T> {
11+
#[inline]
12+
pub fn new() -> Self {
13+
__IncompleteArrayField(::std::marker::PhantomData)
14+
}
15+
#[inline]
16+
pub unsafe fn as_ptr(&self) -> *const T { ::std::mem::transmute(self) }
17+
#[inline]
18+
pub unsafe fn as_mut_ptr(&mut self) -> *mut T {
19+
::std::mem::transmute(self)
20+
}
21+
#[inline]
22+
pub unsafe fn as_slice(&self, len: usize) -> &[T] {
23+
::std::slice::from_raw_parts(self.as_ptr(), len)
24+
}
25+
#[inline]
26+
pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] {
27+
::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len)
28+
}
29+
}
30+
impl <T> ::std::fmt::Debug for __IncompleteArrayField<T> {
31+
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
32+
fmt.write_str("__IncompleteArrayField")
33+
}
34+
}
35+
impl <T> ::std::clone::Clone for __IncompleteArrayField<T> {
36+
#[inline]
37+
fn clone(&self) -> Self { Self::new() }
38+
}
39+
impl <T> ::std::marker::Copy for __IncompleteArrayField<T> { }
40+
#[repr(C)]
41+
#[derive(Debug, Copy)]
42+
pub struct rte_ring {
43+
/**< Name of the ring. */
44+
pub name: [::std::os::raw::c_char; 4usize],
45+
/**< Flags supplied at creation. */
46+
pub flags: ::std::os::raw::c_int,
47+
pub memzone: *mut rte_memzone,
48+
pub prod: rte_ring_prod,
49+
pub cons: rte_ring_cons,
50+
/**< Memory space of ring starts here.
51+
* not volatile so need to be careful
52+
* about compiler re-ordering */
53+
pub ring: __IncompleteArrayField<*mut ::std::os::raw::c_void>,
54+
}
55+
/** Ring producer status. */
56+
#[repr(C)]
57+
#[derive(Debug, Default, Copy)]
58+
pub struct rte_ring_prod {
59+
/**< Maximum items before EDQUOT. */
60+
pub watermark: u32,
61+
/**< True, if single producer. */
62+
pub sp_enqueue: u32,
63+
/**< Size of ring. */
64+
pub size: u32,
65+
/**< Mask (size-1) of ring. */
66+
pub mask: u32,
67+
/**< Producer head. */
68+
pub head: u32,
69+
/**< Producer tail. */
70+
pub tail: u32,
71+
}
72+
#[test]
73+
fn bindgen_test_layout_rte_ring_prod() {
74+
assert_eq!(::std::mem::size_of::<rte_ring_prod>() , 24usize , concat ! (
75+
"Size of: " , stringify ! ( rte_ring_prod ) ));
76+
assert_eq! (::std::mem::align_of::<rte_ring_prod>() , 4usize , concat ! (
77+
"Alignment of " , stringify ! ( rte_ring_prod ) ));
78+
assert_eq! (unsafe {
79+
& ( * ( 0 as * const rte_ring_prod ) ) . watermark as * const
80+
_ as usize } , 0usize , concat ! (
81+
"Alignment of field: " , stringify ! ( rte_ring_prod ) , "::"
82+
, stringify ! ( watermark ) ));
83+
assert_eq! (unsafe {
84+
& ( * ( 0 as * const rte_ring_prod ) ) . sp_enqueue as * const
85+
_ as usize } , 4usize , concat ! (
86+
"Alignment of field: " , stringify ! ( rte_ring_prod ) , "::"
87+
, stringify ! ( sp_enqueue ) ));
88+
assert_eq! (unsafe {
89+
& ( * ( 0 as * const rte_ring_prod ) ) . size as * const _ as
90+
usize } , 8usize , concat ! (
91+
"Alignment of field: " , stringify ! ( rte_ring_prod ) , "::"
92+
, stringify ! ( size ) ));
93+
assert_eq! (unsafe {
94+
& ( * ( 0 as * const rte_ring_prod ) ) . mask as * const _ as
95+
usize } , 12usize , concat ! (
96+
"Alignment of field: " , stringify ! ( rte_ring_prod ) , "::"
97+
, stringify ! ( mask ) ));
98+
assert_eq! (unsafe {
99+
& ( * ( 0 as * const rte_ring_prod ) ) . head as * const _ as
100+
usize } , 16usize , concat ! (
101+
"Alignment of field: " , stringify ! ( rte_ring_prod ) , "::"
102+
, stringify ! ( head ) ));
103+
assert_eq! (unsafe {
104+
& ( * ( 0 as * const rte_ring_prod ) ) . tail as * const _ as
105+
usize } , 20usize , concat ! (
106+
"Alignment of field: " , stringify ! ( rte_ring_prod ) , "::"
107+
, stringify ! ( tail ) ));
108+
}
109+
impl Clone for rte_ring_prod {
110+
fn clone(&self) -> Self { *self }
111+
}
112+
/** Ring consumer status. */
113+
#[repr(C)]
114+
#[derive(Debug, Default, Copy)]
115+
pub struct rte_ring_cons {
116+
/**< True, if single consumer. */
117+
pub sc_dequeue: u32,
118+
/**< Size of the ring. */
119+
pub size: u32,
120+
/**< Mask (size-1) of ring. */
121+
pub mask: u32,
122+
/**< Consumer head. */
123+
pub head: u32,
124+
/**< Consumer tail. */
125+
pub tail: u32,
126+
}
127+
#[test]
128+
fn bindgen_test_layout_rte_ring_cons() {
129+
assert_eq!(::std::mem::size_of::<rte_ring_cons>() , 20usize , concat ! (
130+
"Size of: " , stringify ! ( rte_ring_cons ) ));
131+
assert_eq! (::std::mem::align_of::<rte_ring_cons>() , 4usize , concat ! (
132+
"Alignment of " , stringify ! ( rte_ring_cons ) ));
133+
assert_eq! (unsafe {
134+
& ( * ( 0 as * const rte_ring_cons ) ) . sc_dequeue as * const
135+
_ as usize } , 0usize , concat ! (
136+
"Alignment of field: " , stringify ! ( rte_ring_cons ) , "::"
137+
, stringify ! ( sc_dequeue ) ));
138+
assert_eq! (unsafe {
139+
& ( * ( 0 as * const rte_ring_cons ) ) . size as * const _ as
140+
usize } , 4usize , concat ! (
141+
"Alignment of field: " , stringify ! ( rte_ring_cons ) , "::"
142+
, stringify ! ( size ) ));
143+
assert_eq! (unsafe {
144+
& ( * ( 0 as * const rte_ring_cons ) ) . mask as * const _ as
145+
usize } , 8usize , concat ! (
146+
"Alignment of field: " , stringify ! ( rte_ring_cons ) , "::"
147+
, stringify ! ( mask ) ));
148+
assert_eq! (unsafe {
149+
& ( * ( 0 as * const rte_ring_cons ) ) . head as * const _ as
150+
usize } , 12usize , concat ! (
151+
"Alignment of field: " , stringify ! ( rte_ring_cons ) , "::"
152+
, stringify ! ( head ) ));
153+
assert_eq! (unsafe {
154+
& ( * ( 0 as * const rte_ring_cons ) ) . tail as * const _ as
155+
usize } , 16usize , concat ! (
156+
"Alignment of field: " , stringify ! ( rte_ring_cons ) , "::"
157+
, stringify ! ( tail ) ));
158+
}
159+
impl Clone for rte_ring_cons {
160+
fn clone(&self) -> Self { *self }
161+
}
162+
#[test]
163+
fn bindgen_test_layout_rte_ring() {
164+
assert_eq!(::std::mem::size_of::<rte_ring>() , 64usize , concat ! (
165+
"Size of: " , stringify ! ( rte_ring ) ));
166+
assert_eq! (::std::mem::align_of::<rte_ring>() , 8usize , concat ! (
167+
"Alignment of " , stringify ! ( rte_ring ) ));
168+
}
169+
impl Clone for rte_ring {
170+
fn clone(&self) -> Self { *self }
171+
}
172+
impl Default for rte_ring {
173+
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
174+
}
175+
#[repr(C)]
176+
#[derive(Debug, Default, Copy)]
177+
pub struct rte_memzone {
178+
pub _address: u8,
179+
}
180+
impl Clone for rte_memzone {
181+
fn clone(&self) -> Self { *self }
182+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
typedef unsigned uint32_t;
2+
#define __rte_cache_aligned
3+
4+
// Insert your (minimal) C/C++ header here
5+
struct rte_ring {
6+
/*
7+
* Note: this field kept the RTE_MEMZONE_NAMESIZE size due to ABI
8+
* compatibility requirements, it could be changed to RTE_RING_NAMESIZE
9+
* next time the ABI changes
10+
*/
11+
char name[4]; /**< Name of the ring. */
12+
int flags; /**< Flags supplied at creation. */
13+
const struct rte_memzone *memzone;
14+
/**< Memzone, if any, containing the rte_ring */
15+
16+
/** Ring producer status. */
17+
struct prod {
18+
uint32_t watermark; /**< Maximum items before EDQUOT. */
19+
uint32_t sp_enqueue; /**< True, if single producer. */
20+
uint32_t size; /**< Size of ring. */
21+
uint32_t mask; /**< Mask (size-1) of ring. */
22+
volatile uint32_t head; /**< Producer head. */
23+
volatile uint32_t tail; /**< Producer tail. */
24+
} prod __rte_cache_aligned;
25+
26+
/** Ring consumer status. */
27+
struct cons {
28+
uint32_t sc_dequeue; /**< True, if single consumer. */
29+
uint32_t size; /**< Size of the ring. */
30+
uint32_t mask; /**< Mask (size-1) of ring. */
31+
volatile uint32_t head; /**< Consumer head. */
32+
volatile uint32_t tail; /**< Consumer tail. */
33+
} cons;
34+
35+
void *ring[] __rte_cache_aligned; /**< Memory space of ring starts here.
36+
* not volatile so need to be careful
37+
* about compiler re-ordering */
38+
};

0 commit comments

Comments
 (0)