objc-api.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. /*
  2. * Copyright (c) 1999-2006 Apple Inc. All Rights Reserved.
  3. *
  4. * @APPLE_LICENSE_HEADER_START@
  5. *
  6. * This file contains Original Code and/or Modifications of Original Code
  7. * as defined in and that are subject to the Apple Public Source License
  8. * Version 2.0 (the 'License'). You may not use this file except in
  9. * compliance with the License. Please obtain a copy of the License at
  10. * http://www.opensource.apple.com/apsl/ and read it before using this
  11. * file.
  12. *
  13. * The Original Code and all software distributed under the License are
  14. * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  15. * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
  16. * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
  18. * Please see the License for the specific language governing rights and
  19. * limitations under the License.
  20. *
  21. * @APPLE_LICENSE_HEADER_END@
  22. */
  23. // Copyright 1988-1996 NeXT Software, Inc.
  24. #ifndef _OBJC_OBJC_API_H_
  25. #define _OBJC_OBJC_API_H_
  26. #include <Availability.h>
  27. #include <AvailabilityMacros.h>
  28. #include <TargetConditionals.h>
  29. #include <sys/types.h>
  30. #ifndef __has_feature
  31. # define __has_feature(x) 0
  32. #endif
  33. #ifndef __has_extension
  34. # define __has_extension __has_feature
  35. #endif
  36. #ifndef __has_attribute
  37. # define __has_attribute(x) 0
  38. #endif
  39. #if !__has_feature(nullability)
  40. # ifndef _Nullable
  41. # define _Nullable
  42. # endif
  43. # ifndef _Nonnull
  44. # define _Nonnull
  45. # endif
  46. # ifndef _Null_unspecified
  47. # define _Null_unspecified
  48. # endif
  49. #endif
  50. #ifndef __APPLE_BLEACH_SDK__
  51. # if __has_feature(attribute_availability_bridgeos)
  52. # ifndef __BRIDGEOS_AVAILABLE
  53. # define __BRIDGEOS_AVAILABLE(_vers) __OS_AVAILABILITY(bridgeos,introduced=_vers)
  54. # endif
  55. # ifndef __BRIDGEOS_DEPRECATED
  56. # define __BRIDGEOS_DEPRECATED(_start, _dep, _msg) __BRIDGEOS_AVAILABLE(_start) __OS_AVAILABILITY_MSG(bridgeos,deprecated=_dep,_msg)
  57. # endif
  58. # ifndef __BRIDGEOS_UNAVAILABLE
  59. # define __BRIDGEOS_UNAVAILABLE __OS_AVAILABILITY(bridgeos,unavailable)
  60. # endif
  61. # else
  62. # ifndef __BRIDGEOS_AVAILABLE
  63. # define __BRIDGEOS_AVAILABLE(_vers)
  64. # endif
  65. # ifndef __BRIDGEOS_DEPRECATED
  66. # define __BRIDGEOS_DEPRECATED(_start, _dep, _msg)
  67. # endif
  68. # ifndef __BRIDGEOS_UNAVAILABLE
  69. # define __BRIDGEOS_UNAVAILABLE
  70. # endif
  71. # endif
  72. #endif
  73. /*
  74. * OBJC_API_VERSION 0 or undef: Tiger and earlier API only
  75. * OBJC_API_VERSION 2: Leopard and later API available
  76. */
  77. #if !defined(OBJC_API_VERSION)
  78. # if defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED < __MAC_10_5
  79. # define OBJC_API_VERSION 0
  80. # else
  81. # define OBJC_API_VERSION 2
  82. # endif
  83. #endif
  84. /*
  85. * OBJC_NO_GC 1: GC is not supported
  86. * OBJC_NO_GC undef: GC is supported. This SDK no longer supports this mode.
  87. *
  88. * OBJC_NO_GC_API undef: Libraries must export any symbols that
  89. * dual-mode code may links to.
  90. * OBJC_NO_GC_API 1: Libraries need not export GC-related symbols.
  91. */
  92. #if defined(__OBJC_GC__)
  93. # error Objective-C garbage collection is not supported.
  94. #elif TARGET_OS_OSX
  95. /* GC is unsupported. GC API symbols are exported. */
  96. # define OBJC_NO_GC 1
  97. # undef OBJC_NO_GC_API
  98. #else
  99. /* GC is unsupported. GC API symbols are not exported. */
  100. # define OBJC_NO_GC 1
  101. # define OBJC_NO_GC_API 1
  102. #endif
  103. /* NS_ENFORCE_NSOBJECT_DESIGNATED_INITIALIZER == 1
  104. * marks -[NSObject init] as a designated initializer. */
  105. #if !defined(NS_ENFORCE_NSOBJECT_DESIGNATED_INITIALIZER)
  106. # define NS_ENFORCE_NSOBJECT_DESIGNATED_INITIALIZER 1
  107. #endif
  108. /* OBJC_OLD_DISPATCH_PROTOTYPES == 0 enforces the rule that the dispatch
  109. * functions must be cast to an appropriate function pointer type. */
  110. #if !defined(OBJC_OLD_DISPATCH_PROTOTYPES)
  111. # if __swift__
  112. // Existing Swift code expects IMP to be Comparable.
  113. // Variadic IMP is comparable via OpaquePointer; non-variadic IMP isn't.
  114. # define OBJC_OLD_DISPATCH_PROTOTYPES 1
  115. # else
  116. # define OBJC_OLD_DISPATCH_PROTOTYPES 1
  117. # endif
  118. #endif
  119. /* OBJC_AVAILABLE: shorthand for all-OS availability */
  120. #if !defined(OBJC_AVAILABLE)
  121. # define OBJC_AVAILABLE(x, i, t, w, b) \
  122. __OSX_AVAILABLE(x) __IOS_AVAILABLE(i) __TVOS_AVAILABLE(t) \
  123. __WATCHOS_AVAILABLE(w) __BRIDGEOS_AVAILABLE(b)
  124. #endif
  125. /* OBJC_ISA_AVAILABILITY: `isa` will be deprecated or unavailable
  126. * in the future */
  127. #if !defined(OBJC_ISA_AVAILABILITY)
  128. # if __OBJC2__
  129. # define OBJC_ISA_AVAILABILITY __attribute__((deprecated))
  130. # else
  131. # define OBJC_ISA_AVAILABILITY /* still available */
  132. # endif
  133. #endif
  134. /* OBJC2_UNAVAILABLE: unavailable in objc 2.0, deprecated in Leopard */
  135. #if !defined(OBJC2_UNAVAILABLE)
  136. # if __OBJC2__
  137. # define OBJC2_UNAVAILABLE UNAVAILABLE_ATTRIBUTE
  138. # else
  139. /* plain C code also falls here, but this is close enough */
  140. # define OBJC2_UNAVAILABLE \
  141. __OSX_DEPRECATED(10.5, 10.5, "not available in __OBJC2__") \
  142. __IOS_DEPRECATED(2.0, 2.0, "not available in __OBJC2__") \
  143. __TVOS_UNAVAILABLE __WATCHOS_UNAVAILABLE __BRIDGEOS_UNAVAILABLE
  144. # endif
  145. #endif
  146. /* OBJC_UNAVAILABLE: unavailable, with a message where supported */
  147. #if !defined(OBJC_UNAVAILABLE)
  148. # if __has_extension(attribute_unavailable_with_message)
  149. # define OBJC_UNAVAILABLE(_msg) __attribute__((unavailable(_msg)))
  150. # else
  151. # define OBJC_UNAVAILABLE(_msg) __attribute__((unavailable))
  152. # endif
  153. #endif
  154. /* OBJC_DEPRECATED: deprecated, with a message where supported */
  155. #if !defined(OBJC_DEPRECATED)
  156. # if __has_extension(attribute_deprecated_with_message)
  157. # define OBJC_DEPRECATED(_msg) __attribute__((deprecated(_msg)))
  158. # else
  159. # define OBJC_DEPRECATED(_msg) __attribute__((deprecated))
  160. # endif
  161. #endif
  162. /* OBJC_ARC_UNAVAILABLE: unavailable with -fobjc-arc */
  163. #if !defined(OBJC_ARC_UNAVAILABLE)
  164. # if __has_feature(objc_arc)
  165. # define OBJC_ARC_UNAVAILABLE OBJC_UNAVAILABLE("not available in automatic reference counting mode")
  166. # else
  167. # define OBJC_ARC_UNAVAILABLE
  168. # endif
  169. #endif
  170. /* OBJC_SWIFT_UNAVAILABLE: unavailable in Swift */
  171. #if !defined(OBJC_SWIFT_UNAVAILABLE)
  172. # if __has_feature(attribute_availability_swift)
  173. # define OBJC_SWIFT_UNAVAILABLE(_msg) __attribute__((availability(swift, unavailable, message=_msg)))
  174. # else
  175. # define OBJC_SWIFT_UNAVAILABLE(_msg)
  176. # endif
  177. #endif
  178. /* OBJC_ARM64_UNAVAILABLE: unavailable on arm64 (i.e. stret dispatch) */
  179. #if !defined(OBJC_ARM64_UNAVAILABLE)
  180. # if defined(__arm64__)
  181. # define OBJC_ARM64_UNAVAILABLE OBJC_UNAVAILABLE("not available in arm64")
  182. # else
  183. # define OBJC_ARM64_UNAVAILABLE
  184. # endif
  185. #endif
  186. /* OBJC_GC_UNAVAILABLE: unavailable with -fobjc-gc or -fobjc-gc-only */
  187. #if !defined(OBJC_GC_UNAVAILABLE)
  188. # define OBJC_GC_UNAVAILABLE
  189. #endif
  190. #if !defined(OBJC_EXTERN)
  191. # if defined(__cplusplus)
  192. # define OBJC_EXTERN extern "C"
  193. # else
  194. # define OBJC_EXTERN extern
  195. # endif
  196. #endif
  197. #if !defined(OBJC_VISIBLE)
  198. # if TARGET_OS_WIN32
  199. # if defined(BUILDING_OBJC)
  200. # define OBJC_VISIBLE __declspec(dllexport)
  201. # else
  202. # define OBJC_VISIBLE __declspec(dllimport)
  203. # endif
  204. # else
  205. # define OBJC_VISIBLE __attribute__((visibility("default")))
  206. # endif
  207. #endif
  208. #if !defined(OBJC_EXPORT)
  209. # define OBJC_EXPORT OBJC_EXTERN OBJC_VISIBLE
  210. #endif
  211. #if !defined(OBJC_IMPORT)
  212. # define OBJC_IMPORT extern
  213. #endif
  214. #if !defined(OBJC_ROOT_CLASS)
  215. # if __has_attribute(objc_root_class)
  216. # define OBJC_ROOT_CLASS __attribute__((objc_root_class))
  217. # else
  218. # define OBJC_ROOT_CLASS
  219. # endif
  220. #endif
  221. #ifndef __DARWIN_NULL
  222. #define __DARWIN_NULL NULL
  223. #endif
  224. #if !defined(OBJC_INLINE)
  225. # define OBJC_INLINE __inline
  226. #endif
  227. // Declares an enum type or option bits type as appropriate for each language.
  228. #if (__cplusplus && __cplusplus >= 201103L && (__has_extension(cxx_strong_enums) || __has_feature(objc_fixed_enum))) || (!__cplusplus && __has_feature(objc_fixed_enum))
  229. #define OBJC_ENUM(_type, _name) enum _name : _type _name; enum _name : _type
  230. #if (__cplusplus)
  231. #define OBJC_OPTIONS(_type, _name) _type _name; enum : _type
  232. #else
  233. #define OBJC_OPTIONS(_type, _name) enum _name : _type _name; enum _name : _type
  234. #endif
  235. #else
  236. #define OBJC_ENUM(_type, _name) _type _name; enum
  237. #define OBJC_OPTIONS(_type, _name) _type _name; enum
  238. #endif
  239. #if !defined(OBJC_RETURNS_RETAINED)
  240. # if __OBJC__ && __has_attribute(ns_returns_retained)
  241. # define OBJC_RETURNS_RETAINED __attribute__((ns_returns_retained))
  242. # else
  243. # define OBJC_RETURNS_RETAINED
  244. # endif
  245. #endif
  246. #endif