Rewritten NSNumber implementation. This fixes several OS X-compatibility issues:

The -pointerValue method now returns the value cast to a pointer, not some random value, as the documentation says it should.  This is a change from OpenStep, which said:

> It's an error to send this message to an NSValue that doesn't store a pointer.

The OS X docs now say:

> The receiver's value as a pointer to void. If the receiver was not created to hold a pointer-sized data item, the result is undefined.

This means that any NSNumber created with a word-sized integer should return the same value.

Fixed a number of corner-cases in the compare: implementation caused by incorrect type promotion.  The OS X docs say:

> The compare: method follows the standard C rules for type conversion.

The OS X implementation does not do this.  We now match Apple's conversion rules bug-for-bug: Every value is stored in the smallest signed type that will hold it, unless there is no unsigned type that can hold it, in which case it is stored in an `unsigned long long`, comparisons between integer and floating point values cast both to a double, comparisons between integer types perform a real comparison (so an unsigned long long is always greater than any negative number, at any precision).  The Apple implementation is actually quite sane, it is just completely unrelated to the documentation in any way.

We now use the same range of reusable objects.  Note that there is an error in Cocoa Design Patterns in the description of how Apple's implementation works.  Do not use this as a reference.

We now return `nil` when an NSNumber is sent an -init message.  This is consistent with Apple's implementation but breaks some things in the GNUstep test suite (which RFM said he will fix).

There is a small change in NSValue.h so that the locale parameter is now an `id` not an `NSString*`.  This is because, under recent OS X, it may also be an `NSLocale` instance.  I am not sure how much GNUstep supports `NSLocale`, but this change shouldn't affect anything.

The new (private) GSNumberTypes.h file lets you define macros that are instantiated with each of the names of primitive C types.  These might be useful for simplifying other classes that have -intValue, -floatValue, and so on methods, such as the `NSCell` family.

The old NSConcreteNumberTemplate and NSConcreteNumber stuff has been removed.  The code is now a bit more than 10% of the size of the old NSNumber code, and is hopefully maintainable now, so the next change won't require a complete rewrite.



git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@29618 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
theraven 2010-02-14 12:57:44 +00:00
parent efab71bc46
commit e486341176
9 changed files with 472 additions and 3534 deletions

View file

@ -1,105 +0,0 @@
/* NSConcreteNumber - Interface for Concrete NSNumber classes
Copyright (C) 1993,1994 Free Software Foundation, Inc.
Written by: Adam Fedor <fedor@boulder.colorado.edu>
Date: Mar 1995
This file is part of the GNUstep Base Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02111 USA.
*/
#import "Foundation/NSValue.h"
@interface NSBoolNumber : NSNumber
{
BOOL data;
}
@end
@interface NSUCharNumber : NSNumber
{
unsigned char data;
}
@end
@interface NSCharNumber : NSNumber
{
signed char data;
}
@end
@interface NSUShortNumber : NSNumber
{
unsigned short data;
}
@end
@interface NSShortNumber : NSNumber
{
signed short data;
}
@end
@interface NSUIntNumber : NSNumber
{
unsigned int data;
}
@end
@interface NSIntNumber : NSNumber
{
signed int data;
}
@end
@interface NSULongNumber : NSNumber
{
unsigned long data;
}
@end
@interface NSLongNumber : NSNumber
{
signed long data;
}
@end
@interface NSULongLongNumber : NSNumber
{
unsigned long long data;
}
@end
@interface NSLongLongNumber : NSNumber
{
signed long long data;
}
@end
@interface NSFloatNumber : NSNumber
{
float data;
}
@end
@interface NSDoubleNumber : NSNumber
{
double data;
}
@end