@@ -296,114 +296,46 @@ macro_rules! c_enum {
296
296
( @ty) => { $crate:: prelude:: CEnumRepr } ;
297
297
}
298
298
299
- // This is a pretty horrible hack to allow us to conditionally mark some functions as 'const',
300
- // without requiring users of this macro to care "libc_const_extern_fn".
301
- //
302
- // When 'libc_const_extern_fn' is enabled, we emit the captured 'const' keyword in the expanded
303
- // function.
304
- //
305
- // When 'libc_const_extern_fn' is disabled, we always emit a plain 'pub unsafe extern fn'.
306
- // Note that the expression matched by the macro is exactly the same - this allows
307
- // users of this macro to work whether or not 'libc_const_extern_fn' is enabled
308
- //
309
- // Unfortunately, we need to duplicate most of this macro between the 'cfg_if' blocks.
310
- // This is because 'const unsafe extern fn' won't even parse on older compilers,
311
- // so we need to avoid emitting it at all of 'libc_const_extern_fn'.
312
- //
313
- // Specifically, moving the 'cfg_if' into the macro body will *not* work. Doing so would cause the
314
- // '#[cfg(libc_const_extern_fn)]' to be emitted into user code. The 'cfg' gate will not stop Rust
315
- // from trying to parse the 'pub const unsafe extern fn', so users would get a compiler error even
316
- // when the 'libc_const_extern_fn' feature is disabled.
317
-
318
- // FIXME(ctest): ctest can't handle `const extern` functions, we should be able to remove this
319
- // cfg completely.
320
- // FIXME(ctest): ctest can't handle `$(,)?` so we use `$(,)*` which isn't quite correct.
321
- cfg_if ! {
322
- if #[ cfg( libc_const_extern_fn) ] {
323
- /// Define an `unsafe` function that is const as long as `libc_const_extern_fn` is enabled.
324
- macro_rules! f {
325
- ( $(
326
- $( #[ $attr: meta] ) *
327
- pub $( { $constness: ident} ) * fn $i: ident( $( $arg: ident: $argty: ty) , * $( , ) * ) -> $ret: ty
328
- $body: block
329
- ) * ) => ( $(
330
- #[ inline]
331
- $( #[ $attr] ) *
332
- pub $( $constness) * unsafe extern "C" fn $i( $( $arg: $argty) , * ) -> $ret
333
- $body
334
- ) * )
335
- }
336
-
337
- /// Define a safe function that is const as long as `libc_const_extern_fn` is enabled.
338
- macro_rules! safe_f {
339
- ( $(
340
- $( #[ $attr: meta] ) *
341
- pub $( { $constness: ident} ) * fn $i: ident( $( $arg: ident: $argty: ty) , * $( , ) * ) -> $ret: ty
342
- $body: block
343
- ) * ) => ( $(
344
- #[ inline]
345
- $( #[ $attr] ) *
346
- pub $( $constness) * extern "C" fn $i( $( $arg: $argty) , * ) -> $ret
347
- $body
348
- ) * )
349
- }
350
-
351
- /// A nonpublic function that is const as long as `libc_const_extern_fn` is enabled.
352
- macro_rules! const_fn {
353
- ( $(
354
- $( #[ $attr: meta] ) *
355
- $( { $constness: ident} ) * fn $i: ident( $( $arg: ident: $argty: ty) , * $( , ) * ) -> $ret: ty
356
- $body: block
357
- ) * ) => ( $(
358
- #[ inline]
359
- $( #[ $attr] ) *
360
- $( $constness) * fn $i( $( $arg: $argty) , * ) -> $ret
361
- $body
362
- ) * )
363
- }
364
- } else {
365
- /// Define an `unsafe` function that is const as long as `libc_const_extern_fn` is enabled.
366
- macro_rules! f {
367
- ( $(
368
- $( #[ $attr: meta] ) *
369
- pub $( { $constness: ident} ) * fn $i: ident( $( $arg: ident: $argty: ty) , * $( , ) * ) -> $ret: ty
370
- $body: block
371
- ) * ) => ( $(
372
- #[ inline]
373
- $( #[ $attr] ) *
374
- pub unsafe extern "C" fn $i( $( $arg: $argty) , * ) -> $ret
375
- $body
376
- ) * )
377
- }
299
+ /// Define a `unsafe` function.
300
+ macro_rules! f {
301
+ ( $(
302
+ $( #[ $attr: meta] ) *
303
+ pub $( { $constness: ident} ) ? fn $i: ident( $( $arg: ident: $argty: ty) ,* $( , ) * ) -> $ret: ty
304
+ $body: block
305
+ ) * ) => ( $(
306
+ #[ inline]
307
+ $( #[ $attr] ) *
308
+ pub $( $constness) ? unsafe extern "C" fn $i( $( $arg: $argty) ,* ) -> $ret
309
+ $body
310
+ ) * )
311
+ }
378
312
379
- /// Define a safe function that is const as long as `libc_const_extern_fn` is enabled .
380
- macro_rules! safe_f {
381
- ( $(
382
- $( #[ $attr: meta] ) *
383
- pub $( { $constness: ident} ) * fn $i: ident( $( $arg: ident: $argty: ty) , * $( , ) * ) -> $ret: ty
384
- $body: block
385
- ) * ) => ( $(
386
- #[ inline]
387
- $( #[ $attr] ) *
388
- pub extern "C" fn $i( $( $arg: $argty) , * ) -> $ret
389
- $body
390
- ) * )
391
- }
313
+ /// Define a safe function.
314
+ macro_rules! safe_f {
315
+ ( $(
316
+ $( #[ $attr: meta] ) *
317
+ pub $( { $constness: ident} ) ? fn $i: ident( $( $arg: ident: $argty: ty) ,* $( , ) * ) -> $ret: ty
318
+ $body: block
319
+ ) * ) => ( $(
320
+ #[ inline]
321
+ $( #[ $attr] ) *
322
+ pub $ ( $constness ) ? extern "C" fn $i( $( $arg: $argty) ,* ) -> $ret
323
+ $body
324
+ ) * )
325
+ }
392
326
393
- /// A nonpublic function that is const as long as `libc_const_extern_fn` is enabled.
394
- macro_rules! const_fn {
395
- ( $(
396
- $( #[ $attr: meta] ) *
397
- $( { $constness: ident} ) * fn $i: ident( $( $arg: ident: $argty: ty) , * $( , ) * ) -> $ret: ty
398
- $body: block
399
- ) * ) => ( $(
400
- #[ inline]
401
- $( #[ $attr] ) *
402
- fn $i( $( $arg: $argty) , * ) -> $ret
403
- $body
404
- ) * )
405
- }
406
- }
327
+ /// Define a nonpublic function.
328
+ macro_rules! const_fn {
329
+ ( $(
330
+ $( #[ $attr: meta] ) *
331
+ $( { $constness: ident} ) ? fn $i: ident( $( $arg: ident: $argty: ty) ,* $( , ) * ) -> $ret: ty
332
+ $body: block
333
+ ) * ) => ( $(
334
+ #[ inline]
335
+ $( #[ $attr] ) *
336
+ $( $constness) ? fn $i( $( $arg: $argty) ,* ) -> $ret
337
+ $body
338
+ ) * )
407
339
}
408
340
409
341
macro_rules! __item {
0 commit comments