-
Notifications
You must be signed in to change notification settings - Fork 109
/
CFNumber.c
1679 lines (1530 loc) · 64.6 KB
/
CFNumber.c
1
2
3
4
5
6
7
8
9
10
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
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
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
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
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
996
997
998
999
1000
/*
* Copyright (c) 2015 Apple Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this
* file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
/* CFNumber.c
Copyright (c) 1999-2014, Apple Inc. All rights reserved.
Responsibility: Ali Ozer
*/
#include <CoreFoundation/CFNumber.h>
#include "CFInternal.h"
#include <CoreFoundation/CFPriv.h>
#include <math.h>
#include <float.h>
#if DEPLOYMENT_TARGET_WINDOWS
#define isnan(A) _isnan(A)
#define isinf(A) !_finite(A)
#define copysign(A, B) _copysign(A, B)
#endif
#define __CFAssertIsBoolean(cf) __CFGenericValidateType(cf, CFBooleanGetTypeID())
struct __CFBoolean {
CFRuntimeBase _base;
};
static struct __CFBoolean __kCFBooleanTrue = {
INIT_CFRUNTIME_BASE()
};
const CFBooleanRef kCFBooleanTrue = &__kCFBooleanTrue;
static struct __CFBoolean __kCFBooleanFalse = {
INIT_CFRUNTIME_BASE()
};
const CFBooleanRef kCFBooleanFalse = &__kCFBooleanFalse;
static CFStringRef __CFBooleanCopyDescription(CFTypeRef cf) {
CFBooleanRef boolean = (CFBooleanRef)cf;
return CFStringCreateWithFormat(kCFAllocatorSystemDefault, NULL, CFSTR("<CFBoolean %p [%p]>{value = %s}"), cf, CFGetAllocator(cf), (boolean == kCFBooleanTrue) ? "true" : "false");
}
CF_PRIVATE CFStringRef __CFBooleanCopyFormattingDescription(CFTypeRef cf, CFDictionaryRef formatOptions) {
CFBooleanRef boolean = (CFBooleanRef)cf;
return (CFStringRef)CFRetain((boolean == kCFBooleanTrue) ? CFSTR("true") : CFSTR("false"));
}
static CFHashCode __CFBooleanHash(CFTypeRef cf) {
CFBooleanRef boolean = (CFBooleanRef)cf;
return (boolean == kCFBooleanTrue) ? _CFHashInt(1) : _CFHashInt(0);
}
static void __CFBooleanDeallocate(CFTypeRef cf) {
CFAssert(false, __kCFLogAssertion, "Deallocated CFBoolean!");
}
static CFTypeID __kCFBooleanTypeID = _kCFRuntimeNotATypeID;
static const CFRuntimeClass __CFBooleanClass = {
0,
"CFBoolean",
NULL, // init
NULL, // copy
__CFBooleanDeallocate,
NULL,
__CFBooleanHash,
__CFBooleanCopyFormattingDescription,
__CFBooleanCopyDescription
};
CFTypeID CFBooleanGetTypeID(void) {
static dispatch_once_t initOnce;
dispatch_once(&initOnce, ^{
__kCFBooleanTypeID = _CFRuntimeRegisterClass(&__CFBooleanClass); // initOnce covered
_CFRuntimeSetInstanceTypeIDAndIsa(&__kCFBooleanTrue, __kCFBooleanTypeID);
_CFRuntimeSetInstanceTypeIDAndIsa(&__kCFBooleanFalse, __kCFBooleanTypeID);
});
return __kCFBooleanTypeID;
}
Boolean CFBooleanGetValue(CFBooleanRef boolean) {
CF_OBJC_FUNCDISPATCHV(CFBooleanGetTypeID(), Boolean, (NSNumber *)boolean, boolValue);
return (boolean == kCFBooleanTrue) ? true : false;
}
/*** CFNumber ***/
#define OLD_CRAP_TOO 0
#if OLD_CRAP_TOO
// old implementation, for runtime comparison purposes
typedef union {
SInt32 valSInt32;
int64_t valSInt64;
Float32 valFloat32;
Float64 valFloat64;
} __CFNumberValue_old;
struct __CFNumber_old { /* Only as many bytes as necessary are allocated */
CFRuntimeBase _base;
__CFNumberValue_old value;
};
static Boolean __CFNumberEqual_old(CFTypeRef cf1, CFTypeRef cf2);
static CFHashCode __CFNumberHash_old(CFTypeRef cf);
static CFStringRef __CFNumberCopyDescription_old(CFTypeRef cf);
CF_PRIVATE CFStringRef __CFNumberCopyFormattingDescriptionAsFloat64_old(CFTypeRef cf);
static CFStringRef __CFNumberCopyFormattingDescription_old(CFTypeRef cf, CFDictionaryRef formatOptions);
static struct __CFNumber_old * CFNumberCreate_old(CFAllocatorRef allocator, CFNumberType type, const void *valuePtr);
static CFNumberType CFNumberGetType_old(struct __CFNumber_old * number);
static CFIndex CFNumberGetByteSize_old(struct __CFNumber_old * number);
static Boolean CFNumberIsFloatType_old(struct __CFNumber_old * number);
static Boolean CFNumberGetValue_old(struct __CFNumber_old * number, CFNumberType type, void *valuePtr);
static CFComparisonResult CFNumberCompare_old(struct __CFNumber_old * number1, struct __CFNumber_old * number2, void *context);
#endif
#define __CFAssertIsNumber(cf) __CFGenericValidateType(cf, CFNumberGetTypeID())
#define __CFAssertIsValidNumberType(type) CFAssert2((0 < type && type <= kCFNumberMaxType) || (type == kCFNumberSInt128Type), __kCFLogAssertion, "%s(): bad CFNumber type %d", __PRETTY_FUNCTION__, type);
/* The IEEE bit patterns... Also have:
0x7f800000 float +Inf
0x7fc00000 float NaN
0xff800000 float -Inf
*/
#define BITSFORDOUBLENAN ((uint64_t)0x7ff8000000000000ULL)
#define BITSFORDOUBLEPOSINF ((uint64_t)0x7ff0000000000000ULL)
#define BITSFORDOUBLENEGINF ((uint64_t)0xfff0000000000000ULL)
#if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_EMBEDDED_MINI || DEPLOYMENT_TARGET_LINUX
#define FLOAT_POSITIVE_2_TO_THE_64 0x1.0p+64L
#define FLOAT_NEGATIVE_2_TO_THE_127 -0x1.0p+127L
#define FLOAT_POSITIVE_2_TO_THE_127 0x1.0p+127L
#elif DEPLOYMENT_TARGET_WINDOWS
#define FLOAT_POSITIVE_2_TO_THE_64 18446744073709551616.0
#define FLOAT_NEGATIVE_2_TO_THE_127 -170141183460469231731687303715884105728.0
#define FLOAT_POSITIVE_2_TO_THE_127 170141183460469231731687303715884105728.0
#else
#error Unknown or unspecified DEPLOYMENT_TARGET
#endif
typedef struct { // NOTE WELL: these two fields may switch position someday, do not use '= {high, low}' -style initialization
int64_t high;
uint64_t low;
} CFSInt128Struct;
enum {
kCFNumberSInt128Type = 17
};
static uint8_t isNeg128(const CFSInt128Struct *in) {
return in->high < 0;
}
static CFComparisonResult cmp128(const CFSInt128Struct *in1, const CFSInt128Struct *in2) {
if (in1->high < in2->high) return kCFCompareLessThan;
if (in1->high > in2->high) return kCFCompareGreaterThan;
if (in1->low < in2->low) return kCFCompareLessThan;
if (in1->low > in2->low) return kCFCompareGreaterThan;
return kCFCompareEqualTo;
}
// allows out to be the same as in1 or in2
static void add128(CFSInt128Struct *out, CFSInt128Struct *in1, CFSInt128Struct *in2) {
CFSInt128Struct tmp;
tmp.low = in1->low + in2->low;
tmp.high = in1->high + in2->high;
if (UINT64_MAX - in1->low < in2->low) {
tmp.high++;
}
*out = tmp;
}
// allows out to be the same as in
static void neg128(CFSInt128Struct *out, CFSInt128Struct *in) {
uint64_t tmplow = ~in->low;
out->low = tmplow + 1;
out->high = ~in->high;
if (UINT64_MAX == tmplow) {
out->high++;
}
}
static const CFSInt128Struct powersOf10[] = {
{ 0x4B3B4CA85A86C47ALL, 0x098A224000000000ULL },
{ 0x0785EE10D5DA46D9LL, 0x00F436A000000000ULL },
{ 0x00C097CE7BC90715LL, 0xB34B9F1000000000ULL },
{ 0x0013426172C74D82LL, 0x2B878FE800000000ULL },
{ 0x0001ED09BEAD87C0LL, 0x378D8E6400000000ULL },
{ 0x0000314DC6448D93LL, 0x38C15B0A00000000ULL },
{ 0x000004EE2D6D415BLL, 0x85ACEF8100000000ULL },
{ 0x0000007E37BE2022LL, 0xC0914B2680000000ULL },
{ 0x0000000C9F2C9CD0LL, 0x4674EDEA40000000ULL },
{ 0x00000001431E0FAELL, 0x6D7217CAA0000000ULL },
{ 0x00000000204FCE5ELL, 0x3E25026110000000ULL },
{ 0x00000000033B2E3CLL, 0x9FD0803CE8000000ULL },
{ 0x000000000052B7D2LL, 0xDCC80CD2E4000000ULL },
{ 0x0000000000084595LL, 0x161401484A000000ULL },
{ 0x000000000000D3C2LL, 0x1BCECCEDA1000000ULL },
{ 0x000000000000152DLL, 0x02C7E14AF6800000ULL },
{ 0x000000000000021ELL, 0x19E0C9BAB2400000ULL },
{ 0x0000000000000036LL, 0x35C9ADC5DEA00000ULL },
{ 0x0000000000000005LL, 0x6BC75E2D63100000ULL },
{ 0x0000000000000000LL, 0x8AC7230489E80000ULL },
{ 0x0000000000000000LL, 0x0DE0B6B3A7640000ULL },
{ 0x0000000000000000LL, 0x016345785D8A0000ULL },
{ 0x0000000000000000LL, 0x002386F26FC10000ULL },
{ 0x0000000000000000LL, 0x00038D7EA4C68000ULL },
{ 0x0000000000000000LL, 0x00005AF3107A4000ULL },
{ 0x0000000000000000LL, 0x000009184E72A000ULL },
{ 0x0000000000000000LL, 0x000000E8D4A51000ULL },
{ 0x0000000000000000LL, 0x000000174876E800ULL },
{ 0x0000000000000000LL, 0x00000002540BE400ULL },
{ 0x0000000000000000LL, 0x000000003B9ACA00ULL },
{ 0x0000000000000000LL, 0x0000000005F5E100ULL },
{ 0x0000000000000000LL, 0x0000000000989680ULL },
{ 0x0000000000000000LL, 0x00000000000F4240ULL },
{ 0x0000000000000000LL, 0x00000000000186A0ULL },
{ 0x0000000000000000LL, 0x0000000000002710ULL },
{ 0x0000000000000000LL, 0x00000000000003E8ULL },
{ 0x0000000000000000LL, 0x0000000000000064ULL },
{ 0x0000000000000000LL, 0x000000000000000AULL },
{ 0x0000000000000000LL, 0x0000000000000001ULL },
};
static const CFSInt128Struct neg_powersOf10[] = {
{ 0xB4C4B357A5793B85LL, 0xF675DDC000000000ULL },
{ 0xF87A11EF2A25B926LL, 0xFF0BC96000000000ULL },
{ 0xFF3F68318436F8EALL, 0x4CB460F000000000ULL },
{ 0xFFECBD9E8D38B27DLL, 0xD478701800000000ULL },
{ 0xFFFE12F64152783FLL, 0xC872719C00000000ULL },
{ 0xFFFFCEB239BB726CLL, 0xC73EA4F600000000ULL },
{ 0xFFFFFB11D292BEA4LL, 0x7A53107F00000000ULL },
{ 0xFFFFFF81C841DFDDLL, 0x3F6EB4D980000000ULL },
{ 0xFFFFFFF360D3632FLL, 0xB98B1215C0000000ULL },
{ 0xFFFFFFFEBCE1F051LL, 0x928DE83560000000ULL },
{ 0xFFFFFFFFDFB031A1LL, 0xC1DAFD9EF0000000ULL },
{ 0xFFFFFFFFFCC4D1C3LL, 0x602F7FC318000000ULL },
{ 0xFFFFFFFFFFAD482DLL, 0x2337F32D1C000000ULL },
{ 0xFFFFFFFFFFF7BA6ALL, 0xE9EBFEB7B6000000ULL },
{ 0xFFFFFFFFFFFF2C3DLL, 0xE43133125F000000ULL },
{ 0xFFFFFFFFFFFFEAD2LL, 0xFD381EB509800000ULL },
{ 0xFFFFFFFFFFFFFDE1LL, 0xE61F36454DC00000ULL },
{ 0xFFFFFFFFFFFFFFC9LL, 0xCA36523A21600000ULL },
{ 0xFFFFFFFFFFFFFFFALL, 0x9438A1D29CF00000ULL },
{ 0xFFFFFFFFFFFFFFFFLL, 0x7538DCFB76180000ULL },
{ 0xFFFFFFFFFFFFFFFFLL, 0xF21F494C589C0000ULL },
{ 0xFFFFFFFFFFFFFFFFLL, 0xFE9CBA87A2760000ULL },
{ 0xFFFFFFFFFFFFFFFFLL, 0xFFDC790D903F0000ULL },
{ 0xFFFFFFFFFFFFFFFFLL, 0xFFFC72815B398000ULL },
{ 0xFFFFFFFFFFFFFFFFLL, 0xFFFFA50CEF85C000ULL },
{ 0xFFFFFFFFFFFFFFFFLL, 0xFFFFF6E7B18D6000ULL },
{ 0xFFFFFFFFFFFFFFFFLL, 0xFFFFFF172B5AF000ULL },
{ 0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFE8B7891800ULL },
{ 0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFDABF41C00ULL },
{ 0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFFC4653600ULL },
{ 0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFFFA0A1F00ULL },
{ 0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFFFF676980ULL },
{ 0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFF0BDC0ULL },
{ 0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFE7960ULL },
{ 0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFD8F0ULL },
{ 0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFC18ULL },
{ 0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFF9CULL },
{ 0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFF6ULL },
{ 0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFULL },
};
static void emit128(char *buffer, const CFSInt128Struct *in, Boolean forcePlus) {
CFSInt128Struct tmp = *in;
if (isNeg128(&tmp)) {
neg128(&tmp, &tmp);
*buffer++ = '-';
} else if (forcePlus) {
*buffer++ = '+';
}
Boolean doneOne = false;
int idx;
for (idx = 0; idx < sizeof(powersOf10) / sizeof(powersOf10[0]); idx++) {
int count = 0;
while (cmp128(&powersOf10[idx], &tmp) <= 0) {
add128(&tmp, &tmp, (CFSInt128Struct *)&neg_powersOf10[idx]);
count++;
}
if (0 != count || doneOne) {
*buffer++ = '0' + count;
doneOne = true;
}
}
if (!doneOne) {
*buffer++ = '0';
}
*buffer = '\0';
}
static void cvtSInt128ToFloat64(Float64 *out, const CFSInt128Struct *in) {
// switching to a positive number results in better accuracy
// for negative numbers close to zero, because the multiply
// of -1 by 2^64 (scaling the Float64 high) is avoided
Boolean wasNeg = false;
CFSInt128Struct tmp = *in;
if (isNeg128(&tmp)) {
neg128(&tmp, &tmp);
wasNeg = true;
}
Float64 d = (Float64)tmp.high * FLOAT_POSITIVE_2_TO_THE_64 + (Float64)tmp.low;
if (wasNeg) d = -d;
*out = d;
}
static void cvtFloat64ToSInt128(CFSInt128Struct *out, const Float64 *in) {
CFSInt128Struct i;
Float64 d = *in;
if (d < FLOAT_NEGATIVE_2_TO_THE_127) {
i.high = 0x8000000000000000LL;
i.low = 0x0000000000000000ULL;
*out = i;
return;
}
if (FLOAT_POSITIVE_2_TO_THE_127<= d) {
i.high = 0x7fffffffffffffffLL;
i.low = 0xffffffffffffffffULL;
*out = i;
return;
}
Float64 t = floor(d / FLOAT_POSITIVE_2_TO_THE_64);
i.high = (int64_t)t;
i.low = (uint64_t)(d - t * FLOAT_POSITIVE_2_TO_THE_64);
*out = i;
}
struct __CFNumber {
CFRuntimeBase _base;
#if OLD_CRAP_TOO
struct __CFNumber_old *__old__;
void * __dummy__;
#endif
uint64_t _pad; // need this space here for the constant objects
/* 0 or 8 more bytes allocated here */
};
/* Seven bits in base:
Bits 6..5: unused
Bits 4..0: CFNumber type
*/
static struct __CFNumber __kCFNumberNaN = {
INIT_CFRUNTIME_BASE(), 0ULL
};
const CFNumberRef kCFNumberNaN = &__kCFNumberNaN;
static struct __CFNumber __kCFNumberNegativeInfinity = {
INIT_CFRUNTIME_BASE(), 0ULL
};
const CFNumberRef kCFNumberNegativeInfinity = &__kCFNumberNegativeInfinity;
static struct __CFNumber __kCFNumberPositiveInfinity = {
INIT_CFRUNTIME_BASE(), 0ULL
};
const CFNumberRef kCFNumberPositiveInfinity = &__kCFNumberPositiveInfinity;
static const struct {
uint16_t canonicalType:5; // canonical fixed-width type
uint16_t floatBit:1; // is float
uint16_t storageBit:1; // storage size (0: (float ? 4 : 8), 1: (float ? 8 : 16) bits)
uint16_t lgByteSize:3; // base-2 log byte size of public type
uint16_t unused:6;
} __CFNumberTypeTable[] = {
/* 0 */ {0, 0, 0, 0},
/* kCFNumberSInt8Type */ {kCFNumberSInt8Type, 0, 0, 0, 0},
/* kCFNumberSInt16Type */ {kCFNumberSInt16Type, 0, 0, 1, 0},
/* kCFNumberSInt32Type */ {kCFNumberSInt32Type, 0, 0, 2, 0},
/* kCFNumberSInt64Type */ {kCFNumberSInt64Type, 0, 0, 3, 0},
/* kCFNumberFloat32Type */ {kCFNumberFloat32Type, 1, 0, 2, 0},
/* kCFNumberFloat64Type */ {kCFNumberFloat64Type, 1, 1, 3, 0},
/* kCFNumberCharType */ {kCFNumberSInt8Type, 0, 0, 0, 0},
/* kCFNumberShortType */ {kCFNumberSInt16Type, 0, 0, 1, 0},
/* kCFNumberIntType */ {kCFNumberSInt32Type, 0, 0, 2, 0},
#if __LP64__
/* kCFNumberLongType */ {kCFNumberSInt64Type, 0, 0, 3, 0},
#else
/* kCFNumberLongType */ {kCFNumberSInt32Type, 0, 0, 2, 0},
#endif
/* kCFNumberLongLongType */ {kCFNumberSInt64Type, 0, 0, 3, 0},
/* kCFNumberFloatType */ {kCFNumberFloat32Type, 1, 0, 2, 0},
/* kCFNumberDoubleType */ {kCFNumberFloat64Type, 1, 1, 3, 0},
#if __LP64__
/* kCFNumberCFIndexType */ {kCFNumberSInt64Type, 0, 0, 3, 0},
/* kCFNumberNSIntegerType */ {kCFNumberSInt64Type, 0, 0, 3, 0},
/* kCFNumberCGFloatType */ {kCFNumberFloat64Type, 1, 1, 3, 0},
#else
/* kCFNumberCFIndexType */ {kCFNumberSInt32Type, 0, 0, 2, 0},
/* kCFNumberNSIntegerType */ {kCFNumberSInt32Type, 0, 0, 2, 0},
/* kCFNumberCGFloatType */ {kCFNumberFloat32Type, 1, 0, 2, 0},
#endif
/* kCFNumberSInt128Type */ {kCFNumberSInt128Type, 0, 1, 4, 0},
};
CF_INLINE CFNumberType __CFNumberGetType(CFNumberRef num) {
return __CFBitfieldGetValue(num->_base._cfinfo[CF_INFO_BITS], 4, 0);
}
#define CVT(SRC_TYPE, DST_TYPE, DST_MIN, DST_MAX) do { \
SRC_TYPE sv; memmove(&sv, data, sizeof(SRC_TYPE)); \
DST_TYPE dv = (sv < DST_MIN) ? (DST_TYPE)DST_MIN : (DST_TYPE)(((DST_MAX < sv) ? DST_MAX : sv)); \
memmove(valuePtr, &dv, sizeof(DST_TYPE)); \
SRC_TYPE vv = (SRC_TYPE)dv; return (vv == sv); \
} while (0)
#define CVT128ToInt(SRC_TYPE, DST_TYPE, DST_MIN, DST_MAX) do { \
SRC_TYPE sv; memmove(&sv, data, sizeof(SRC_TYPE)); \
DST_TYPE dv; Boolean noLoss = false; \
if (0 < sv.high || (0 == sv.high && (int64_t)DST_MAX < sv.low)) { \
dv = DST_MAX; \
} else if (sv.high < -1 || (-1 == sv.high && sv.low < (int64_t)DST_MIN)) { \
dv = DST_MIN; \
} else { \
dv = (DST_TYPE)sv.low; \
noLoss = true; \
} \
memmove(valuePtr, &dv, sizeof(DST_TYPE)); \
return noLoss; \
} while (0)
// returns false if the output value is not the same as the number's value, which
// can occur due to accuracy loss and the value not being within the target range
static Boolean __CFNumberGetValue(CFNumberRef number, CFNumberType type, void *valuePtr) {
type = __CFNumberTypeTable[type].canonicalType;
CFNumberType ntype = __CFNumberGetType(number);
const void *data = &(number->_pad);
switch (type) {
case kCFNumberSInt8Type:
if (__CFNumberTypeTable[ntype].floatBit) {
if (0 == __CFNumberTypeTable[ntype].storageBit) {
CVT(Float32, int8_t, INT8_MIN, INT8_MAX);
} else {
CVT(Float64, int8_t, INT8_MIN, INT8_MAX);
}
} else {
if (0 == __CFNumberTypeTable[ntype].storageBit) {
CVT(int64_t, int8_t, INT8_MIN, INT8_MAX);
} else {
CVT128ToInt(CFSInt128Struct, int8_t, INT8_MIN, INT8_MAX);
}
}
return true;
case kCFNumberSInt16Type:
if (__CFNumberTypeTable[ntype].floatBit) {
if (0 == __CFNumberTypeTable[ntype].storageBit) {
CVT(Float32, int16_t, INT16_MIN, INT16_MAX);
} else {
CVT(Float64, int16_t, INT16_MIN, INT16_MAX);
}
} else {
if (0 == __CFNumberTypeTable[ntype].storageBit) {
CVT(int64_t, int16_t, INT16_MIN, INT16_MAX);
} else {
CVT128ToInt(CFSInt128Struct, int16_t, INT16_MIN, INT16_MAX);
}
}
return true;
case kCFNumberSInt32Type:
if (__CFNumberTypeTable[ntype].floatBit) {
if (0 == __CFNumberTypeTable[ntype].storageBit) {
CVT(Float32, int32_t, INT32_MIN, INT32_MAX);
} else {
CVT(Float64, int32_t, INT32_MIN, INT32_MAX);
}
} else {
if (0 == __CFNumberTypeTable[ntype].storageBit) {
CVT(int64_t, int32_t, INT32_MIN, INT32_MAX);
} else {
CVT128ToInt(CFSInt128Struct, int32_t, INT32_MIN, INT32_MAX);
}
}
return true;
case kCFNumberSInt64Type:
if (__CFNumberTypeTable[ntype].floatBit) {
if (0 == __CFNumberTypeTable[ntype].storageBit) {
CVT(Float32, int64_t, INT64_MIN, INT64_MAX);
} else {
CVT(Float64, int64_t, INT64_MIN, INT64_MAX);
}
} else {
if (0 == __CFNumberTypeTable[ntype].storageBit) {
memmove(valuePtr, data, 8);
} else {
CVT128ToInt(CFSInt128Struct, int64_t, INT64_MIN, INT64_MAX);
}
}
return true;
case kCFNumberSInt128Type:
if (__CFNumberTypeTable[ntype].floatBit) {
if (0 == __CFNumberTypeTable[ntype].storageBit) {
Float32 f;
memmove(&f, data, 4);
Float64 d = f;
CFSInt128Struct i;
cvtFloat64ToSInt128(&i, &d);
memmove(valuePtr, &i, 16);
Float64 d2;
cvtSInt128ToFloat64(&d2, &i);
Float32 f2 = (Float32)d2;
return (f2 == f);
} else {
Float64 d;
memmove(&d, data, 8);
CFSInt128Struct i;
cvtFloat64ToSInt128(&i, &d);
memmove(valuePtr, &i, 16);
Float64 d2;
cvtSInt128ToFloat64(&d2, &i);
return (d2 == d);
}
} else {
if (0 == __CFNumberTypeTable[ntype].storageBit) {
int64_t j;
memmove(&j, data, 8);
CFSInt128Struct i;
i.low = j;
i.high = (j < 0) ? -1LL : 0LL;
memmove(valuePtr, &i, 16);
} else {
memmove(valuePtr, data, 16);
}
}
return true;
case kCFNumberFloat32Type:
if (__CFNumberTypeTable[ntype].floatBit) {
if (0 == __CFNumberTypeTable[ntype].storageBit) {
memmove(valuePtr, data, 4);
} else {
double d;
memmove(&d, data, 8);
if (isnan(d)) {
uint32_t l = 0x7fc00000;
memmove(valuePtr, &l, 4);
return true;
} else if (isinf(d)) {
uint32_t l = 0x7f800000;
if (d < 0.0) l += 0x80000000UL;
memmove(valuePtr, &l, 4);
return true;
}
CVT(Float64, Float32, -FLT_MAX, FLT_MAX);
}
} else {
if (0 == __CFNumberTypeTable[ntype].storageBit) {
CVT(int64_t, Float32, -FLT_MAX, FLT_MAX);
} else {
CFSInt128Struct i;
memmove(&i, data, 16);
Float64 d;
cvtSInt128ToFloat64(&d, &i);
Float32 f = (Float32)d;
memmove(valuePtr, &f, 4);
d = f;
CFSInt128Struct i2;
cvtFloat64ToSInt128(&i2, &d);
return cmp128(&i2, &i) == kCFCompareEqualTo;
}
}
return true;
case kCFNumberFloat64Type:
if (__CFNumberTypeTable[ntype].floatBit) {
if (0 == __CFNumberTypeTable[ntype].storageBit) {
float f;
memmove(&f, data, 4);
if (isnan(f)) {
uint64_t l = BITSFORDOUBLENAN;
memmove(valuePtr, &l, 8);
return true;
} else if (isinf(f)) {
uint64_t l = BITSFORDOUBLEPOSINF;
if (f < 0.0) l += 0x8000000000000000ULL;
memmove(valuePtr, &l, 8);
return true;
}
CVT(Float32, Float64, -DBL_MAX, DBL_MAX);
} else {
memmove(valuePtr, data, 8);
}
} else {
if (0 == __CFNumberTypeTable[ntype].storageBit) {
CVT(int64_t, Float64, -DBL_MAX, DBL_MAX);
} else {
CFSInt128Struct i;
memmove(&i, data, 16);
Float64 d;
cvtSInt128ToFloat64(&d, &i);
memmove(valuePtr, &d, 8);
CFSInt128Struct i2;
cvtFloat64ToSInt128(&i2, &d);
return cmp128(&i2, &i) == kCFCompareEqualTo;
}
}
return true;
}
return false;
}
#define CVT_COMPAT(SRC_TYPE, DST_TYPE, FT) do { \
SRC_TYPE sv; memmove(&sv, data, sizeof(SRC_TYPE)); \
DST_TYPE dv = (DST_TYPE)(sv); \
memmove(valuePtr, &dv, sizeof(DST_TYPE)); \
SRC_TYPE vv = (SRC_TYPE)dv; return (FT) || (vv == sv); \
} while (0)
#define CVT128ToInt_COMPAT(SRC_TYPE, DST_TYPE) do { \
SRC_TYPE sv; memmove(&sv, data, sizeof(SRC_TYPE)); \
DST_TYPE dv; dv = (DST_TYPE)sv.low; \
memmove(valuePtr, &dv, sizeof(DST_TYPE)); \
uint64_t vv = (uint64_t)dv; return (vv == sv.low); \
} while (0)
// this has the old cast-style behavior
static Boolean __CFNumberGetValueCompat(CFNumberRef number, CFNumberType type, void *valuePtr) {
type = __CFNumberTypeTable[type].canonicalType;
CFNumberType ntype = __CFNumberGetType(number);
const void *data = &(number->_pad);
switch (type) {
case kCFNumberSInt8Type:
if (__CFNumberTypeTable[ntype].floatBit) {
if (0 == __CFNumberTypeTable[ntype].storageBit) {
CVT_COMPAT(Float32, int8_t, 0);
} else {
CVT_COMPAT(Float64, int8_t, 0);
}
} else {
if (0 == __CFNumberTypeTable[ntype].storageBit) {
// Leopard's implemenation of this always returned true. We should only return true when the conversion is lossless. However, there are some clients who use CFNumber with small unsigned values disguised as signed values. Since there is no CFNumber API yet for unsigned values, we need to accomodate those clients for now. <rdar://problem/6471866>
// This accomodation should be removed if CFNumber ever provides API for unsigned values. <rdar://problem/6473890>
int64_t sv; memmove(&sv, data, sizeof(int64_t));
int8_t dv = (int8_t)(sv);
memmove(valuePtr, &dv, sizeof(int8_t));
int64_t vv = (int64_t)dv; return !_CFExecutableLinkedOnOrAfter(CFSystemVersionSnowLeopard) || ((sv >> 8LL) == 0LL) || (vv == sv);
} else {
CVT128ToInt_COMPAT(CFSInt128Struct, int8_t);
}
}
return true;
case kCFNumberSInt16Type:
if (__CFNumberTypeTable[ntype].floatBit) {
if (0 == __CFNumberTypeTable[ntype].storageBit) {
CVT_COMPAT(Float32, int16_t, 0);
} else {
CVT_COMPAT(Float64, int16_t, 0);
}
} else {
if (0 == __CFNumberTypeTable[ntype].storageBit) {
// Leopard's implemenation of this always returned true. We should only return true when the conversion is lossless. However, there are some clients who use CFNumber with small unsigned values disguised as signed values. Since there is no CFNumber API yet for unsigned values, we need to accomodate those clients for now. <rdar://problem/6471866>
// This accomodation should be removed if CFNumber ever provides API for unsigned values. <rdar://problem/6473890>
int64_t sv; memmove(&sv, data, sizeof(int64_t));
int16_t dv = (int16_t)(sv);
memmove(valuePtr, &dv, sizeof(int16_t));
int64_t vv = (int64_t)dv; return !_CFExecutableLinkedOnOrAfter(CFSystemVersionSnowLeopard) || ((sv >> 16LL) == 0LL) || (vv == sv);
} else {
CVT128ToInt_COMPAT(CFSInt128Struct, int16_t);
}
}
return true;
case kCFNumberSInt32Type:
if (__CFNumberTypeTable[ntype].floatBit) {
if (0 == __CFNumberTypeTable[ntype].storageBit) {
CVT_COMPAT(Float32, int32_t, 0);
} else {
CVT_COMPAT(Float64, int32_t, 0);
}
} else {
if (0 == __CFNumberTypeTable[ntype].storageBit) {
CVT_COMPAT(int64_t, int32_t, 0);
} else {
CVT128ToInt_COMPAT(CFSInt128Struct, int32_t);
}
}
return true;
case kCFNumberSInt64Type:
if (__CFNumberTypeTable[ntype].floatBit) {
if (0 == __CFNumberTypeTable[ntype].storageBit) {
CVT_COMPAT(Float32, int64_t, 0);
} else {
CVT_COMPAT(Float64, int64_t, 0);
}
} else {
if (0 == __CFNumberTypeTable[ntype].storageBit) {
CVT_COMPAT(int64_t, int64_t, 0);
} else {
CVT128ToInt_COMPAT(CFSInt128Struct, int64_t);
}
}
return true;
case kCFNumberSInt128Type:
if (__CFNumberTypeTable[ntype].floatBit) {
if (0 == __CFNumberTypeTable[ntype].storageBit) {
Float32 f;
memmove(&f, data, 4);
Float64 d = f;
CFSInt128Struct i;
cvtFloat64ToSInt128(&i, &d);
memmove(valuePtr, &i, 16);
Float64 d2;
cvtSInt128ToFloat64(&d2, &i);
Float32 f2 = (Float32)d2;
return (f2 == f);
} else {
Float64 d;
memmove(&d, data, 8);
CFSInt128Struct i;
cvtFloat64ToSInt128(&i, &d);
memmove(valuePtr, &i, 16);
Float64 d2;
cvtSInt128ToFloat64(&d2, &i);
return (d2 == d);
}
} else {
if (0 == __CFNumberTypeTable[ntype].storageBit) {
int64_t j;
memmove(&j, data, 8);
CFSInt128Struct i;
i.low = j;
i.high = (j < 0) ? -1LL : 0LL;
memmove(valuePtr, &i, 16);
} else {
memmove(valuePtr, data, 16);
}
}
return true;
case kCFNumberFloat32Type:
if (__CFNumberTypeTable[ntype].floatBit) {
if (0 == __CFNumberTypeTable[ntype].storageBit) {
memmove(valuePtr, data, 4);
} else {
CVT_COMPAT(Float64, Float32, 0);
}
} else {
if (0 == __CFNumberTypeTable[ntype].storageBit) {
CVT_COMPAT(int64_t, Float32, 0);
} else {
CFSInt128Struct i;
memmove(&i, data, 16);
Float64 d;
cvtSInt128ToFloat64(&d, &i);
Float32 f = (Float32)d;
memmove(valuePtr, &f, 4);
d = f;
CFSInt128Struct i2;
cvtFloat64ToSInt128(&i2, &d);
return cmp128(&i2, &i) == kCFCompareEqualTo;
}
}
return true;
case kCFNumberFloat64Type:
if (__CFNumberTypeTable[ntype].floatBit) {
if (0 == __CFNumberTypeTable[ntype].storageBit) {
CVT_COMPAT(Float32, Float64, 0);
} else {
memmove(valuePtr, data, 8);
}
} else {
if (0 == __CFNumberTypeTable[ntype].storageBit) {
CVT_COMPAT(int64_t, Float64, 0);
} else {
CFSInt128Struct i;
memmove(&i, data, 16);
Float64 d;
cvtSInt128ToFloat64(&d, &i);
memmove(valuePtr, &d, 8);
CFSInt128Struct i2;
cvtFloat64ToSInt128(&i2, &d);
return cmp128(&i2, &i) == kCFCompareEqualTo;
}
}
return true;
}
return false;
}
#if OLD_CRAP_TOO
static void FAIL(void) {}
#endif
static CFStringRef __CFNumberCopyDescription(CFTypeRef cf) {
CFNumberRef number = (CFNumberRef)cf;
CFNumberType type = __CFNumberGetType(number);
CFMutableStringRef mstr = CFStringCreateMutable(kCFAllocatorSystemDefault, 0);
CFStringAppendFormat(mstr, NULL, CFSTR("<CFNumber %p [%p]>{value = "), cf, CFGetAllocator(cf));
if (__CFNumberTypeTable[type].floatBit) {
Float64 d;
__CFNumberGetValue(number, kCFNumberFloat64Type, &d);
if (isnan(d)) {
CFStringAppend(mstr, CFSTR("nan"));
} else if (isinf(d)) {
CFStringAppend(mstr, (0.0 < d) ? CFSTR("+infinity") : CFSTR("-infinity"));
} else if (0.0 == d) {
CFStringAppend(mstr, (copysign(1.0, d) < 0.0) ? CFSTR("-0.0") : CFSTR("+0.0"));
} else {
CFStringAppendFormat(mstr, NULL, CFSTR("%+.*f"), (__CFNumberTypeTable[type].storageBit ? 20 : 10), d);
}
const char *typeName = "unknown float";
switch (type) {
case kCFNumberFloat32Type: typeName = "kCFNumberFloat32Type"; break;
case kCFNumberFloat64Type: typeName = "kCFNumberFloat64Type"; break;
}
CFStringAppendFormat(mstr, NULL, CFSTR(", type = %s}"), typeName);
} else {
CFSInt128Struct i;
__CFNumberGetValue(number, kCFNumberSInt128Type, &i);
char buffer[128];
emit128(buffer, &i, true);
const char *typeName = "unknown integer";
switch (type) {
case kCFNumberSInt8Type: typeName = "kCFNumberSInt8Type"; break;
case kCFNumberSInt16Type: typeName = "kCFNumberSInt16Type"; break;
case kCFNumberSInt32Type: typeName = "kCFNumberSInt32Type"; break;
case kCFNumberSInt64Type: typeName = "kCFNumberSInt64Type"; break;
case kCFNumberSInt128Type: typeName = "kCFNumberSInt128Type"; break;
}
CFStringAppendFormat(mstr, NULL, CFSTR("%s, type = %s}"), buffer, typeName);
}
#if OLD_CRAP_TOO
if (! number->__old__) {
printf("*** Test skipped in __CFNumberCopyDescription for number %p\n", cf);
} else {
CFStringRef test = __CFNumberCopyDescription_old(number->__old__);
if (!CFEqual(test, mstr)) {
CFLog(kCFLogLevelWarning, CFSTR("*** TEST FAIL in __CFNumberCopyDescription: '%@' '%@'"), test, mstr); FAIL();
}
}
#endif
return mstr;
}
// This function separated out from __CFNumberCopyFormattingDescription() so the plist creation can use it as well.
static CFStringRef __CFNumberCreateFormattingDescriptionAsFloat64(CFAllocatorRef allocator, CFTypeRef cf) {
Float64 d;
CFNumberGetValue((CFNumberRef)cf, kCFNumberFloat64Type, &d);
if (isnan(d)) {
return (CFStringRef)CFRetain(CFSTR("nan"));
}
if (isinf(d)) {
return (CFStringRef)CFRetain((0.0 < d) ? CFSTR("+infinity") : CFSTR("-infinity"));
}
if (0.0 == d) {
return (CFStringRef)CFRetain(CFSTR("0.0"));
}
// if %g is used here, need to use DBL_DIG + 2 on Mac OS X, but %f needs +1
return CFStringCreateWithFormat(allocator, NULL, CFSTR("%.*g"), DBL_DIG + 2, d);
}
CF_PRIVATE CFStringRef __CFNumberCopyFormattingDescriptionAsFloat64(CFTypeRef cf) {
CFStringRef result = __CFNumberCreateFormattingDescriptionAsFloat64(kCFAllocatorSystemDefault, cf);
#if OLD_CRAP_TOO
CFNumberRef number = (CFNumberRef)cf;
if (! number->__old__) {
printf("*** Test skipped in __CFNumberCopyFormattingDescriptionAsFloat64 for number %p\n", cf);
} else {
CFStringRef test = __CFNumberCopyFormattingDescriptionAsFloat64_old(number->__old__);
if (!CFEqual(test, result)) {
CFLog(kCFLogLevelWarning, CFSTR("*** TEST FAIL in __CFNumberCopyFormattingDescriptionAsFloat64: '%@' '%@'"), test, result); FAIL();
}
}
#endif
return result;
}
CF_PRIVATE CFStringRef __CFNumberCreateFormattingDescription(CFAllocatorRef allocator, CFTypeRef cf, CFDictionaryRef formatOptions) {
CFNumberRef number = (CFNumberRef)cf;
CFNumberType type = __CFNumberGetType(number);
if (__CFNumberTypeTable[type].floatBit) {
return __CFNumberCreateFormattingDescriptionAsFloat64(allocator, number);
}
CFSInt128Struct i;
__CFNumberGetValue(number, kCFNumberSInt128Type, &i);
char buffer[128];
emit128(buffer, &i, false);
return CFStringCreateWithFormat(allocator, NULL, CFSTR("%s"), buffer);
}
static CFStringRef __CFNumberCopyFormattingDescription_new(CFTypeRef cf, CFDictionaryRef formatOptions) {
CFNumberRef number = (CFNumberRef)cf;
CFNumberType type = __CFNumberGetType(number);
if (__CFNumberTypeTable[type].floatBit) {
return __CFNumberCopyFormattingDescriptionAsFloat64(number);
}
CFSInt128Struct i;
__CFNumberGetValue(number, kCFNumberSInt128Type, &i);
char buffer[128];
emit128(buffer, &i, false);
return CFStringCreateWithFormat(kCFAllocatorSystemDefault, NULL, CFSTR("%s"), buffer);
}
CF_PRIVATE CFStringRef __CFNumberCopyFormattingDescription(CFTypeRef cf, CFDictionaryRef formatOptions) {
CFStringRef result = __CFNumberCopyFormattingDescription_new(cf, formatOptions);
#if OLD_CRAP_TOO
CFNumberRef number = (CFNumberRef)cf;
if (! number->__old__) {
printf("*** Test skipped in __CFNumberCopyFormattingDescription for number %p\n", cf);
} else {
CFStringRef test = __CFNumberCopyFormattingDescription_old(number->__old__, formatOptions);
if (!CFEqual(test, result)) {
CFLog(kCFLogLevelWarning, CFSTR("*** TEST FAIL in __CFNumberCopyFormattingDescription: '%@' '%@'"), test, result); FAIL();
}
}
#endif
return result;
}
static Boolean __CFNumberEqual(CFTypeRef cf1, CFTypeRef cf2) {
Boolean b = CFNumberCompare((CFNumberRef)cf1, (CFNumberRef)cf2, 0) == kCFCompareEqualTo;
#if OLD_CRAP_TOO
CFNumberRef number1 = (CFNumberRef)cf1;
CFNumberRef number2 = (CFNumberRef)cf2;
if (! number1->__old__ || !number2->__old__) {
printf("*** Test skipped in __CFNumberEqual for numbers %p %p\n", cf1, cf2);
} else {
Boolean b2 = __CFNumberEqual_old(number1->__old__, number2->__old__);
if (b2 != b) {
CFLog(kCFLogLevelWarning, CFSTR("*** TEST FAIL in __CFNumberEqual: '%d' '%d'"), b2, b); FAIL();
}
}
#endif
return b;
}
static CFHashCode __CFNumberHash(CFTypeRef cf) {
CFHashCode h;
CFNumberRef number = (CFNumberRef)cf;
switch (__CFNumberGetType(number)) {
case kCFNumberSInt8Type:
case kCFNumberSInt16Type:
case kCFNumberSInt32Type: {
SInt32 i;
__CFNumberGetValue(number, kCFNumberSInt32Type, &i);
h = _CFHashInt(i);
break;
}
default: {
Float64 d;
__CFNumberGetValue(number, kCFNumberFloat64Type, &d);
h = _CFHashDouble((double)d);
break;
}
}
#if OLD_CRAP_TOO
CFNumberRef number1 = (CFNumberRef)cf;
if (! number1->__old__) {
printf("*** Test skipped in __CFNumberHash for number %p\n", cf);
} else {
CFHashCode h2 = __CFNumberHash_old(number1->__old__);
if (h2 != h) {
CFLog(kCFLogLevelWarning, CFSTR("*** TEST FAIL in __CFNumberHash: '%d' '%d'"), h2, h); FAIL();
}
}
#endif
return h;
}
static CFTypeID __kCFNumberTypeID = _kCFRuntimeNotATypeID;
enum {
kCFNumberCachingEnabled = 0,
kCFNumberCachingDisabled = 1,
kCFNumberCachingFullyDisabled = 2
};
static char __CFNumberCaching = kCFNumberCachingEnabled;
static const CFRuntimeClass __CFNumberClass = {
0,
"CFNumber",
NULL, // init