forked from gnustep/libobjc2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgc_none.c
133 lines (119 loc) · 3.4 KB
/
gc_none.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#include "visibility.h"
#include "objc/runtime.h"
#include "gc_ops.h"
#include "class.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
static id allocate_class(Class cls, size_t extraBytes)
{
size_t size = cls->instance_size + extraBytes + sizeof(intptr_t);
intptr_t *addr =
#ifdef _WIN32
// Malloc on Windows doesn't guarantee 32-byte alignment, but we
// require this for any class that may contain vectors
_aligned_malloc(size, 32);
memset(addr, 0, size);
#else
calloc(size, 1);
#endif
return (id)(addr + 1);
}
static void free_object(id obj)
{
#ifdef _WIN32
_aligned_free((void*)(((intptr_t*)obj) - 1));
#else
free((void*)(((intptr_t*)obj) - 1));
#endif
}
static void *alloc(size_t size)
{
return calloc(size, 1);
}
void objc_registerThreadWithCollector(void) {}
void objc_unregisterThreadWithCollector(void) {}
void objc_assertRegisteredThreadWithCollector() {}
PRIVATE struct gc_ops gc_ops_none =
{
.allocate_class = allocate_class,
.free_object = free_object,
.malloc = alloc,
.free = free
};
PRIVATE struct gc_ops *gc = &gc_ops_none;
PRIVATE BOOL isGCEnabled = NO;
#ifndef ENABLE_GC
PRIVATE void enableGC(BOOL exclusive)
{
fprintf(stderr, "Attempting to enable garbage collection, but your"
"Objective-C runtime was built without garbage collection"
"support\n");
abort();
}
#endif
void objc_set_collection_threshold(size_t threshold) {}
void objc_set_collection_ratio(size_t ratio) {}
void objc_collect(unsigned long options) {}
BOOL objc_collectingEnabled(void) { return NO; }
BOOL objc_atomicCompareAndSwapPtr(id predicate, id replacement, volatile id *objectLocation)
{
return __sync_bool_compare_and_swap(objectLocation, predicate, replacement);
}
BOOL objc_atomicCompareAndSwapPtrBarrier(id predicate, id replacement, volatile id *objectLocation)
{
return __sync_bool_compare_and_swap(objectLocation, predicate, replacement);
}
BOOL objc_atomicCompareAndSwapGlobal(id predicate, id replacement, volatile id *objectLocation)
{
return objc_atomicCompareAndSwapPtr(predicate, replacement, objectLocation);
}
BOOL objc_atomicCompareAndSwapGlobalBarrier(id predicate, id replacement, volatile id *objectLocation)
{
return objc_atomicCompareAndSwapPtr(predicate, replacement, objectLocation);
}
BOOL objc_atomicCompareAndSwapInstanceVariable(id predicate, id replacement, volatile id *objectLocation)
{
return objc_atomicCompareAndSwapPtr(predicate, replacement, objectLocation);
}
BOOL objc_atomicCompareAndSwapInstanceVariableBarrier(id predicate, id replacement, volatile id *objectLocation)
{
return objc_atomicCompareAndSwapPtr(predicate, replacement, objectLocation);
}
id objc_assign_strongCast(id val, id *ptr)
{
*ptr = val;
return val;
}
id objc_assign_global(id val, id *ptr)
{
*ptr = val;
return val;
}
id objc_assign_ivar(id val, id dest, ptrdiff_t offset)
{
*(id*)((char*)dest+offset) = val;
return val;
}
void *objc_memmove_collectable(void *dst, const void *src, size_t size)
{
return memmove(dst, src, size);
}
id objc_read_weak(id *location)
{
return *location;
}
id objc_assign_weak(id value, id *location)
{
*location = value;
return value;
}
id objc_allocate_object(Class cls, int extra)
{
return class_createInstance(cls, extra);
}
BOOL objc_collecting_enabled(void) { return NO; }
void objc_startCollectorThread(void) {}
void objc_clear_stack(unsigned long options) {}
BOOL objc_is_finalized(void *ptr) { return NO; }
void objc_finalizeOnMainThread(Class cls) {}