]> git.saurik.com Git - apple/objc4.git/blob - runtime/objc-auto.h
objc4-709.tar.gz
[apple/objc4.git] / runtime / objc-auto.h
1 /*
2 * Copyright (c) 2004-2007 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
24 #ifndef _OBJC_AUTO_H_
25 #define _OBJC_AUTO_H_
26
27 #pragma GCC system_header
28
29 #include <objc/objc.h>
30 #include <malloc/malloc.h>
31 #include <stdint.h>
32 #include <stddef.h>
33 #include <string.h>
34 #include <Availability.h>
35 #include <TargetConditionals.h>
36
37 #include <sys/types.h>
38 #include <libkern/OSAtomic.h>
39
40
41 // Define OBJC_SILENCE_GC_DEPRECATIONS=1 to temporarily
42 // silence deprecation warnings for GC functions.
43
44 #if OBJC_SILENCE_GC_DEPRECATIONS
45 # define OBJC_GC_DEPRECATED(message)
46 #elif __has_extension(attribute_deprecated_with_message)
47 # define OBJC_GC_DEPRECATED(message) __attribute__((deprecated(message ". Define OBJC_SILENCE_GC_DEPRECATIONS=1 to temporarily silence this diagnostic.")))
48 #else
49 # define OBJC_GC_DEPRECATED(message) __attribute__((deprecated))
50 #endif
51
52
53 enum {
54 OBJC_RATIO_COLLECTION = (0 << 0),
55 OBJC_GENERATIONAL_COLLECTION = (1 << 0),
56 OBJC_FULL_COLLECTION = (2 << 0),
57 OBJC_EXHAUSTIVE_COLLECTION = (3 << 0),
58
59 OBJC_COLLECT_IF_NEEDED = (1 << 3),
60 OBJC_WAIT_UNTIL_DONE = (1 << 4),
61 };
62
63 enum {
64 OBJC_CLEAR_RESIDENT_STACK = (1 << 0)
65 };
66
67
68 #ifndef OBJC_NO_GC
69
70
71 /* Out-of-line declarations */
72
73 OBJC_EXPORT void objc_collect(unsigned long options)
74 __OSX_DEPRECATED(10.6, 10.8, "it does nothing") __IOS_UNAVAILABLE __TVOS_UNAVAILABLE __WATCHOS_UNAVAILABLE;
75 OBJC_EXPORT BOOL objc_collectingEnabled(void)
76 __OSX_DEPRECATED(10.5, 10.8, "it always returns NO") __IOS_UNAVAILABLE __TVOS_UNAVAILABLE __WATCHOS_UNAVAILABLE;
77 OBJC_EXPORT malloc_zone_t *objc_collectableZone(void)
78 __OSX_DEPRECATED(10.7, 10.8, "it always returns nil") __IOS_UNAVAILABLE __TVOS_UNAVAILABLE __WATCHOS_UNAVAILABLE;
79 OBJC_EXPORT void objc_setCollectionThreshold(size_t threshold)
80 __OSX_DEPRECATED(10.5, 10.8, "it does nothing") __IOS_UNAVAILABLE __TVOS_UNAVAILABLE __WATCHOS_UNAVAILABLE;
81 OBJC_EXPORT void objc_setCollectionRatio(size_t ratio)
82 __OSX_DEPRECATED(10.5, 10.8, "it does nothing") __IOS_UNAVAILABLE __TVOS_UNAVAILABLE __WATCHOS_UNAVAILABLE;
83 OBJC_EXPORT BOOL objc_atomicCompareAndSwapPtr(id predicate, id replacement, volatile id *objectLocation)
84 __OSX_DEPRECATED(10.6, 10.8, "use OSAtomicCompareAndSwapPtr instead") __IOS_UNAVAILABLE __TVOS_UNAVAILABLE __WATCHOS_UNAVAILABLE OBJC_ARC_UNAVAILABLE;
85 OBJC_EXPORT BOOL objc_atomicCompareAndSwapPtrBarrier(id predicate, id replacement, volatile id *objectLocation)
86 __OSX_DEPRECATED(10.6, 10.8, "use OSAtomicCompareAndSwapPtrBarrier instead") __IOS_UNAVAILABLE __TVOS_UNAVAILABLE __WATCHOS_UNAVAILABLE OBJC_ARC_UNAVAILABLE;
87 OBJC_EXPORT BOOL objc_atomicCompareAndSwapGlobal(id predicate, id replacement, volatile id *objectLocation)
88 __OSX_DEPRECATED(10.6, 10.8, "use OSAtomicCompareAndSwapPtr instead") __IOS_UNAVAILABLE __TVOS_UNAVAILABLE __WATCHOS_UNAVAILABLE OBJC_ARC_UNAVAILABLE;
89 OBJC_EXPORT BOOL objc_atomicCompareAndSwapGlobalBarrier(id predicate, id replacement, volatile id *objectLocation)
90 __OSX_DEPRECATED(10.6, 10.8, "use OSAtomicCompareAndSwapPtrBarrier instead") __IOS_UNAVAILABLE __TVOS_UNAVAILABLE __WATCHOS_UNAVAILABLE OBJC_ARC_UNAVAILABLE;
91 OBJC_EXPORT BOOL objc_atomicCompareAndSwapInstanceVariable(id predicate, id replacement, volatile id *objectLocation)
92 __OSX_DEPRECATED(10.6, 10.8, "use OSAtomicCompareAndSwapPtr instead") __IOS_UNAVAILABLE __TVOS_UNAVAILABLE __WATCHOS_UNAVAILABLE OBJC_ARC_UNAVAILABLE;
93 OBJC_EXPORT BOOL objc_atomicCompareAndSwapInstanceVariableBarrier(id predicate, id replacement, volatile id *objectLocation)
94 __OSX_DEPRECATED(10.6, 10.8, "use OSAtomicCompareAndSwapPtrBarrier instead") __IOS_UNAVAILABLE __TVOS_UNAVAILABLE __WATCHOS_UNAVAILABLE OBJC_ARC_UNAVAILABLE;
95 OBJC_EXPORT id objc_assign_strongCast(id val, id *dest)
96 __OSX_DEPRECATED(10.4, 10.8, "use a simple assignment instead") __IOS_UNAVAILABLE __TVOS_UNAVAILABLE __WATCHOS_UNAVAILABLE;
97 OBJC_EXPORT id objc_assign_global(id val, id *dest)
98 __OSX_DEPRECATED(10.4, 10.8, "use a simple assignment instead") __IOS_UNAVAILABLE __TVOS_UNAVAILABLE __WATCHOS_UNAVAILABLE;
99 OBJC_EXPORT id objc_assign_threadlocal(id val, id *dest)
100 __OSX_DEPRECATED(10.7, 10.8, "use a simple assignment instead") __IOS_UNAVAILABLE __TVOS_UNAVAILABLE __WATCHOS_UNAVAILABLE;
101 OBJC_EXPORT id objc_assign_ivar(id value, id dest, ptrdiff_t offset)
102 __OSX_DEPRECATED(10.4, 10.8, "use a simple assignment instead") __IOS_UNAVAILABLE __TVOS_UNAVAILABLE __WATCHOS_UNAVAILABLE;
103 OBJC_EXPORT void *objc_memmove_collectable(void *dst, const void *src, size_t size)
104 __OSX_DEPRECATED(10.4, 10.8, "use memmove instead") __IOS_UNAVAILABLE __TVOS_UNAVAILABLE __WATCHOS_UNAVAILABLE;
105 OBJC_EXPORT id objc_read_weak(id *location)
106 __OSX_DEPRECATED(10.5, 10.8, "use a simple read instead, or convert to zeroing __weak") __IOS_UNAVAILABLE __TVOS_UNAVAILABLE __WATCHOS_UNAVAILABLE;
107 OBJC_EXPORT id objc_assign_weak(id value, id *location)
108 __OSX_DEPRECATED(10.5, 10.8, "use a simple assignment instead, or convert to zeroing __weak") __IOS_UNAVAILABLE __TVOS_UNAVAILABLE __WATCHOS_UNAVAILABLE;
109 OBJC_EXPORT void objc_registerThreadWithCollector(void)
110 __OSX_DEPRECATED(10.6, 10.8, "it does nothing") __IOS_UNAVAILABLE __TVOS_UNAVAILABLE __WATCHOS_UNAVAILABLE;
111 OBJC_EXPORT void objc_unregisterThreadWithCollector(void)
112 __OSX_DEPRECATED(10.6, 10.8, "it does nothing") __IOS_UNAVAILABLE __TVOS_UNAVAILABLE __WATCHOS_UNAVAILABLE;
113 OBJC_EXPORT void objc_assertRegisteredThreadWithCollector(void)
114 __OSX_DEPRECATED(10.6, 10.8, "it does nothing") __IOS_UNAVAILABLE __TVOS_UNAVAILABLE __WATCHOS_UNAVAILABLE;
115 OBJC_EXPORT void objc_clear_stack(unsigned long options)
116 __OSX_DEPRECATED(10.5, 10.8, "it does nothing") __IOS_UNAVAILABLE __TVOS_UNAVAILABLE __WATCHOS_UNAVAILABLE;
117 OBJC_EXPORT BOOL objc_is_finalized(void *ptr)
118 __OSX_DEPRECATED(10.4, 10.8, "it always returns NO") __IOS_UNAVAILABLE __TVOS_UNAVAILABLE __WATCHOS_UNAVAILABLE;
119 OBJC_EXPORT void objc_finalizeOnMainThread(Class cls)
120 __OSX_DEPRECATED(10.5, 10.5, "it does nothing") __IOS_UNAVAILABLE __TVOS_UNAVAILABLE __WATCHOS_UNAVAILABLE;
121 OBJC_EXPORT BOOL objc_collecting_enabled(void)
122 __OSX_DEPRECATED(10.4, 10.5, "it always returns NO") __IOS_UNAVAILABLE __TVOS_UNAVAILABLE __WATCHOS_UNAVAILABLE;
123 OBJC_EXPORT void objc_set_collection_threshold(size_t threshold)
124 __OSX_DEPRECATED(10.4, 10.5, "it does nothing") __IOS_UNAVAILABLE __TVOS_UNAVAILABLE __WATCHOS_UNAVAILABLE;
125 OBJC_EXPORT void objc_set_collection_ratio(size_t ratio)
126 __OSX_DEPRECATED(10.4, 10.5, "it does nothing") __IOS_UNAVAILABLE __TVOS_UNAVAILABLE __WATCHOS_UNAVAILABLE;
127 OBJC_EXPORT void objc_start_collector_thread(void)
128 __OSX_DEPRECATED(10.4, 10.5, "it does nothing") __IOS_UNAVAILABLE __TVOS_UNAVAILABLE __WATCHOS_UNAVAILABLE;
129 OBJC_EXPORT void objc_startCollectorThread(void)
130 __OSX_DEPRECATED(10.5, 10.7, "it does nothing") __IOS_UNAVAILABLE __TVOS_UNAVAILABLE __WATCHOS_UNAVAILABLE;
131 OBJC_EXPORT id objc_allocate_object(Class cls, int extra)
132 __OSX_DEPRECATED(10.4, 10.4, "use class_createInstance instead") __IOS_UNAVAILABLE __TVOS_UNAVAILABLE __WATCHOS_UNAVAILABLE;
133
134
135 /* !defined(OBJC_NO_GC) */
136 #else
137 /* defined(OBJC_NO_GC) */
138
139
140 /* Inline declarations */
141
142 OBJC_GC_DEPRECATED("it does nothing")
143 static OBJC_INLINE void objc_collect(unsigned long options __unused) { }
144 OBJC_GC_DEPRECATED("it always returns NO")
145 static OBJC_INLINE BOOL objc_collectingEnabled(void) { return NO; }
146 #if TARGET_OS_OSX
147 OBJC_GC_DEPRECATED("it always returns nil")
148 static OBJC_INLINE malloc_zone_t *objc_collectableZone(void) { return nil; }
149 #endif
150 OBJC_GC_DEPRECATED("it does nothing")
151 static OBJC_INLINE void objc_setCollectionThreshold(size_t threshold __unused) { }
152 OBJC_GC_DEPRECATED("it does nothing")
153 static OBJC_INLINE void objc_setCollectionRatio(size_t ratio __unused) { }
154 OBJC_GC_DEPRECATED("it does nothing")
155 static OBJC_INLINE void objc_startCollectorThread(void) { }
156
157 #if __has_feature(objc_arc)
158
159 /* Covers for GC memory operations are unavailable in ARC */
160
161 #else
162
163 OBJC_GC_DEPRECATED("use OSAtomicCompareAndSwapPtr instead")
164 static OBJC_INLINE BOOL objc_atomicCompareAndSwapPtr(id predicate, id replacement, volatile id *objectLocation)
165 { return OSAtomicCompareAndSwapPtr((void *)predicate, (void *)replacement, (void * volatile *)objectLocation); }
166
167 OBJC_GC_DEPRECATED("use OSAtomicCompareAndSwapPtrBarrier instead")
168 static OBJC_INLINE BOOL objc_atomicCompareAndSwapPtrBarrier(id predicate, id replacement, volatile id *objectLocation)
169 { return OSAtomicCompareAndSwapPtrBarrier((void *)predicate, (void *)replacement, (void * volatile *)objectLocation); }
170
171 OBJC_GC_DEPRECATED("use OSAtomicCompareAndSwapPtr instead")
172 static OBJC_INLINE BOOL objc_atomicCompareAndSwapGlobal(id predicate, id replacement, volatile id *objectLocation)
173 { return objc_atomicCompareAndSwapPtr(predicate, replacement, objectLocation); }
174
175 OBJC_GC_DEPRECATED("use OSAtomicCompareAndSwapPtrBarrier instead")
176 static OBJC_INLINE BOOL objc_atomicCompareAndSwapGlobalBarrier(id predicate, id replacement, volatile id *objectLocation)
177 { return objc_atomicCompareAndSwapPtrBarrier(predicate, replacement, objectLocation); }
178
179 OBJC_GC_DEPRECATED("use OSAtomicCompareAndSwapPtr instead")
180 static OBJC_INLINE BOOL objc_atomicCompareAndSwapInstanceVariable(id predicate, id replacement, volatile id *objectLocation)
181 { return objc_atomicCompareAndSwapPtr(predicate, replacement, objectLocation); }
182
183 OBJC_GC_DEPRECATED("use OSAtomicCompareAndSwapPtrBarrier instead")
184 static OBJC_INLINE BOOL objc_atomicCompareAndSwapInstanceVariableBarrier(id predicate, id replacement, volatile id *objectLocation)
185 { return objc_atomicCompareAndSwapPtrBarrier(predicate, replacement, objectLocation); }
186
187
188 OBJC_GC_DEPRECATED("use a simple assignment instead")
189 static OBJC_INLINE id objc_assign_strongCast(id val, id *dest)
190 { return (*dest = val); }
191
192 OBJC_GC_DEPRECATED("use a simple assignment instead")
193 static OBJC_INLINE id objc_assign_global(id val, id *dest)
194 { return (*dest = val); }
195
196 OBJC_GC_DEPRECATED("use a simple assignment instead")
197 static OBJC_INLINE id objc_assign_threadlocal(id val, id *dest)
198 { return (*dest = val); }
199
200 OBJC_GC_DEPRECATED("use a simple assignment instead")
201 static OBJC_INLINE id objc_assign_ivar(id val, id dest, ptrdiff_t offset)
202 { return (*(id*)((char *)dest+offset) = val); }
203
204 OBJC_GC_DEPRECATED("use a simple read instead, or convert to zeroing __weak")
205 static OBJC_INLINE id objc_read_weak(id *location)
206 { return *location; }
207
208 OBJC_GC_DEPRECATED("use a simple assignment instead, or convert to zeroing __weak")
209 static OBJC_INLINE id objc_assign_weak(id value, id *location)
210 { return (*location = value); }
211
212 /* MRC */
213 #endif
214
215 OBJC_GC_DEPRECATED("use memmove instead")
216 static OBJC_INLINE void *objc_memmove_collectable(void *dst, const void *src, size_t size)
217 { return memmove(dst, src, size); }
218
219 OBJC_GC_DEPRECATED("it does nothing")
220 static OBJC_INLINE void objc_finalizeOnMainThread(Class cls __unused) { }
221 OBJC_GC_DEPRECATED("it always returns NO")
222 static OBJC_INLINE BOOL objc_is_finalized(void *ptr __unused) { return NO; }
223 OBJC_GC_DEPRECATED("it does nothing")
224 static OBJC_INLINE void objc_clear_stack(unsigned long options __unused) { }
225 OBJC_GC_DEPRECATED("it always returns NO")
226 static OBJC_INLINE BOOL objc_collecting_enabled(void) { return NO; }
227 OBJC_GC_DEPRECATED("it does nothing")
228 static OBJC_INLINE void objc_set_collection_threshold(size_t threshold __unused) { }
229 OBJC_GC_DEPRECATED("it does nothing")
230 static OBJC_INLINE void objc_set_collection_ratio(size_t ratio __unused) { }
231 OBJC_GC_DEPRECATED("it does nothing")
232 static OBJC_INLINE void objc_start_collector_thread(void) { }
233
234 #if __has_feature(objc_arc)
235 extern id objc_allocate_object(Class cls, int extra) UNAVAILABLE_ATTRIBUTE;
236 #else
237 OBJC_EXPORT id class_createInstance(Class cls, size_t extraBytes)
238 OBJC_AVAILABLE(10.0, 2.0, 9.0, 1.0);
239 OBJC_GC_DEPRECATED("use class_createInstance instead")
240 static OBJC_INLINE id objc_allocate_object(Class cls, int extra)
241 { return class_createInstance(cls, extra); }
242 #endif
243
244 OBJC_GC_DEPRECATED("it does nothing")
245 static OBJC_INLINE void objc_registerThreadWithCollector() { }
246 OBJC_GC_DEPRECATED("it does nothing")
247 static OBJC_INLINE void objc_unregisterThreadWithCollector() { }
248 OBJC_GC_DEPRECATED("it does nothing")
249 static OBJC_INLINE void objc_assertRegisteredThreadWithCollector() { }
250
251 /* defined(OBJC_NO_GC) */
252 #endif
253
254
255 #endif