backport fixes

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@29787 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
rfm 2010-02-27 19:23:58 +00:00
parent 1a6af09e33
commit 837d04cc56
4 changed files with 131 additions and 89 deletions

View file

@ -1,3 +1,11 @@
2010-02-27 Richard Frith-Macdonald <rfm@gnu.org>
* runtime.c:
* sync.m:
* runtime.h:
Backport David's fixes for @synchronize(class), suitably modified to
build with older compilers.
2010-02-27 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSObject.m: ([methodSignatureForSelector:]) remote the check

View file

@ -100,8 +100,7 @@ class_getInstanceMethodNonrecursive(Class aClass, SEL aSelector)
if (strcmp(sel_get_name(method->method_name), name) == 0)
{
if (NULL == types
|| strcmp(types, method->method_types) == 0)
if (NULL == types || strcmp(types, method->method_types) == 0)
{
return method;
}
@ -135,9 +134,7 @@ objc_updateDtableForClassContainingMethod(Method m)
BOOL
class_addIvar(Class cls,
const char *name,
size_t size,
uint8_t alignment,
const char *types)
size_t size, uint8_t alignment, const char *types)
{
struct objc_ivar_list *ivarlist;
Ivar ivar;
@ -164,7 +161,8 @@ class_addIvar(Class cls,
ivarlist->ivar_count++;
// objc_ivar_list contains one ivar. Others follow it.
cls->ivars = objc_realloc(ivarlist, sizeof(struct objc_ivar_list)
+ (ivarlist->ivar_count - 1) * sizeof(struct objc_ivar));
+ (ivarlist->ivar_count -
1) * sizeof(struct objc_ivar));
}
ivar = &cls->ivars->ivar_list[cls->ivars->ivar_count - 1];
@ -183,7 +181,8 @@ class_addMethod(Class cls, SEL name, IMP imp, const char *types)
const char *methodName = sel_get_name(name);
struct objc_method_list *methods;
for (methods = cls->methods; methods != NULL; methods = methods->method_next)
for (methods = cls->methods; methods != NULL;
methods = methods->method_next)
{
int i;
@ -298,7 +297,8 @@ class_copyMethodList(Class cls, unsigned int *outCount)
Method *copyDest;
struct objc_method_list *methods;
for (methods = cls->methods; methods != NULL; methods = methods->method_next)
for (methods = cls->methods; methods != NULL;
methods = methods->method_next)
{
count += methods->method_count;
}
@ -314,7 +314,8 @@ class_copyMethodList(Class cls, unsigned int *outCount)
list = malloc(count * sizeof(struct objc_method *));
copyDest = list;
for (methods = cls->methods; methods != NULL; methods = methods->method_next)
for (methods = cls->methods; methods != NULL;
methods = methods->method_next)
{
unsigned int i;
@ -520,8 +521,7 @@ class_setIvarLayout(Class cls, const char *layout)
memcpy(cls->ivars, list, listsize);
}
OBJC_DEPRECATED
Class
OBJC_DEPRECATED Class
class_setSuperclass(Class cls, Class newSuper)
{
Class oldSuper = cls->super_class;
@ -632,9 +632,7 @@ method_exchangeImplementations(Method m1, Method m2)
void
method_getArgumentType(Method method,
unsigned int index,
char *dst,
size_t dst_len)
unsigned int index, char *dst, size_t dst_len)
{
const char *types;
size_t length;
@ -910,6 +908,22 @@ objc_allocateClassPair(Class superclass, const char *name, size_t extraBytes)
return newClass;
}
Class
objc_allocateMetaClass(Class superclass, size_t extraBytes)
{
Class metaClass = calloc(1, sizeof(struct objc_class) + extraBytes);
// Initialize the metaclass
metaClass->class_pointer = superclass->class_pointer->class_pointer;
metaClass->super_class = superclass->class_pointer;
metaClass->name = strdup(superclass->name);
metaClass->info = _CLS_META;
metaClass->dtable = __objc_uninstalled_dtable;
metaClass->instance_size = sizeof(struct objc_class);
return metaClass;
}
void *
object_getIndexedIvars(id obj)
{
@ -997,7 +1011,8 @@ protocol_conformsToProtocol(Protocol *p, Protocol *other)
struct objc_method_description *
protocol_copyMethodDescriptionList(Protocol * p,
BOOL isRequiredMethod, BOOL isInstanceMethod, unsigned int *count)
BOOL isRequiredMethod,
BOOL isInstanceMethod, unsigned int *count)
{
*count = 0;
return NULL;
@ -1027,8 +1042,7 @@ protocol_isEqual(Protocol *p, Protocol *other)
{
return NO;
}
if (p == other
|| 0 == strcmp(p->protocol_name, other->protocol_name))
if (p == other || 0 == strcmp(p->protocol_name, other->protocol_name))
{
return YES;
}
@ -1038,14 +1052,16 @@ protocol_isEqual(Protocol *p, Protocol *other)
const char *
sel_getName(SEL sel)
{
if (sel == 0) return "<null selector>";
if (sel == 0)
return "<null selector>";
return sel_get_name(sel);
}
SEL
sel_getUid(const char *selName)
{
if (selName == 0) return 0;
if (selName == 0)
return 0;
return sel_get_uid(selName);
}
@ -1058,7 +1074,7 @@ sel_isEqual(SEL sel1, SEL sel2)
SEL
sel_registerName(const char *selName)
{
if (selName == 0) return 0;
if (selName == 0)
return 0;
return sel_register_name(selName);
}

View file

@ -1,6 +1,7 @@
#include <stdint.h>
#include <stddef.h>
#include <sys/types.h>
#include "Availability.h"
#if defined(ERROR_UNSUPPORTED_RUNTIME_FUNCTIONS)
# define OBJC_GNU_RUNTIME_UNSUPPORTED(x) \
@ -199,7 +200,11 @@ const char * method_getTypeEncoding(Method method);
IMP method_setImplementation(Method method, IMP imp);
Class objc_allocateClassPair(Class superclass, const char *name, size_t extraBytes);
Class
objc_allocateClassPair(Class superclass, const char *name, size_t extraBytes);
OBJC_NONPORTABLE
Class objc_allocateMetaClass(Class superclass, size_t extraBytes);
void objc_disposeClassPair(Class cls);

View file

@ -53,19 +53,32 @@ findLockClass(id obj)
static inline Class
initLockObject(id obj)
{
char nameBuffer[40];
Class lockClass;
const char *types;
pthread_mutex_t *lock;
pthread_mutexattr_t attr;
if (class_isMetaClass(obj->isa))
{
lockClass = objc_allocateMetaClass(obj, sizeof(pthread_mutex_t));
}
else
{
char nameBuffer[40];
snprintf(nameBuffer, 39, "hiddenlockClass%lld", lockClassId++);
lockClass = objc_allocateClassPair(obj->isa, nameBuffer,
sizeof(pthread_mutex_t));
}
types = method_getTypeEncoding(class_getInstanceMethod(obj->isa,
@selector(dealloc)));
class_addMethod(lockClass, @selector(dealloc), (IMP)deallocLockClass, types);
if (!class_isMetaClass(obj->isa))
{
objc_registerClassPair(lockClass);
}
lock = object_getIndexedIvars(lockClass);
pthread_mutexattr_init(&attr);