fix YSObject

main
sandyx86 1 year ago
parent ee80c7abdf
commit 24b116037b

@ -10,30 +10,30 @@
} }
-(void) addObject: (id) theObject { -(void) addObject: (id) theObject {
printf("%s\n", "YSArray: addObject"); //printf("%s\n", "YSArray: addObject");
if (array == NULL) { if (array == NULL) {
printf("%s\n", "before malloc"); //printf("%s\n", "before malloc");
array = malloc(sizeof(id)); array = malloc(sizeof(id));
if (array == NULL) { if (array == NULL) {
printf("%s\n", "addObject: malloc failed."); //printf("%s\n", "addObject: malloc failed.");
return; return;
} }
printf("%s\n", "after malloc"); //printf("%s\n", "after malloc");
} else { } else {
printf("%s\n", "before realloc"); //printf("%s\n", "before realloc");
array = realloc(array, count * sizeof(id)); array = realloc(array, count * sizeof(id));
if (array == NULL) { if (array == NULL) {
printf("%s\n", "addObject: realloc failed."); //printf("%s\n", "addObject: realloc failed.");
return; return;
} }
} }
array[count++] = theObject; array[count++] = theObject;
printf("%s\n", "YSArray: object added."); //printf("%s\n", "YSArray: object added.");
} }
-(void) removeObject: (unsigned int) index { -(void) removeObject: (unsigned int) index {

@ -2,10 +2,11 @@
#define YSOBJECT_H #define YSOBJECT_H
#import "YSZone.h" #import "YSZone.h"
#import <objc/Object.h>
typedef unsigned int YSUInteger; typedef unsigned int YSUInteger;
@protocol YSObject /* @protocol YSObject
-(Class) class; -(Class) class;
-(Class) superclass; -(Class) superclass;
//-(BOOL) isEqual: (id)anObject; //-(BOOL) isEqual: (id)anObject;
@ -33,20 +34,12 @@ typedef unsigned int YSUInteger;
//-(YSUInteger) retainCount; //-(YSUInteger) retainCount;
//-(YSString *) description; //-(YSString *) description;
-(YSZone *)zone; -(YSZone *)zone;
@end @end */
@interface YSObject <YSObject> { @interface YSObject : Object {
} }
-(Class) class;
-(Class) superclass;
-(id) self;
//-(YSString *) description;
+(id) copyWithZone: (YSZone *) zone;
-(YSZone *) zone;
+(YSZone *) zone;
@end @end
#endif #endif

@ -1,169 +1,9 @@
#include <malloc.h> #include <malloc.h>
#include <string.h> #include <string.h>
#include <inttypes.h> #include <inttypes.h>
#include <objc/runtime.h>
#include <objc/objc.h>
#import "YSObject.h" #import "YSObject.h"
#import "YSZone.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 @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 @end

@ -4,27 +4,29 @@ CC=gcc
LIB := -L LIB := -L
OS := OS :=
ifeq ($(OS),windows) ifeq ($(OS),windows)
LIB += lib/win64 #change these if needed
LIB += ../lib
LIB += -l:objc-1.dll -l:test.dll
CC=x86_64-w64-mingw32-gcc CC=x86_64-w64-mingw32-gcc
endif endif
ifeq ($(OS),linux) ifeq ($(OS),linux)
LIB += lib/linux64 LIB += ~/code/objc/wow/lib/linux64
endif endif
LIB += -lobjc
static: static:
$(CC) YSObject.m -c $(CC) YSObject.m -c
$(CC) YSZone.m -c $(CC) YSZone.m -c
$(CC) YSArray.m -c $(CC) YSArray.m -c
ar rcs libyeslib.a YSObject.o YSZone.o YSArray.o $(CC) -I ../include YSTest.m -c
ar rcs libyeslib.a YSObject.o YSZone.o YSArray.o YSTest.o
shared: shared:
$(CC) YSObject.m -c $(CC) YSObject.m -c -Wl,--enable-auto-import
$(CC) YSZone.m -c $(CC) YSZone.m -c
$(CC) YSArray.m -c $(CC) YSArray.m -c
$(CC) -shared -fPIC -o yeslib.dll YSObject.o YSZone.o YSArray.o $(LIB) $(CC) -I ../include YSTest.m -c
$(CC) -shared -o yeslib.dll YSObject.o YSZone.o YSArray.o YSTest.o $(LIB)
clean: clean:
rm *.o rm *.o
Loading…
Cancel
Save