Overview
Comment: | Merge trunk into branch "tagged-pointers" |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | tagged-pointers |
Files: | files | file ages | folders |
SHA3-256: |
e2a53689c602cb7d0b578bf51001e0f5 |
User & Date: | js on 2020-07-19 16:17:41 |
Other Links: | branch diff | manifest | tags |
Context
2020-07-20
| ||
22:02 | lookup-asm-x86_64-macho.S: Fix missing underscore check-in: 2c435f2422 user: js tags: tagged-pointers | |
2020-07-19
| ||
16:17 | Merge trunk into branch "tagged-pointers" check-in: e2a53689c6 user: js tags: tagged-pointers | |
16:12 | OFNumber: Add singletons for 0, 1, 2, true & false check-in: d8123a1f26 user: js tags: trunk | |
2020-07-18
| ||
22:54 | Add objc_setTaggedPointerSecret() to Amiga linklib check-in: 5769ce64b3 user: js tags: tagged-pointers | |
Changes
Added .github/FUNDING.yml version [ebf2f393db].
> | 1 | github: Midar |
Modified .travis.yml from [0b214ac062] to [159ce14eb5].
︙ | ︙ | |||
285 286 287 288 289 290 291 | script: - build() { if ! git clean -fxd >/tmp/clean_log 2>&1; then cat /tmp/clean_log; exit 1; fi; | | | | 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 | script: - build() { if ! git clean -fxd >/tmp/clean_log 2>&1; then cat /tmp/clean_log; exit 1; fi; ./autogen.sh || exit 1; .travis/build.sh "$@" || exit 1; } - if [ "$TRAVIS_OS_NAME" = "linux" -a -z "$config" ]; then build_32_64() { build OBJC="$CC" $@; case "$TRAVIS_CPU_ARCH" in |
︙ | ︙ |
Modified Makefile from [a860b9a6b0] to [4fc78820e4].
︙ | ︙ | |||
21 22 23 24 25 26 27 | doxygen >/dev/null tarball: docs echo "Generating tarball for version ${PACKAGE_VERSION}..." rm -fr objfw-${PACKAGE_VERSION} objfw-${PACKAGE_VERSION}.tar \ objfw-${PACKAGE_VERSION}.tar.gz fossil tarball --name objfw-${PACKAGE_VERSION} current - \ | | | 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | doxygen >/dev/null tarball: docs echo "Generating tarball for version ${PACKAGE_VERSION}..." rm -fr objfw-${PACKAGE_VERSION} objfw-${PACKAGE_VERSION}.tar \ objfw-${PACKAGE_VERSION}.tar.gz fossil tarball --name objfw-${PACKAGE_VERSION} current - \ --exclude '.cirrus*,.fossil*,.git*,.travis*' | \ ofarc -ttgz -xq - cp configure config.h.in objfw-${PACKAGE_VERSION}/ ofarc -cq objfw-${PACKAGE_VERSION}.tar \ $$(find objfw-${PACKAGE_VERSION} | sort) rm -fr objfw-${PACKAGE_VERSION} gzip -9 objfw-${PACKAGE_VERSION}.tar rm -f objfw-${PACKAGE_VERSION}.tar |
︙ | ︙ |
Modified PLATFORMS.md from [90d4315b90] to [d2995207f3].
︙ | ︙ | |||
31 32 33 34 35 36 37 | * Runtimes: ObjFW * Notes: Bootloader, libc (newlib) and possibly external RAM required DOS --- | | | 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | * Runtimes: ObjFW * Notes: Bootloader, libc (newlib) and possibly external RAM required DOS --- * OS Versions: Windows XP DOS Emulation, DOSBox, MS-DOS 6.0, FreeDOS 1.2 * Architectures: x86 * Compilers: DJGPP GCC 4.7.3 (djdev204) * Runtimes: ObjFW DragonFlyBSD ------------ |
︙ | ︙ |
Modified README.md from [d6ae3e7b42] to [c7f0f5d8b7].
︙ | ︙ | |||
184 185 186 187 188 189 190 | 1 error generated. Unfortunately, there is no workaround for this other than to upgrade/downgrade Xcode or to build upstream Clang yourself. In particular, Xcode 11 Beta 1 to Beta 3 are known to be affected. While Xcode 11 Beta 4 to Xcode 11.3 work, the bug was unfortunately reintroduced in | | | 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | 1 error generated. Unfortunately, there is no workaround for this other than to upgrade/downgrade Xcode or to build upstream Clang yourself. In particular, Xcode 11 Beta 1 to Beta 3 are known to be affected. While Xcode 11 Beta 4 to Xcode 11.3 work, the bug was unfortunately reintroduced in Xcode 11.4.1 and was only fixed in Xcode 12 Beta 1. You can get older versions of Xcode [here](https://developer.apple.com/download) by clicking on "More" in the top-right corner. <h2 id='windows'>Windows</h2> |
︙ | ︙ |
Modified src/OFNumber.h from [b2aed0c6f3] to [8668a7987f].
︙ | ︙ | |||
33 34 35 36 37 38 39 40 | #import "OFSerialization.h" #import "OFValue.h" OF_ASSUME_NONNULL_BEGIN /*! @file */ /*! | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < > > | < < < < < < < < < < < < < < < < < < < < | | < < < < < | > > > | > | < < < < | | | | | | | | | 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | #import "OFSerialization.h" #import "OFValue.h" OF_ASSUME_NONNULL_BEGIN /*! @file */ /*! * @class OFNumber OFNumber.h ObjFW/OFNumber.h * * @brief Provides a way to store a number in an object. */ #ifndef OF_NUMBER_M OF_SUBCLASSING_RESTRICTED #endif @interface OFNumber: OFValue <OFComparing, OFSerialization, OFJSONRepresentation, OFMessagePackRepresentation> { union of_number_value { double float_; intmax_t signed_; uintmax_t unsigned_; } _value; enum of_number_type { OF_NUMBER_TYPE_FLOAT = 1, OF_NUMBER_TYPE_SIGNED, OF_NUMBER_TYPE_UNSIGNED } _type; const char *_typeEncoding; } /*! * @brief The OFNumber as a `bool`. */ @property (readonly, nonatomic) bool boolValue; /*! * @brief The OFNumber as a `signed char`. */ @property (readonly, nonatomic) signed char charValue; /*! * @brief The OFNumber as a `short`. */ @property (readonly, nonatomic) short shortValue; /*! * @brief The OFNumber as an `int`. */ @property (readonly, nonatomic) int intValue; /*! * @brief The OFNumber as a `long`. */ @property (readonly, nonatomic) long longValue; /*! * @brief The OFNumber as a `long long`. */ @property (readonly, nonatomic) long long longLongValue; /*! * @brief The OFNumber as an `unsigned char`. */ @property (readonly, nonatomic) unsigned char unsignedCharValue; /*! |
︙ | ︙ | |||
327 328 329 330 331 332 333 | * * @param sChar A `signed char` which the OFNumber should contain * @return A new autoreleased OFNumber */ + (instancetype)numberWithChar: (signed char)sChar; /*! | | | | | | | | | | | | | | 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 | * * @param sChar A `signed char` which the OFNumber should contain * @return A new autoreleased OFNumber */ + (instancetype)numberWithChar: (signed char)sChar; /*! * @brief Creates a new OFNumber with the specified `short`. * * @param sShort A `short` which the OFNumber should contain * @return A new autoreleased OFNumber */ + (instancetype)numberWithShort: (short)sShort; /*! * @brief Creates a new OFNumber with the specified `int`. * * @param sInt An `int` which the OFNumber should contain * @return A new autoreleased OFNumber */ + (instancetype)numberWithInt: (int)sInt; /*! * @brief Creates a new OFNumber with the specified `long`. * * @param sLong A `long` which the OFNumber should contain * @return A new autoreleased OFNumber */ + (instancetype)numberWithLong: (long)sLong; /*! * @brief Creates a new OFNumber with the specified `long long`. * * @param sLongLong A `long long` which the OFNumber should contain * @return A new autoreleased OFNumber */ + (instancetype)numberWithLongLong: (long long)sLongLong; /*! * @brief Creates a new OFNumber with the specified `unsigned char`. * * @param uChar An `unsigned char` which the OFNumber should contain * @return A new autoreleased OFNumber */ |
︙ | ︙ | |||
564 565 566 567 568 569 570 | * * @param sChar A `signed char` which the OFNumber should contain * @return An initialized OFNumber */ - (instancetype)initWithChar: (signed char)sChar; /*! | | < | | | < | | | < | | | | | | 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 | * * @param sChar A `signed char` which the OFNumber should contain * @return An initialized OFNumber */ - (instancetype)initWithChar: (signed char)sChar; /*! * @brief Initializes an already allocated OFNumber with the specified `short`. * * @param sShort A `short` which the OFNumber should contain * @return An initialized OFNumber */ - (instancetype)initWithShort: (short)sShort; /*! * @brief Initializes an already allocated OFNumber with the specified `int`. * * @param sInt An `int` which the OFNumber should contain * @return An initialized OFNumber */ - (instancetype)initWithInt: (int)sInt; /*! * @brief Initializes an already allocated OFNumber with the specified `long`. * * @param sLong A `long` which the OFNumber should contain * @return An initialized OFNumber */ - (instancetype)initWithLong: (long)sLong; /*! * @brief Initializes an already allocated OFNumber with the specified * `long long`. * * @param sLongLong A `long long` which the OFNumber should contain * @return An initialized OFNumber */ - (instancetype)initWithLongLong: (long long)sLongLong; /*! * @brief Initializes an already allocated OFNumber with the specified * `unsigned char`. * * @param uChar An `unsigned char` which the OFNumber should contain * @return An initialized OFNumber |
︙ | ︙ |
Modified src/OFNumber.m from [f96cb2d4be] to [57186c2c7a].
︙ | ︙ | |||
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | * * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" #include <math.h> #import "OFNumber.h" #import "OFString.h" #import "OFXMLElement.h" #import "OFXMLAttribute.h" #import "OFData.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFOutOfRangeException.h" | > > < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | > > > > > > > > > > > > | | | | | 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 | * * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #define OF_NUMBER_M #include "config.h" #include <math.h> #import "OFNumber.h" #import "OFString.h" #import "OFXMLElement.h" #import "OFXMLAttribute.h" #import "OFData.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFOutOfRangeException.h" @interface OFNumber () + (instancetype)of_alloc; - (OFString *)of_JSONRepresentationWithOptions: (int)options depth: (size_t)depth; @end @interface OFNumberPlaceholder: OFNumber @end @interface OFNumberSingleton: OFNumber @end static struct { Class isa; } placeholder; static OFNumberSingleton *zeroNumber, *oneNumber, *twoNumber; static OFNumberSingleton *trueNumber, *falseNumber; static void initZeroNumber(void) { zeroNumber = [[OFNumberSingleton alloc] initWithUnsignedChar: 0]; } static void initOneNumber(void) { oneNumber = [[OFNumberSingleton alloc] initWithUnsignedChar: 1]; } static void initTwoNumber(void) { twoNumber = [[OFNumberSingleton alloc] initWithUnsignedChar: 2]; } static void initTrueNumber(void) { trueNumber = [[OFNumberSingleton alloc] initWithBool: true]; } static void initFalseNumber(void) { falseNumber = [[OFNumberSingleton alloc] initWithBool: false]; } @implementation OFNumberPlaceholder - (instancetype)initWithBool: (bool)bool_ { if (bool_) { static of_once_t once; of_once(&once, initTrueNumber); return (id)trueNumber; } else { static of_once_t once; of_once(&once, initFalseNumber); return (id)falseNumber; } } - (instancetype)initWithChar: (signed char)sChar { if (sChar >= 0) return [self initWithUnsignedChar: sChar]; return (id)[[OFNumber of_alloc] initWithChar: sChar]; } - (instancetype)initWithShort: (short)sShort { if (sShort >= 0) return [self initWithUnsignedShort: sShort]; if (sShort >= SCHAR_MIN) return [self initWithChar: (signed char)sShort]; return (id)[[OFNumber of_alloc] initWithShort: sShort]; } - (instancetype)initWithInt: (int)sInt { if (sInt >= 0) return [self initWithUnsignedInt: sInt]; if (sInt >= SHRT_MIN) return [self initWithShort: (short)sInt]; return (id)[[OFNumber of_alloc] initWithInt: sInt]; } - (instancetype)initWithLong: (long)sLong { if (sLong >= 0) return [self initWithUnsignedLong: sLong]; if (sLong >= INT_MIN) return [self initWithShort: (int)sLong]; return (id)[[OFNumber of_alloc] initWithLong: sLong]; } - (instancetype)initWithLongLong: (long long)sLongLong { if (sLongLong >= 0) return [self initWithUnsignedLongLong: sLongLong]; if (sLongLong >= LONG_MIN) return [self initWithLong: (long)sLongLong]; return (id)[[OFNumber of_alloc] initWithLongLong: sLongLong]; } - (instancetype)initWithUnsignedChar: (unsigned char)uChar { switch (uChar) { case 0: { static of_once_t once = OF_ONCE_INIT; of_once(&once, initZeroNumber); return (id)zeroNumber; } case 1: { static of_once_t once = OF_ONCE_INIT; of_once(&once, initOneNumber); return (id)oneNumber; } case 2: { static of_once_t once = OF_ONCE_INIT; of_once(&once, initTwoNumber); return (id)twoNumber; } } return (id)[[OFNumber of_alloc] initWithUnsignedChar: uChar]; } - (instancetype)initWithUnsignedShort: (unsigned short)uShort { if (uShort <= UCHAR_MAX) return [self initWithUnsignedChar: (unsigned char)uShort]; return (id)[[OFNumber of_alloc] initWithUnsignedShort: uShort]; } - (instancetype)initWithUnsignedInt: (unsigned int)uInt { if (uInt <= USHRT_MAX) return [self initWithUnsignedShort: (unsigned short)uInt]; return (id)[[OFNumber of_alloc] initWithUnsignedInt: uInt]; } - (instancetype)initWithUnsignedLong: (unsigned long)uLong { if (uLong <= UINT_MAX) return [self initWithUnsignedInt: (unsigned int)uLong]; return (id)[[OFNumber of_alloc] initWithUnsignedLong: uLong]; } - (instancetype)initWithUnsignedLongLong: (unsigned long long)uLongLong { if (uLongLong <= ULONG_MAX) return [self initWithUnsignedLong: (unsigned long)uLongLong]; return (id)[[OFNumber of_alloc] initWithUnsignedLongLong: uLongLong]; } - (instancetype)initWithInt8: (int8_t)int8 { if (int8 >= 0) return [self initWithUInt8: int8]; return (id)[[OFNumber of_alloc] initWithInt8: int8]; } - (instancetype)initWithInt16: (int16_t)int16 { if (int16 >= 0) return [self initWithUInt16: int16]; if (int16 >= INT8_MIN) return [self initWithInt8: (int8_t)int16]; return (id)[[OFNumber of_alloc] initWithInt16: int16]; } - (instancetype)initWithInt32: (int32_t)int32 { if (int32 >= 0) return [self initWithUInt32: int32]; if (int32 >= INT16_MIN) return [self initWithInt16: (int16_t)int32]; return (id)[[OFNumber of_alloc] initWithInt32: int32]; } - (instancetype)initWithInt64: (int64_t)int64 { if (int64 >= 0) return [self initWithUInt64: int64]; if (int64 >= INT32_MIN) return [self initWithInt32: (int32_t)int64]; return (id)[[OFNumber of_alloc] initWithInt64: int64]; } - (instancetype)initWithUInt8: (uint8_t)uInt8 { return (id)[[OFNumber of_alloc] initWithUInt8: uInt8]; } - (instancetype)initWithUInt16: (uint16_t)uInt16 { if (uInt16 <= UINT8_MAX) return [self initWithUInt8: (uint8_t)uInt16]; return (id)[[OFNumber of_alloc] initWithUInt16: uInt16]; } - (instancetype)initWithUInt32: (uint32_t)uInt32 { if (uInt32 <= UINT16_MAX) return [self initWithUInt16: (uint16_t)uInt32]; return (id)[[OFNumber of_alloc] initWithUInt32: uInt32]; } - (instancetype)initWithUInt64: (uint64_t)uInt64 { if (uInt64 <= UINT32_MAX) return [self initWithUInt32: (uint32_t)uInt64]; return (id)[[OFNumber of_alloc] initWithUInt64: uInt64]; } - (instancetype)initWithSize: (size_t)size { if (size <= ULONG_MAX) return [self initWithUnsignedLong: (unsigned long)size]; return (id)[[OFNumber of_alloc] initWithSize: size]; } - (instancetype)initWithSSize: (ssize_t)sSize { if (sSize >= 0) return [self initWithSize: sSize]; if (sSize <= LONG_MIN) return [self initWithLong: (long)sSize]; return (id)[[OFNumber of_alloc] initWithSSize: sSize]; } - (instancetype)initWithIntMax: (intmax_t)intMax { if (intMax >= 0) return [self initWithUIntMax: intMax]; if (intMax <= LLONG_MIN) return [self initWithLongLong: (long long)intMax]; return (id)[[OFNumber of_alloc] initWithIntMax: intMax]; } - (instancetype)initWithUIntMax: (uintmax_t)uIntMax { if (uIntMax <= ULLONG_MAX) return [self initWithUnsignedLongLong: (unsigned long long)uIntMax]; return (id)[[OFNumber of_alloc] initWithUIntMax: uIntMax]; } #ifdef __clang__ /* * This warning should probably not exist at all, as it prevents checking * whether one type fits into another in a portable way. */ # pragma clang diagnostic push # pragma clang diagnostic ignored "-Wtautological-constant-out-of-range-compare" #endif - (instancetype)initWithPtrDiff: (ptrdiff_t)ptrDiff { if (ptrDiff >= LLONG_MIN && ptrDiff <= LLONG_MAX) return [self initWithLongLong: (long long)ptrDiff]; return (id)[[OFNumber of_alloc] initWithPtrDiff: ptrDiff]; } - (instancetype)initWithIntPtr: (intptr_t)intPtr { if (intPtr >= 0) return [self initWithUIntPtr: intPtr]; if (intPtr >= LLONG_MIN) return [self initWithLongLong: (long long)intPtr]; return (id)[[OFNumber of_alloc] initWithIntPtr: intPtr]; } - (instancetype)initWithUIntPtr: (uintptr_t)uIntPtr { if (uIntPtr <= ULLONG_MAX) return [self initWithUnsignedLongLong: (unsigned long long)uIntPtr]; return (id)[[OFNumber of_alloc] initWithUIntPtr: uIntPtr]; } #ifdef __clang__ # pragma clang diagnostic pop #endif - (instancetype)initWithFloat: (float)float_ { if (float_ == (uintmax_t)float_) return [self initWithUIntMax: (uintmax_t)float_]; if (float_ == (intmax_t)float_) return [self initWithIntMax: (intmax_t)float_]; return (id)[[OFNumber of_alloc] initWithFloat: float_]; } - (instancetype)initWithDouble: (double)double_ { if (double_ == (uintmax_t)double_) return [self initWithUIntMax: (uintmax_t)double_]; if (double_ == (intmax_t)double_) return [self initWithIntMax: (intmax_t)double_]; if (double_ == (float)double_) return [self initWithFloat: (float)double_]; return (id)[[OFNumber of_alloc] initWithDouble: double_]; } - (instancetype)initWithSerialization: (OFXMLElement *)element { return (id)[[OFNumber of_alloc] initWithSerialization: element]; } @end @implementation OFNumberSingleton - (instancetype)autorelease { return self; } - (instancetype)retain { return self; } - (void)release { } - (unsigned int)retainCount { return OF_RETAIN_COUNT_MAX; } @end @implementation OFNumber + (void)initialize { if (self == [OFNumber class]) placeholder.isa = [OFNumberPlaceholder class]; } + (instancetype)of_alloc { return [super alloc]; } + (instancetype)alloc { if (self == [OFNumber class]) return (id)&placeholder; return [super alloc]; } + (instancetype)numberWithBool: (bool)bool_ { return [[[self alloc] initWithBool: bool_] autorelease]; } + (instancetype)numberWithChar: (signed char)sChar { return [[[self alloc] initWithChar: sChar] autorelease]; } + (instancetype)numberWithShort: (short)sShort { return [[[self alloc] initWithShort: sShort] autorelease]; } + (instancetype)numberWithInt: (int)sInt { return [[[self alloc] initWithInt: sInt] autorelease]; } + (instancetype)numberWithLong: (long)sLong { return [[[self alloc] initWithLong: sLong] autorelease]; } + (instancetype)numberWithLongLong: (long long)sLongLong { return [[[self alloc] initWithLongLong: sLongLong] autorelease]; } + (instancetype)numberWithUnsignedChar: (unsigned char)uChar { return [[[self alloc] initWithUnsignedChar: uChar] autorelease]; |
︙ | ︙ | |||
244 245 246 247 248 249 250 | OF_INVALID_INIT_METHOD } - (instancetype)initWithBool: (bool)bool_ { self = [super init]; | | | > | | > | | | > | | | > | | | > | | | > | | > | | > | | > | | > | | > | | > | | > | | > | | > | | > | | > | | > | | > | | > | | > | | > | | > | | > | | > | | > > | | > | < | | | | | | > > > > > > < < < < | < < < < < < < < < < | < < | > | > | < > | > | < | > | < | < > | < < < < < < < < < < < < < | < > | | > | < | | | | | | | < < < < < < < < < < < < < | < | > | < < | | < < | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | < < | < < | < < | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | | < < | | | | | | | | | 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 | OF_INVALID_INIT_METHOD } - (instancetype)initWithBool: (bool)bool_ { self = [super init]; _value.unsigned_ = bool_; _type = OF_NUMBER_TYPE_UNSIGNED; _typeEncoding = @encode(bool); return self; } - (instancetype)initWithChar: (signed char)sChar { self = [super init]; _value.signed_ = sChar; _type = OF_NUMBER_TYPE_SIGNED; _typeEncoding = @encode(signed char); return self; } - (instancetype)initWithShort: (short)sShort { self = [super init]; _value.signed_ = sShort; _type = OF_NUMBER_TYPE_SIGNED; _typeEncoding = @encode(short); return self; } - (instancetype)initWithInt: (int)sInt { self = [super init]; _value.signed_ = sInt; _type = OF_NUMBER_TYPE_SIGNED; _typeEncoding = @encode(int); return self; } - (instancetype)initWithLong: (long)sLong { self = [super init]; _value.signed_ = sLong; _type = OF_NUMBER_TYPE_SIGNED; _typeEncoding = @encode(long); return self; } - (instancetype)initWithLongLong: (long long)sLongLong { self = [super init]; _value.signed_ = sLongLong; _type = OF_NUMBER_TYPE_SIGNED; _typeEncoding = @encode(long long); return self; } - (instancetype)initWithUnsignedChar: (unsigned char)uChar { self = [super init]; _value.unsigned_ = uChar; _type = OF_NUMBER_TYPE_UNSIGNED; _typeEncoding = @encode(unsigned long); return self; } - (instancetype)initWithUnsignedShort: (unsigned short)uShort { self = [super init]; _value.unsigned_ = uShort; _type = OF_NUMBER_TYPE_UNSIGNED; _typeEncoding = @encode(unsigned short); return self; } - (instancetype)initWithUnsignedInt: (unsigned int)uInt { self = [super init]; _value.unsigned_ = uInt; _type = OF_NUMBER_TYPE_UNSIGNED; _typeEncoding = @encode(unsigned int); return self; } - (instancetype)initWithUnsignedLong: (unsigned long)uLong { self = [super init]; _value.unsigned_ = uLong; _type = OF_NUMBER_TYPE_UNSIGNED; _typeEncoding = @encode(unsigned long); return self; } - (instancetype)initWithUnsignedLongLong: (unsigned long long)uLongLong { self = [super init]; _value.unsigned_ = uLongLong; _type = OF_NUMBER_TYPE_UNSIGNED; _typeEncoding = @encode(unsigned long long); return self; } - (instancetype)initWithInt8: (int8_t)int8 { self = [super init]; _value.signed_ = int8; _type = OF_NUMBER_TYPE_SIGNED; _typeEncoding = @encode(int8_t); return self; } - (instancetype)initWithInt16: (int16_t)int16 { self = [super init]; _value.signed_ = int16; _type = OF_NUMBER_TYPE_SIGNED; _typeEncoding = @encode(int16_t); return self; } - (instancetype)initWithInt32: (int32_t)int32 { self = [super init]; _value.signed_ = int32; _type = OF_NUMBER_TYPE_SIGNED; _typeEncoding = @encode(int32_t); return self; } - (instancetype)initWithInt64: (int64_t)int64 { self = [super init]; _value.signed_ = int64; _type = OF_NUMBER_TYPE_SIGNED; _typeEncoding = @encode(int64_t); return self; } - (instancetype)initWithUInt8: (uint8_t)uInt8 { self = [super init]; _value.unsigned_ = uInt8; _type = OF_NUMBER_TYPE_UNSIGNED; _typeEncoding = @encode(uint8_t); return self; } - (instancetype)initWithUInt16: (uint16_t)uInt16 { self = [super init]; _value.unsigned_ = uInt16; _type = OF_NUMBER_TYPE_UNSIGNED; _typeEncoding = @encode(uint16_t); return self; } - (instancetype)initWithUInt32: (uint32_t)uInt32 { self = [super init]; _value.unsigned_ = uInt32; _type = OF_NUMBER_TYPE_UNSIGNED; _typeEncoding = @encode(uint32_t); return self; } - (instancetype)initWithUInt64: (uint64_t)uInt64 { self = [super init]; _value.unsigned_ = uInt64; _type = OF_NUMBER_TYPE_UNSIGNED; _typeEncoding = @encode(uint64_t); return self; } - (instancetype)initWithSize: (size_t)size { self = [super init]; _value.unsigned_ = size; _type = OF_NUMBER_TYPE_UNSIGNED; _typeEncoding = @encode(size_t); return self; } - (instancetype)initWithSSize: (ssize_t)sSize { self = [super init]; _value.signed_ = sSize; _type = OF_NUMBER_TYPE_SIGNED; _typeEncoding = @encode(ssize_t); return self; } - (instancetype)initWithIntMax: (intmax_t)intMax { self = [super init]; _value.signed_ = intMax; _type = OF_NUMBER_TYPE_SIGNED; _typeEncoding = @encode(intmax_t); return self; } - (instancetype)initWithUIntMax: (uintmax_t)uIntMax { self = [super init]; _value.unsigned_ = uIntMax; _type = OF_NUMBER_TYPE_UNSIGNED; _typeEncoding = @encode(uintmax_t); return self; } - (instancetype)initWithPtrDiff: (ptrdiff_t)ptrDiff { self = [super init]; _value.signed_ = ptrDiff; _type = OF_NUMBER_TYPE_SIGNED; _typeEncoding = @encode(ptrdiff_t); return self; } - (instancetype)initWithIntPtr: (intptr_t)intPtr { self = [super init]; _value.signed_ = intPtr; _type = OF_NUMBER_TYPE_SIGNED; _typeEncoding = @encode(intptr_t); return self; } - (instancetype)initWithUIntPtr: (uintptr_t)uIntPtr { self = [super init]; _value.unsigned_ = uIntPtr; _type = OF_NUMBER_TYPE_UNSIGNED; _typeEncoding = @encode(uintptr_t); return self; } - (instancetype)initWithFloat: (float)float_ { self = [super init]; _value.float_ = float_; _type = OF_NUMBER_TYPE_FLOAT; _typeEncoding = @encode(float); return self; } - (instancetype)initWithDouble: (double)double_ { self = [super init]; _value.float_ = double_; _type = OF_NUMBER_TYPE_FLOAT; _typeEncoding = @encode(double); return self; } - (instancetype)initWithSerialization: (OFXMLElement *)element { self = [super init]; @try { void *pool = objc_autoreleasePoolPush(); OFString *typeString; if (![element.name isEqual: self.className] || ![element.namespace isEqual: OF_SERIALIZATION_NS]) @throw [OFInvalidArgumentException exception]; typeString = [element attributeForName: @"type"].stringValue; if ([typeString isEqual: @"bool"]) { OFString *stringValue = element.stringValue; if ([stringValue isEqual: @"true"]) self = [self initWithBool: true]; else if ([stringValue isEqual: @"false"]) self = [self initWithBool: false]; else @throw [OFInvalidArgumentException exception]; } else if ([typeString isEqual: @"float"]) self = [self initWithDouble: OF_BSWAP_DOUBLE_IF_LE( OF_INT_TO_DOUBLE_RAW(OF_BSWAP64_IF_LE( (uint64_t)element.hexadecimalValue)))]; else if ([typeString isEqual: @"signed"]) self = [self initWithIntMax: element.doubleValue]; else if ([typeString isEqual: @"unsigned"]) /* * FIXME: This will fail if the value is bigger than * INTMAX_MAX! */ self = [self initWithUIntMax: element.decimalValue]; else @throw [OFInvalidArgumentException exception]; objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } return self; } - (const char *)objCType { return _typeEncoding; } - (void)getValue: (void *)value size: (size_t)size { switch (*_typeEncoding) { #define CASE(enc, type, field) \ case enc: { \ type tmp = (type)_value.field; \ \ if (size != sizeof(type)) \ @throw [OFOutOfRangeException exception]; \ \ memcpy(value, &tmp, size); \ break; \ } CASE('B', bool, unsigned_) CASE('c', signed char, signed_) CASE('s', short, signed_) CASE('i', int, signed_) CASE('l', long, signed_) CASE('q', long long, signed_) CASE('C', unsigned char, unsigned_) CASE('S', unsigned short, unsigned_) CASE('I', unsigned int, unsigned_) CASE('L', unsigned long, unsigned_) CASE('Q', unsigned long long, unsigned_) CASE('f', float, float_) CASE('d', double, float_) #undef CASE default: @throw [OFInvalidFormatException exception]; } } #define RETURN_AS(t) \ switch (_type) { \ case OF_NUMBER_TYPE_FLOAT: \ return (t)_value.float_; \ case OF_NUMBER_TYPE_SIGNED: \ return (t)_value.signed_; \ case OF_NUMBER_TYPE_UNSIGNED: \ return (t)_value.unsigned_; \ default: \ @throw [OFInvalidFormatException exception]; \ } - (bool)boolValue { RETURN_AS(bool) } - (signed char)charValue { RETURN_AS(signed char) } - (short)shortValue { RETURN_AS(short) } - (int)intValue { RETURN_AS(int) } - (long)longValue { RETURN_AS(long) } - (long long)longLongValue { RETURN_AS(long long) } - (unsigned char)unsignedCharValue { RETURN_AS(unsigned char) } |
︙ | ︙ | |||
955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 | RETURN_AS(float) } - (double)doubleValue { RETURN_AS(double) } - (bool)isEqual: (id)object { OFNumber *number; if (object == self) return true; if (![object isKindOfClass: [OFNumber class]]) return false; number = object; | > | | | | | | | | | 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 | RETURN_AS(float) } - (double)doubleValue { RETURN_AS(double) } #undef RETURN_AS - (bool)isEqual: (id)object { OFNumber *number; if (object == self) return true; if (![object isKindOfClass: [OFNumber class]]) return false; number = object; if (_type == OF_NUMBER_TYPE_FLOAT || number->_type == OF_NUMBER_TYPE_FLOAT) { double value1 = number.doubleValue; double value2 = self.doubleValue; if (isnan(value1) && isnan(value2)) return true; if (isnan(value1) || isnan(value2)) return false; return (value1 == value2); } if (_type == OF_NUMBER_TYPE_SIGNED || number->_type == OF_NUMBER_TYPE_SIGNED) return (number.intMaxValue == self.intMaxValue); return (number.uIntMaxValue == self.uIntMaxValue); } - (of_comparison_result_t)compare: (id <OFComparing>)object { OFNumber *number; if (![(id)object isKindOfClass: [OFNumber class]]) @throw [OFInvalidArgumentException exception]; number = (OFNumber *)object; if (_type == OF_NUMBER_TYPE_FLOAT || number->_type == OF_NUMBER_TYPE_FLOAT) { double double1 = self.doubleValue; double double2 = number.doubleValue; if (double1 > double2) return OF_ORDERED_DESCENDING; if (double1 < double2) return OF_ORDERED_ASCENDING; return OF_ORDERED_SAME; } else if (_type == OF_NUMBER_TYPE_SIGNED || number->_type == OF_NUMBER_TYPE_SIGNED) { intmax_t int1 = self.intMaxValue; intmax_t int2 = number.intMaxValue; if (int1 > int2) return OF_ORDERED_DESCENDING; if (int1 < int2) return OF_ORDERED_ASCENDING; |
︙ | ︙ | |||
1034 1035 1036 1037 1038 1039 1040 | return OF_ORDERED_SAME; } } - (uint32_t)hash { | | < < < < < < < < < < < < < < < < < < < | | | | > < | < < | < < | < < < < < < < < < | < | < < < < < < < < < < < | | | < < < < < < < < < < < < < < < < | < | < < < < < < < < < < < < < < < < | < < < < < < < < < < < < < < < < < | < < < < < < < < | | | > > > > | < | 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 | return OF_ORDERED_SAME; } } - (uint32_t)hash { enum of_number_type type = _type; uint32_t hash; OF_HASH_INIT(hash); if (type == OF_NUMBER_TYPE_FLOAT) { double d; if (isnan(self.doubleValue)) return 0; d = OF_BSWAP_DOUBLE_IF_BE(self.doubleValue); for (uint_fast8_t i = 0; i < sizeof(double); i++) OF_HASH_ADD(hash, ((char *)&d)[i]); } else if (type == OF_NUMBER_TYPE_SIGNED) { intmax_t v = self.intMaxValue * -1; while (v != 0) { OF_HASH_ADD(hash, v & 0xFF); v >>= 8; } OF_HASH_ADD(hash, 1); } else if (type == OF_NUMBER_TYPE_UNSIGNED) { uintmax_t v = self.uIntMaxValue; while (v != 0) { OF_HASH_ADD(hash, v & 0xFF); v >>= 8; } } else @throw [OFInvalidFormatException exception]; OF_HASH_FINALIZE(hash); return hash; } - (id)copy { return [self retain]; } - (OFString *)description { return [self stringValue]; } - (OFString *)stringValue { if (*_typeEncoding == 'B') return (_value.unsigned_ ? @"true" : @"false"); if (_type == OF_NUMBER_TYPE_FLOAT) return [OFString stringWithFormat: @"%g", _value.float_]; if (_type == OF_NUMBER_TYPE_SIGNED) return [OFString stringWithFormat: @"%jd", _value.signed_]; if (_type == OF_NUMBER_TYPE_UNSIGNED) return [OFString stringWithFormat: @"%ju", _value.unsigned_]; @throw [OFInvalidFormatException exception]; } - (OFXMLElement *)XMLElementBySerializing { void *pool = objc_autoreleasePoolPush(); OFXMLElement *element; element = [OFXMLElement elementWithName: self.className namespace: OF_SERIALIZATION_NS stringValue: self.description]; if (*_typeEncoding == 'B') [element addAttributeWithName: @"type" stringValue: @"bool"]; else if (_type == OF_NUMBER_TYPE_FLOAT) { [element addAttributeWithName: @"type" stringValue: @"float"]; element.stringValue = [OFString stringWithFormat: @"%016" PRIx64, OF_BSWAP64_IF_LE(OF_DOUBLE_TO_INT_RAW(OF_BSWAP_DOUBLE_IF_LE( _value.float_)))]; } else if (_type == OF_NUMBER_TYPE_SIGNED) [element addAttributeWithName: @"type" stringValue: @"signed"]; else if (_type == OF_NUMBER_TYPE_UNSIGNED) [element addAttributeWithName: @"type" stringValue: @"unsigned"]; else @throw [OFInvalidFormatException exception]; [element retain]; objc_autoreleasePoolPop(pool); return [element autorelease]; } |
︙ | ︙ | |||
1248 1249 1250 1251 1252 1253 1254 | } - (OFString *)of_JSONRepresentationWithOptions: (int)options depth: (size_t)depth { double doubleValue; | | | | | | | | | | 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 | } - (OFString *)of_JSONRepresentationWithOptions: (int)options depth: (size_t)depth { double doubleValue; if (*_typeEncoding == 'B') return (_value.unsigned_ ? @"true" : @"false"); doubleValue = self.doubleValue; if (isinf(doubleValue)) { if (options & OF_JSON_REPRESENTATION_JSON5) { if (doubleValue > 0) return @"Infinity"; else return @"-Infinity"; } else @throw [OFInvalidArgumentException exception]; } return self.description; } - (OFData *)messagePackRepresentation { OFMutableData *data; if (*_typeEncoding == 'B') { uint8_t type = (_value.unsigned_ ? 0xC3 : 0xC2); data = [OFMutableData dataWithItems: &type count: 1]; } else if (*_typeEncoding == 'f') { uint8_t type = 0xCA; float tmp = OF_BSWAP_FLOAT_IF_LE(_value.float_); data = [OFMutableData dataWithItemSize: 1 capacity: 5]; [data addItem: &type]; [data addItems: &tmp count: sizeof(tmp)]; } else if (*_typeEncoding == 'd') { uint8_t type = 0xCB; double tmp = OF_BSWAP_DOUBLE_IF_LE(_value.float_); data = [OFMutableData dataWithItemSize: 1 capacity: 9]; [data addItem: &type]; [data addItems: &tmp count: sizeof(tmp)]; } else if (_type == OF_NUMBER_TYPE_SIGNED) { intmax_t value = self.intMaxValue; if (value >= -32 && value < 0) { uint8_t tmp = 0xE0 | ((uint8_t)(value - 32) & 0x1F); data = [OFMutableData dataWithItems: &tmp count: 1]; |
︙ | ︙ | |||
1343 1344 1345 1346 1347 1348 1349 | capacity: 9]; [data addItem: &type]; [data addItems: &tmp count: sizeof(tmp)]; } else @throw [OFOutOfRangeException exception]; | | | 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 | capacity: 9]; [data addItem: &type]; [data addItems: &tmp count: sizeof(tmp)]; } else @throw [OFOutOfRangeException exception]; } else if (_type == OF_NUMBER_TYPE_UNSIGNED) { uintmax_t value = self.uIntMaxValue; if (value <= 127) { uint8_t tmp = ((uint8_t)value & 0x7F); data = [OFMutableData dataWithItems: &tmp count: 1]; |
︙ | ︙ | |||
1392 1393 1394 1395 1396 1397 1398 | capacity: 9]; [data addItem: &type]; [data addItems: &tmp count: sizeof(tmp)]; } else @throw [OFOutOfRangeException exception]; | | > | 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 | capacity: 9]; [data addItem: &type]; [data addItems: &tmp count: sizeof(tmp)]; } else @throw [OFOutOfRangeException exception]; } else @throw [OFInvalidFormatException exception]; [data makeImmutable]; return data; } @end |
Modified tests/serialization.xml from [173d674534] to [904cd48eb0].
︙ | ︙ | |||
13 14 15 16 17 18 19 | <object> <OFString>data</OFString> </object> <key> <OFArray> <OFString>Qu"xbar test</OFString> | | | | 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | <object> <OFString>data</OFString> </object> <key> <OFArray> <OFString>Qu"xbar test</OFString> <OFNumber type='unsigned'>1234</OFNumber> <OFNumber type='float'>40934a456d5cfaad</OFNumber> <OFMutableString>asd</OFMutableString> <OFDate>40934a456d5cfaad</OFDate> </OFArray> </key> <object> <OFString>Hello</OFString> </object> |
︙ | ︙ |