backport fixes from trunk

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/branches/stable@25231 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2007-06-08 08:19:56 +00:00
parent 9043b1304b
commit d5afd6d3a6
2 changed files with 49 additions and 30 deletions

View file

@ -38,7 +38,11 @@
#include "Foundation/NSKeyValueCoding.h"
#include "Foundation/NSNull.h"
NSString* const NSUndefinedKeyException = @"NSUndefinedKeyException";
/* For backward compatibility NSUndefinedKeyException is actually the same
* as the older NSUnknownKeyException
*/
NSString* const NSUnknownKeyException = @"NSUnknownKeyException";
NSString* const NSUndefinedKeyException = @"NSUnknownKeyException";
static void
@ -107,7 +111,7 @@ SetValueForKey(NSObject *self, id anObject, const char *key, unsigned size)
}
else
{
GSOnceFLog(@"Key-value access using _setKey: isdeprecated:");
GSOnceFLog(@"Key-value access using _setKey: is deprecated:");
}
}
}
@ -282,19 +286,20 @@ static id ValueForKey(NSObject *self, const char *key, unsigned size)
- (void) setValue: (id)anObject forKey: (NSString*)aKey
{
unsigned size = [aKey length];
unsigned size = [aKey length] * 8;
char key[size+1];
[aKey getCString: key
maxLength: size+1
encoding: NSASCIIStringEncoding];
encoding: NSUTF8StringEncoding];
size = strlen(key);
SetValueForKey(self, anObject, key, size);
}
- (void) setValue: (id)anObject forKeyPath: (NSString*)aKey
{
unsigned size = [aKey length];
unsigned size = [aKey length] * 8;
char buf[size+1];
unsigned start = 0;
unsigned end = 0;
@ -302,7 +307,8 @@ static id ValueForKey(NSObject *self, const char *key, unsigned size)
[aKey getCString: buf
maxLength: size+1
encoding: NSASCIIStringEncoding];
encoding: NSUTF8StringEncoding];
size = strlen(buf);
while (o != nil)
{
end = start;
@ -310,9 +316,9 @@ static id ValueForKey(NSObject *self, const char *key, unsigned size)
{
end++;
}
aKey = [[NSString alloc] initWithBytes: buf + start
length: end - start
encoding: NSASCIIStringEncoding];
aKey = [[NSString alloc] initWithBytes: buf + start
length: end - start
encoding: NSUTF8StringEncoding];
AUTORELEASE(aKey);
if (end >= size)
{
@ -347,7 +353,7 @@ static id ValueForKey(NSObject *self, const char *key, unsigned size)
(anObject ? (id)anObject : (id)@"(nil)"), @"NSTargetObjectUserInfoKey",
(aKey ? (id)aKey : (id)@"(nil)"), @"NSUnknownUserInfoKey",
nil];
exp = [NSException exceptionWithName: NSInvalidArgumentException
exp = [NSException exceptionWithName: NSUndefinedKeyException
reason: @"Unable to set nil value for key"
userInfo: dict];
[exp raise];
@ -375,7 +381,7 @@ static id ValueForKey(NSObject *self, const char *key, unsigned size)
return [self valueForKey: aKey];
}
size = [aKey length];
size = [aKey length] * 8;
if (size > 0)
{
SEL sel = 0;
@ -390,7 +396,8 @@ static id ValueForKey(NSObject *self, const char *key, unsigned size)
strcpy(buf, "_get");
[aKey getCString: key
maxLength: size+1
encoding: NSASCIIStringEncoding];
encoding: NSUTF8StringEncoding];
size = strlen(key);
strcpy(&buf[4], key);
lo = buf[4];
hi = islower(lo) ? toupper(lo) : lo;
@ -458,7 +465,7 @@ static id ValueForKey(NSObject *self, const char *key, unsigned size)
return;
}
size = [aKey length];
size = [aKey length] * 8;
if (size > 0)
{
SEL sel;
@ -473,7 +480,8 @@ static id ValueForKey(NSObject *self, const char *key, unsigned size)
strcpy(buf, "_set");
[aKey getCString: key
maxLength: size+1
encoding: NSASCIIStringEncoding];
encoding: NSUTF8StringEncoding];
size = strlen(key);
strcpy(&buf[4], key);
lo = buf[4];
hi = islower(lo) ? toupper(lo) : lo;
@ -546,13 +554,19 @@ static id ValueForKey(NSObject *self, const char *key, unsigned size)
SEL sel = 0;
const char *type = 0;
int off;
unsigned size = [aKey length];
unsigned size = [aKey length] * 8;
char key[size+1];
GSOnceMLog(@"This method is deprecated, use -setValue:forKey:");
if (anObject == nil)
{
[NSException raise: NSInvalidArgumentException
format: @"Attempt to set nil value for key '%@'", aKey];
}
[aKey getCString: key
maxLength: size+1
encoding: NSASCIIStringEncoding];
encoding: NSUTF8StringEncoding];
size = strlen(key);
if (size > 0)
{
const char *name;
@ -651,7 +665,7 @@ static id ValueForKey(NSObject *self, const char *key, unsigned size)
{
unsigned size;
if (aValue == 0 || (size = [aKey length]) == 0)
if (aValue == 0 || (size = [aKey length] * 8) == 0)
{
[NSException raise: NSInvalidArgumentException format: @"nil argument"];
}
@ -664,7 +678,8 @@ static id ValueForKey(NSObject *self, const char *key, unsigned size)
strcpy(name, "validate");
[aKey getCString: &name[8]
maxLength: size+1
encoding: NSASCIIStringEncoding];
encoding: NSUTF8StringEncoding];
size = strlen(&name[8]);
strcpy(&name[size+8], ":error:");
if (islower(name[8]))
{
@ -684,7 +699,7 @@ static id ValueForKey(NSObject *self, const char *key, unsigned size)
forKeyPath: (NSString*)aKey
error: (NSError**)anError
{
unsigned size = [aKey length];
unsigned size = [aKey length] * 8;
char buf[size+1];
unsigned start = 0;
unsigned end = 0;
@ -692,7 +707,8 @@ static id ValueForKey(NSObject *self, const char *key, unsigned size)
[aKey getCString: buf
maxLength: size+1
encoding: NSASCIIStringEncoding];
encoding: NSUTF8StringEncoding];
size = strlen(buf);
while (o != nil)
{
end = start;
@ -704,9 +720,9 @@ static id ValueForKey(NSObject *self, const char *key, unsigned size)
{
break;
}
aKey = [[NSString alloc] initWithBytes: buf + start
length: end - start
encoding: NSASCIIStringEncoding];
aKey = [[NSString alloc] initWithBytes: buf + start
length: end - start
encoding: NSUTF8StringEncoding];
AUTORELEASE(aKey);
o = [o valueForKey: aKey];
start = ++end;
@ -742,19 +758,20 @@ static id ValueForKey(NSObject *self, const char *key, unsigned size)
- (id) valueForKey: (NSString*)aKey
{
unsigned size = [aKey length];
unsigned size = [aKey length] * 8;
char key[size+1];
[aKey getCString: key
maxLength: size+1
encoding: NSASCIIStringEncoding];
encoding: NSUTF8StringEncoding];
size = strlen(key);
return ValueForKey(self, key, size);
}
- (id) valueForKeyPath: (NSString*)aKey
{
unsigned size = [aKey length];
unsigned size = [aKey length] * 8;
char buf[size+1];
unsigned start = 0;
unsigned end = 0;
@ -762,7 +779,8 @@ static id ValueForKey(NSObject *self, const char *key, unsigned size)
[aKey getCString: buf
maxLength: size+1
encoding: NSASCIIStringEncoding];
encoding: NSUTF8StringEncoding];
size = strlen(buf);
while (start < size && o != nil)
{
end = start;
@ -770,9 +788,9 @@ static id ValueForKey(NSObject *self, const char *key, unsigned size)
{
end++;
}
aKey = [[NSString alloc] initWithBytes: buf + start
length: end - start
encoding: NSASCIIStringEncoding];
aKey = [[NSString alloc] initWithBytes: buf + start
length: end - start
encoding: NSUTF8StringEncoding];
AUTORELEASE(aKey);
o = [o valueForKey: aKey];
start = ++end;