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