- several KVC/KVO fixes for the new compiler's signatures (which include stack offsets; it's no longer a good idea to compare function call signatures with @encode signatures)

- small improvements to NSRecursiveLock and NSValue
This commit is contained in:
Johannes Fortmann 2008-07-09 19:44:16 +00:00
parent f89b680522
commit 289c66689a
5 changed files with 47 additions and 16 deletions

View File

@ -16,9 +16,14 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
#define PAGESIZE 1024
void objc_noAutoreleasePool(id object)
{
OBJCLog("autorelease pool is nil, leaking %@", object);
}
static inline void addObject(NSAutoreleasePool *self,id object){
if(self==nil){
OBJCLog("autorelease pool is nil, leaking %@",[object class]);
objc_noAutoreleasePool(object);
return;
}

View File

@ -51,12 +51,12 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
-(id)_wrapValue:(void*)value ofType:(const char*)type
{
if(type[0]!='@' && strlen(type)>1)
{
// valueWithBytes:objCType: doesn't like quotes in its types
char* cleanType=__builtin_alloca(strlen(type)+1);
// strip offsets & quotes from type
[self _demangleTypeEncoding:type to:cleanType];
if(type[0]!='@' && strlen(cleanType)>1)
{
return [NSValue valueWithBytes:value objCType:cleanType];
}

View File

@ -684,15 +684,19 @@ CHANGE_DECLARATION(SEL)
const char* firstParameterType=[[self methodSignatureForSelector:method->method_name] getArgumentTypeAtIndex:2];
const char* returnType=[[self methodSignatureForSelector:method->method_name] methodReturnType];
char *cleanFirstParameterType=alloca(strlen(firstParameterType)+1);
[self _demangleTypeEncoding:firstParameterType to:cleanFirstParameterType];
/* check for correct type: either perfect match
or primitive signed type matching unsigned type
(i.e. tolower(@encode(unsigned long)[0])==@encode(long)[0])
*/
#define CHECK_AND_ASSIGN(a) \
if(!strcmp(firstParameterType, @encode(a)) || \
if(!strcmp(cleanFirstParameterType, @encode(a)) || \
(strlen(@encode(a))==1 && \
strlen(firstParameterType)==1 && \
tolower(firstParameterType[0])==@encode(a)[0])) \
strlen(cleanFirstParameterType)==1 && \
tolower(cleanFirstParameterType[0])==@encode(a)[0])) \
{ \
kvoSelector = @selector( CHANGE_SELECTOR(a) ); \
}
@ -711,18 +715,22 @@ CHANGE_DECLARATION(SEL)
if(kvoSelector==0 && NSDebugEnabled)
{
//NSLog(@"type %s not defined in %s:%i (selector %s on class %@)", firstParameterType, __FILE__, __LINE__, SELNAME(method->method_name), [self className]);
NSLog(@"type %s not defined in %s:%i (selector %s on class %@)", cleanFirstParameterType, __FILE__, __LINE__, SELNAME(method->method_name), [self className]);
}
if(strcmp(returnType, @encode(void)))
if(returnType[0]!=_C_VOID)
{
if(NSDebugEnabled)
NSLog(@"selector %s on class %@ has return type %s and will not be modified for automatic KVO notification", SELNAME(method->method_name), [self className], returnType);
kvoSelector=0;
}
}
// long selectors
if(!kvoSelector)
if(kvoSelector==0)
{
id ret=nil;

View File

@ -41,7 +41,16 @@
-(void)lock
{
[self lockBeforeDate:[NSDate distantFuture]];
if(_lockingThread==[NSThread currentThread])
{
_numberOfLocks++;
return;
}
[_lock lock];
// got the lock. so it's ours now
_lockingThread=[NSThread currentThread];
_numberOfLocks=1;
}
-(void)unlock

View File

@ -175,5 +175,14 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
return rect;
}
-(id)descriptionWithLocale:(id)locale
{
return [self description];
}
-(id)description
{
return [NSString stringWithFormat:@"<%@, %s>", [super description], [self objCType]];
}
@end