@@ -8,8 +8,10 @@ use core::fmt;
8
8
use core:: panic:: { RefUnwindSafe , UnwindSafe } ;
9
9
use core:: ptr;
10
10
use core:: str;
11
+ #[ cfg( feature = "malloc" ) ]
11
12
use malloc_buf:: Malloc ;
12
13
use std:: ffi:: { CStr , CString } ;
14
+ #[ cfg( feature = "malloc" ) ]
13
15
use std:: os:: raw:: c_uint;
14
16
15
17
pub use super :: bool:: Bool ;
@@ -177,6 +179,7 @@ impl Method {
177
179
}
178
180
179
181
/// Returns the `Encoding` of self's return type.
182
+ #[ cfg( feature = "malloc" ) ]
180
183
pub fn return_type ( & self ) -> Malloc < str > {
181
184
unsafe {
182
185
let encoding = ffi:: method_copyReturnType ( self . as_ptr ( ) ) ;
@@ -186,6 +189,7 @@ impl Method {
186
189
187
190
/// Returns the `Encoding` of a single parameter type of self, or
188
191
/// [`None`] if self has no parameter at the given index.
192
+ #[ cfg( feature = "malloc" ) ]
189
193
pub fn argument_type ( & self , index : usize ) -> Option < Malloc < str > > {
190
194
unsafe {
191
195
let encoding = ffi:: method_copyArgumentType ( self . as_ptr ( ) , index as c_uint ) ;
@@ -243,6 +247,7 @@ impl Class {
243
247
// fn lookup(name: &str) -> Option<&'static Self>;
244
248
245
249
/// Obtains the list of registered class definitions.
250
+ #[ cfg( feature = "malloc" ) ]
246
251
pub fn classes ( ) -> Malloc < [ & ' static Self ] > {
247
252
unsafe {
248
253
let mut count: c_uint = 0 ;
@@ -340,6 +345,7 @@ impl Class {
340
345
}
341
346
342
347
/// Describes the instance methods implemented by self.
348
+ #[ cfg( feature = "malloc" ) ]
343
349
pub fn instance_methods ( & self ) -> Malloc < [ & Method ] > {
344
350
unsafe {
345
351
let mut count: c_uint = 0 ;
@@ -356,6 +362,7 @@ impl Class {
356
362
}
357
363
358
364
/// Get a list of the protocols to which this class conforms.
365
+ #[ cfg( feature = "malloc" ) ]
359
366
pub fn adopted_protocols ( & self ) -> Malloc < [ & Protocol ] > {
360
367
unsafe {
361
368
let mut count: c_uint = 0 ;
@@ -365,6 +372,7 @@ impl Class {
365
372
}
366
373
367
374
/// Describes the instance variables declared by self.
375
+ #[ cfg( feature = "malloc" ) ]
368
376
pub fn instance_variables ( & self ) -> Malloc < [ & Ivar ] > {
369
377
unsafe {
370
378
let mut count: c_uint = 0 ;
@@ -431,6 +439,7 @@ impl Protocol {
431
439
}
432
440
433
441
/// Obtains the list of registered protocol definitions.
442
+ #[ cfg( feature = "malloc" ) ]
434
443
pub fn protocols ( ) -> Malloc < [ & ' static Protocol ] > {
435
444
unsafe {
436
445
let mut count: c_uint = 0 ;
@@ -440,6 +449,7 @@ impl Protocol {
440
449
}
441
450
442
451
/// Get a list of the protocols to which this protocol conforms.
452
+ #[ cfg( feature = "malloc" ) ]
443
453
pub fn adopted_protocols ( & self ) -> Malloc < [ & Protocol ] > {
444
454
unsafe {
445
455
let mut count: c_uint = 0 ;
@@ -612,8 +622,8 @@ mod tests {
612
622
assert ! ( <u32 >:: ENCODING . equivalent_to_str( ivar. type_encoding( ) ) ) ;
613
623
assert ! ( ivar. offset( ) > 0 ) ;
614
624
615
- let ivars = cls . instance_variables ( ) ;
616
- assert ! ( ivars . len( ) > 0 ) ;
625
+ # [ cfg ( feature = "malloc" ) ]
626
+ assert ! ( cls . instance_variables ( ) . len( ) > 0 ) ;
617
627
}
618
628
619
629
#[ test]
@@ -623,11 +633,14 @@ mod tests {
623
633
let method = cls. instance_method ( sel) . unwrap ( ) ;
624
634
assert_eq ! ( method. name( ) . name( ) , "foo" ) ;
625
635
assert_eq ! ( method. arguments_count( ) , 2 ) ;
626
- assert ! ( <u32 >:: ENCODING . equivalent_to_str( & method. return_type( ) ) ) ;
627
- assert ! ( Sel :: ENCODING . equivalent_to_str( & method. argument_type( 1 ) . unwrap( ) ) ) ;
636
+ #[ cfg( feature = "malloc" ) ]
637
+ {
638
+ assert ! ( <u32 >:: ENCODING . equivalent_to_str( & method. return_type( ) ) ) ;
639
+ assert ! ( Sel :: ENCODING . equivalent_to_str( & method. argument_type( 1 ) . unwrap( ) ) ) ;
628
640
629
- let methods = cls. instance_methods ( ) ;
630
- assert ! ( methods. len( ) > 0 ) ;
641
+ let methods = cls. instance_methods ( ) ;
642
+ assert ! ( methods. len( ) > 0 ) ;
643
+ }
631
644
}
632
645
633
646
#[ test]
@@ -648,8 +661,13 @@ mod tests {
648
661
}
649
662
650
663
#[ test]
651
- fn test_classes ( ) {
664
+ fn test_classes_count ( ) {
652
665
assert ! ( Class :: classes_count( ) > 0 ) ;
666
+ }
667
+
668
+ #[ test]
669
+ #[ cfg( feature = "malloc" ) ]
670
+ fn test_classes ( ) {
653
671
let classes = Class :: classes ( ) ;
654
672
assert ! ( classes. len( ) > 0 ) ;
655
673
}
@@ -660,8 +678,8 @@ mod tests {
660
678
assert_eq ! ( proto. name( ) , "CustomProtocol" ) ;
661
679
let class = test_utils:: custom_class ( ) ;
662
680
assert ! ( class. conforms_to( proto) ) ;
663
- let class_protocols = class . adopted_protocols ( ) ;
664
- assert ! ( class_protocols . len( ) > 0 ) ;
681
+ # [ cfg ( feature = "malloc" ) ]
682
+ assert ! ( class . adopted_protocols ( ) . len( ) > 0 ) ;
665
683
}
666
684
667
685
#[ test]
@@ -676,17 +694,17 @@ mod tests {
676
694
let sub_proto = test_utils:: custom_subprotocol ( ) ;
677
695
let super_proto = test_utils:: custom_protocol ( ) ;
678
696
assert ! ( sub_proto. conforms_to( super_proto) ) ;
679
- let adopted_protocols = sub_proto . adopted_protocols ( ) ;
680
- assert_eq ! ( adopted_protocols[ 0 ] , super_proto) ;
697
+ # [ cfg ( feature = "malloc" ) ]
698
+ assert_eq ! ( sub_proto . adopted_protocols( ) [ 0 ] , super_proto) ;
681
699
}
682
700
683
701
#[ test]
684
702
fn test_protocols ( ) {
685
703
// Ensure that a protocol has been registered on linux
686
704
let _ = test_utils:: custom_protocol ( ) ;
687
705
688
- let protocols = Protocol :: protocols ( ) ;
689
- assert ! ( protocols. len( ) > 0 ) ;
706
+ # [ cfg ( feature = "malloc" ) ]
707
+ assert ! ( Protocol :: protocols( ) . len( ) > 0 ) ;
690
708
}
691
709
692
710
#[ test]
0 commit comments