Fix for NOB generation

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@31183 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
rfm 2010-08-18 12:34:56 +00:00
parent 871a3bfcfe
commit f7193b19c0
3 changed files with 47 additions and 11 deletions

View file

@ -1,3 +1,8 @@
2010-08-18 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSNumber.m: Modifications to permit generation of NIBs that
OSX can read again ... functionality was lost in recent rewrite.
2010-08-17 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSObject.m:

View file

@ -587,7 +587,9 @@ static NSDictionary *makeReference(unsigned ref)
[_enc setObject: [NSNumber numberWithBool: aBool] forKey: aKey];
}
- (void) encodeBytes: (const uint8_t*)aPointer length: (NSUInteger)length forKey: (NSString*)aKey
- (void) encodeBytes: (const uint8_t*)aPointer
length: (NSUInteger)length
forKey: (NSString*)aKey
{
CHECKKEY

View file

@ -3,7 +3,9 @@
Written by: David Chisnall
Partial rewrite: Richard Frith-Macdonld <rfm@gnu.org>
(to compile on gnu/linux and mswindows, to meet coding/style standards)
(to compile on gnu/linux and mswindows,
to meet coding/style standards,
to restore lost functionality)
Date: February 2010
@ -52,6 +54,8 @@
* singletons. All other values are mapped to the smallest signed value that
* will store them, unless they are greater than LLONG_MAX, in which case
* they are stored in an unsigned long long.
* Booleans are handled as a special case since some stuff (notably interface
* builder (nib) archives) needs to differentiate between booleans and integers.
*/
@interface NSSignedIntegerNumber : NSNumber
@ -64,6 +68,12 @@
}
@end
/* Some code needs to differentiate between booleans and other NSNumber
* instances, so we need a special subclass to permit that.
*/
@interface NSBoolNumber : NSIntNumber
@end
@interface NSLongLongNumber : NSSignedIntegerNumber
{
@public
@ -169,6 +179,13 @@ return NSOrderedSame;
#include "NSNumberMethods.h"
@end
@implementation NSBoolNumber
- (const char *) objCType
{
return @encode(BOOL);
}
@end
@implementation NSLongLongNumber
#define FORMAT @"%lli"
#include "NSNumberMethods.h"
@ -294,17 +311,21 @@ return NSOrderedSame;
@implementation NSNumber
/*
* Numbers from -1 to 12 inclusive that are reused.
*/
static NSNumber *ReusedInstances[14];
static Class NSNumberClass;
static Class NSBoolNumberClass;
static Class NSIntNumberClass;
static Class NSLongLongNumberClass;
static Class NSUnsignedLongLongNumberClass;
static Class NSFloatNumberClass;
static Class NSDoubleNumberClass;
/*
* Numbers from -1 to 12 inclusive that are reused.
*/
static NSNumber *ReusedInstances[14];
static NSBoolNumber *boolY; // Boolean YES (integer 1)
static NSBoolNumber *boolN; // Boolean NO (integer 0)
+ (void) initialize
{
int i;
@ -315,12 +336,18 @@ static Class NSDoubleNumberClass;
}
NSNumberClass = self;
NSBoolNumberClass = [NSBoolNumber class];
NSIntNumberClass = [NSIntNumber class];
NSLongLongNumberClass = [NSLongLongNumber class];
NSUnsignedLongLongNumberClass = [NSUnsignedLongLongNumber class];
NSFloatNumberClass = [NSFloatNumber class];
NSDoubleNumberClass = [NSDoubleNumber class];
boolY = NSAllocateObject (NSBoolNumberClass, 0, 0);
boolY->value = 1;
boolN = NSAllocateObject (NSBoolNumberClass, 0, 0);
boolN->value = 0;
for (i = 0; i < 14; i++)
{
NSIntNumber *n = NSAllocateObject (NSIntNumberClass, 0, 0);
@ -332,7 +359,7 @@ static Class NSDoubleNumberClass;
- (const char *) objCType
{
/* All concrete NSNumber types must implement this so we know which oen
/* All concrete NSNumber types must implement this so we know which one
* they are.
*/
[self subclassResponsibility: _cmd];
@ -396,7 +423,7 @@ static Class NSDoubleNumberClass;
- (id) initWithBool: (BOOL)aValue
{
DESTROY(self);
return [ReusedInstances[aValue ? 2 : 1] retain];\
return [(aValue == 0 ? boolN : boolY) retain];\
}
/*
@ -416,9 +443,11 @@ if (aValue >= -1 && aValue <= 12)\
return [[[self alloc] initWithBytes: (const void *)&aValue
objCType: @encode(BOOL)] autorelease];
}
CHECK_SINGLETON (((signed char) aValue));
return [self numberWithInt: aValue];
// Not reached (BOOL is always 0 or 1)
if (0 == aValue)
{
return boolN;
}
return boolY;
}
+ (NSNumber *) numberWithChar: (signed char)aValue