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
2010-02-14 12:57:44 +00:00
|
|
|
/**
|
|
|
|
* GSNumberTypes expects the INTEGER_MACRO macro to be defined. This macro is
|
|
|
|
* invoked once for every type and its Objective-C name. Use this file when
|
|
|
|
* implementing things like the -unsignedIntValue family of methods. For this
|
|
|
|
* case, the macro will be invoked with unsigned int as the type and
|
|
|
|
* unsignedInt as the name.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#ifndef INTEGER_MACRO
|
2010-09-24 19:20:16 +00:00
|
|
|
#error Define INTEGER_MACRO(encoding, type, name, capitalizedName) before including GSNumberTypes.h
|
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
2010-02-14 12:57:44 +00:00
|
|
|
#endif
|
2010-09-24 19:20:16 +00:00
|
|
|
INTEGER_MACRO('d', double, double, Double)
|
|
|
|
INTEGER_MACRO('f', float, float, Float)
|
|
|
|
INTEGER_MACRO('c', signed char, char, Char)
|
|
|
|
INTEGER_MACRO('i', int, int, Int)
|
|
|
|
INTEGER_MACRO('s', short, short, Short)
|
|
|
|
INTEGER_MACRO('l', long, long, Long)
|
|
|
|
#ifndef NO_NSNUMBER
|
|
|
|
# if SIZEOF_VOIDP == 4
|
|
|
|
INTEGER_MACRO('i', NSInteger, integer, Integer)
|
|
|
|
INTEGER_MACRO('I', NSUInteger, unsignedInteger, UnsignedInteger)
|
|
|
|
# undef NO_NSNUMBER
|
|
|
|
# else
|
|
|
|
INTEGER_MACRO('q', NSInteger, integer, Integer)
|
|
|
|
INTEGER_MACRO('Q', NSUInteger, unsignedInteger, UnsignedInteger)
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
INTEGER_MACRO('q', long long, longLong, LongLong)
|
|
|
|
INTEGER_MACRO('C', unsigned char, unsignedChar, UnsignedChar)
|
|
|
|
INTEGER_MACRO('S', unsigned short, unsignedShort, UnsignedShort)
|
|
|
|
INTEGER_MACRO('I', unsigned int, unsignedInt, UnsignedInt)
|
|
|
|
INTEGER_MACRO('L', unsigned long, unsignedLong, UnsignedLong)
|
|
|
|
INTEGER_MACRO('Q', unsigned long long, unsignedLongLong, UnsignedLongLong)
|
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
2010-02-14 12:57:44 +00:00
|
|
|
#undef INTEGER_MACRO
|