@@ -43,15 +43,15 @@ mod extern_class;
43
43
#[ macro_export]
44
44
macro_rules! class {
45
45
( $name: ident) => { {
46
- $crate:: __class_inner!( $name)
46
+ $crate:: __class_inner!( $name, $crate :: __hash_idents! ( $name ) )
47
47
} } ;
48
48
}
49
49
50
50
#[ doc( hidden) ]
51
51
#[ macro_export]
52
52
#[ cfg( not( feature = "unstable-static-class" ) ) ]
53
53
macro_rules! __class_inner {
54
- ( $name: ident) => { {
54
+ ( $name: ident, $_hash : expr ) => { {
55
55
use $crate:: __macro_helpers:: { concat, panic, stringify, CachedClass , None , Some } ;
56
56
static CACHED_CLASS : CachedClass = CachedClass :: new( ) ;
57
57
let name = concat!( stringify!( $name) , '\0' ) ;
@@ -191,15 +191,15 @@ macro_rules! sel {
191
191
( $first: ident $( : $( $rest: ident : ) * ) ?) => ( {
192
192
use $crate:: __macro_helpers:: { concat, stringify, str } ;
193
193
const SELECTOR_DATA : & str = concat!( stringify!( $first) , $( ':' , $( stringify!( $rest) , ':' , ) * ) ? '\0' ) ;
194
- $crate:: __sel_inner!( SELECTOR_DATA , $first $( $( $rest) * ) ?)
194
+ $crate:: __sel_inner!( SELECTOR_DATA , $crate :: __hash_idents! ( $ first $( $( $rest) * ) ?) )
195
195
} ) ;
196
196
}
197
197
198
198
#[ doc( hidden) ]
199
199
#[ macro_export]
200
200
#[ cfg( not( feature = "unstable-static-sel" ) ) ]
201
201
macro_rules! __sel_inner {
202
- ( $data: expr, $( $idents : ident ) + ) => { {
202
+ ( $data: expr, $_hash : expr ) => { {
203
203
use $crate:: __macro_helpers:: CachedSel ;
204
204
static CACHED_SEL : CachedSel = CachedSel :: new( ) ;
205
205
#[ allow( unused_unsafe) ]
@@ -229,7 +229,7 @@ macro_rules! __inner_statics_apple_generic {
229
229
{
230
230
@image_info;
231
231
$image_info_section: literal;
232
- $( $idents : ident ) +
232
+ $hash : expr ;
233
233
} => {
234
234
/// We always emit the image info tag, since we need it to:
235
235
/// - End up in the same codegen unit as the other statics below.
@@ -241,19 +241,19 @@ macro_rules! __inner_statics_apple_generic {
241
241
#[ link_section = $image_info_section]
242
242
#[ export_name = $crate:: __macro_helpers:: concat!(
243
243
"\x01 L_OBJC_IMAGE_INFO_" ,
244
- $crate :: __macro_helpers :: __hash_idents! ( $ ( $idents ) + ) ,
244
+ $hash ,
245
245
) ]
246
246
#[ used] // Make sure this reaches the linker
247
247
static _IMAGE_INFO: $crate:: ffi:: __ImageInfo = $crate:: ffi:: __ImageInfo:: system( ) ;
248
248
} ;
249
249
{
250
250
@module_info;
251
- $( $idents : ident ) +
251
+ $hash : expr ;
252
252
} => {
253
253
#[ link_section = "__TEXT,__cstring,cstring_literals" ]
254
254
#[ export_name = $crate:: __macro_helpers:: concat!(
255
255
"\x01 L_OBJC_CLASS_NAME_" ,
256
- $crate :: __macro_helpers :: __hash_idents! ( $ ( $idents ) + ) ,
256
+ $hash ,
257
257
"_MODULE_INFO"
258
258
) ]
259
259
static MODULE_INFO_NAME : [ $crate:: __macro_helpers:: u8 ; 1 ] = [ 0 ] ;
@@ -265,7 +265,7 @@ macro_rules! __inner_statics_apple_generic {
265
265
#[ link_section = "__OBJC,__module_info,regular,no_dead_strip" ]
266
266
#[ export_name = $crate:: __macro_helpers:: concat!(
267
267
"\x01 L_OBJC_MODULES_" ,
268
- $crate :: __macro_helpers :: __hash_idents! ( $ ( $idents ) + )
268
+ $hash ,
269
269
) ]
270
270
#[ used] // Make sure this reaches the linker
271
271
static _MODULE_INFO: $crate:: __macro_helpers:: ModuleInfo = $crate:: __macro_helpers:: ModuleInfo :: new(
@@ -276,8 +276,8 @@ macro_rules! __inner_statics_apple_generic {
276
276
@sel;
277
277
$var_name_section: literal;
278
278
$selector_ref_section: literal;
279
- $data: expr,
280
- $( $idents : ident ) +
279
+ $data: expr;
280
+ $hash : expr ;
281
281
} => {
282
282
use $crate:: __macro_helpers:: { u8 , UnsafeCell } ;
283
283
use $crate:: runtime:: Sel ;
@@ -290,7 +290,7 @@ macro_rules! __inner_statics_apple_generic {
290
290
#[ link_section = $var_name_section]
291
291
#[ export_name = $crate:: __macro_helpers:: concat!(
292
292
"\x01 L_OBJC_METH_VAR_NAME_" ,
293
- $crate :: __macro_helpers :: __hash_idents! ( $ ( $idents ) + ) ,
293
+ $hash ,
294
294
) ]
295
295
static NAME_DATA : [ u8 ; X . len( ) ] = $crate:: __inner_statics_apple_generic! {
296
296
@string_to_known_length_bytes;
@@ -323,15 +323,16 @@ macro_rules! __inner_statics_apple_generic {
323
323
#[ link_section = $selector_ref_section]
324
324
#[ export_name = $crate:: __macro_helpers:: concat!(
325
325
"\x01 L_OBJC_SELECTOR_REFERENCES_" ,
326
- $crate :: __macro_helpers :: __hash_idents! ( $ ( $idents ) + ) ,
326
+ $hash ,
327
327
) ]
328
328
static mut REF : UnsafeCell <Sel > = unsafe {
329
329
UnsafeCell :: new( Sel :: __internal_from_ptr( NAME_DATA . as_ptr( ) . cast( ) ) )
330
330
} ;
331
331
} ;
332
332
{
333
333
@class;
334
- $name: ident
334
+ $name: ident;
335
+ $hash: expr;
335
336
} => {
336
337
use $crate:: __macro_helpers:: UnsafeCell ;
337
338
use $crate:: runtime:: Class ;
@@ -366,15 +367,16 @@ macro_rules! __inner_statics_apple_generic {
366
367
#[ link_section = "__DATA,__objc_classrefs,regular,no_dead_strip" ]
367
368
#[ export_name = $crate:: __macro_helpers:: concat!(
368
369
"\x01 L_OBJC_CLASSLIST_REFERENCES_$_" ,
369
- $crate:: __macro_helpers :: __hash_idents!( $name) ,
370
+ $crate:: __hash_idents!( $name) ,
370
371
) ]
371
372
static mut REF : UnsafeCell <& Class > = unsafe {
372
373
UnsafeCell :: new( & CLASS )
373
374
} ;
374
375
} ;
375
376
{
376
377
@class_old;
377
- $name: ident
378
+ $name: ident;
379
+ $hash: expr;
378
380
} => {
379
381
use $crate:: __macro_helpers:: { u8 , UnsafeCell } ;
380
382
use $crate:: runtime:: Class ;
@@ -385,7 +387,7 @@ macro_rules! __inner_statics_apple_generic {
385
387
#[ link_section = "__TEXT,__cstring,cstring_literals" ]
386
388
#[ export_name = $crate:: __macro_helpers:: concat!(
387
389
"\x01 L_OBJC_CLASS_NAME_" ,
388
- $crate:: __macro_helpers :: __hash_idents!( $name) ,
390
+ $crate:: __hash_idents!( $name) ,
389
391
) ]
390
392
static NAME_DATA : [ u8 ; X . len( ) ] = $crate:: __inner_statics_apple_generic! {
391
393
@string_to_known_length_bytes;
@@ -396,7 +398,7 @@ macro_rules! __inner_statics_apple_generic {
396
398
#[ link_section = "__OBJC,__cls_refs,literal_pointers,no_dead_strip" ]
397
399
#[ export_name = $crate:: __macro_helpers:: concat!(
398
400
"\x01 L_OBJC_CLASS_REFERENCES_" ,
399
- $crate:: __macro_helpers :: __hash_idents!( $name) ,
401
+ $crate:: __hash_idents!( $name) ,
400
402
) ]
401
403
static mut REF : UnsafeCell <& Class > = unsafe {
402
404
let ptr: * const Class = NAME_DATA . as_ptr( ) . cast( ) ;
@@ -410,28 +412,30 @@ macro_rules! __inner_statics_apple_generic {
410
412
#[ macro_export]
411
413
#[ cfg( all( feature = "apple" , not( all( target_os = "macos" , target_arch = "x86" ) ) ) ) ]
412
414
macro_rules! __inner_statics {
413
- ( @image_info $( $args : tt ) * ) => {
415
+ ( @image_info $hash : expr ) => {
414
416
$crate:: __inner_statics_apple_generic! {
415
417
@image_info;
416
418
"__DATA,__objc_imageinfo,regular,no_dead_strip" ;
417
- $( $args ) *
419
+ $hash ;
418
420
}
419
421
} ;
420
- ( @sel $( $args : tt ) * ) => {
422
+ ( @sel $data : expr , $hash : expr ) => {
421
423
$crate:: __inner_statics_apple_generic! {
422
424
@sel;
423
425
"__TEXT,__objc_methname,cstring_literals" ;
424
426
// Clang uses `no_dead_strip` in the link section for some reason,
425
427
// which other tools (notably some LLVM tools) now assume is
426
428
// present, so we have to add it as well.
427
429
"__DATA,__objc_selrefs,literal_pointers,no_dead_strip" ;
428
- $( $args) *
430
+ $data;
431
+ $hash;
429
432
}
430
433
} ;
431
- ( @class $( $args : tt ) * ) => {
434
+ ( @class $name : ident , $hash : expr ) => {
432
435
$crate:: __inner_statics_apple_generic! {
433
436
@class;
434
- $( $args) *
437
+ $name;
438
+ $hash;
435
439
}
436
440
} ;
437
441
}
@@ -440,29 +444,31 @@ macro_rules! __inner_statics {
440
444
#[ macro_export]
441
445
#[ cfg( all( feature = "apple" , target_os = "macos" , target_arch = "x86" ) ) ]
442
446
macro_rules! __inner_statics {
443
- ( @image_info $( $args : tt ) * ) => {
447
+ ( @image_info $hash : expr ) => {
444
448
$crate:: __inner_statics_apple_generic! {
445
449
@image_info;
446
450
"__OBJC,__image_info,regular" ;
447
- $( $args ) *
451
+ $hash ;
448
452
}
449
453
} ;
450
- ( @sel $( $args : tt ) * ) => {
454
+ ( @sel $data : expr , $hash : expr ) => {
451
455
$crate:: __inner_statics_apple_generic! {
452
456
@sel;
453
457
"__TEXT,__cstring,cstring_literals" ;
454
458
"__OBJC,__message_refs,literal_pointers,no_dead_strip" ;
455
- $( $args) *
459
+ $data;
460
+ $hash;
456
461
}
457
462
} ;
458
- ( @class $( $args : tt ) * ) => {
463
+ ( @class $name : ident , $hash : expr ) => {
459
464
$crate:: __inner_statics_apple_generic! {
460
465
@class_old;
461
- $( $args) *
466
+ $name;
467
+ $hash;
462
468
}
463
469
$crate:: __inner_statics_apple_generic! {
464
470
@module_info;
465
- $( $args ) *
471
+ $hash ;
466
472
}
467
473
} ;
468
474
}
@@ -495,9 +501,9 @@ macro_rules! __inner_statics {
495
501
not( feature = "unstable-static-sel-inlined" )
496
502
) ) ]
497
503
macro_rules! __sel_inner {
498
- ( $data: expr, $( $idents : ident ) + ) => { {
499
- $crate:: __inner_statics!( @image_info $( $idents ) + ) ;
500
- $crate:: __inner_statics!( @sel $data, $( $idents ) + ) ;
504
+ ( $data: expr, $hash : expr ) => { {
505
+ $crate:: __inner_statics!( @image_info $hash ) ;
506
+ $crate:: __inner_statics!( @sel $data, $hash ) ;
501
507
502
508
/// HACK: Wrap the access in a non-generic, `#[inline(never)]`
503
509
/// function to make the compiler group it into the same codegen unit
@@ -524,9 +530,9 @@ macro_rules! __sel_inner {
524
530
#[ macro_export]
525
531
#[ cfg( all( feature = "unstable-static-sel-inlined" ) ) ]
526
532
macro_rules! __sel_inner {
527
- ( $data: expr, $( $idents : ident ) + ) => { {
528
- $crate:: __inner_statics!( @image_info $( $idents ) + ) ;
529
- $crate:: __inner_statics!( @sel $data, $( $idents ) + ) ;
533
+ ( $data: expr, $hash : expr ) => { {
534
+ $crate:: __inner_statics!( @image_info $hash ) ;
535
+ $crate:: __inner_statics!( @sel $data, $hash ) ;
530
536
531
537
#[ allow( unused_unsafe) ]
532
538
// SAFETY: See above
@@ -541,9 +547,9 @@ macro_rules! __sel_inner {
541
547
not( feature = "unstable-static-class-inlined" )
542
548
) ) ]
543
549
macro_rules! __class_inner {
544
- ( $name: ident) => { {
545
- $crate:: __inner_statics!( @image_info $name ) ;
546
- $crate:: __inner_statics!( @class $name) ;
550
+ ( $name: ident, $hash : expr ) => { {
551
+ $crate:: __inner_statics!( @image_info $hash ) ;
552
+ $crate:: __inner_statics!( @class $name, $hash ) ;
547
553
548
554
#[ inline( never) ]
549
555
fn objc_static_workaround( ) -> & ' static Class {
@@ -559,9 +565,9 @@ macro_rules! __class_inner {
559
565
#[ macro_export]
560
566
#[ cfg( all( feature = "unstable-static-class-inlined" ) ) ]
561
567
macro_rules! __class_inner {
562
- ( $name: ident) => { {
563
- $crate:: __inner_statics!( @image_info $name ) ;
564
- $crate:: __inner_statics!( @class $name) ;
568
+ ( $name: ident, $hash : expr ) => { {
569
+ $crate:: __inner_statics!( @image_info $hash ) ;
570
+ $crate:: __inner_statics!( @class $name, $hash ) ;
565
571
566
572
#[ allow( unused_unsafe) ]
567
573
// SAFETY: See above
0 commit comments