]> git.saurik.com Git - apple/objc4.git/blob - runtime/objc-auto.mm
objc4-750.tar.gz
[apple/objc4.git] / runtime / objc-auto.mm
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 #define OBJC_DECLARE_SYMBOLS 1
25 #include "objc-private.h"
26 #include "objc-auto.h"
27
28 // GC is no longer supported.
29
30 #if OBJC_NO_GC_API
31
32 // No GC and no GC symbols needed. We're done here.
33 # if SUPPORT_GC_COMPAT
34 # error inconsistent config settings
35 # endif
36
37 #else
38
39 // No GC but we do need to export GC symbols.
40
41 # if !SUPPORT_GC_COMPAT
42 # error inconsistent config settings
43 # endif
44
45 void objc_collect(unsigned long options __unused) { }
46 BOOL objc_collectingEnabled(void) { return NO; }
47 void objc_setCollectionThreshold(size_t threshold __unused) { }
48 void objc_setCollectionRatio(size_t ratio __unused) { }
49 void objc_startCollectorThread(void) { }
50
51 #if TARGET_OS_WIN32
52 BOOL objc_atomicCompareAndSwapPtr(id predicate, id replacement, volatile id *objectLocation)
53 { void *original = InterlockedCompareExchangePointer((void * volatile *)objectLocation, (void *)replacement, (void *)predicate); return (original == predicate); }
54
55 BOOL objc_atomicCompareAndSwapPtrBarrier(id predicate, id replacement, volatile id *objectLocation)
56 { void *original = InterlockedCompareExchangePointer((void * volatile *)objectLocation, (void *)replacement, (void *)predicate); return (original == predicate); }
57 #else
58 BOOL objc_atomicCompareAndSwapPtr(id predicate, id replacement, volatile id *objectLocation)
59 { return OSAtomicCompareAndSwapPtr((void *)predicate, (void *)replacement, (void * volatile *)objectLocation); }
60
61 BOOL objc_atomicCompareAndSwapPtrBarrier(id predicate, id replacement, volatile id *objectLocation)
62 { return OSAtomicCompareAndSwapPtrBarrier((void *)predicate, (void *)replacement, (void * volatile *)objectLocation); }
63 #endif
64
65 BOOL objc_atomicCompareAndSwapGlobal(id predicate, id replacement, volatile id *objectLocation)
66 { return objc_atomicCompareAndSwapPtr(predicate, replacement, objectLocation); }
67
68 BOOL objc_atomicCompareAndSwapGlobalBarrier(id predicate, id replacement, volatile id *objectLocation)
69 { return objc_atomicCompareAndSwapPtrBarrier(predicate, replacement, objectLocation); }
70
71 BOOL objc_atomicCompareAndSwapInstanceVariable(id predicate, id replacement, volatile id *objectLocation)
72 { return objc_atomicCompareAndSwapPtr(predicate, replacement, objectLocation); }
73
74 BOOL objc_atomicCompareAndSwapInstanceVariableBarrier(id predicate, id replacement, volatile id *objectLocation)
75 { return objc_atomicCompareAndSwapPtrBarrier(predicate, replacement, objectLocation); }
76
77 id objc_assign_strongCast(id val, id *dest)
78 { return (*dest = val); }
79
80 id objc_assign_global(id val, id *dest)
81 { return (*dest = val); }
82
83 id objc_assign_threadlocal(id val, id *dest)
84 { return (*dest = val); }
85
86 id objc_assign_ivar(id val, id dest, ptrdiff_t offset)
87 { return (*(id*)((char *)dest+offset) = val); }
88
89 id objc_read_weak(id *location)
90 { return *location; }
91
92 id objc_assign_weak(id value, id *location)
93 { return (*location = value); }
94
95 void *objc_memmove_collectable(void *dst, const void *src, size_t size)
96 { return memmove(dst, src, size); }
97
98 void objc_finalizeOnMainThread(Class cls __unused) { }
99 BOOL objc_is_finalized(void *ptr __unused) { return NO; }
100 void objc_clear_stack(unsigned long options __unused) { }
101
102 BOOL objc_collecting_enabled(void) { return NO; }
103 void objc_set_collection_threshold(size_t threshold __unused) { }
104 void objc_set_collection_ratio(size_t ratio __unused) { }
105 void objc_start_collector_thread(void) { }
106
107 id objc_allocate_object(Class cls, int extra)
108 { return class_createInstance(cls, extra); }
109
110 void objc_registerThreadWithCollector() { }
111 void objc_unregisterThreadWithCollector() { }
112 void objc_assertRegisteredThreadWithCollector() { }
113
114 malloc_zone_t* objc_collect_init(int(*callback)() __unused) { return nil; }
115 malloc_zone_t* objc_collectableZone() { return nil; }
116
117 BOOL objc_isAuto(id object __unused) { return NO; }
118 BOOL objc_dumpHeap(char *filename __unused, unsigned long length __unused)
119 { return NO; }
120
121 // not OBJC_NO_GC_API
122 #endif