fix cross compilability
parent
24b116037b
commit
d8df3f3539
@ -1,9 +1,175 @@
|
|||||||
|
//yes its ugly i know, but it works
|
||||||
|
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
#if !defined(__MINGW32__) && !defined(__MINGW64__)
|
||||||
|
#include <objc/runtime.h>
|
||||||
|
#include <objc/objc.h>
|
||||||
|
#endif
|
||||||
#import "YSObject.h"
|
#import "YSObject.h"
|
||||||
#import "YSZone.h"
|
#import "YSZone.h"
|
||||||
|
|
||||||
|
#if !defined(__MINGW32__) && !defined(__MINGW64__)
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
@implementation YSObject
|
@implementation YSObject
|
||||||
|
#if !defined(__MINGW32__) && !defined(__MINGW64__)
|
||||||
|
/*
|
||||||
|
+(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;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@ -0,0 +1,30 @@
|
|||||||
|
#include <stdlib.h>
|
||||||
|
#include <objc/objc.h>
|
||||||
|
#include <objc/runtime.h>
|
||||||
|
|
||||||
|
//a wrapper to make linking easier
|
||||||
|
#define YLAPI
|
||||||
|
|
||||||
|
#if defined(__MINGW32__) || defined(__MINGW64__)
|
||||||
|
#define YLAPI __declspec(dllexport)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
YLAPI size_t __imp_class_getInstanceSize(Class class_) {
|
||||||
|
extern size_t class_getInstanceSize(class_);
|
||||||
|
}
|
||||||
|
|
||||||
|
YLAPI Class __imp_object_setClass(id object, Class class_) {
|
||||||
|
extern Class object_setClass(object, class_);
|
||||||
|
}
|
||||||
|
|
||||||
|
YLAPI BOOL __imp_class_isMetaClass(Class class_) {
|
||||||
|
extern BOOL class_isMetaClass(class_);
|
||||||
|
}
|
||||||
|
|
||||||
|
YLAPI id __imp_object_dispose(id object) {
|
||||||
|
extern id object_dispose(object);
|
||||||
|
}
|
||||||
|
|
||||||
|
YLAPI Class __imp_class_getSuperclass(Class class_) {
|
||||||
|
extern Class class_getSuperclass(class_);
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue