fix YSObject
parent
ee80c7abdf
commit
24b116037b
@ -1,169 +1,9 @@
|
||||
#include <malloc.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
#include <objc/runtime.h>
|
||||
#include <objc/objc.h>
|
||||
#import "YSObject.h"
|
||||
#import "YSZone.h"
|
||||
|
||||
#ifdef __MINGW32__
|
||||
#define DLLSPEC __declspec(dllexport)
|
||||
#endif
|
||||
|
||||
typedef struct obj_layout_unpadded {
|
||||
int32_t retained;
|
||||
} unp;
|
||||
#define UNP sizeof(unp)
|
||||
|
||||
#ifndef __BIGGEST_ALIGNMENT__
|
||||
#define __BIGGEST_ALIGNMENT__ sizeof(void *) + sizeof(void *)
|
||||
#endif
|
||||
|
||||
struct obj_layout {
|
||||
char padding[__BIGGEST_ALIGNMENT__ - ((UNP % __BIGGEST_ALIGNMENT__)
|
||||
? (UNP % __BIGGEST_ALIGNMENT__) : __BIGGEST_ALIGNMENT__)];
|
||||
int32_t retained;
|
||||
};
|
||||
typedef struct obj_layout *obj;
|
||||
|
||||
|
||||
inline id YSAllocateObject(Class theClass, YSUInteger extraBytes, YSZone *zone) {
|
||||
id new;
|
||||
int size;
|
||||
|
||||
size = class_getInstanceSize(theClass) + extraBytes + sizeof(struct obj_layout);
|
||||
if (zone == 0) {
|
||||
zone = YSDefaultMallocZone();
|
||||
}
|
||||
|
||||
new = YSZoneMalloc(zone, size);
|
||||
if (new != nil) {
|
||||
memset(new, 0, size);
|
||||
new = (id) &( (obj)new )[1];
|
||||
object_setClass(new, theClass);
|
||||
//AADD
|
||||
}
|
||||
|
||||
return new;
|
||||
}
|
||||
|
||||
inline id YSDeallocateObject(id theObject) {
|
||||
Class theClass = object_getClass(theObject);
|
||||
|
||||
if ( (theObject != nil) && !class_isMetaClass(theClass) ) {
|
||||
object_dispose(theObject);
|
||||
}
|
||||
}
|
||||
|
||||
@implementation YSObject
|
||||
|
||||
/*
|
||||
+(void) load {
|
||||
//impl
|
||||
return;
|
||||
}*/
|
||||
|
||||
-(id) init {
|
||||
return self;
|
||||
}
|
||||
|
||||
-(id) self {
|
||||
return self;
|
||||
}
|
||||
|
||||
+(void) initialize {
|
||||
//implement later
|
||||
return;
|
||||
}
|
||||
|
||||
+(id) allocWithZone: (YSZone *) zone {
|
||||
return YSAllocateObject(self, 0, zone);
|
||||
}
|
||||
|
||||
+(id) copyWithZone: (YSZone *) zone {
|
||||
return self;
|
||||
}
|
||||
|
||||
+(id) alloc {
|
||||
return [self allocWithZone: YSDefaultMallocZone()];
|
||||
}
|
||||
|
||||
+(id) new {
|
||||
return [[self alloc] init];
|
||||
}
|
||||
|
||||
-(Class) class {
|
||||
return object_getClass(self);
|
||||
}
|
||||
|
||||
-(void) dealloc {
|
||||
YSDeallocateObject(self);
|
||||
}
|
||||
|
||||
-(id) copy {
|
||||
return [(id)self copyWithZone: YSDefaultMallocZone()];
|
||||
}
|
||||
|
||||
+(Class) superclass {
|
||||
return class_getSuperclass(self);
|
||||
}
|
||||
-(Class) superclass {
|
||||
return class_getSuperclass(object_getClass(self));
|
||||
}
|
||||
|
||||
+(Class) class {
|
||||
return self;
|
||||
}
|
||||
|
||||
-(BOOL) isEqual: (id) anObject {
|
||||
return (self == anObject);
|
||||
}
|
||||
|
||||
+(BOOL) isKindOfClass: (Class) theClass {
|
||||
if (theClass == [YSObject class]) {
|
||||
return YES;
|
||||
}
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
-(BOOL) isProxy {
|
||||
return NO;
|
||||
}
|
||||
|
||||
-(id) performSelector: (SEL) theSelector {
|
||||
IMP msg;
|
||||
|
||||
if (theSelector == 0) {
|
||||
//raise exception
|
||||
perror("null selector given");
|
||||
return;
|
||||
}
|
||||
|
||||
msg = objc_msg_lookup(self, theSelector);
|
||||
if (!msg) {
|
||||
//raise exception
|
||||
perror("invalid selector");
|
||||
return nil;
|
||||
}
|
||||
|
||||
return (*msg)(self, theSelector);
|
||||
}
|
||||
|
||||
-(YSZone *) zone {
|
||||
return YSZoneFromPointer(self);
|
||||
}
|
||||
|
||||
+(YSZone *) zone {
|
||||
return YSDefaultMallocZone();
|
||||
}
|
||||
|
||||
//dummy methods
|
||||
+(oneway void) release {
|
||||
return;
|
||||
}
|
||||
|
||||
+(id) retain {
|
||||
return self;
|
||||
}
|
||||
@end
|
||||
|
||||
Loading…
Reference in New Issue