objc-api.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  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 0
  117. # endif
  118. #endif
  119. /* OBJC_AVAILABLE: shorthand for all-OS availability */
  120. #ifndef __APPLE_BLEACH_SDK__
  121. # if !defined(OBJC_AVAILABLE)
  122. # define OBJC_AVAILABLE(x, i, t, w, b) \
  123. __OSX_AVAILABLE(x) __IOS_AVAILABLE(i) __TVOS_AVAILABLE(t) \
  124. __WATCHOS_AVAILABLE(w) __BRIDGEOS_AVAILABLE(b)
  125. # endif
  126. #else
  127. # if !defined(OBJC_AVAILABLE)
  128. # define OBJC_AVAILABLE(x, i, t, w, b) \
  129. __OSX_AVAILABLE(x) __IOS_AVAILABLE(i) __TVOS_AVAILABLE(t) \
  130. __WATCHOS_AVAILABLE(w)
  131. # endif
  132. #endif
  133. /* OBJC_OSX_DEPRECATED_OTHERS_UNAVAILABLE: Deprecated on OS X,
  134. * unavailable everywhere else. */
  135. #ifndef __APPLE_BLEACH_SDK__
  136. # if !defined(OBJC_OSX_DEPRECATED_OTHERS_UNAVAILABLE)
  137. # define OBJC_OSX_DEPRECATED_OTHERS_UNAVAILABLE(_start, _dep, _msg) \
  138. __OSX_DEPRECATED(_start, _dep, _msg) \
  139. __IOS_UNAVAILABLE __TVOS_UNAVAILABLE \
  140. __WATCHOS_UNAVAILABLE __BRIDGEOS_UNAVAILABLE
  141. # endif
  142. #else
  143. # if !defined(OBJC_OSX_DEPRECATED_OTHERS_UNAVAILABLE)
  144. # define OBJC_OSX_DEPRECATED_OTHERS_UNAVAILABLE(_start, _dep, _msg) \
  145. __OSX_DEPRECATED(_start, _dep, _msg) \
  146. __IOS_UNAVAILABLE __TVOS_UNAVAILABLE \
  147. __WATCHOS_UNAVAILABLE
  148. # endif
  149. #endif
  150. /* OBJC_OSX_AVAILABLE_OTHERS_UNAVAILABLE: Available on OS X,
  151. * unavailable everywhere else. */
  152. #ifndef __APPLE_BLEACH_SDK__
  153. # if !defined(OBJC_OSX_AVAILABLE_OTHERS_UNAVAILABLE)
  154. # define OBJC_OSX_AVAILABLE_OTHERS_UNAVAILABLE(vers) \
  155. __OSX_AVAILABLE(vers) \
  156. __IOS_UNAVAILABLE __TVOS_UNAVAILABLE \
  157. __WATCHOS_UNAVAILABLE __BRIDGEOS_UNAVAILABLE
  158. # endif
  159. #else
  160. # if !defined(OBJC_OSX_AVAILABLE_OTHERS_UNAVAILABLE)
  161. # define OBJC_OSX_AVAILABLE_OTHERS_UNAVAILABLE(vers) \
  162. __OSX_AVAILABLE(vers) \
  163. __IOS_UNAVAILABLE __TVOS_UNAVAILABLE \
  164. __WATCHOS_UNAVAILABLE
  165. # endif
  166. #endif
  167. /* OBJC_ISA_AVAILABILITY: `isa` will be deprecated or unavailable
  168. * in the future */
  169. #if !defined(OBJC_ISA_AVAILABILITY)
  170. # if __OBJC2__
  171. # define OBJC_ISA_AVAILABILITY __attribute__((deprecated))
  172. # else
  173. # define OBJC_ISA_AVAILABILITY /* still available */
  174. # endif
  175. #endif
  176. /* OBJC2_UNAVAILABLE: unavailable in objc 2.0, deprecated in Leopard */
  177. #if !defined(OBJC2_UNAVAILABLE)
  178. # if __OBJC2__
  179. # define OBJC2_UNAVAILABLE UNAVAILABLE_ATTRIBUTE
  180. # else
  181. /* plain C code also falls here, but this is close enough */
  182. # define OBJC2_UNAVAILABLE \
  183. __OSX_DEPRECATED(10.5, 10.5, "not available in __OBJC2__") \
  184. __IOS_DEPRECATED(2.0, 2.0, "not available in __OBJC2__") \
  185. __TVOS_UNAVAILABLE __WATCHOS_UNAVAILABLE __BRIDGEOS_UNAVAILABLE
  186. # endif
  187. #endif
  188. /* OBJC_UNAVAILABLE: unavailable, with a message where supported */
  189. #if !defined(OBJC_UNAVAILABLE)
  190. # if __has_extension(attribute_unavailable_with_message)
  191. # define OBJC_UNAVAILABLE(_msg) __attribute__((unavailable(_msg)))
  192. # else
  193. # define OBJC_UNAVAILABLE(_msg) __attribute__((unavailable))
  194. # endif
  195. #endif
  196. /* OBJC_DEPRECATED: deprecated, with a message where supported */
  197. #if !defined(OBJC_DEPRECATED)
  198. # if __has_extension(attribute_deprecated_with_message)
  199. # define OBJC_DEPRECATED(_msg) __attribute__((deprecated(_msg)))
  200. # else
  201. # define OBJC_DEPRECATED(_msg) __attribute__((deprecated))
  202. # endif
  203. #endif
  204. /* OBJC_ARC_UNAVAILABLE: unavailable with -fobjc-arc */
  205. #if !defined(OBJC_ARC_UNAVAILABLE)
  206. # if __has_feature(objc_arc)
  207. # define OBJC_ARC_UNAVAILABLE OBJC_UNAVAILABLE("not available in automatic reference counting mode")
  208. # else
  209. # define OBJC_ARC_UNAVAILABLE
  210. # endif
  211. #endif
  212. /* OBJC_SWIFT_UNAVAILABLE: unavailable in Swift */
  213. #if !defined(OBJC_SWIFT_UNAVAILABLE)
  214. # if __has_feature(attribute_availability_swift)
  215. # define OBJC_SWIFT_UNAVAILABLE(_msg) __attribute__((availability(swift, unavailable, message=_msg)))
  216. # else
  217. # define OBJC_SWIFT_UNAVAILABLE(_msg)
  218. # endif
  219. #endif
  220. /* OBJC_ARM64_UNAVAILABLE: unavailable on arm64 (i.e. stret dispatch) */
  221. #if !defined(OBJC_ARM64_UNAVAILABLE)
  222. # if defined(__arm64__)
  223. # define OBJC_ARM64_UNAVAILABLE OBJC_UNAVAILABLE("not available in arm64")
  224. # else
  225. # define OBJC_ARM64_UNAVAILABLE
  226. # endif
  227. #endif
  228. /* OBJC_GC_UNAVAILABLE: unavailable with -fobjc-gc or -fobjc-gc-only */
  229. #if !defined(OBJC_GC_UNAVAILABLE)
  230. # define OBJC_GC_UNAVAILABLE
  231. #endif
  232. #if !defined(OBJC_EXTERN)
  233. # if defined(__cplusplus)
  234. # define OBJC_EXTERN extern "C"
  235. # else
  236. # define OBJC_EXTERN extern
  237. # endif
  238. #endif
  239. #if !defined(OBJC_VISIBLE)
  240. # if TARGET_OS_WIN32
  241. # if defined(BUILDING_OBJC)
  242. # define OBJC_VISIBLE __declspec(dllexport)
  243. # else
  244. # define OBJC_VISIBLE __declspec(dllimport)
  245. # endif
  246. # else
  247. # define OBJC_VISIBLE __attribute__((visibility("default")))
  248. # endif
  249. #endif
  250. #if !defined(OBJC_EXPORT)
  251. # define OBJC_EXPORT OBJC_EXTERN OBJC_VISIBLE
  252. #endif
  253. #if !defined(OBJC_IMPORT)
  254. # define OBJC_IMPORT extern
  255. #endif
  256. #if !defined(OBJC_ROOT_CLASS)
  257. # if __has_attribute(objc_root_class)
  258. # define OBJC_ROOT_CLASS __attribute__((objc_root_class))
  259. # else
  260. # define OBJC_ROOT_CLASS
  261. # endif
  262. #endif
  263. #ifndef __DARWIN_NULL
  264. #define __DARWIN_NULL NULL
  265. #endif
  266. #if !defined(OBJC_INLINE)
  267. # define OBJC_INLINE __inline
  268. #endif
  269. // Declares an enum type or option bits type as appropriate for each language.
  270. #if (__cplusplus && __cplusplus >= 201103L && (__has_extension(cxx_strong_enums) || __has_feature(objc_fixed_enum))) || (!__cplusplus && __has_feature(objc_fixed_enum))
  271. #define OBJC_ENUM(_type, _name) enum _name : _type _name; enum _name : _type
  272. #if (__cplusplus)
  273. #define OBJC_OPTIONS(_type, _name) _type _name; enum : _type
  274. #else
  275. #define OBJC_OPTIONS(_type, _name) enum _name : _type _name; enum _name : _type
  276. #endif
  277. #else
  278. #define OBJC_ENUM(_type, _name) _type _name; enum
  279. #define OBJC_OPTIONS(_type, _name) _type _name; enum
  280. #endif
  281. #if !defined(OBJC_RETURNS_RETAINED)
  282. # if __OBJC__ && __has_attribute(ns_returns_retained)
  283. # define OBJC_RETURNS_RETAINED __attribute__((ns_returns_retained))
  284. # else
  285. # define OBJC_RETURNS_RETAINED
  286. # endif
  287. #endif
  288. #endif