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! missing {
124 ($($(#[$attr:meta])* pub enum $i:ident {})*) => ($(
125 $(#[$attr])* #[allow(missing_copy_implementations)] pub enum $i { }
126 )*);
127}
128
129macro_rules! e {
130 ($($(#[$attr:meta])* pub enum $i:ident { $($field:tt)* })*) => ($(
131 __item! {
132 #[cfg_attr(feature = "extra_traits", derive(Debug, Eq, Hash, PartialEq))]
133 $(#[$attr])*
134 pub enum $i { $($field)* }
135 }
136 impl ::Copy for $i {}
137 impl ::Clone for $i {
138 fn clone(&self) -> $i { *self }
139 }
140 )*);
141}
142
143macro_rules! s_paren {
144 ($($(#[$attr:meta])* pub struct $i:ident ( $($field:tt)* ); )* ) => ($(
145 __item! {
146 #[cfg_attr(feature = "extra_traits", derive(Debug, Eq, Hash, PartialEq))]
147 $(#[$attr])*
148 pub struct $i ( $($field)* );
149 }
150 impl ::Copy for $i {}
151 impl ::Clone for $i {
152 fn clone(&self) -> $i { *self }
153 }
154 )*);
155}
156
157cfg_if! {
185 if #[cfg(libc_const_extern_fn)] {
186 macro_rules! f {
187 ($($(#[$attr:meta])* pub $({$constness:ident})* fn $i:ident(
188 $($arg:ident: $argty:ty),*
189 ) -> $ret:ty {
190 $($body:stmt);*
191 })*) => ($(
192 #[inline]
193 $(#[$attr])*
194 pub $($constness)* unsafe extern fn $i($($arg: $argty),*
195 ) -> $ret {
196 $($body);*
197 }
198 )*)
199 }
200
201 macro_rules! safe_f {
202 ($($(#[$attr:meta])* pub $({$constness:ident})* fn $i:ident(
203 $($arg:ident: $argty:ty),*
204 ) -> $ret:ty {
205 $($body:stmt);*
206 })*) => ($(
207 #[inline]
208 $(#[$attr])*
209 pub $($constness)* extern fn $i($($arg: $argty),*
210 ) -> $ret {
211 $($body);*
212 }
213 )*)
214 }
215
216 macro_rules! const_fn {
217 ($($(#[$attr:meta])* $({$constness:ident})* fn $i:ident(
218 $($arg:ident: $argty:ty),*
219 ) -> $ret:ty {
220 $($body:stmt);*
221 })*) => ($(
222 #[inline]
223 $(#[$attr])*
224 $($constness)* fn $i($($arg: $argty),*
225 ) -> $ret {
226 $($body);*
227 }
228 )*)
229 }
230
231 } else {
232 macro_rules! f {
233 ($($(#[$attr:meta])* pub $({$constness:ident})* fn $i:ident(
234 $($arg:ident: $argty:ty),*
235 ) -> $ret:ty {
236 $($body:stmt);*
237 })*) => ($(
238 #[inline]
239 $(#[$attr])*
240 pub unsafe extern fn $i($($arg: $argty),*
241 ) -> $ret {
242 $($body);*
243 }
244 )*)
245 }
246
247 macro_rules! safe_f {
248 ($($(#[$attr:meta])* pub $({$constness:ident})* fn $i:ident(
249 $($arg:ident: $argty:ty),*
250 ) -> $ret:ty {
251 $($body:stmt);*
252 })*) => ($(
253 #[inline]
254 $(#[$attr])*
255 pub extern fn $i($($arg: $argty),*
256 ) -> $ret {
257 $($body);*
258 }
259 )*)
260 }
261
262 macro_rules! const_fn {
263 ($($(#[$attr:meta])* $({$constness:ident})* fn $i:ident(
264 $($arg:ident: $argty:ty),*
265 ) -> $ret:ty {
266 $($body:stmt);*
267 })*) => ($(
268 #[inline]
269 $(#[$attr])*
270 fn $i($($arg: $argty),*
271 ) -> $ret {
272 $($body);*
273 }
274 )*)
275 }
276 }
277}
278
279macro_rules! __item {
280 ($i:item) => {
281 $i
282 };
283}
284
285macro_rules! align_const {
286 ($($(#[$attr:meta])*
287 pub const $name:ident : $t1:ty
288 = $t2:ident { $($field:tt)* };)*) => ($(
289 #[cfg(libc_align)]
290 $(#[$attr])*
291 pub const $name : $t1 = $t2 {
292 $($field)*
293 };
294 #[cfg(not(libc_align))]
295 $(#[$attr])*
296 pub const $name : $t1 = $t2 {
297 $($field)*
298 __align: [],
299 };
300 )*)
301}
302
303macro_rules! deprecated_mach {
305 (pub const $id:ident: $ty:ty = $expr:expr;) => {
306 #[deprecated(
307 since = "0.2.55",
308 note = "Use the `mach2` crate instead",
309 )]
310 #[allow(deprecated)]
311 pub const $id: $ty = $expr;
312 };
313 ($(pub const $id:ident: $ty:ty = $expr:expr;)*) => {
314 $(
315 deprecated_mach!(
316 pub const $id: $ty = $expr;
317 );
318 )*
319 };
320 (pub type $id:ident = $ty:ty;) => {
321 #[deprecated(
322 since = "0.2.55",
323 note = "Use the `mach2` crate instead",
324 )]
325 #[allow(deprecated)]
326 pub type $id = $ty;
327 };
328 ($(pub type $id:ident = $ty:ty;)*) => {
329 $(
330 deprecated_mach!(
331 pub type $id = $ty;
332 );
333 )*
334 }
335}
336
337#[cfg(not(libc_ptr_addr_of))]
338macro_rules! ptr_addr_of {
339 ($place:expr) => {
340 &$place
341 };
342}
343
344#[cfg(libc_ptr_addr_of)]
345macro_rules! ptr_addr_of {
346 ($place:expr) => {
347 ::core::ptr::addr_of!($place)
348 };
349}