mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-31 16:50:58 +00:00
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:
parent
1a6af09e33
commit
837d04cc56
4 changed files with 131 additions and 89 deletions
|
@ -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>
|
2010-02-27 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
* Source/NSObject.m: ([methodSignatureForSelector:]) remote the check
|
* Source/NSObject.m: ([methodSignatureForSelector:]) remote the check
|
||||||
|
|
|
@ -100,8 +100,7 @@ class_getInstanceMethodNonrecursive(Class aClass, SEL aSelector)
|
||||||
|
|
||||||
if (strcmp(sel_get_name(method->method_name), name) == 0)
|
if (strcmp(sel_get_name(method->method_name), name) == 0)
|
||||||
{
|
{
|
||||||
if (NULL == types
|
if (NULL == types || strcmp(types, method->method_types) == 0)
|
||||||
|| strcmp(types, method->method_types) == 0)
|
|
||||||
{
|
{
|
||||||
return method;
|
return method;
|
||||||
}
|
}
|
||||||
|
@ -135,9 +134,7 @@ objc_updateDtableForClassContainingMethod(Method m)
|
||||||
BOOL
|
BOOL
|
||||||
class_addIvar(Class cls,
|
class_addIvar(Class cls,
|
||||||
const char *name,
|
const char *name,
|
||||||
size_t size,
|
size_t size, uint8_t alignment, const char *types)
|
||||||
uint8_t alignment,
|
|
||||||
const char *types)
|
|
||||||
{
|
{
|
||||||
struct objc_ivar_list *ivarlist;
|
struct objc_ivar_list *ivarlist;
|
||||||
Ivar ivar;
|
Ivar ivar;
|
||||||
|
@ -164,7 +161,8 @@ class_addIvar(Class cls,
|
||||||
ivarlist->ivar_count++;
|
ivarlist->ivar_count++;
|
||||||
// objc_ivar_list contains one ivar. Others follow it.
|
// objc_ivar_list contains one ivar. Others follow it.
|
||||||
cls->ivars = objc_realloc(ivarlist, sizeof(struct objc_ivar_list)
|
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];
|
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);
|
const char *methodName = sel_get_name(name);
|
||||||
struct objc_method_list *methods;
|
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;
|
int i;
|
||||||
|
|
||||||
|
@ -298,7 +297,8 @@ class_copyMethodList(Class cls, unsigned int *outCount)
|
||||||
Method *copyDest;
|
Method *copyDest;
|
||||||
struct objc_method_list *methods;
|
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;
|
count += methods->method_count;
|
||||||
}
|
}
|
||||||
|
@ -314,7 +314,8 @@ class_copyMethodList(Class cls, unsigned int *outCount)
|
||||||
list = malloc(count * sizeof(struct objc_method *));
|
list = malloc(count * sizeof(struct objc_method *));
|
||||||
copyDest = list;
|
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;
|
unsigned int i;
|
||||||
|
|
||||||
|
@ -520,8 +521,7 @@ class_setIvarLayout(Class cls, const char *layout)
|
||||||
memcpy(cls->ivars, list, listsize);
|
memcpy(cls->ivars, list, listsize);
|
||||||
}
|
}
|
||||||
|
|
||||||
OBJC_DEPRECATED
|
OBJC_DEPRECATED Class
|
||||||
Class
|
|
||||||
class_setSuperclass(Class cls, Class newSuper)
|
class_setSuperclass(Class cls, Class newSuper)
|
||||||
{
|
{
|
||||||
Class oldSuper = cls->super_class;
|
Class oldSuper = cls->super_class;
|
||||||
|
@ -632,9 +632,7 @@ method_exchangeImplementations(Method m1, Method m2)
|
||||||
|
|
||||||
void
|
void
|
||||||
method_getArgumentType(Method method,
|
method_getArgumentType(Method method,
|
||||||
unsigned int index,
|
unsigned int index, char *dst, size_t dst_len)
|
||||||
char *dst,
|
|
||||||
size_t dst_len)
|
|
||||||
{
|
{
|
||||||
const char *types;
|
const char *types;
|
||||||
size_t length;
|
size_t length;
|
||||||
|
@ -910,6 +908,22 @@ objc_allocateClassPair(Class superclass, const char *name, size_t extraBytes)
|
||||||
return newClass;
|
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 *
|
void *
|
||||||
object_getIndexedIvars(id obj)
|
object_getIndexedIvars(id obj)
|
||||||
{
|
{
|
||||||
|
@ -997,7 +1011,8 @@ protocol_conformsToProtocol(Protocol *p, Protocol *other)
|
||||||
|
|
||||||
struct objc_method_description *
|
struct objc_method_description *
|
||||||
protocol_copyMethodDescriptionList(Protocol * p,
|
protocol_copyMethodDescriptionList(Protocol * p,
|
||||||
BOOL isRequiredMethod, BOOL isInstanceMethod, unsigned int *count)
|
BOOL isRequiredMethod,
|
||||||
|
BOOL isInstanceMethod, unsigned int *count)
|
||||||
{
|
{
|
||||||
*count = 0;
|
*count = 0;
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -1027,8 +1042,7 @@ protocol_isEqual(Protocol *p, Protocol *other)
|
||||||
{
|
{
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
if (p == other
|
if (p == other || 0 == strcmp(p->protocol_name, other->protocol_name))
|
||||||
|| 0 == strcmp(p->protocol_name, other->protocol_name))
|
|
||||||
{
|
{
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
@ -1038,14 +1052,16 @@ protocol_isEqual(Protocol *p, Protocol *other)
|
||||||
const char *
|
const char *
|
||||||
sel_getName(SEL sel)
|
sel_getName(SEL sel)
|
||||||
{
|
{
|
||||||
if (sel == 0) return "<null selector>";
|
if (sel == 0)
|
||||||
|
return "<null selector>";
|
||||||
return sel_get_name(sel);
|
return sel_get_name(sel);
|
||||||
}
|
}
|
||||||
|
|
||||||
SEL
|
SEL
|
||||||
sel_getUid(const char *selName)
|
sel_getUid(const char *selName)
|
||||||
{
|
{
|
||||||
if (selName == 0) return 0;
|
if (selName == 0)
|
||||||
|
return 0;
|
||||||
return sel_get_uid(selName);
|
return sel_get_uid(selName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1058,7 +1074,7 @@ sel_isEqual(SEL sel1, SEL sel2)
|
||||||
SEL
|
SEL
|
||||||
sel_registerName(const char *selName)
|
sel_registerName(const char *selName)
|
||||||
{
|
{
|
||||||
if (selName == 0) return 0;
|
if (selName == 0)
|
||||||
|
return 0;
|
||||||
return sel_register_name(selName);
|
return sel_register_name(selName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include "Availability.h"
|
||||||
|
|
||||||
#if defined(ERROR_UNSUPPORTED_RUNTIME_FUNCTIONS)
|
#if defined(ERROR_UNSUPPORTED_RUNTIME_FUNCTIONS)
|
||||||
# define OBJC_GNU_RUNTIME_UNSUPPORTED(x) \
|
# define OBJC_GNU_RUNTIME_UNSUPPORTED(x) \
|
||||||
|
@ -199,7 +200,11 @@ const char * method_getTypeEncoding(Method method);
|
||||||
|
|
||||||
IMP method_setImplementation(Method method, IMP imp);
|
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);
|
void objc_disposeClassPair(Class cls);
|
||||||
|
|
||||||
|
|
|
@ -53,19 +53,32 @@ findLockClass(id obj)
|
||||||
static inline Class
|
static inline Class
|
||||||
initLockObject(id obj)
|
initLockObject(id obj)
|
||||||
{
|
{
|
||||||
char nameBuffer[40];
|
|
||||||
Class lockClass;
|
Class lockClass;
|
||||||
const char *types;
|
const char *types;
|
||||||
pthread_mutex_t *lock;
|
pthread_mutex_t *lock;
|
||||||
pthread_mutexattr_t attr;
|
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++);
|
snprintf(nameBuffer, 39, "hiddenlockClass%lld", lockClassId++);
|
||||||
lockClass = objc_allocateClassPair(obj->isa, nameBuffer,
|
lockClass = objc_allocateClassPair(obj->isa, nameBuffer,
|
||||||
sizeof(pthread_mutex_t));
|
sizeof(pthread_mutex_t));
|
||||||
|
}
|
||||||
|
|
||||||
types = method_getTypeEncoding(class_getInstanceMethod(obj->isa,
|
types = method_getTypeEncoding(class_getInstanceMethod(obj->isa,
|
||||||
@selector(dealloc)));
|
@selector(dealloc)));
|
||||||
class_addMethod(lockClass, @selector(dealloc), (IMP)deallocLockClass, types);
|
class_addMethod(lockClass, @selector(dealloc), (IMP)deallocLockClass, types);
|
||||||
|
|
||||||
|
if (!class_isMetaClass(obj->isa))
|
||||||
|
{
|
||||||
objc_registerClassPair(lockClass);
|
objc_registerClassPair(lockClass);
|
||||||
|
}
|
||||||
|
|
||||||
lock = object_getIndexedIvars(lockClass);
|
lock = object_getIndexedIvars(lockClass);
|
||||||
pthread_mutexattr_init(&attr);
|
pthread_mutexattr_init(&attr);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue