1 #![allow(unused_macros)]
3 // vendored from the cfg-if crate to avoid breaking ctest
5 // match if/else chains with a final `else`
7 if #[cfg($($meta:meta),*)] { $($it:item)* }
14 $
( ( ($
($meta
),*) ($
($it
)*) ), )*
19 // match if/else chains lacking a final `else`
21 if #[cfg($($i_met:meta),*)] { $($i_it:item)* }
23 else if #[cfg($($e_met:meta),*)] { $($e_it:item)* }
29 ( ($
($i_met
),*) ($
($i_it
)*) ),
30 $
( ( ($
($e_met
),*) ($
($e_it
)*) ), )*
35 // Internal and recursive macro to emit all the items
37 // Collects all the negated cfgs in a list at the beginning and after the
38 // semicolon is all the remaining items
39 (@
__items ($
($not
:meta
,)*) ; ) => {}
;
40 (@
__items ($
($not
:meta
,)*) ; ( ($
($m
:meta
),*) ($
($it
:item
)*) ), $
($rest
:tt
)*) => {
41 // Emit all items within one block, applying an appropriate #[cfg]. The
42 // #[cfg] will require all `$m` matchers specified and must also negate
43 // all previous matchers.
44 cfg_if
! { @__apply cfg(all($($m,)* not(any($($not),*)))), $($it)* }
46 // Recurse to emit all other items in `$rest`, and when we do so add all
47 // our `$m` matchers to the list of `$not` matchers as future emissions
48 // will have to negate everything we just matched as well.
49 cfg_if
! { @__items ($($not,)* $($m,)*) ; $($rest)* }
52 // Internal macro to Apply a cfg attribute to a list of items
53 (@__apply $m
:meta
, $
($it
:item
)*) => {
66 pub stack
: $
crate::_STACK
,
73 // openssl changes `*mut` to `*const` in certain parameters in certain versions;
74 // in C this is ABI and (mostly) API compatible.
76 // We need to handle this explicitly, and this macro helps annotate which
77 // parameter got converted in which version.
82 // pub fn name(args) -> rettype; // `-> rettype` optional
83 // // more functions...
86 // This macro replaces `#[const_ptr_if(...)]` in types with `*const` or `*mut`
87 // (depending on the inner cfg flags)
89 // Walks through all argument and return types, but only finds inner types of
90 // `*const` and `*mut`; doesn't walk arrays or generics.
92 // NOTE: can't abstract `pub` as `$fn_vis:vis`, as ctest macro handling doesn't
93 // support it (old syntax crate). But we really only need `pub` anyway.
95 // NOTE: ctest seams to simply ignore macros it can't expand (whatever the
97 macro_rules
! const_ptr_api
{
98 // ----------------------------------------------------------------
99 // (partialarg): partial argument, waiting for "final" argument type
100 // MAGIC PART 1: hande conditional const ptr in argument type
102 { $(#[$fn_attr:meta])* pub fn $fn_name:ident }
105 [ #[const_ptr_if( $($cfg:tt)* )] $($arg_rem:tt)* ]
108 const_ptr_api
!( (partialarg
) { #[cfg($($cfg)*)] $(#[$fn_attr])* pub fn $fn_name } $args_packed
[ $
($part_arg
)* *const ] [ $
($arg_rem
)* ] $ret_packed
);
109 const_ptr_api
!( (partialarg
) { #[cfg(not($($cfg)*))] $(#[$fn_attr])* pub fn $fn_name } $args_packed
[ $
($part_arg
)* *mut ] [ $
($arg_rem
)* ] $ret_packed
);
111 // continue partial argument with `*mut` pointer (might need special const handling in inner type)
116 [ *mut $
($arg_rem
:tt
)* ]
119 const_ptr_api
!( (partialarg
) $def_packed $args_packed
[ $
($part_arg
)* *mut ] [ $
($arg_rem
)* ] $ret_packed
);
121 // continue partial argument with `*const` pointer (might need special const handling in inner type)
126 [ *const $
($arg_rem
:tt
)* ]
129 const_ptr_api
!( (partialarg
) $def_packed $args_packed
[ $
($part_arg
)* *const ] [ $
($arg_rem
)* ] $ret_packed
);
131 // finish partial argument with trailing comma
136 [ $arg_ty
:ty
, $
($arg_rem
:tt
)* ]
139 const_ptr_api
!( (parseargs
) $def_packed { $($args_tt)* { $($part_arg)* $arg_ty }
} [ $
($arg_rem
)* ] $ret_packed
);
141 // finish final partial argument (no trailing comma)
149 const_ptr_api
!( (parseargs
) $def_packed { $($args_tt)* { $($part_arg)* $arg_ty }
} [ ] $ret_packed
);
152 // ----------------------------------------------------------------
153 // (parseargs): parsing arguments
154 // start next argument
158 [ $arg_name
:ident
: $
($arg_rem
:tt
)* ]
161 const_ptr_api
!( (partialarg
) $def_packed $args_packed
[ $arg_name
: ] [ $
($arg_rem
)* ] $ret_packed
);
163 // end of arguments, there is a return type; start parsing it
170 const_ptr_api
!( (partialret
) $def_packed $args_packed
[] [ $
($rem
)* ] );
172 // end of arguments, no return type
179 const_ptr_api
!( (generate
) $def_packed $args_packed { () }
);
182 // ----------------------------------------------------------------
183 // (partialret): have partial return type, waiting for final return type
184 // MAGIC PART 2: hande conditional const ptr in return type
186 { $(#[$fn_attr:meta])* pub fn $fn_name:ident }
189 [ #[const_ptr_if( $($cfg:tt)* )] $($rem:tt)* ]
191 const_ptr_api
!( (partialret
) { #[cfg($($cfg)*)] $(#[$fn_attr])* pub fn $fn_name } $args_packed
[ $
($part_ret
)* *const ] [ $
($rem
)* ] );
192 const_ptr_api
!( (partialret
) { #[cfg(not($($cfg)*))] $(#[$fn_attr])* pub fn $fn_name } $args_packed
[ $
($part_ret
)* *mut ] [ $
($rem
)* ] );
194 // `* mut` part in return type; continue parsing to find inner conditional const ptr
201 const_ptr_api
!( (partialret
) $def_packed $args_packed
[ $
($part_ret
)* *mut ] [ $
($rem
)* ] );
203 // `* const` part in return type; continue parsing to find inner conditional const ptr
208 [ *const $
($rem
:tt
)* ]
210 const_ptr_api
!( (partialret
) $def_packed $args_packed
[ $
($part_ret
)* *const ] [ $
($rem
)* ] );
212 // final part of return type
219 const_ptr_api
!( (generate
) $def_packed $args_packed { $($part_ret)* $ret_ty }
);
222 // ----------------------------------------------------------------
225 { $(#[$fn_attr:meta])* pub fn $fn_name:ident }
226 { $({ $arg_name:ident: $($arg_ty:tt)* }
)* }
232 $arg_name
: $
($arg_ty
)*
237 // ----------------------------------------------------------------
238 // (fn): gather tokens for return type until ";"
239 // found end; start parsing current function, and parse remaining functions
246 const_ptr_api
!( (parseargs
) $def_packed {} $arg_tts_packed $ret_packed
);
247 const_ptr_api
!( (extern) [ $
($rem
)* ] );
249 // not ";" - all other tokens are part of the return type.
250 // don't expand return type yet; otherwise we'd have to remember in which branch `rem` needs
251 // to be used to parse further functions.
256 [ $tt
:tt $
($rem
:tt
)* ]
258 const_ptr_api
!( (fn) $def_packed $arg_tts_packed
[ $
($ret_tt
)* $tt
] [ $
($rem
)* ] );
261 // ----------------------------------------------------------------
262 // (extern): in extern block, find next function
263 // try to split into functions as fast as possible to reduce recursion depth
266 pub fn $fn_name
:ident( $
($arg_rem
:tt
)* ) $
($rem
:tt
)*
269 { $(#[$fn_attr])* pub fn $fn_name }
[ $
($arg_rem
)* ] [] [ $
($rem
)* ]
272 // end of extern block
273 ( (extern) [] ) => {}
;
275 // ----------------------------------------------------------------
276 // macro start; find extern block
277 ( extern "C" { $($rem:tt)* }
) => {
278 const_ptr_api
!( (extern) [ $
($rem
)* ] );