mirror of
https://github.com/gnustep/libs-base.git
synced 2025-06-02 01:21:08 +00:00
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:
parent
9043b1304b
commit
d5afd6d3a6
2 changed files with 49 additions and 30 deletions
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
* Source/GSString.m: fix error getting cstring from literal containing
|
* Source/GSString.m: fix error getting cstring from literal containing
|
||||||
illegal characters.
|
illegal characters.
|
||||||
|
* Source/NSKeyValueCoding.m: backport fixes from trunk
|
||||||
|
|
||||||
2007-06-03 Richard Frith-Macdonald <rfm@gnu.org>
|
2007-06-03 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,11 @@
|
||||||
#include "Foundation/NSKeyValueCoding.h"
|
#include "Foundation/NSKeyValueCoding.h"
|
||||||
#include "Foundation/NSNull.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
|
static void
|
||||||
|
@ -107,7 +111,7 @@ SetValueForKey(NSObject *self, id anObject, const char *key, unsigned size)
|
||||||
}
|
}
|
||||||
else
|
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
|
- (void) setValue: (id)anObject forKey: (NSString*)aKey
|
||||||
{
|
{
|
||||||
unsigned size = [aKey length];
|
unsigned size = [aKey length] * 8;
|
||||||
char key[size+1];
|
char key[size+1];
|
||||||
|
|
||||||
[aKey getCString: key
|
[aKey getCString: key
|
||||||
maxLength: size+1
|
maxLength: size+1
|
||||||
encoding: NSASCIIStringEncoding];
|
encoding: NSUTF8StringEncoding];
|
||||||
|
size = strlen(key);
|
||||||
SetValueForKey(self, anObject, key, size);
|
SetValueForKey(self, anObject, key, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
- (void) setValue: (id)anObject forKeyPath: (NSString*)aKey
|
- (void) setValue: (id)anObject forKeyPath: (NSString*)aKey
|
||||||
{
|
{
|
||||||
unsigned size = [aKey length];
|
unsigned size = [aKey length] * 8;
|
||||||
char buf[size+1];
|
char buf[size+1];
|
||||||
unsigned start = 0;
|
unsigned start = 0;
|
||||||
unsigned end = 0;
|
unsigned end = 0;
|
||||||
|
@ -302,7 +307,8 @@ static id ValueForKey(NSObject *self, const char *key, unsigned size)
|
||||||
|
|
||||||
[aKey getCString: buf
|
[aKey getCString: buf
|
||||||
maxLength: size+1
|
maxLength: size+1
|
||||||
encoding: NSASCIIStringEncoding];
|
encoding: NSUTF8StringEncoding];
|
||||||
|
size = strlen(buf);
|
||||||
while (o != nil)
|
while (o != nil)
|
||||||
{
|
{
|
||||||
end = start;
|
end = start;
|
||||||
|
@ -310,9 +316,9 @@ static id ValueForKey(NSObject *self, const char *key, unsigned size)
|
||||||
{
|
{
|
||||||
end++;
|
end++;
|
||||||
}
|
}
|
||||||
aKey = [[NSString alloc] initWithBytes: buf + start
|
aKey = [[NSString alloc] initWithBytes: buf + start
|
||||||
length: end - start
|
length: end - start
|
||||||
encoding: NSASCIIStringEncoding];
|
encoding: NSUTF8StringEncoding];
|
||||||
AUTORELEASE(aKey);
|
AUTORELEASE(aKey);
|
||||||
if (end >= size)
|
if (end >= size)
|
||||||
{
|
{
|
||||||
|
@ -347,7 +353,7 @@ static id ValueForKey(NSObject *self, const char *key, unsigned size)
|
||||||
(anObject ? (id)anObject : (id)@"(nil)"), @"NSTargetObjectUserInfoKey",
|
(anObject ? (id)anObject : (id)@"(nil)"), @"NSTargetObjectUserInfoKey",
|
||||||
(aKey ? (id)aKey : (id)@"(nil)"), @"NSUnknownUserInfoKey",
|
(aKey ? (id)aKey : (id)@"(nil)"), @"NSUnknownUserInfoKey",
|
||||||
nil];
|
nil];
|
||||||
exp = [NSException exceptionWithName: NSInvalidArgumentException
|
exp = [NSException exceptionWithName: NSUndefinedKeyException
|
||||||
reason: @"Unable to set nil value for key"
|
reason: @"Unable to set nil value for key"
|
||||||
userInfo: dict];
|
userInfo: dict];
|
||||||
[exp raise];
|
[exp raise];
|
||||||
|
@ -375,7 +381,7 @@ static id ValueForKey(NSObject *self, const char *key, unsigned size)
|
||||||
return [self valueForKey: aKey];
|
return [self valueForKey: aKey];
|
||||||
}
|
}
|
||||||
|
|
||||||
size = [aKey length];
|
size = [aKey length] * 8;
|
||||||
if (size > 0)
|
if (size > 0)
|
||||||
{
|
{
|
||||||
SEL sel = 0;
|
SEL sel = 0;
|
||||||
|
@ -390,7 +396,8 @@ static id ValueForKey(NSObject *self, const char *key, unsigned size)
|
||||||
strcpy(buf, "_get");
|
strcpy(buf, "_get");
|
||||||
[aKey getCString: key
|
[aKey getCString: key
|
||||||
maxLength: size+1
|
maxLength: size+1
|
||||||
encoding: NSASCIIStringEncoding];
|
encoding: NSUTF8StringEncoding];
|
||||||
|
size = strlen(key);
|
||||||
strcpy(&buf[4], key);
|
strcpy(&buf[4], key);
|
||||||
lo = buf[4];
|
lo = buf[4];
|
||||||
hi = islower(lo) ? toupper(lo) : lo;
|
hi = islower(lo) ? toupper(lo) : lo;
|
||||||
|
@ -458,7 +465,7 @@ static id ValueForKey(NSObject *self, const char *key, unsigned size)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
size = [aKey length];
|
size = [aKey length] * 8;
|
||||||
if (size > 0)
|
if (size > 0)
|
||||||
{
|
{
|
||||||
SEL sel;
|
SEL sel;
|
||||||
|
@ -473,7 +480,8 @@ static id ValueForKey(NSObject *self, const char *key, unsigned size)
|
||||||
strcpy(buf, "_set");
|
strcpy(buf, "_set");
|
||||||
[aKey getCString: key
|
[aKey getCString: key
|
||||||
maxLength: size+1
|
maxLength: size+1
|
||||||
encoding: NSASCIIStringEncoding];
|
encoding: NSUTF8StringEncoding];
|
||||||
|
size = strlen(key);
|
||||||
strcpy(&buf[4], key);
|
strcpy(&buf[4], key);
|
||||||
lo = buf[4];
|
lo = buf[4];
|
||||||
hi = islower(lo) ? toupper(lo) : lo;
|
hi = islower(lo) ? toupper(lo) : lo;
|
||||||
|
@ -546,13 +554,19 @@ static id ValueForKey(NSObject *self, const char *key, unsigned size)
|
||||||
SEL sel = 0;
|
SEL sel = 0;
|
||||||
const char *type = 0;
|
const char *type = 0;
|
||||||
int off;
|
int off;
|
||||||
unsigned size = [aKey length];
|
unsigned size = [aKey length] * 8;
|
||||||
char key[size+1];
|
char key[size+1];
|
||||||
|
|
||||||
GSOnceMLog(@"This method is deprecated, use -setValue:forKey:");
|
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
|
[aKey getCString: key
|
||||||
maxLength: size+1
|
maxLength: size+1
|
||||||
encoding: NSASCIIStringEncoding];
|
encoding: NSUTF8StringEncoding];
|
||||||
|
size = strlen(key);
|
||||||
if (size > 0)
|
if (size > 0)
|
||||||
{
|
{
|
||||||
const char *name;
|
const char *name;
|
||||||
|
@ -651,7 +665,7 @@ static id ValueForKey(NSObject *self, const char *key, unsigned size)
|
||||||
{
|
{
|
||||||
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"];
|
[NSException raise: NSInvalidArgumentException format: @"nil argument"];
|
||||||
}
|
}
|
||||||
|
@ -664,7 +678,8 @@ static id ValueForKey(NSObject *self, const char *key, unsigned size)
|
||||||
strcpy(name, "validate");
|
strcpy(name, "validate");
|
||||||
[aKey getCString: &name[8]
|
[aKey getCString: &name[8]
|
||||||
maxLength: size+1
|
maxLength: size+1
|
||||||
encoding: NSASCIIStringEncoding];
|
encoding: NSUTF8StringEncoding];
|
||||||
|
size = strlen(&name[8]);
|
||||||
strcpy(&name[size+8], ":error:");
|
strcpy(&name[size+8], ":error:");
|
||||||
if (islower(name[8]))
|
if (islower(name[8]))
|
||||||
{
|
{
|
||||||
|
@ -684,7 +699,7 @@ static id ValueForKey(NSObject *self, const char *key, unsigned size)
|
||||||
forKeyPath: (NSString*)aKey
|
forKeyPath: (NSString*)aKey
|
||||||
error: (NSError**)anError
|
error: (NSError**)anError
|
||||||
{
|
{
|
||||||
unsigned size = [aKey length];
|
unsigned size = [aKey length] * 8;
|
||||||
char buf[size+1];
|
char buf[size+1];
|
||||||
unsigned start = 0;
|
unsigned start = 0;
|
||||||
unsigned end = 0;
|
unsigned end = 0;
|
||||||
|
@ -692,7 +707,8 @@ static id ValueForKey(NSObject *self, const char *key, unsigned size)
|
||||||
|
|
||||||
[aKey getCString: buf
|
[aKey getCString: buf
|
||||||
maxLength: size+1
|
maxLength: size+1
|
||||||
encoding: NSASCIIStringEncoding];
|
encoding: NSUTF8StringEncoding];
|
||||||
|
size = strlen(buf);
|
||||||
while (o != nil)
|
while (o != nil)
|
||||||
{
|
{
|
||||||
end = start;
|
end = start;
|
||||||
|
@ -704,9 +720,9 @@ static id ValueForKey(NSObject *self, const char *key, unsigned size)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
aKey = [[NSString alloc] initWithBytes: buf + start
|
aKey = [[NSString alloc] initWithBytes: buf + start
|
||||||
length: end - start
|
length: end - start
|
||||||
encoding: NSASCIIStringEncoding];
|
encoding: NSUTF8StringEncoding];
|
||||||
AUTORELEASE(aKey);
|
AUTORELEASE(aKey);
|
||||||
o = [o valueForKey: aKey];
|
o = [o valueForKey: aKey];
|
||||||
start = ++end;
|
start = ++end;
|
||||||
|
@ -742,19 +758,20 @@ static id ValueForKey(NSObject *self, const char *key, unsigned size)
|
||||||
|
|
||||||
- (id) valueForKey: (NSString*)aKey
|
- (id) valueForKey: (NSString*)aKey
|
||||||
{
|
{
|
||||||
unsigned size = [aKey length];
|
unsigned size = [aKey length] * 8;
|
||||||
char key[size+1];
|
char key[size+1];
|
||||||
|
|
||||||
[aKey getCString: key
|
[aKey getCString: key
|
||||||
maxLength: size+1
|
maxLength: size+1
|
||||||
encoding: NSASCIIStringEncoding];
|
encoding: NSUTF8StringEncoding];
|
||||||
|
size = strlen(key);
|
||||||
return ValueForKey(self, key, size);
|
return ValueForKey(self, key, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
- (id) valueForKeyPath: (NSString*)aKey
|
- (id) valueForKeyPath: (NSString*)aKey
|
||||||
{
|
{
|
||||||
unsigned size = [aKey length];
|
unsigned size = [aKey length] * 8;
|
||||||
char buf[size+1];
|
char buf[size+1];
|
||||||
unsigned start = 0;
|
unsigned start = 0;
|
||||||
unsigned end = 0;
|
unsigned end = 0;
|
||||||
|
@ -762,7 +779,8 @@ static id ValueForKey(NSObject *self, const char *key, unsigned size)
|
||||||
|
|
||||||
[aKey getCString: buf
|
[aKey getCString: buf
|
||||||
maxLength: size+1
|
maxLength: size+1
|
||||||
encoding: NSASCIIStringEncoding];
|
encoding: NSUTF8StringEncoding];
|
||||||
|
size = strlen(buf);
|
||||||
while (start < size && o != nil)
|
while (start < size && o != nil)
|
||||||
{
|
{
|
||||||
end = start;
|
end = start;
|
||||||
|
@ -770,9 +788,9 @@ static id ValueForKey(NSObject *self, const char *key, unsigned size)
|
||||||
{
|
{
|
||||||
end++;
|
end++;
|
||||||
}
|
}
|
||||||
aKey = [[NSString alloc] initWithBytes: buf + start
|
aKey = [[NSString alloc] initWithBytes: buf + start
|
||||||
length: end - start
|
length: end - start
|
||||||
encoding: NSASCIIStringEncoding];
|
encoding: NSUTF8StringEncoding];
|
||||||
AUTORELEASE(aKey);
|
AUTORELEASE(aKey);
|
||||||
o = [o valueForKey: aKey];
|
o = [o valueForKey: aKey];
|
||||||
start = ++end;
|
start = ++end;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue