2011-05-22 23:02:04 +00:00
|
|
|
#include "visibility.h"
|
|
|
|
#include "objc/runtime.h"
|
|
|
|
#include "gc_ops.h"
|
|
|
|
#include "class.h"
|
|
|
|
#include <stdlib.h>
|
2011-05-25 12:25:27 +00:00
|
|
|
#include <stdio.h>
|
2011-05-22 23:02:04 +00:00
|
|
|
|
|
|
|
static id allocate_class(Class cls, size_t extraBytes)
|
|
|
|
{
|
2011-07-03 11:14:29 +00:00
|
|
|
intptr_t *addr = calloc(cls->instance_size + extraBytes + sizeof(intptr_t), 1);
|
|
|
|
return (id)(addr + 1);
|
2011-05-22 23:02:04 +00:00
|
|
|
}
|
|
|
|
|
2011-07-31 16:30:33 +00:00
|
|
|
static void free_object(id obj)
|
|
|
|
{
|
2011-08-16 09:13:43 +00:00
|
|
|
free((void*)(((intptr_t*)obj) - 1));
|
2011-07-31 16:30:33 +00:00
|
|
|
}
|
|
|
|
|
2011-05-23 16:24:45 +00:00
|
|
|
static void *alloc(size_t size)
|
|
|
|
{
|
|
|
|
return calloc(size, 1);
|
|
|
|
}
|
|
|
|
|
2011-05-22 23:02:04 +00:00
|
|
|
PRIVATE struct gc_ops gc_ops_none =
|
|
|
|
{
|
2011-05-23 16:24:45 +00:00
|
|
|
.allocate_class = allocate_class,
|
2011-07-31 16:30:33 +00:00
|
|
|
.free_object = free_object,
|
2011-05-23 16:24:45 +00:00
|
|
|
.malloc = alloc,
|
|
|
|
.free = free
|
2011-05-22 23:02:04 +00:00
|
|
|
};
|
|
|
|
PRIVATE struct gc_ops *gc = &gc_ops_none;
|
|
|
|
|
|
|
|
PRIVATE BOOL isGCEnabled = NO;
|
|
|
|
|
2011-05-25 12:25:27 +00:00
|
|
|
#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
|