| ︙ | | | ︙ | |
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
# define of_forward of_method_not_found
# define of_forward_stret of_method_not_found_stret
#endif
struct pre_ivar {
int retainCount;
#if !defined(OF_HAVE_ATOMIC_OPS) && !defined(OF_AMIGAOS)
of_spinlock_t retainCountSpinlock;
#endif
};
#define PRE_IVARS_ALIGN ((sizeof(struct pre_ivar) + \
(OF_BIGGEST_ALIGNMENT - 1)) & ~(OF_BIGGEST_ALIGNMENT - 1))
#define PRE_IVARS ((struct pre_ivar *)(void *)((char *)self - PRE_IVARS_ALIGN))
|
|
|
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
# define of_forward of_method_not_found
# define of_forward_stret of_method_not_found_stret
#endif
struct pre_ivar {
int retainCount;
#if !defined(OF_HAVE_ATOMIC_OPS) && !defined(OF_AMIGAOS)
OFSpinlock retainCountSpinlock;
#endif
};
#define PRE_IVARS_ALIGN ((sizeof(struct pre_ivar) + \
(OF_BIGGEST_ALIGNMENT - 1)) & ~(OF_BIGGEST_ALIGNMENT - 1))
#define PRE_IVARS ((struct pre_ivar *)(void *)((char *)self - PRE_IVARS_ALIGN))
|
| ︙ | | | ︙ | |
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
|
#elif defined(HAVE_GETRANDOM)
uint16_t buffer;
OF_ENSURE(getrandom(&buffer, sizeof(buffer), 0) == sizeof(buffer));
return buffer;
#else
static of_once_t onceControl = OF_ONCE_INIT;
of_once(&onceControl, initRandom);
# ifdef HAVE_RANDOM
return random() & 0xFFFF;
# else
return rand() & 0xFFFF;
# endif
#endif
}
|
<
|
|
|
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
|
#elif defined(HAVE_GETRANDOM)
uint16_t buffer;
OF_ENSURE(getrandom(&buffer, sizeof(buffer), 0) == sizeof(buffer));
return buffer;
#else
static OFOnceControl onceControl = OFOnceControlInitValue;
OFOnce(&onceControl, initRandom);
# ifdef HAVE_RANDOM
return random() & 0xFFFF;
# else
return rand() & 0xFFFF;
# endif
#endif
}
|
| ︙ | | | ︙ | |
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
|
#if !defined(OF_APPLE_RUNTIME) || defined(__OBJC2__)
static void
uncaughtExceptionHandler(id exception)
{
OFString *description = [exception description];
OFArray *backtrace = nil;
of_string_encoding_t encoding = [OFLocale encoding];
fprintf(stderr, "\nRuntime error: Unhandled exception:\n%s\n",
[description cStringWithEncoding: encoding]);
if ([exception respondsToSelector: @selector(backtrace)])
backtrace = [exception backtrace];
|
|
|
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
|
#if !defined(OF_APPLE_RUNTIME) || defined(__OBJC2__)
static void
uncaughtExceptionHandler(id exception)
{
OFString *description = [exception description];
OFArray *backtrace = nil;
OFStringEncoding encoding = [OFLocale encoding];
fprintf(stderr, "\nRuntime error: Unhandled exception:\n%s\n",
[description cStringWithEncoding: encoding]);
if ([exception respondsToSelector: @selector(backtrace)])
backtrace = [exception backtrace];
|
| ︙ | | | ︙ | |
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
|
allocFailedException.isa = [OFAllocFailedException class];
@throw (id)&allocFailedException;
}
((struct pre_ivar *)instance)->retainCount = 1;
#if !defined(OF_HAVE_ATOMIC_OPS) && !defined(OF_AMIGAOS)
if OF_UNLIKELY (of_spinlock_new(
&((struct pre_ivar *)instance)->retainCountSpinlock) != 0) {
free(instance);
@throw [OFInitializationFailedException
exceptionWithClass: class];
}
#endif
|
|
|
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
|
allocFailedException.isa = [OFAllocFailedException class];
@throw (id)&allocFailedException;
}
((struct pre_ivar *)instance)->retainCount = 1;
#if !defined(OF_HAVE_ATOMIC_OPS) && !defined(OF_AMIGAOS)
if OF_UNLIKELY (OFSpinlockNew(
&((struct pre_ivar *)instance)->retainCountSpinlock) != 0) {
free(instance);
@throw [OFInitializationFailedException
exceptionWithClass: class];
}
#endif
|
| ︙ | | | ︙ | |
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
|
{
return self;
}
+ (OFString *)className
{
return [OFString stringWithCString: class_getName(self)
encoding: OF_STRING_ENCODING_ASCII];
}
+ (bool)isSubclassOfClass: (Class)class
{
for (Class iter = self; iter != Nil; iter = class_getSuperclass(iter))
if (iter == class)
return true;
|
|
|
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
|
{
return self;
}
+ (OFString *)className
{
return [OFString stringWithCString: class_getName(self)
encoding: OFStringEncodingASCII];
}
+ (bool)isSubclassOfClass: (Class)class
{
for (Class iter = self; iter != Nil; iter = class_getSuperclass(iter))
if (iter == class)
return true;
|
| ︙ | | | ︙ | |
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
|
{
return class_getSuperclass(object_getClass(self));
}
- (OFString *)className
{
return [OFString stringWithCString: object_getClassName(self)
encoding: OF_STRING_ENCODING_ASCII];
}
- (bool)isKindOfClass: (Class)class
{
for (Class iter = object_getClass(self); iter != Nil;
iter = class_getSuperclass(iter))
if (iter == class)
|
|
|
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
|
{
return class_getSuperclass(object_getClass(self));
}
- (OFString *)className
{
return [OFString stringWithCString: object_getClassName(self)
encoding: OFStringEncodingASCII];
}
- (bool)isKindOfClass: (Class)class
{
for (Class iter = object_getClass(self); iter != Nil;
iter = class_getSuperclass(iter))
if (iter == class)
|
| ︙ | | | ︙ | |
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
|
id (*imp)(id, SEL, id, id, id, id) =
(id (*)(id, SEL, id, id, id, id))objc_msgSend;
#endif
return imp(self, selector, object1, object2, object3, object4);
}
- (void)performSelector: (SEL)selector afterDelay: (of_time_interval_t)delay
{
void *pool = objc_autoreleasePoolPush();
[OFTimer scheduledTimerWithTimeInterval: delay
target: self
selector: selector
repeats: false];
objc_autoreleasePoolPop(pool);
}
- (void)performSelector: (SEL)selector
withObject: (id)object
afterDelay: (of_time_interval_t)delay
{
void *pool = objc_autoreleasePoolPush();
[OFTimer scheduledTimerWithTimeInterval: delay
target: self
selector: selector
object: object
repeats: false];
objc_autoreleasePoolPop(pool);
}
- (void)performSelector: (SEL)selector
withObject: (id)object1
withObject: (id)object2
afterDelay: (of_time_interval_t)delay
{
void *pool = objc_autoreleasePoolPush();
[OFTimer scheduledTimerWithTimeInterval: delay
target: self
selector: selector
object: object1
object: object2
repeats: false];
objc_autoreleasePoolPop(pool);
}
- (void)performSelector: (SEL)selector
withObject: (id)object1
withObject: (id)object2
withObject: (id)object3
afterDelay: (of_time_interval_t)delay
{
void *pool = objc_autoreleasePoolPush();
[OFTimer scheduledTimerWithTimeInterval: delay
target: self
selector: selector
object: object1
object: object2
object: object3
repeats: false];
objc_autoreleasePoolPop(pool);
}
- (void)performSelector: (SEL)selector
withObject: (id)object1
withObject: (id)object2
withObject: (id)object3
withObject: (id)object4
afterDelay: (of_time_interval_t)delay
{
void *pool = objc_autoreleasePoolPush();
[OFTimer scheduledTimerWithTimeInterval: delay
target: self
selector: selector
object: object1
|
|
|
|
|
|
|
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
|
id (*imp)(id, SEL, id, id, id, id) =
(id (*)(id, SEL, id, id, id, id))objc_msgSend;
#endif
return imp(self, selector, object1, object2, object3, object4);
}
- (void)performSelector: (SEL)selector afterDelay: (OFTimeInterval)delay
{
void *pool = objc_autoreleasePoolPush();
[OFTimer scheduledTimerWithTimeInterval: delay
target: self
selector: selector
repeats: false];
objc_autoreleasePoolPop(pool);
}
- (void)performSelector: (SEL)selector
withObject: (id)object
afterDelay: (OFTimeInterval)delay
{
void *pool = objc_autoreleasePoolPush();
[OFTimer scheduledTimerWithTimeInterval: delay
target: self
selector: selector
object: object
repeats: false];
objc_autoreleasePoolPop(pool);
}
- (void)performSelector: (SEL)selector
withObject: (id)object1
withObject: (id)object2
afterDelay: (OFTimeInterval)delay
{
void *pool = objc_autoreleasePoolPush();
[OFTimer scheduledTimerWithTimeInterval: delay
target: self
selector: selector
object: object1
object: object2
repeats: false];
objc_autoreleasePoolPop(pool);
}
- (void)performSelector: (SEL)selector
withObject: (id)object1
withObject: (id)object2
withObject: (id)object3
afterDelay: (OFTimeInterval)delay
{
void *pool = objc_autoreleasePoolPush();
[OFTimer scheduledTimerWithTimeInterval: delay
target: self
selector: selector
object: object1
object: object2
object: object3
repeats: false];
objc_autoreleasePoolPop(pool);
}
- (void)performSelector: (SEL)selector
withObject: (id)object1
withObject: (id)object2
withObject: (id)object3
withObject: (id)object4
afterDelay: (OFTimeInterval)delay
{
void *pool = objc_autoreleasePoolPush();
[OFTimer scheduledTimerWithTimeInterval: delay
target: self
selector: selector
object: object1
|
| ︙ | | | ︙ | |
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
|
[timer waitUntilDone];
objc_autoreleasePoolPop(pool);
}
- (void)performSelector: (SEL)selector
onThread: (OFThread *)thread
afterDelay: (of_time_interval_t)delay
{
void *pool = objc_autoreleasePoolPush();
[thread.runLoop addTimer: [OFTimer timerWithTimeInterval: delay
target: self
selector: selector
repeats: false]];
objc_autoreleasePoolPop(pool);
}
- (void)performSelector: (SEL)selector
onThread: (OFThread *)thread
withObject: (id)object
afterDelay: (of_time_interval_t)delay
{
void *pool = objc_autoreleasePoolPush();
[thread.runLoop addTimer: [OFTimer timerWithTimeInterval: delay
target: self
selector: selector
object: object
repeats: false]];
objc_autoreleasePoolPop(pool);
}
- (void)performSelector: (SEL)selector
onThread: (OFThread *)thread
withObject: (id)object1
withObject: (id)object2
afterDelay: (of_time_interval_t)delay
{
void *pool = objc_autoreleasePoolPush();
[thread.runLoop addTimer: [OFTimer timerWithTimeInterval: delay
target: self
selector: selector
object: object1
object: object2
repeats: false]];
objc_autoreleasePoolPop(pool);
}
- (void)performSelector: (SEL)selector
onThread: (OFThread *)thread
withObject: (id)object1
withObject: (id)object2
withObject: (id)object3
afterDelay: (of_time_interval_t)delay
{
void *pool = objc_autoreleasePoolPush();
[thread.runLoop addTimer: [OFTimer timerWithTimeInterval: delay
target: self
selector: selector
object: object1
object: object2
object: object3
repeats: false]];
objc_autoreleasePoolPop(pool);
}
- (void)performSelector: (SEL)selector
onThread: (OFThread *)thread
withObject: (id)object1
withObject: (id)object2
withObject: (id)object3
withObject: (id)object4
afterDelay: (of_time_interval_t)delay
{
void *pool = objc_autoreleasePoolPush();
[thread.runLoop addTimer: [OFTimer timerWithTimeInterval: delay
target: self
selector: selector
object: object1
|
|
|
|
|
|
|
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
|
[timer waitUntilDone];
objc_autoreleasePoolPop(pool);
}
- (void)performSelector: (SEL)selector
onThread: (OFThread *)thread
afterDelay: (OFTimeInterval)delay
{
void *pool = objc_autoreleasePoolPush();
[thread.runLoop addTimer: [OFTimer timerWithTimeInterval: delay
target: self
selector: selector
repeats: false]];
objc_autoreleasePoolPop(pool);
}
- (void)performSelector: (SEL)selector
onThread: (OFThread *)thread
withObject: (id)object
afterDelay: (OFTimeInterval)delay
{
void *pool = objc_autoreleasePoolPush();
[thread.runLoop addTimer: [OFTimer timerWithTimeInterval: delay
target: self
selector: selector
object: object
repeats: false]];
objc_autoreleasePoolPop(pool);
}
- (void)performSelector: (SEL)selector
onThread: (OFThread *)thread
withObject: (id)object1
withObject: (id)object2
afterDelay: (OFTimeInterval)delay
{
void *pool = objc_autoreleasePoolPush();
[thread.runLoop addTimer: [OFTimer timerWithTimeInterval: delay
target: self
selector: selector
object: object1
object: object2
repeats: false]];
objc_autoreleasePoolPop(pool);
}
- (void)performSelector: (SEL)selector
onThread: (OFThread *)thread
withObject: (id)object1
withObject: (id)object2
withObject: (id)object3
afterDelay: (OFTimeInterval)delay
{
void *pool = objc_autoreleasePoolPush();
[thread.runLoop addTimer: [OFTimer timerWithTimeInterval: delay
target: self
selector: selector
object: object1
object: object2
object: object3
repeats: false]];
objc_autoreleasePoolPop(pool);
}
- (void)performSelector: (SEL)selector
onThread: (OFThread *)thread
withObject: (id)object1
withObject: (id)object2
withObject: (id)object3
withObject: (id)object4
afterDelay: (OFTimeInterval)delay
{
void *pool = objc_autoreleasePoolPush();
[thread.runLoop addTimer: [OFTimer timerWithTimeInterval: delay
target: self
selector: selector
object: object1
|
| ︙ | | | ︙ | |
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
1163
|
@throw [OFNotImplementedException exceptionWithSelector: selector
object: self];
}
- (instancetype)retain
{
#if defined(OF_HAVE_ATOMIC_OPS)
of_atomic_int_inc(&PRE_IVARS->retainCount);
#elif defined(OF_AMIGAOS)
/*
* On AmigaOS, we can only have one CPU. As increasing a variable is a
* single instruction on M68K, we don't need Forbid() / Permit() on
* M68K.
*/
# ifndef OF_AMIGAOS_M68K
Forbid();
# endif
PRE_IVARS->retainCount++;
# ifndef OF_AMIGAOS_M68K
Permit();
# endif
#else
OF_ENSURE(of_spinlock_lock(&PRE_IVARS->retainCountSpinlock) == 0);
PRE_IVARS->retainCount++;
OF_ENSURE(of_spinlock_unlock(&PRE_IVARS->retainCountSpinlock) == 0);
#endif
return self;
}
- (unsigned int)retainCount
{
assert(PRE_IVARS->retainCount >= 0);
return PRE_IVARS->retainCount;
}
- (void)release
{
#if defined(OF_HAVE_ATOMIC_OPS)
of_memory_barrier_release();
if (of_atomic_int_dec(&PRE_IVARS->retainCount) <= 0) {
of_memory_barrier_acquire();
[self dealloc];
}
#elif defined(OF_AMIGAOS)
int retainCount;
Forbid();
retainCount = --PRE_IVARS->retainCount;
Permit();
if (retainCount == 0)
[self dealloc];
#else
int retainCount;
OF_ENSURE(of_spinlock_lock(&PRE_IVARS->retainCountSpinlock) == 0);
retainCount = --PRE_IVARS->retainCount;
OF_ENSURE(of_spinlock_unlock(&PRE_IVARS->retainCountSpinlock) == 0);
if (retainCount == 0)
[self dealloc];
#endif
}
- (instancetype)autorelease
|
|
|
|
|
|
|
|
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
|
@throw [OFNotImplementedException exceptionWithSelector: selector
object: self];
}
- (instancetype)retain
{
#if defined(OF_HAVE_ATOMIC_OPS)
OFAtomicIntIncrease(&PRE_IVARS->retainCount);
#elif defined(OF_AMIGAOS)
/*
* On AmigaOS, we can only have one CPU. As increasing a variable is a
* single instruction on M68K, we don't need Forbid() / Permit() on
* M68K.
*/
# ifndef OF_AMIGAOS_M68K
Forbid();
# endif
PRE_IVARS->retainCount++;
# ifndef OF_AMIGAOS_M68K
Permit();
# endif
#else
OF_ENSURE(OFSpinlockLock(&PRE_IVARS->retainCountSpinlock) == 0);
PRE_IVARS->retainCount++;
OF_ENSURE(OFSpinlockUnlock(&PRE_IVARS->retainCountSpinlock) == 0);
#endif
return self;
}
- (unsigned int)retainCount
{
assert(PRE_IVARS->retainCount >= 0);
return PRE_IVARS->retainCount;
}
- (void)release
{
#if defined(OF_HAVE_ATOMIC_OPS)
of_memory_barrier_release();
if (OFAtomicIntDecrease(&PRE_IVARS->retainCount) <= 0) {
of_memory_barrier_acquire();
[self dealloc];
}
#elif defined(OF_AMIGAOS)
int retainCount;
Forbid();
retainCount = --PRE_IVARS->retainCount;
Permit();
if (retainCount == 0)
[self dealloc];
#else
int retainCount;
OF_ENSURE(OFSpinlockLock(&PRE_IVARS->retainCountSpinlock) == 0);
retainCount = --PRE_IVARS->retainCount;
OF_ENSURE(OFSpinlockUnlock(&PRE_IVARS->retainCountSpinlock) == 0);
if (retainCount == 0)
[self dealloc];
#endif
}
- (instancetype)autorelease
|
| ︙ | | | ︙ | |