1macro_rules! cfg_if {
10 ($(
12 if #[cfg($($meta:meta),*)] { $($it:item)* }
13 ) else * else {
14 $($it2:item)*
15 }) => {
16 cfg_if! {
17 @__items
18 () ;
19 $( ( ($($meta),*) ($($it)*) ), )*
20 ( () ($($it2)*) ),
21 }
22 };
23
24 (
26 if #[cfg($($i_met:meta),*)] { $($i_it:item)* }
27 $(
28 else if #[cfg($($e_met:meta),*)] { $($e_it:item)* }
29 )*
30 ) => {
31 cfg_if! {
32 @__items
33 () ;
34 ( ($($i_met),*) ($($i_it)*) ),
35 $( ( ($($e_met),*) ($($e_it)*) ), )*
36 ( () () ),
37 }
38 };
39
40 (@__items ($($not:meta,)*) ; ) => {};
45 (@__items ($($not:meta,)*) ; ( ($($m:meta),*) ($($it:item)*) ),
46 $($rest:tt)*) => {
47 cfg_if! { @__apply cfg(all($($m,)* not(any($($not),*)))), $($it)* }
51
52 cfg_if! { @__items ($($not,)* $($m,)*) ; $($rest)* }
56 };
57
58 (@__apply $m:meta, $($it:item)*) => {
60 $(#[$m] $it)*
61 };
62}
63
64macro_rules! s {
65 ($($(#[$attr:meta])* pub $t:ident $i:ident { $($field:tt)* })*) => ($(
66 s!(it: $(#[$attr])* pub $t $i { $($field)* });
67 )*);
68 (it: $(#[$attr:meta])* pub union $i:ident { $($field:tt)* }) => (
69 compile_error!("unions cannot derive extra traits, use s_no_extra_traits instead");
70 );
71 (it: $(#[$attr:meta])* pub struct $i:ident { $($field:tt)* }) => (
72 __item! {
73 #[repr(C)]
74 #[cfg_attr(feature = "extra_traits", derive(Debug, Eq, Hash, PartialEq))]
75 #[allow(deprecated)]
76 $(#[$attr])*
77 pub struct $i { $($field)* }
78 }
79 #[allow(deprecated)]
80 impl ::Copy for $i {}
81 #[allow(deprecated)]
82 impl ::Clone for $i {
83 fn clone(&self) -> $i { *self }
84 }
85 );
86}
87
88macro_rules! s_no_extra_traits {
89 ($($(#[$attr:meta])* pub $t:ident $i:ident { $($field:tt)* })*) => ($(
90 s_no_extra_traits!(it: $(#[$attr])* pub $t $i { $($field)* });
91 )*);
92 (it: $(#[$attr:meta])* pub union $i:ident { $($field:tt)* }) => (
93 cfg_if! {
94 if #[cfg(libc_union)] {
95 __item! {
96 #[repr(C)]
97 $(#[$attr])*
98 pub union $i { $($field)* }
99 }
100
101 impl ::Copy for $i {}
102 impl ::Clone for $i {
103 fn clone(&self) -> $i { *self }
104 }
105 }
106 }
107 );
108 (it: $(#[$attr:meta])* pub struct $i:ident { $($field:tt)* }) => (
109 __item! {
110 #[repr(C)]
111 $(#[$attr])*
112 pub struct $i { $($field)* }
113 }
114 #[allow(deprecated)]
115 impl ::Copy for $i {}
116 #[allow(deprecated)]
117 impl ::Clone for $i {
118 fn clone(&self) -> $i { *self }
119 }
120 );
121}
122
123macro_rules! e {
124 ($($(#[$attr:meta])* pub enum $i:ident { $($field:tt)* })*) => ($(
125 __item! {
126 #[cfg_attr(feature = "extra_traits", derive(Debug, Eq, Hash, PartialEq))]
127 $(#[$attr])*
128 pub enum $i { $($field)* }
129 }
130 impl ::Copy for $i {}
131 impl ::Clone for $i {
132 fn clone(&self) -> $i { *self }
133 }
134 )*);
135}
136
137macro_rules! s_paren {
138 ($($(#[$attr:meta])* pub struct $i:ident ( $($field:tt)* ); )* ) => ($(
139 __item! {
140 #[cfg_attr(feature = "extra_traits", derive(Debug, Eq, Hash, PartialEq))]
141 $(#[$attr])*
142 pub struct $i ( $($field)* );
143 }
144 impl ::Copy for $i {}
145 impl ::Clone for $i {
146 fn clone(&self) -> $i { *self }
147 }
148 )*);
149}
150
151cfg_if! {
179 if #[cfg(libc_const_extern_fn)] {
180 macro_rules! f {
181 ($($(#[$attr:meta])* pub $({$constness:ident})* fn $i:ident(
182 $($arg:ident: $argty:ty),*
183 ) -> $ret:ty {
184 $($body:stmt);*
185 })*) => ($(
186 #[inline]
187 $(#[$attr])*
188 pub $($constness)* unsafe extern fn $i($($arg: $argty),*
189 ) -> $ret {
190 $($body);*
191 }
192 )*)
193 }
194
195 macro_rules! safe_f {
196 ($($(#[$attr:meta])* pub $({$constness:ident})* fn $i:ident(
197 $($arg:ident: $argty:ty),*
198 ) -> $ret:ty {
199 $($body:stmt);*
200 })*) => ($(
201 #[inline]
202 $(#[$attr])*
203 pub $($constness)* extern fn $i($($arg: $argty),*
204 ) -> $ret {
205 $($body);*
206 }
207 )*)
208 }
209
210 macro_rules! const_fn {
211 ($($(#[$attr:meta])* $({$constness:ident})* fn $i:ident(
212 $($arg:ident: $argty:ty),*
213 ) -> $ret:ty {
214 $($body:stmt);*
215 })*) => ($(
216 #[inline]
217 $(#[$attr])*
218 $($constness)* fn $i($($arg: $argty),*
219 ) -> $ret {
220 $($body);*
221 }
222 )*)
223 }
224
225 } else {
226 macro_rules! f {
227 ($($(#[$attr:meta])* pub $({$constness:ident})* fn $i:ident(
228 $($arg:ident: $argty:ty),*
229 ) -> $ret:ty {
230 $($body:stmt);*
231 })*) => ($(
232 #[inline]
233 $(#[$attr])*
234 pub unsafe extern fn $i($($arg: $argty),*
235 ) -> $ret {
236 $($body);*
237 }
238 )*)
239 }
240
241 macro_rules! safe_f {
242 ($($(#[$attr:meta])* pub $({$constness:ident})* fn $i:ident(
243 $($arg:ident: $argty:ty),*
244 ) -> $ret:ty {
245 $($body:stmt);*
246 })*) => ($(
247 #[inline]
248 $(#[$attr])*
249 pub extern fn $i($($arg: $argty),*
250 ) -> $ret {
251 $($body);*
252 }
253 )*)
254 }
255
256 macro_rules! const_fn {
257 ($($(#[$attr:meta])* $({$constness:ident})* fn $i:ident(
258 $($arg:ident: $argty:ty),*
259 ) -> $ret:ty {
260 $($body:stmt);*
261 })*) => ($(
262 #[inline]
263 $(#[$attr])*
264 fn $i($($arg: $argty),*
265 ) -> $ret {
266 $($body);*
267 }
268 )*)
269 }
270 }
271}
272
273macro_rules! __item {
274 ($i:item) => {
275 $i
276 };
277}
278
279macro_rules! align_const {
280 ($($(#[$attr:meta])*
281 pub const $name:ident : $t1:ty
282 = $t2:ident { $($field:tt)* };)*) => ($(
283 #[cfg(libc_align)]
284 $(#[$attr])*
285 pub const $name : $t1 = $t2 {
286 $($field)*
287 };
288 #[cfg(not(libc_align))]
289 $(#[$attr])*
290 pub const $name : $t1 = $t2 {
291 $($field)*
292 __align: [],
293 };
294 )*)
295}
296
297macro_rules! deprecated_mach {
299 (pub const $id:ident: $ty:ty = $expr:expr;) => {
300 #[deprecated(
301 since = "0.2.55",
302 note = "Use the `mach2` crate instead",
303 )]
304 #[allow(deprecated)]
305 pub const $id: $ty = $expr;
306 };
307 ($(pub const $id:ident: $ty:ty = $expr:expr;)*) => {
308 $(
309 deprecated_mach!(
310 pub const $id: $ty = $expr;
311 );
312 )*
313 };
314 (pub type $id:ident = $ty:ty;) => {
315 #[deprecated(
316 since = "0.2.55",
317 note = "Use the `mach2` crate instead",
318 )]
319 #[allow(deprecated)]
320 pub type $id = $ty;
321 };
322 ($(pub type $id:ident = $ty:ty;)*) => {
323 $(
324 deprecated_mach!(
325 pub type $id = $ty;
326 );
327 )*
328 }
329}
330
331#[cfg(not(libc_ptr_addr_of))]
332macro_rules! ptr_addr_of {
333 ($place:expr) => {
334 &$place
335 };
336}
337
338#[cfg(libc_ptr_addr_of)]
339macro_rules! ptr_addr_of {
340 ($place:expr) => {
341 ::core::ptr::addr_of!($place)
342 };
343}