object_private.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /*
  2. * Copyright (c) 2011-2012 Apple Inc. All rights reserved.
  3. *
  4. * @APPLE_APACHE_LICENSE_HEADER_START@
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the "License");
  7. * you may not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. *
  18. * @APPLE_APACHE_LICENSE_HEADER_END@
  19. */
  20. /*
  21. * IMPORTANT: This header file describes INTERNAL interfaces to libdispatch
  22. * which are subject to change in future releases of Mac OS X. Any applications
  23. * relying on these interfaces WILL break.
  24. */
  25. #ifndef __OS_OBJECT_PRIVATE__
  26. #define __OS_OBJECT_PRIVATE__
  27. #include <os/object.h>
  28. #include <stddef.h>
  29. #include <stdint.h>
  30. #if __GNUC__
  31. #define OS_OBJECT_NOTHROW __attribute__((__nothrow__))
  32. #define OS_OBJECT_NONNULL __attribute__((__nonnull__))
  33. #define OS_OBJECT_WARN_RESULT __attribute__((__warn_unused_result__))
  34. #define OS_OBJECT_MALLOC __attribute__((__malloc__))
  35. #ifndef OS_OBJECT_EXPORT
  36. #define OS_OBJECT_EXPORT extern __attribute__((visibility("default")))
  37. #endif
  38. #else
  39. /*! @parseOnly */
  40. #define OS_OBJECT_NOTHROW
  41. /*! @parseOnly */
  42. #define OS_OBJECT_NONNULL
  43. /*! @parseOnly */
  44. #define OS_OBJECT_WARN_RESULT
  45. /*! @parseOnly */
  46. #define OS_OBJECT_MALLOC
  47. #ifndef OS_OBJECT_EXPORT
  48. /*! @parseOnly */
  49. #define OS_OBJECT_EXPORT extern
  50. #endif
  51. #endif
  52. #if OS_OBJECT_USE_OBJC && __has_feature(objc_arc)
  53. #define _OS_OBJECT_OBJC_ARC 1
  54. #else
  55. #define _OS_OBJECT_OBJC_ARC 0
  56. #endif
  57. #define _OS_OBJECT_GLOBAL_REFCNT INT_MAX
  58. #define _OS_OBJECT_HEADER(isa, ref_cnt, xref_cnt) \
  59. isa; /* must be pointer-sized */ \
  60. int volatile ref_cnt; \
  61. int volatile xref_cnt
  62. #if OS_OBJECT_HAVE_OBJC_SUPPORT
  63. #define OS_OBJECT_CLASS_SYMBOL(name) OS_##name##_class
  64. #if TARGET_OS_MAC && !TARGET_OS_SIMULATOR && defined(__i386__)
  65. #define OS_OBJECT_HAVE_OBJC1 1
  66. #define OS_OBJECT_HAVE_OBJC2 0
  67. #define OS_OBJC_CLASS_RAW_SYMBOL_NAME(name) \
  68. ".objc_class_name_" OS_STRINGIFY(name)
  69. #define _OS_OBJECT_CLASS_HEADER() \
  70. const void *_os_obj_objc_isa
  71. #else
  72. #define OS_OBJECT_HAVE_OBJC1 0
  73. #define OS_OBJECT_HAVE_OBJC2 1
  74. #define OS_OBJC_CLASS_RAW_SYMBOL_NAME(name) "_OBJC_CLASS_$_" OS_STRINGIFY(name)
  75. // Must match size of compiler-generated OBJC_CLASS structure rdar://10640168
  76. #define _OS_OBJECT_CLASS_HEADER() \
  77. void *_os_obj_objc_class_t[5]
  78. #endif
  79. #define OS_OBJECT_OBJC_CLASS_DECL(name) \
  80. extern void *OS_OBJECT_CLASS_SYMBOL(name) \
  81. __asm__(OS_OBJC_CLASS_RAW_SYMBOL_NAME(OS_OBJECT_CLASS(name)))
  82. #else
  83. #define OS_OBJECT_HAVE_OBJC1 0
  84. #define OS_OBJECT_HAVE_OBJC2 0
  85. #define _OS_OBJECT_CLASS_HEADER() \
  86. void (*_os_obj_xref_dispose)(_os_object_t); \
  87. void (*_os_obj_dispose)(_os_object_t)
  88. #endif
  89. #define OS_OBJECT_CLASS(name) OS_##name
  90. #if OS_OBJECT_USE_OBJC && OS_OBJECT_SWIFT3
  91. @interface OS_OBJECT_CLASS(object) (OSObjectPrivate)
  92. - (void)_xref_dispose;
  93. - (void)_dispose;
  94. @end
  95. OS_OBJECT_DECL_PROTOCOL(object, <NSObject>);
  96. typedef OS_OBJECT_CLASS(object) *_os_object_t;
  97. #define _OS_OBJECT_DECL_SUBCLASS_INTERFACE(name, super) \
  98. @interface OS_OBJECT_CLASS(name) : OS_OBJECT_CLASS(super) \
  99. <OS_OBJECT_CLASS(name)> \
  100. @end
  101. #define _OS_OBJECT_DECL_PROTOCOL(name, super) \
  102. OS_OBJECT_DECL_PROTOCOL(name, <OS_OBJECT_CLASS(super)>)
  103. #define _OS_OBJECT_CLASS_IMPLEMENTS_PROTOCOL(name, super) \
  104. OS_OBJECT_CLASS_IMPLEMENTS_PROTOCOL(name, super)
  105. #elif OS_OBJECT_USE_OBJC
  106. API_AVAILABLE(macos(10.8), ios(6.0))
  107. OS_OBJECT_EXPORT
  108. @interface OS_OBJECT_CLASS(object) : NSObject
  109. - (void)_xref_dispose;
  110. - (void)_dispose;
  111. @end
  112. typedef OS_OBJECT_CLASS(object) *_os_object_t;
  113. #define _OS_OBJECT_DECL_SUBCLASS_INTERFACE(name, super) \
  114. @interface OS_OBJECT_CLASS(name) : OS_OBJECT_CLASS(super) \
  115. <OS_OBJECT_CLASS(name)> \
  116. @end
  117. #else
  118. #define _OS_OBJECT_DECL_SUBCLASS_INTERFACE(name, super)
  119. #define _OS_OBJECT_DECL_PROTOCOL(name, super)
  120. #define _OS_OBJECT_CLASS_IMPLEMENTS_PROTOCOL(name, super)
  121. typedef struct _os_object_s *_os_object_t;
  122. #endif
  123. OS_ASSUME_NONNULL_BEGIN
  124. __BEGIN_DECLS
  125. #if !_OS_OBJECT_OBJC_ARC
  126. API_AVAILABLE(macos(10.8), ios(6.0))
  127. OS_OBJECT_EXPORT OS_OBJECT_MALLOC OS_OBJECT_WARN_RESULT OS_OBJECT_NOTHROW
  128. OS_SWIFT_UNAVAILABLE("Unavailable in Swift")
  129. _os_object_t
  130. _os_object_alloc(const void *cls, size_t size);
  131. API_AVAILABLE(macos(10.8), ios(6.0))
  132. OS_OBJECT_EXPORT OS_OBJECT_MALLOC OS_OBJECT_WARN_RESULT OS_OBJECT_NOTHROW
  133. OS_SWIFT_UNAVAILABLE("Unavailable in Swift")
  134. _os_object_t
  135. _os_object_alloc_realized(const void *cls, size_t size);
  136. API_AVAILABLE(macos(10.8), ios(6.0))
  137. OS_OBJECT_EXPORT OS_OBJECT_NONNULL OS_OBJECT_NOTHROW
  138. OS_SWIFT_UNAVAILABLE("Unavailable in Swift")
  139. void _os_object_dealloc(_os_object_t object);
  140. API_AVAILABLE(macos(10.8), ios(6.0))
  141. OS_OBJECT_EXPORT OS_OBJECT_NONNULL OS_OBJECT_NOTHROW
  142. OS_SWIFT_UNAVAILABLE("Unavailable in Swift")
  143. _os_object_t
  144. _os_object_retain(_os_object_t object);
  145. API_AVAILABLE(macos(10.8), ios(6.0))
  146. OS_OBJECT_EXPORT OS_OBJECT_NONNULL OS_OBJECT_NOTHROW
  147. OS_SWIFT_UNAVAILABLE("Unavailable in Swift")
  148. _os_object_t
  149. _os_object_retain_with_resurrect(_os_object_t obj);
  150. API_AVAILABLE(macos(10.8), ios(6.0))
  151. OS_OBJECT_EXPORT OS_OBJECT_NONNULL OS_OBJECT_NOTHROW
  152. OS_SWIFT_UNAVAILABLE("Unavailable in Swift")
  153. void
  154. _os_object_release(_os_object_t object);
  155. API_AVAILABLE(macos(10.8), ios(6.0))
  156. OS_OBJECT_EXPORT OS_OBJECT_NONNULL OS_OBJECT_NOTHROW
  157. OS_SWIFT_UNAVAILABLE("Unavailable in Swift")
  158. _os_object_t
  159. _os_object_retain_internal(_os_object_t object);
  160. API_AVAILABLE(macos(10.8), ios(6.0))
  161. OS_OBJECT_EXPORT OS_OBJECT_NONNULL OS_OBJECT_NOTHROW
  162. OS_SWIFT_UNAVAILABLE("Unavailable in Swift")
  163. void
  164. _os_object_release_internal(_os_object_t object);
  165. API_AVAILABLE(macos(10.13), ios(11.0), tvos(11.0), watchos(4.0))
  166. OS_OBJECT_EXPORT OS_OBJECT_NONNULL OS_OBJECT_NOTHROW
  167. OS_SWIFT_UNAVAILABLE("Unavailable in Swift")
  168. _os_object_t
  169. _os_object_retain_internal_n(_os_object_t object, uint16_t n);
  170. API_AVAILABLE(macos(10.13), ios(11.0), tvos(11.0), watchos(4.0))
  171. OS_OBJECT_EXPORT OS_OBJECT_NONNULL OS_OBJECT_NOTHROW
  172. OS_SWIFT_UNAVAILABLE("Unavailable in Swift")
  173. void
  174. _os_object_release_internal_n(_os_object_t object, uint16_t n);
  175. #endif // !_OS_OBJECT_OBJC_ARC
  176. __END_DECLS
  177. OS_ASSUME_NONNULL_END
  178. #endif