mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-11 16:50:42 +00:00
Several minor bugfixes in handling BOOL values, fix crash in shrinking
mutable data. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@18507 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
30bceb8753
commit
1c24d6feb9
4 changed files with 46 additions and 32 deletions
|
@ -2,6 +2,12 @@
|
||||||
|
|
||||||
* Source/NSString.m: Added two new MacOS-X initialisers.
|
* Source/NSString.m: Added two new MacOS-X initialisers.
|
||||||
* Headers/Foundation/NSString.h: ditto
|
* Headers/Foundation/NSString.h: ditto
|
||||||
|
* Source/NSData.m: ([replaceBytesInRange:withBytes:length:) rewrite
|
||||||
|
to fix crash when new data is smaller than orignal.
|
||||||
|
* Source/NSNumber.m: ([numberWithBool:]) and ([initWithBool:])
|
||||||
|
returns yes value for any non-zero argument. ([boolValue]) returns
|
||||||
|
either YES or NO. So we are tolerant in what we accept, strict in
|
||||||
|
what we produce.
|
||||||
|
|
||||||
2004-01-28 Fred Kiefer <FredKiefer@gmx.de>
|
2004-01-28 Fred Kiefer <FredKiefer@gmx.de>
|
||||||
|
|
||||||
|
|
|
@ -117,7 +117,7 @@ enum {
|
||||||
#ifndef STRICT_OPENSTEP
|
#ifndef STRICT_OPENSTEP
|
||||||
- (id) initWithBytes: (const void*)bytes
|
- (id) initWithBytes: (const void*)bytes
|
||||||
length: (unsigned int)length
|
length: (unsigned int)length
|
||||||
encoding: (NSStringEncoding)encoding ;
|
encoding: (NSStringEncoding)encoding;
|
||||||
- (id) initWithBytesNoCopy: (const void*)bytes
|
- (id) initWithBytesNoCopy: (const void*)bytes
|
||||||
length: (unsigned int)length
|
length: (unsigned int)length
|
||||||
encoding: (NSStringEncoding)encoding
|
encoding: (NSStringEncoding)encoding
|
||||||
|
|
|
@ -1742,37 +1742,45 @@ failure:
|
||||||
unsigned size = [self length];
|
unsigned size = [self length];
|
||||||
unsigned end = NSMaxRange(aRange);
|
unsigned end = NSMaxRange(aRange);
|
||||||
int shift = length - aRange.length;
|
int shift = length - aRange.length;
|
||||||
unsigned need = end + shift;
|
unsigned need = size + shift;
|
||||||
|
void *buf;
|
||||||
|
|
||||||
if (aRange.location > size)
|
if (aRange.location > size)
|
||||||
{
|
{
|
||||||
[NSException raise: NSRangeException
|
[NSException raise: NSRangeException
|
||||||
format: @"location bad in replaceByteInRange:withBytes:"];
|
format: @"location bad in replaceByteInRange:withBytes:"];
|
||||||
}
|
}
|
||||||
if (length > aRange.length)
|
|
||||||
{
|
|
||||||
need += (length - aRange.length);
|
|
||||||
}
|
|
||||||
if (need > size)
|
if (need > size)
|
||||||
{
|
{
|
||||||
[self setLength: need];
|
[self setLength: need];
|
||||||
}
|
}
|
||||||
if (aRange.length > 0 || aRange.length != length)
|
buf = [self mutableBytes];
|
||||||
|
if (shift < 0)
|
||||||
{
|
{
|
||||||
void *buf = [self mutableBytes];
|
if (length > 0)
|
||||||
|
|
||||||
if (end < size && shift != 0)
|
|
||||||
{
|
{
|
||||||
|
// Copy bytes into place.
|
||||||
|
memmove(buf + aRange.location, bytes, length);
|
||||||
|
}
|
||||||
|
// Fill gap
|
||||||
|
memmove(buf + end + shift, buf + end, size - end);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (shift > 0)
|
||||||
|
{
|
||||||
|
// Open space
|
||||||
memmove(buf + end + shift, buf + end, size - end);
|
memmove(buf + end + shift, buf + end, size - end);
|
||||||
}
|
}
|
||||||
if (length > 0)
|
if (length > 0)
|
||||||
{
|
{
|
||||||
|
// Copy bytes into place.
|
||||||
memmove(buf + aRange.location, bytes, length);
|
memmove(buf + aRange.location, bytes, length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (shift < 0)
|
if (need < size)
|
||||||
{
|
{
|
||||||
[self setLength: need + shift];
|
[self setLength: need];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -326,13 +326,13 @@ static Class doubleNumberClass;
|
||||||
|
|
||||||
+ (NSNumber*) numberWithBool: (BOOL)value
|
+ (NSNumber*) numberWithBool: (BOOL)value
|
||||||
{
|
{
|
||||||
if (value == YES)
|
if (value == NO)
|
||||||
{
|
{
|
||||||
return boolY;
|
return boolN;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return boolN;
|
return boolY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -507,13 +507,13 @@ static Class doubleNumberClass;
|
||||||
- (id) initWithBool: (BOOL)value
|
- (id) initWithBool: (BOOL)value
|
||||||
{
|
{
|
||||||
NSDeallocateObject(self);
|
NSDeallocateObject(self);
|
||||||
if (value == YES)
|
if (value == NO)
|
||||||
{
|
{
|
||||||
self = boolY;
|
self = boolN;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
self = boolN;
|
self = boolY;
|
||||||
}
|
}
|
||||||
return RETAIN(self);
|
return RETAIN(self);
|
||||||
}
|
}
|
||||||
|
@ -822,98 +822,98 @@ static Class doubleNumberClass;
|
||||||
BOOL oData;
|
BOOL oData;
|
||||||
|
|
||||||
(*(info->getValue))(self, @selector(getValue:), &oData);
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
||||||
return oData;
|
return (oData == 0) ? NO : YES;
|
||||||
}
|
}
|
||||||
case 1:
|
case 1:
|
||||||
{
|
{
|
||||||
signed char oData;
|
signed char oData;
|
||||||
|
|
||||||
(*(info->getValue))(self, @selector(getValue:), &oData);
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
||||||
return oData;
|
return (oData == 0) ? NO : YES;
|
||||||
}
|
}
|
||||||
case 2:
|
case 2:
|
||||||
{
|
{
|
||||||
unsigned char oData;
|
unsigned char oData;
|
||||||
|
|
||||||
(*(info->getValue))(self, @selector(getValue:), &oData);
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
||||||
return oData;
|
return (oData == 0) ? NO : YES;
|
||||||
}
|
}
|
||||||
case 3:
|
case 3:
|
||||||
{
|
{
|
||||||
signed short oData;
|
signed short oData;
|
||||||
|
|
||||||
(*(info->getValue))(self, @selector(getValue:), &oData);
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
||||||
return oData;
|
return (oData == 0) ? NO : YES;
|
||||||
}
|
}
|
||||||
case 4:
|
case 4:
|
||||||
{
|
{
|
||||||
unsigned short oData;
|
unsigned short oData;
|
||||||
|
|
||||||
(*(info->getValue))(self, @selector(getValue:), &oData);
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
||||||
return oData;
|
return (oData == 0) ? NO : YES;
|
||||||
}
|
}
|
||||||
case 5:
|
case 5:
|
||||||
{
|
{
|
||||||
signed int oData;
|
signed int oData;
|
||||||
|
|
||||||
(*(info->getValue))(self, @selector(getValue:), &oData);
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
||||||
return oData;
|
return (oData == 0) ? NO : YES;
|
||||||
}
|
}
|
||||||
case 6:
|
case 6:
|
||||||
{
|
{
|
||||||
unsigned int oData;
|
unsigned int oData;
|
||||||
|
|
||||||
(*(info->getValue))(self, @selector(getValue:), &oData);
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
||||||
return oData;
|
return (oData == 0) ? NO : YES;
|
||||||
}
|
}
|
||||||
case 7:
|
case 7:
|
||||||
{
|
{
|
||||||
signed long oData;
|
signed long oData;
|
||||||
|
|
||||||
(*(info->getValue))(self, @selector(getValue:), &oData);
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
||||||
return oData;
|
return (oData == 0) ? NO : YES;
|
||||||
}
|
}
|
||||||
case 8:
|
case 8:
|
||||||
{
|
{
|
||||||
unsigned long oData;
|
unsigned long oData;
|
||||||
|
|
||||||
(*(info->getValue))(self, @selector(getValue:), &oData);
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
||||||
return oData;
|
return (oData == 0) ? NO : YES;
|
||||||
}
|
}
|
||||||
case 9:
|
case 9:
|
||||||
{
|
{
|
||||||
signed long long oData;
|
signed long long oData;
|
||||||
|
|
||||||
(*(info->getValue))(self, @selector(getValue:), &oData);
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
||||||
return oData;
|
return (oData == 0) ? NO : YES;
|
||||||
}
|
}
|
||||||
case 10:
|
case 10:
|
||||||
{
|
{
|
||||||
unsigned long long oData;
|
unsigned long long oData;
|
||||||
|
|
||||||
(*(info->getValue))(self, @selector(getValue:), &oData);
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
||||||
return oData;
|
return (oData == 0) ? NO : YES;
|
||||||
}
|
}
|
||||||
case 11:
|
case 11:
|
||||||
{
|
{
|
||||||
float oData;
|
float oData;
|
||||||
|
|
||||||
(*(info->getValue))(self, @selector(getValue:), &oData);
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
||||||
return oData;
|
return (oData == 0) ? NO : YES;
|
||||||
}
|
}
|
||||||
case 12:
|
case 12:
|
||||||
{
|
{
|
||||||
double oData;
|
double oData;
|
||||||
|
|
||||||
(*(info->getValue))(self, @selector(getValue:), &oData);
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
||||||
return oData;
|
return (oData == 0) ? NO : YES;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
[NSException raise: NSInvalidArgumentException
|
[NSException raise: NSInvalidArgumentException
|
||||||
format: @"unknown number type value for get"];
|
format: @"unknown number type value for get"];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (signed char) charValue
|
- (signed char) charValue
|
||||||
|
|
Loading…
Reference in a new issue