more changes for new runtime

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@29828 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
rfm 2010-03-04 08:15:08 +00:00
parent cb8bfd40eb
commit cdc8b38bb9
4 changed files with 37 additions and 86 deletions

View file

@ -1,3 +1,10 @@
2010-03-03 Richard Frith-Macdonald <rfm@gnu.org>
* Source/ObjectiveC2/runtime.c: Fix class data copying functions to
match OSX.
* Source/Additions/GSObjCRuntime.m: Implement adding classes using
new runtime functions.
2010-03-03 Doug Simons <dpsimons@testplant.com> 2010-03-03 Doug Simons <dpsimons@testplant.com>
* Source/NSDate.m: Fix natural language date parsing to handle AM/PM. * Source/NSDate.m: Fix natural language date parsing to handle AM/PM.

View file

@ -552,7 +552,7 @@ GS_EXPORT int GSObjCVersion(Class cls);
#endif #endif
/** /**
* Return the zone in which an object belongs, without using the zone method * GSObjCZone() is deprecated ... use -zone
*/ */
GS_EXPORT NSZone * GS_EXPORT NSZone *
GSObjCZone(NSObject *obj); GSObjCZone(NSObject *obj);

View file

@ -523,66 +523,18 @@ GSObjCMakeClass(NSString *name, NSString *superName, NSDictionary *iVars)
* The classes argument is an array of NSValue objects containing pointers * The classes argument is an array of NSValue objects containing pointers
* to classes previously created by the GSObjCMakeClass() function. * to classes previously created by the GSObjCMakeClass() function.
*/ */
#ifdef NeXT_RUNTIME
void void
GSObjCAddClasses(NSArray *classes) GSObjCAddClasses(NSArray *classes)
{ {
unsigned int numClasses = [classes count]; NSUInteger numClasses = [classes count];
unsigned int i; NSUInteger i;
for (i = 0; i < numClasses; i++)
{
objc_addClass((Class)[[classes objectAtIndex: i] pointerValue]);
}
}
#else
/*
* NOTE - OBJC_VERSION needs to be defined to be the version of the
* Objective-C runtime you are using. You can find this in the file
* 'init.c' in the GNU objective-C runtime source.
*/
#define OBJC_VERSION 8
void
GSObjCAddClasses(NSArray *classes)
{
void __objc_exec_class (void* module);
void __objc_resolve_class_links ();
Module_t module;
Symtab_t symtab;
unsigned int numClasses = [classes count];
unsigned int i;
Class c;
NSCAssert(numClasses > 0, @"No classes (array is NULL)");
c = (Class)[[classes objectAtIndex: 0] pointerValue];
// Prepare a fake module containing only the new classes
module = objc_calloc (1, sizeof (Module));
module->version = OBJC_VERSION;
module->size = sizeof (Module);
module->name = malloc (strlen(c->name) + 15);
strcpy ((char*)module->name, "GNUstep-Proxy-");
strcat ((char*)module->name, c->name);
module->symtab = malloc(sizeof(Symtab) + numClasses * sizeof(void *));
symtab = module->symtab;
symtab->sel_ref_cnt = 0;
symtab->refs = 0;
symtab->cls_def_cnt = numClasses; // We are defining numClasses classes.
symtab->cat_def_cnt = 0; // But no categories
for (i = 0; i < numClasses; i++) for (i = 0; i < numClasses; i++)
{ {
symtab->defs[i] = (Class)[[classes objectAtIndex: i] pointerValue]; objc_registerClassPair((Class)[[classes objectAtIndex: i] pointerValue]);
} }
symtab->defs[numClasses] = NULL; //null terminated list
// Insert our new class into the runtime.
__objc_exec_class (module);
__objc_resolve_class_links();
} }
#endif
static int behavior_debug = 0; static int behavior_debug = 0;

View file

@ -117,7 +117,7 @@ static void
objc_updateDtableForClassContainingMethod(Method m) objc_updateDtableForClassContainingMethod(Method m)
{ {
Class nextClass = Nil; Class nextClass = Nil;
void *state; void *state = NULL;
SEL sel = method_getName(m); SEL sel = method_getName(m);
while (Nil != (nextClass = objc_next_class(&state))) while (Nil != (nextClass = objc_next_class(&state)))
@ -268,7 +268,6 @@ class_copyIvarList(Class cls, unsigned int *outCount)
{ {
struct objc_ivar_list *ivarlist = cls->ivars; struct objc_ivar_list *ivarlist = cls->ivars;
unsigned int count = 0; unsigned int count = 0;
unsigned int i;
Ivar *list; Ivar *list;
if (ivarlist != NULL) if (ivarlist != NULL)
@ -284,11 +283,10 @@ class_copyIvarList(Class cls, unsigned int *outCount)
return NULL; return NULL;
} }
list = malloc(count * sizeof(struct objc_ivar *)); list = malloc((count + 1) * sizeof(struct objc_ivar *));
for (i = 0; i < ivarlist->ivar_count; i++) list[count] = NULL;
{ memcpy(list, ivarlist->ivar_list,
list[i] = &(ivarlist->ivar_list[i]); ivarlist->ivar_count * sizeof(struct objc_ivar *));
}
return list; return list;
} }
@ -297,11 +295,9 @@ class_copyMethodList(Class cls, unsigned int *outCount)
{ {
unsigned int count = 0; unsigned int count = 0;
Method *list; Method *list;
Method *copyDest;
struct objc_method_list *methods; struct objc_method_list *methods;
for (methods = cls->methods; methods != NULL; for (methods = cls->methods; methods != NULL; methods = methods->method_next)
methods = methods->method_next)
{ {
count += methods->method_count; count += methods->method_count;
} }
@ -314,19 +310,14 @@ class_copyMethodList(Class cls, unsigned int *outCount)
return NULL; return NULL;
} }
list = malloc(count * sizeof(struct objc_method *)); list = malloc((count + 1) * sizeof(struct objc_method *));
copyDest = list; list[count] = NULL;
count = 0;
for (methods = cls->methods; methods != NULL; for (methods = cls->methods; methods != NULL; methods = methods->method_next)
methods = methods->method_next)
{ {
unsigned int i; memcpy(&list[count], methods->method_list,
methods->method_count * sizeof(struct objc_method *));
for (i = 0; i < methods->method_count; i++) count += methods->method_count;
{
copyDest[i] = &(methods->method_list[i]);
}
copyDest += methods->method_count;
} }
return list; return list;
@ -337,29 +328,30 @@ class_copyProtocolList(Class cls, unsigned int *outCount)
{ {
struct objc_protocol_list *protocolList = cls->protocols; struct objc_protocol_list *protocolList = cls->protocols;
struct objc_protocol_list *list; struct objc_protocol_list *list;
int listSize = 0; unsigned int count = 0;
Protocol **protocols; Protocol **protocols;
int index;
for (list = protocolList; list != NULL; list = list->next) for (list = protocolList; list != NULL; list = list->next)
{ {
listSize += list->count; count += list->count;
} }
if (listSize == 0) if (outCount != NULL)
{
*outCount = count;
}
if (count == 0)
{ {
*outCount = 0;
return NULL; return NULL;
} }
protocols = calloc(listSize, sizeof(Protocol *) + 1); protocols = malloc((count + 1) * sizeof(Protocol *));
index = 0; protocols[count] = NULL;
count = 0;
for (list = protocolList; list != NULL; list = list->next) for (list = protocolList; list != NULL; list = list->next)
{ {
memcpy(&protocols[index], list->list, list->count * sizeof(Protocol *)); memcpy(&protocols[count], list->list, list->count * sizeof(Protocol *));
index += list->count; count += list->count;
} }
protocols[listSize] = NULL;
*outCount = listSize + 1;
return protocols; return protocols;
} }