/
runtime.h
1227 lines (1082 loc) · 36.3 KB
/
runtime.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#if defined(__clang__) && !defined(__OBJC_RUNTIME_INTERNAL__)
#pragma clang system_header
#endif
#include "objc-visibility.h"
#ifndef __LIBOBJC_RUNTIME_H_INCLUDED__
#define __LIBOBJC_RUNTIME_H_INCLUDED__
#ifdef __cplusplus
extern "C" {
#endif
#ifndef __GNUSTEP_RUNTIME__
# define __GNUSTEP_RUNTIME__
#endif
#ifndef __has_feature
# define __has_feature(x) 0
#endif
#ifndef __unsafe_unretained
# ifndef __has_feature
# define __unsafe_unretained
# elif !__has_feature(objc_arc)
# define __unsafe_unretained
# endif
#endif
#if defined(__OBJC__) && __has_attribute(ns_returns_retained)
# define OBJC_RETURNS_RETAINED __attribute__((ns_returns_retained))
#else
# define OBJC_RETURNS_RETAINED
#endif
// Make sure we get the limit macros, even in C++ mode
#ifndef __STDC_LIMIT_MACROS
# define __STDC_LIMIT_MACROS 1
#endif
#include <stdint.h>
#include <limits.h>
#include <stddef.h>
#include <sys/types.h>
#include "Availability.h"
// Undo GNUstep substitutions
#ifdef class_setVersion
# undef class_setVersion
#endif
#ifdef class_getClassMethod
# undef class_getClassMethod
#endif
#ifdef objc_getClass
# undef objc_getClass
#endif
#ifdef objc_lookUpClass
# undef objc_lookUpClass
#endif
/**
* Opaque type for Objective-C instance variable metadata.
*/
typedef struct objc_ivar* Ivar;
// Don't redefine these types if the old GCC header was included first.
#ifndef __objc_INCLUDE_GNU
// Define the macro so that including the old GCC header does nothing.
# define __objc_INCLUDE_GNU
# define __objc_api_INCLUDE_GNU
/**
* Opaque type used for selectors.
*/
#if !defined(__clang__) && !defined(__OBJC_RUNTIME_INTERNAL__)
typedef const struct objc_selector *SEL;
#else
typedef struct objc_selector *SEL;
#endif
/**
* Opaque type for Objective-C classes.
*/
typedef struct objc_class *Class;
/**
* Type for Objective-C objects.
*/
typedef struct objc_object
{
/**
* Pointer to this object's class. Accessing this directly is STRONGLY
* discouraged. You are recommended to use object_getClass() instead.
*/
#ifndef __OBJC_RUNTIME_INTERNAL__
__attribute__((deprecated))
#endif
Class isa;
} *id;
/**
* Structure used for calling superclass methods.
*/
struct objc_super
{
/** The receiver of the message. */
__unsafe_unretained id receiver;
/** The class containing the method to call. */
# if !defined(__cplusplus) && !__OBJC2__
Class class;
# else
Class super_class;
# endif
};
/**
* Instance Method Pointer type. Note: Since the calling convention for
* variadic functions sometimes differs from the calling convention for
* non-variadic functions, you must cast an IMP to the correct type before
* calling.
*/
typedef id (*IMP)(id, SEL, ...);
/**
* Opaque type for Objective-C method metadata.
*/
typedef struct objc_method *Method;
/**
* Objective-C boolean type.
*/
# ifdef STRICT_APPLE_COMPATIBILITY
typedef signed char BOOL;
# else
# if defined(__vxworks) || defined(_WIN32)
typedef int BOOL;
# else
typedef unsigned char BOOL;
# endif
# endif
#else
// Method in the GCC runtime is a struct, Method_t is the pointer
# define Method Method_t
#endif // __objc_INCLUDE_GNU
/**
* Opaque type for Objective-C property metadata.
*/
typedef struct objc_property* objc_property_t;
/**
* Opaque type for Objective-C protocols. Note that, although protocols are
* objects, sending messages to them is deprecated in Objective-C 2 and may not
* work in the future.
*/
#ifdef __OBJC__
@class Protocol;
#else
typedef struct objc_protocol Protocol;
#endif
/**
* Objective-C method description.
*/
struct objc_method_description
{
/**
* The name of this method.
*/
SEL name;
/**
* The types of this method.
*/
const char *types;
};
/**
* The objc_property_attribute_t type is used to store attributes for
* properties. This is used to store a decomposed version of the property
* encoding, with each flag stored in the name and each value in the value.
*
* All of the strings that these refer to are internal to the runtime and
* should not be freed.
*/
typedef struct
{
/**
* The flag that this attribute describes. All current flags are single characters,
*/
const char *name;
/**
*/
const char *value;
} objc_property_attribute_t;
#ifndef YES
# if __has_feature(objc_bool)
# define YES __objc_yes
# else
# define YES ((BOOL)1)
# endif
#endif
#ifndef NO
# if __has_feature(objc_bool)
# define NO __objc_no
# else
# define NO ((BOOL)0)
# endif
#endif
#if __has_feature(cxx_nullptr)
# define _OBJC_NULL_PTR nullptr
#else
# define _OBJC_NULL_PTR NULL
#endif
#ifndef nil
# define nil _OBJC_NULL_PTR
#endif
#ifndef Nil
# define Nil _OBJC_NULL_PTR
#endif
#include "slot.h"
#include "message.h"
/**
* Adds an instance variable to the named class. The class must not have been
* registered by the runtime. The alignment must be the base-2 logarithm of
* the alignment requirement and the types should be an Objective-C type encoding.
*/
OBJC_PUBLIC
BOOL class_addIvar(Class cls,
const char *name,
size_t size,
uint8_t alignment,
const char *types);
/**
* Adds a method to the class.
*/
OBJC_PUBLIC
BOOL class_addMethod(Class cls, SEL name, IMP imp, const char *types);
/**
* Adds a protocol to the class.
*/
OBJC_PUBLIC
BOOL class_addProtocol(Class cls, Protocol *protocol);
/**
* Tests for protocol conformance. Note: Currently, protocols with the same
* name are regarded as equivalent, even if they have different methods. This
* behaviour will change in a future version.
*/
OBJC_PUBLIC
BOOL class_conformsToProtocol(Class cls, Protocol *protocol);
/**
* Copies the instance variable list for this class. The integer pointed to by
* the outCount argument is set to the number of instance variables returned.
* The caller is responsible for freeing the returned buffer.
*/
OBJC_PUBLIC
Ivar* class_copyIvarList(Class cls, unsigned int *outCount);
/**
* Copies the method list for this class. The integer pointed to by the
* outCount argument is set to the number of methods returned. The caller is
* responsible for freeing the returned buffer.
*/
OBJC_PUBLIC
Method * class_copyMethodList(Class cls, unsigned int *outCount);
/**
* Copies the declared property list for this class. The integer pointed to by
* the outCount argument is set to the number of declared properties returned.
* The caller is responsible for freeing the returned buffer.
*/
OBJC_PUBLIC
objc_property_t* class_copyPropertyList(Class cls, unsigned int *outCount);
/**
* Copies the protocol list for this class. The integer pointed to by the
* outCount argument is set to the number of protocols returned. The caller is
* responsible for freeing the returned buffer.
*/
OBJC_PUBLIC
Protocol *__unsafe_unretained* class_copyProtocolList(Class cls, unsigned int *outCount);
/**
* Creates an instance of this class, allocating memory using malloc.
*/
OBJC_PUBLIC OBJC_RETURNS_RETAINED
id class_createInstance(Class cls, size_t extraBytes);
/**
* Returns a pointer to the method metadata for the specified method in this
* class. This is an opaque data type and must be accessed with the method_*()
* family of functions.
*/
OBJC_PUBLIC
Method class_getClassMethod(Class aClass, SEL aSelector);
/**
* Returns a pointer to the metadata for the specified class variable in
* this class. This is an opaque data type and must be accessed with the
* ivar_*() family of functions.
*/
OBJC_PUBLIC
Ivar class_getClassVariable(Class cls, const char* name);
/**
* Returns a pointer to the method metadata for the specified instance method
* in this class. This is an opaque data type and must be accessed with the
* method_*() family of functions.
*/
OBJC_PUBLIC
Method class_getInstanceMethod(Class aClass, SEL aSelector);
/**
* Returns the size of an instance of the named class, in bytes. All of the
* class's superclasses must be loaded before this call, or the result is
* undefined with the non-fragile ABI.
*/
OBJC_PUBLIC
size_t class_getInstanceSize(Class cls);
/**
* Look up the named instance variable in the class (and its superclasses)
* returning a pointer to the instance variable definition or a null
* pointer if no instance variable of that name was found.
*/
OBJC_PUBLIC
Ivar class_getInstanceVariable(Class cls, const char* name);
/**
* Sets the object value of a specified instance variable.
*/
OBJC_PUBLIC
void object_setIvar(id object, Ivar ivar, id value);
/**
* Sets a named instance variable to the value specified by *value. Note that
* the instance variable must be a pointer-sized quantity.
*/
OBJC_PUBLIC
Ivar object_setInstanceVariable(id obj, const char *name, void *value);
/**
* Returns the value of the named instance variable. This should not be used
* with instance variables that are not pointers.
*/
OBJC_PUBLIC
id object_getIvar(id object, Ivar ivar);
/**
* Returns a named instance variable via the final parameter. Note that
* calling object_getIvar() on the value returned from this function is faster.
*
* Note that the instance variable must be a pointer-sized quantity.
*/
OBJC_PUBLIC
Ivar object_getInstanceVariable(id obj, const char *name, void **outValue);
/**
* Returns a pointer to the function used to handle the specified message. If
* the receiver does not have a method corresponding to this message then this
* function may return a runtime function that performs forwarding.
*/
OBJC_PUBLIC
IMP class_getMethodImplementation(Class cls, SEL name);
/**
* Identical to class_getMethodImplementation().
*/
OBJC_PUBLIC
IMP class_getMethodImplementation_stret(Class cls, SEL name);
/**
* Returns the name of the class. This string is owned by the runtime and is
* valid for (at least) as long as the class remains loaded.
*/
OBJC_PUBLIC
const char * class_getName(Class cls);
/**
* Retrieves metadata about the property with the specified name.
*/
OBJC_PUBLIC
objc_property_t class_getProperty(Class cls, const char *name);
/**
* Returns the superclass of the specified class.
*/
OBJC_PUBLIC
Class class_getSuperclass(Class cls);
/**
* Returns the version of the class. Currently, the class version is not used
* inside the runtime at all, however it may be used for the developer-mode ABI.
*/
OBJC_PUBLIC
int class_getVersion(Class theClass);
/**
* Sets the version for this class.
*/
OBJC_PUBLIC
void class_setVersion(Class theClass, int version);
OBJC_PUBLIC OBJC_GNUSTEP_RUNTIME_UNSUPPORTED("Weak instance variables")
const char *class_getWeakIvarLayout(Class cls);
/**
* Returns whether the class is a metaclass. This can be used in conjunction
* with object_getClass() for differentiating between objects and classes.
*/
OBJC_PUBLIC
BOOL class_isMetaClass(Class cls);
/**
* Registers an alias for the class. Returns YES if the alias could be
* registered successfully.
*/
OBJC_PUBLIC OBJC_NONPORTABLE
BOOL class_registerAlias_np(Class cls, const char *alias);
/**
* Replaces the named method with a new implementation. Note: the GNUstep
* Objective-C runtime uses typed selectors, however the types of the selector
* will be ignored and a new selector registered with the specified types.
*/
OBJC_PUBLIC
IMP class_replaceMethod(Class cls, SEL name, IMP imp, const char *types);
/**
* Returns YES if instances of this class has a method that implements the
* specified message, NO otherwise. If the class handles this message via one
* or more of the various forwarding mechanisms, then this will still return
* NO.
*/
OBJC_PUBLIC
BOOL class_respondsToSelector(Class cls, SEL sel);
/**
* Returns the instance variable layout of this class as an opaque list that
* can be applied to other classes.
*/
OBJC_PUBLIC
const char *class_getIvarLayout(Class cls);
/**
* Sets the class's instance variable layout. The layout argument must be a
* value returned by class_getIvarLayout().
*/
OBJC_PUBLIC
void class_setIvarLayout(Class cls, const char *layout);
/**
* Sets the superclass of the specified class. This function is deprecated,
* because modifying the superclass of a class at run time is a very complex
* operation and this function is almost always used incorrectly.
*/
OBJC_PUBLIC __attribute__((deprecated))
Class class_setSuperclass(Class cls, Class newSuper);
OBJC_PUBLIC OBJC_GNUSTEP_RUNTIME_UNSUPPORTED("Weak instance variables")
void class_setWeakIvarLayout(Class cls, const char *layout);
/**
* Returns the name of an instance variable.
*/
OBJC_PUBLIC
const char* ivar_getName(Ivar ivar);
/**
* Returns the offset of an instance variable. This value can be added to the
* object pointer to get the address of the instance variable.
*/
OBJC_PUBLIC
ptrdiff_t ivar_getOffset(Ivar ivar);
/**
* Returns the Objective-C type encoding of the instance variable.
*/
OBJC_PUBLIC
const char* ivar_getTypeEncoding(Ivar ivar);
/**
* Copies the type encoding of an argument of this method. The caller is
* responsible for freeing the returned C string. Arguments 0 and 1 of any
* Objective-C method will be the self and _cmd parameters, so the returned
* value will be "@" and ":" respectively.
*/
OBJC_PUBLIC
char* method_copyArgumentType(Method method, unsigned int index);
/**
* Copies the type encoding of an argument of this method. The caller is
* responsible for freeing the returned C string.
*/
OBJC_PUBLIC
char* method_copyReturnType(Method method);
/**
* Exchanges the implementations of the two methods. Note: this call is very
* expensive on the GNUstep runtime and its use is discouraged. It is
* recommended that users call class_replaceMethod() instead.
*/
OBJC_PUBLIC
void method_exchangeImplementations(Method m1, Method m2);
/**
* Copies the Objective-C type encoding of a specified method parameter into a
* buffer provided by the caller. This method does not provide any means for
* the caller to easily detect truncation, and will only NULL-terminate the
* output string if there is enough space for the argument type and the NULL
* terminator. Its use is therefore discouraged.
*/
OBJC_PUBLIC
void method_getArgumentType(Method method, unsigned int index, char *dst, size_t dst_len);
/**
* Returns a pointer to the function used to implement this method.
*/
OBJC_PUBLIC
IMP method_getImplementation(Method method);
/**
* Returns the selector used to identify this method. Note that, unlike the
* Apple runtimes, the GNUstep runtime uses typed selectors, so the return
* value for this also identifies the type of the method, not just its name,
* although calling method_getTypeEncoding() is faster if you just require the
* types.
*/
OBJC_PUBLIC
SEL method_getName(Method method);
/**
* Returns the number of arguments (including self and _cmd) that this method
* expects.
*/
OBJC_PUBLIC
unsigned method_getNumberOfArguments(Method method);
/**
* Copies the Objective-C type encoding of a method's return value into a
* buffer provided by the caller. This method does not provide any means for
* the caller to easily detect truncation, and will only NULL-terminate the
* output string if there is enough space for the argument type and the NULL
* terminator. Its use is therefore discouraged.
*/
OBJC_PUBLIC
void method_getReturnType(Method method, char *dst, size_t dst_len);
/**
* Returns the type encoding for the method. This string is owned by the
* runtime and will persist for (at least) as long as the class owning the
* method is loaded.
*/
OBJC_PUBLIC
const char * method_getTypeEncoding(Method method);
/**
* Sets the function used to implement this method. This function is very
* expensive with the GNUstep runtime and its use is discouraged. It is
* recommended that you call class_replaceMethod() instead.
*/
OBJC_PUBLIC
IMP method_setImplementation(Method method, IMP imp);
/**
* Allocates a new class and metaclass inheriting from the specified class,
* with some space after the class for storing extra data. This space can be
* used for class variables by adding instance variables to the returned
* metaclass.
*/
OBJC_PUBLIC
Class objc_allocateClassPair(Class superclass, const char *name, size_t extraBytes);
/**
* Frees a class and metaclass allocated with objc_allocateClassPair(). Any
* attempts to send messages to instances of this class or its subclasses
* result in undefined behaviour.
*/
OBJC_PUBLIC
void objc_disposeClassPair(Class cls);
/**
* Returns the class with the specified name, if one has been registered with
* the runtime, or nil if one does not exist. If no class of this name is
* loaded, it calls the _objc_lookup_class() callback to allow an external
* library to load the module providing this class.
*/
OBJC_PUBLIC
id objc_getClass(const char *name);
/**
* Copies all of the classes currently registered with the runtime into the
* buffer specified as the first argument. If the buffer is NULL or its length
* is 0, it returns the total number of classes registered with the runtime.
* Otherwise, it copies classes and returns the number copied.
*/
OBJC_PUBLIC
int objc_getClassList(Class *buffer, int bufferLen);
/**
* Returns a copy of the list of all classes in the system. The caller is
* responsible for freeing this list. The number of classes is returned in the
* parameter.
*/
OBJC_PUBLIC
Class *objc_copyClassList(unsigned int *outCount);
/**
* Returns the metaclass with the specified name. This is equivalent to
* calling object_getClass() on the result of objc_getClass().
*/
OBJC_PUBLIC
id objc_getMetaClass(const char *name);
/**
* Returns the class with the specified name, aborting if none is found. This
* function should generally only be called early on in a program, to ensure
* that all required libraries are loaded.
*/
OBJC_PUBLIC
id objc_getRequiredClass(const char *name);
/**
* Looks up the class with the specified name, but does not invoke any
* external lazy loading mechanisms.
*/
OBJC_PUBLIC
id objc_lookUpClass(const char *name);
/**
* Returns the protocol with the specified name.
*/
OBJC_PUBLIC
Protocol *objc_getProtocol(const char *name);
/**
* Allocates a new protocol. This returns NULL if a protocol with the same
* name already exists in the system.
*
* Protocols are immutable after they have been registered, so may only be
* modified between calling this function and calling objc_registerProtocol().
*/
OBJC_PUBLIC
Protocol *objc_allocateProtocol(const char *name);
/**
* Registers a protocol with the runtime. After this point, the protocol may
* not be modified.
*/
OBJC_PUBLIC
void objc_registerProtocol(Protocol *proto);
/**
* Adds a method to the protocol.
*/
OBJC_PUBLIC
void protocol_addMethodDescription(Protocol *aProtocol,
SEL name,
const char *types,
BOOL isRequiredMethod,
BOOL isInstanceMethod);
/**
* Adds a protocol to the protocol.
*/
OBJC_PUBLIC
void protocol_addProtocol(Protocol *aProtocol, Protocol *addition);
/**
* Adds a property to the protocol.
*/
OBJC_PUBLIC
void protocol_addProperty(Protocol *aProtocol,
const char *name,
const objc_property_attribute_t *attributes,
unsigned int attributeCount,
BOOL isRequiredProperty,
BOOL isInstanceProperty);
/**
* Registers a new class and its metaclass with the runtime. This function
* should be called after allocating a class with objc_allocateClassPair() and
* adding instance variables and methods to it. A class can not have instance
* variables added to it after objc_registerClassPair() has been called.
*/
OBJC_PUBLIC
void objc_registerClassPair(Class cls);
/**
* Returns a pointer immediately after the instance variables declared in an
* object. This is a pointer to the storage specified with the extraBytes
* parameter given when allocating an object.
*/
OBJC_PUBLIC
void *object_getIndexedIvars(id obj);
// FIXME: The GNU runtime has a version of this which omits the size parameter
//id object_copy(id obj, size_t size);
/**
* Free an object created with class_createInstance().
*/
OBJC_PUBLIC
id object_dispose(id obj);
/**
* Returns the class of the object. Note: the isa pointer should not be
* accessed directly with the GNUstep runtime.
*/
OBJC_PUBLIC
Class object_getClass(id obj);
/**
* Sets the class of the object. Note: the isa pointer should not be
* accessed directly with the GNUstep runtime.
*/
OBJC_PUBLIC
Class object_setClass(id obj, Class cls);
/**
* Returns the name of the class of the object. This is equivalent to calling
* class_getName() on the result of object_getClass().
*/
OBJC_PUBLIC
const char *object_getClassName(id obj);
/**
* Returns the name of a specified property.
*/
OBJC_PUBLIC
const char *property_getName(objc_property_t property);
/**
* Returns the attributes for the specified property. This is similar to an
* Objective-C type encoding, but contains some extra information. A full
* description of the format for this string may be found in Apple's
* Objective-C Runtime Programming Guide.
*/
OBJC_PUBLIC
const char *property_getAttributes(objc_property_t property);
/**
* Returns an array of attributes for this property.
*/
OBJC_PUBLIC
objc_property_attribute_t *property_copyAttributeList(objc_property_t property,
unsigned int *outCount);
/**
* Adds a property to the class, given a specified set of attributes. Note
* that this only sets the property metadata. The property accessor methods
* must already be created.
*/
OBJC_PUBLIC
BOOL class_addProperty(Class cls,
const char *name,
const objc_property_attribute_t *attributes,
unsigned int attributeCount);
/**
* Replaces property metadata. If the property does not exist, then this is
* equivalent to calling class_addProperty().
*/
OBJC_PUBLIC
void class_replaceProperty(Class cls,
const char *name,
const objc_property_attribute_t *attributes,
unsigned int attributeCount);
/**
* Returns a copy of a single attribute.
*/
OBJC_PUBLIC
char *property_copyAttributeValue(objc_property_t property,
const char *attributeName);
/**
* Testswhether a protocol conforms to another protocol.
*/
OBJC_PUBLIC
BOOL protocol_conformsToProtocol(Protocol *p, Protocol *other);
/**
* Returns an array of method descriptions. Stores the number of elements in
* the array in the variable pointed to by the last parameter. The caller is
* responsible for freeing this array.
*/
OBJC_PUBLIC
struct objc_method_description *protocol_copyMethodDescriptionList(Protocol *p,
BOOL isRequiredMethod, BOOL isInstanceMethod, unsigned int *count);
/**
* Returns an array of required instance properties, with the number being
* stored in the variable pointed to by the last argument. The caller is
* responsible for freeing the returned array.
*/
OBJC_PUBLIC
objc_property_t *protocol_copyPropertyList(Protocol *p, unsigned int *count);
/**
* Returns an array of properties specified by this class, with the number
* being stored in the variable pointed to by the last argument. The caller is
* responsible for freeing the returned array.
*/
OBJC_PUBLIC
objc_property_t *protocol_copyPropertyList2(Protocol *p, unsigned int *count,
BOOL isRequiredProperty, BOOL isInstanceProperty);
/**
* Returns an array of protocols that this protocol conforms to, with the
* number of protocols in the array being returned via the last argument. The
* caller is responsible for freeing this array.
*/
OBJC_PUBLIC
Protocol *__unsafe_unretained*protocol_copyProtocolList(Protocol *p, unsigned int *count);
/**
* Returns all of the protocols that the runtime is aware of. Note that
* protocols compiled by GCC and not attacked to classes may not have been
* registered with the runtime. The number of protocols returned is stored at
* the address indicated by the pointer argument.
*
* The caller is responsible for freeing the returned array.
*/
OBJC_PUBLIC
Protocol *__unsafe_unretained*objc_copyProtocolList(unsigned int *outCount);
/**
* Returns the method description for the specified method within a given
* protocol.
*/
OBJC_PUBLIC
struct objc_method_description protocol_getMethodDescription(Protocol *p,
SEL aSel, BOOL isRequiredMethod, BOOL isInstanceMethod);
/**
* Returns the extended type encoding of the specified method.
*
* Note: This function is used by JavaScriptCore but is not public in Apple's
* implementation and so its semantics may change in the future and this
* runtime may diverge from Apple's.
*/
OBJC_PUBLIC
const char *_protocol_getMethodTypeEncoding(Protocol *p, SEL aSel,
BOOL isRequiredMethod, BOOL isInstanceMethod);
/**
* Returns the name of the specified protocol.
*/
OBJC_PUBLIC
const char* protocol_getName(Protocol *p);
/**
* Returns the property metadata for the property with the specified name.
*/
OBJC_PUBLIC
objc_property_t protocol_getProperty(Protocol *p, const char *name,
BOOL isRequiredProperty, BOOL isInstanceProperty);
/**
* Compares two protocols. Currently, protocols are assumed to be equal if
* their names match. This is required for compatibility with the GCC ABI,
* which made not attempt to unique protocols (or even register them with the
* runtime).
*/
OBJC_PUBLIC
BOOL protocol_isEqual(Protocol *p, Protocol *other);
/**
* The message lookup function used by the GCC ABI. This returns a pointer to
* the function (either a method or a forwarding hook) that should be called in
* response to a given message.
*/
OBJC_PUBLIC
IMP objc_msg_lookup(id, SEL) OBJC_NONPORTABLE;
/**
* The message lookup function used for messages sent to super in the GCC ABI.
* This specifies both the class and the
*/
OBJC_PUBLIC
IMP objc_msg_lookup_super(struct objc_super*, SEL) OBJC_NONPORTABLE;
/**
* Returns the name of the specified selector.
*/
OBJC_PUBLIC
const char *sel_getName(SEL sel);
/**
* Registers a selector with the runtime. This is equivalent to sel_registerName().
*/
OBJC_PUBLIC
SEL sel_getUid(const char *selName);
/**
* Returns whether two selectors are equal. For the purpose of comparison,
* selectors with the same name and type are regarded as equal. Selectors with
* the same name and different types are regarded as different. If one
* selector is typed and the other is untyped, but the names are the same, then
* they are regarded as equal. This means that sel_isEqual(a, b) and
* sel_isEqual(a, c) does not imply sel_isEqual(b, c) - if a is untyped but
* both b and c are typed selectors with different types, then then the first
* two will return YES, but the third case will return NO.
*/
OBJC_PUBLIC
BOOL sel_isEqual(SEL sel1, SEL sel2);
/**
* Registers an untyped selector with the runtime.
*/
OBJC_PUBLIC
SEL sel_registerName(const char *selName);
/**
* Register a typed selector.
*/
OBJC_PUBLIC
SEL sel_registerTypedName_np(const char *selName, const char *types) OBJC_NONPORTABLE;
/**
* Returns the type encoding associated with a selector, or the empty string is
* there is no such type.
*/
OBJC_PUBLIC
const char *sel_getType_np(SEL aSel) OBJC_NONPORTABLE;
/**
* Enumerates all of the type encodings associated with a given selector name
* (up to a specified limit). This function returns the number of types that
* exist for a specific selector, but only copies up to count of them into the
* array passed as the types argument. This allows you to call the function
* once with a relatively small on-stack buffer and then only call it again
* with a heap-allocated buffer if there is not enough space.
*/
OBJC_PUBLIC
unsigned sel_copyTypes_np(const char *selName, const char **types, unsigned count) OBJC_NONPORTABLE;
/**
* Enumerates all of the type encodings associated with a given selector name
* (up to a specified limit). This function returns the number of types that
* exist for a specific selector, but only copies up to count of them into the
* array passed as the types argument. This allows you to call the function
* once with a relatively small on-stack buffer and then only call it again
* with a heap-allocated buffer if there is not enough space.
*/
OBJC_PUBLIC
unsigned sel_copyTypedSelectors_np(const char *selName, SEL *const sels, unsigned count) OBJC_NONPORTABLE;
/**
* New ABI lookup function. Receiver may be modified during lookup or proxy
* forwarding and the sender may affect how lookup occurs.
*/
OBJC_PUBLIC
extern struct objc_slot *objc_msg_lookup_sender(id *receiver, SEL selector, id sender)
OBJC_NONPORTABLE OBJC_DEPRECATED;
/**
* Deprecated function for accessing a slot without going via any forwarding
* mechanisms.
*/
OBJC_PUBLIC
extern struct objc_slot *objc_get_slot(Class, SEL)
OBJC_NONPORTABLE OBJC_DEPRECATED;
/**
* Look up a slot, without invoking any forwarding mechanisms. The third
* parameter is used to return a pointer to the current value of the version
* counter. If this value is equal to `objc_method_cache_version` then the
* slot is safe to reuse without performing another lookup.
*/
OBJC_PUBLIC
extern struct objc_slot2 *objc_get_slot2(Class, SEL, uint64_t*)
OBJC_NONPORTABLE;
/**
* Look up a slot, invoking any required forwarding mechanisms. The third
* parameter is used to return a pointer to the current value of the version
* counter. If this value is equal to `objc_method_cache_version` then the
* slot is safe to reuse without performing another lookup.
*/
OBJC_PUBLIC
extern struct objc_slot2 *objc_slot_lookup_version(id *receiver, SEL selector, uint64_t*)
OBJC_NONPORTABLE;
/**
* Look up a slot, invoking any required forwarding mechanisms.
*/
OBJC_PUBLIC
extern IMP objc_msg_lookup2(id *receiver, SEL selector) OBJC_NONPORTABLE;
/**
* Registers a class for small objects. Small objects are stored inside a
* pointer. If the class can be registered, then this returns YES. The second
* argument specifies the bit pattern to use to identify the small object.
*/
OBJC_PUBLIC