fix cross compilability

main
sandyx86 1 year ago
parent 24b116037b
commit d8df3f3539

@ -5,35 +5,29 @@
@implementation YSArray
-(id) init {
self = [super init];
array = NULL;
array = malloc(sizeof(id)); //allocate for one id
return self;
}
-(void) addObject: (id) theObject {
//printf("%s\n", "YSArray: addObject");
if (array == NULL) {
//printf("%s\n", "before malloc");
printf("%s\n", "addObject Init");
array = malloc(sizeof(id));
if (array == NULL) {
//printf("%s\n", "addObject: malloc failed.");
return;
}
//printf("%s\n", "after malloc");
} else {
//printf("%s\n", "before realloc");
array = realloc(array, count * sizeof(id));
array = realloc(array, (count + 1) * sizeof(id));
if (array == NULL) {
//printf("%s\n", "addObject: realloc failed.");
return;
}
}
array[count++] = theObject;
//printf("%s\n", "YSArray: object added.");
}
-(void) removeObject: (unsigned int) index {

@ -1,9 +1,175 @@
//yes its ugly i know, but it works
#include <malloc.h>
#include <string.h>
#include <inttypes.h>
#if !defined(__MINGW32__) && !defined(__MINGW64__)
#include <objc/runtime.h>
#include <objc/objc.h>
#endif
#import "YSObject.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
#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

@ -18,15 +18,13 @@ static:
$(CC) YSObject.m -c
$(CC) YSZone.m -c
$(CC) YSArray.m -c
$(CC) -I ../include YSTest.m -c
ar rcs libyeslib.a YSObject.o YSZone.o YSArray.o YSTest.o
ar rcs libyeslib.a YSObject.o YSZone.o YSArray.o
shared:
$(CC) YSObject.m -c -Wl,--enable-auto-import
$(CC) YSZone.m -c
$(CC) YSArray.m -c
$(CC) -I ../include YSTest.m -c
$(CC) -shared -o yeslib.dll YSObject.o YSZone.o YSArray.o YSTest.o $(LIB)
$(CC) -shared -o yeslib.dll YSObject.o YSZone.o YSArray.o $(LIB)
clean:
rm *.o

@ -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…
Cancel
Save