]> git.saurik.com Git - apple/libdispatch.git/blob - os/object_private.h
libdispatch-913.30.4.tar.gz
[apple/libdispatch.git] / os / object_private.h
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 /*
22 * IMPORTANT: This header file describes INTERNAL interfaces to libdispatch
23 * which are subject to change in future releases of Mac OS X. Any applications
24 * relying on these interfaces WILL break.
25 */
26
27 #ifndef __OS_OBJECT_PRIVATE__
28 #define __OS_OBJECT_PRIVATE__
29
30 #include <os/object.h>
31 #include <stddef.h>
32 #include <stdint.h>
33
34 #if __GNUC__
35 #define OS_OBJECT_NOTHROW __attribute__((__nothrow__))
36 #define OS_OBJECT_NONNULL __attribute__((__nonnull__))
37 #define OS_OBJECT_WARN_RESULT __attribute__((__warn_unused_result__))
38 #define OS_OBJECT_MALLOC __attribute__((__malloc__))
39 #ifndef OS_OBJECT_EXPORT
40 #define OS_OBJECT_EXPORT extern __attribute__((visibility("default")))
41 #endif
42 #else
43 /*! @parseOnly */
44 #define OS_OBJECT_NOTHROW
45 /*! @parseOnly */
46 #define OS_OBJECT_NONNULL
47 /*! @parseOnly */
48 #define OS_OBJECT_WARN_RESULT
49 /*! @parseOnly */
50 #define OS_OBJECT_MALLOC
51 #ifndef OS_OBJECT_EXPORT
52 /*! @parseOnly */
53 #define OS_OBJECT_EXPORT extern
54 #endif
55 #endif
56
57 #if OS_OBJECT_USE_OBJC && __has_feature(objc_arc)
58 #define _OS_OBJECT_OBJC_ARC 1
59 #else
60 #define _OS_OBJECT_OBJC_ARC 0
61 #endif
62
63 #define _OS_OBJECT_GLOBAL_REFCNT INT_MAX
64
65 #define _OS_OBJECT_HEADER(isa, ref_cnt, xref_cnt) \
66 isa; /* must be pointer-sized */ \
67 int volatile ref_cnt; \
68 int volatile xref_cnt
69
70 #if OS_OBJECT_HAVE_OBJC_SUPPORT
71 #define OS_OBJECT_CLASS_SYMBOL(name) OS_##name##_class
72 #if TARGET_OS_MAC && !TARGET_OS_SIMULATOR && defined(__i386__)
73 #define OS_OBJECT_HAVE_OBJC1 1
74 #define OS_OBJECT_HAVE_OBJC2 0
75 #define OS_OBJC_CLASS_RAW_SYMBOL_NAME(name) \
76 ".objc_class_name_" OS_STRINGIFY(name)
77 #define _OS_OBJECT_CLASS_HEADER() \
78 const void *_os_obj_objc_isa
79 #else
80 #define OS_OBJECT_HAVE_OBJC1 0
81 #define OS_OBJECT_HAVE_OBJC2 1
82 #define OS_OBJC_CLASS_RAW_SYMBOL_NAME(name) "_OBJC_CLASS_$_" OS_STRINGIFY(name)
83 // Must match size of compiler-generated OBJC_CLASS structure rdar://10640168
84 #define _OS_OBJECT_CLASS_HEADER() \
85 void *_os_obj_objc_class_t[5]
86 #endif
87 #define OS_OBJECT_OBJC_CLASS_DECL(name) \
88 extern void *OS_OBJECT_CLASS_SYMBOL(name) \
89 asm(OS_OBJC_CLASS_RAW_SYMBOL_NAME(OS_OBJECT_CLASS(name)))
90 #else
91 #define OS_OBJECT_HAVE_OBJC1 0
92 #define OS_OBJECT_HAVE_OBJC2 0
93 #define _OS_OBJECT_CLASS_HEADER() \
94 void (*_os_obj_xref_dispose)(_os_object_t); \
95 void (*_os_obj_dispose)(_os_object_t)
96 #endif
97
98 #define OS_OBJECT_CLASS(name) OS_##name
99
100 #if OS_OBJECT_USE_OBJC && OS_OBJECT_SWIFT3
101 @interface OS_OBJECT_CLASS(object) (OSObjectPrivate)
102 - (void)_xref_dispose;
103 - (void)_dispose;
104 @end
105 OS_OBJECT_DECL_PROTOCOL(object, <NSObject>);
106 typedef OS_OBJECT_CLASS(object) *_os_object_t;
107 #define _OS_OBJECT_DECL_SUBCLASS_INTERFACE(name, super) \
108 @interface OS_OBJECT_CLASS(name) : OS_OBJECT_CLASS(super) \
109 <OS_OBJECT_CLASS(name)> \
110 @end
111 #define _OS_OBJECT_DECL_PROTOCOL(name, super) \
112 OS_OBJECT_DECL_PROTOCOL(name, <OS_OBJECT_CLASS(super)>)
113 #define _OS_OBJECT_CLASS_IMPLEMENTS_PROTOCOL(name, super) \
114 OS_OBJECT_CLASS_IMPLEMENTS_PROTOCOL(name, super)
115 #elif OS_OBJECT_USE_OBJC
116 API_AVAILABLE(macos(10.8), ios(6.0))
117 OS_OBJECT_EXPORT
118 @interface OS_OBJECT_CLASS(object) : NSObject
119 - (void)_xref_dispose;
120 - (void)_dispose;
121 @end
122 typedef OS_OBJECT_CLASS(object) *_os_object_t;
123 #define _OS_OBJECT_DECL_SUBCLASS_INTERFACE(name, super) \
124 @interface OS_OBJECT_CLASS(name) : OS_OBJECT_CLASS(super) \
125 <OS_OBJECT_CLASS(name)> \
126 @end
127 #else
128 #define _OS_OBJECT_DECL_SUBCLASS_INTERFACE(name, super)
129 #define _OS_OBJECT_DECL_PROTOCOL(name, super)
130 #define _OS_OBJECT_CLASS_IMPLEMENTS_PROTOCOL(name, super)
131 typedef struct _os_object_s *_os_object_t;
132 #endif
133
134 OS_ASSUME_NONNULL_BEGIN
135
136 __BEGIN_DECLS
137
138 #if !_OS_OBJECT_OBJC_ARC
139
140 API_AVAILABLE(macos(10.8), ios(6.0))
141 OS_OBJECT_EXPORT OS_OBJECT_MALLOC OS_OBJECT_WARN_RESULT OS_OBJECT_NOTHROW
142 OS_SWIFT_UNAVAILABLE("Unavailable in Swift")
143 _os_object_t
144 _os_object_alloc(const void *cls, size_t size);
145
146 API_AVAILABLE(macos(10.8), ios(6.0))
147 OS_OBJECT_EXPORT OS_OBJECT_MALLOC OS_OBJECT_WARN_RESULT OS_OBJECT_NOTHROW
148 OS_SWIFT_UNAVAILABLE("Unavailable in Swift")
149 _os_object_t
150 _os_object_alloc_realized(const void *cls, size_t size);
151
152 API_AVAILABLE(macos(10.8), ios(6.0))
153 OS_OBJECT_EXPORT OS_OBJECT_NONNULL OS_OBJECT_NOTHROW
154 OS_SWIFT_UNAVAILABLE("Unavailable in Swift")
155 void _os_object_dealloc(_os_object_t object);
156
157 API_AVAILABLE(macos(10.8), ios(6.0))
158 OS_OBJECT_EXPORT OS_OBJECT_NONNULL OS_OBJECT_NOTHROW
159 OS_SWIFT_UNAVAILABLE("Unavailable in Swift")
160 _os_object_t
161 _os_object_retain(_os_object_t object);
162
163 API_AVAILABLE(macos(10.8), ios(6.0))
164 OS_OBJECT_EXPORT OS_OBJECT_NONNULL OS_OBJECT_NOTHROW
165 OS_SWIFT_UNAVAILABLE("Unavailable in Swift")
166 _os_object_t
167 _os_object_retain_with_resurrect(_os_object_t obj);
168
169 API_AVAILABLE(macos(10.8), ios(6.0))
170 OS_OBJECT_EXPORT OS_OBJECT_NONNULL OS_OBJECT_NOTHROW
171 OS_SWIFT_UNAVAILABLE("Unavailable in Swift")
172 void
173 _os_object_release(_os_object_t object);
174
175 API_AVAILABLE(macos(10.8), ios(6.0))
176 OS_OBJECT_EXPORT OS_OBJECT_NONNULL OS_OBJECT_NOTHROW
177 OS_SWIFT_UNAVAILABLE("Unavailable in Swift")
178 _os_object_t
179 _os_object_retain_internal(_os_object_t object);
180
181 API_AVAILABLE(macos(10.8), ios(6.0))
182 OS_OBJECT_EXPORT OS_OBJECT_NONNULL OS_OBJECT_NOTHROW
183 OS_SWIFT_UNAVAILABLE("Unavailable in Swift")
184 void
185 _os_object_release_internal(_os_object_t object);
186
187 API_AVAILABLE(macos(10.12), ios(10.0), tvos(10.0), watchos(3.0))
188 OS_OBJECT_EXPORT OS_OBJECT_NONNULL OS_OBJECT_NOTHROW
189 OS_SWIFT_UNAVAILABLE("Unavailable in Swift")
190 _os_object_t
191 _os_object_retain_internal_n(_os_object_t object, uint16_t n);
192
193 API_AVAILABLE(macos(10.12), ios(10.0), tvos(10.0), watchos(3.0))
194 OS_OBJECT_EXPORT OS_OBJECT_NONNULL OS_OBJECT_NOTHROW
195 OS_SWIFT_UNAVAILABLE("Unavailable in Swift")
196 void
197 _os_object_release_internal_n(_os_object_t object, uint16_t n);
198
199 #endif // !_OS_OBJECT_OBJC_ARC
200
201 __END_DECLS
202
203 OS_ASSUME_NONNULL_END
204
205 #endif