40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
#import "OFRunLoop.h"
#if !defined(OF_HAVE_ATOMIC_OPS) && defined(OF_HAVE_THREADS)
# import "OFPlainMutex.h" /* For OFSpinlock */
#endif
#import "OFString.h"
#import "OFThread.h"
#import "OFTimer.h"
#import "OFAllocFailedException.h"
#import "OFEnumerationMutationException.h"
#import "OFInitializationFailedException.h"
#import "OFInvalidArgumentException.h"
#import "OFNotImplementedException.h"
#import "OFOutOfMemoryException.h"
|
>
|
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
#import "OFRunLoop.h"
#if !defined(OF_HAVE_ATOMIC_OPS) && defined(OF_HAVE_THREADS)
# import "OFPlainMutex.h" /* For OFSpinlock */
#endif
#import "OFString.h"
#import "OFThread.h"
#import "OFTimer.h"
#import "OFValue.h"
#import "OFAllocFailedException.h"
#import "OFEnumerationMutationException.h"
#import "OFInitializationFailedException.h"
#import "OFInvalidArgumentException.h"
#import "OFNotImplementedException.h"
#import "OFOutOfMemoryException.h"
|
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
|
}
#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];
if (backtrace != nil) {
OFString *s = [backtrace componentsJoinedByString: @"\n "];
fprintf(stderr, "\nBacktrace:\n %s\n\n",
[s cStringWithEncoding: encoding]);
}
abort();
}
#endif
static void
|
|
>
|
>
|
>
>
>
>
>
|
>
>
|
>
|
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
|
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
|
}
#if !defined(OF_APPLE_RUNTIME) || defined(__OBJC2__)
static void
uncaughtExceptionHandler(id exception)
{
OFString *description = [exception description];
OFArray OF_GENERIC(OFValue *) *stackTraceAddresses = nil;
OFArray OF_GENERIC(OFString *) *stackTraceSymbols = nil;
OFStringEncoding encoding = [OFLocale encoding];
fprintf(stderr, "\nRuntime error: Unhandled exception:\n%s\n",
[description cStringWithEncoding: encoding]);
if ([exception respondsToSelector: @selector(stackTraceAddresses)])
stackTraceAddresses = [exception stackTraceAddresses];
if (stackTraceAddresses != nil) {
size_t count = stackTraceAddresses.count;
if ([exception respondsToSelector:
@selector(stackTraceSymbols)])
stackTraceSymbols = [exception stackTraceSymbols];
if (stackTraceSymbols.count != count)
stackTraceSymbols = nil;
fputs("\nStack trace:\n", stderr);
if (stackTraceSymbols != nil) {
for (size_t i = 0; i < count; i++) {
void *address = [[stackTraceAddresses
objectAtIndex: i] pointerValue];
const char *symbol = [[stackTraceSymbols
objectAtIndex: i]
cStringWithEncoding: encoding];
fprintf(stderr, " %p %s\n", address, symbol);
}
} else {
for (size_t i = 0; i < count; i++) {
void *address = [[stackTraceAddresses
objectAtIndex: i] pointerValue];
fprintf(stderr, " %p\n", address);
}
}
fputs("\n", stderr);
}
abort();
}
#endif
static void
|
336
337
338
339
340
341
342
343
344
345
346
347
348
349
|
exceptionWithClass: class];
}
#endif
instance = (OFObject *)(void *)((char *)instance + PRE_IVARS_ALIGN);
if (!objc_constructInstance(class, instance)) {
free((char *)instance - PRE_IVARS_ALIGN);
@throw [OFInitializationFailedException
exceptionWithClass: class];
}
if OF_UNLIKELY (extra != NULL)
*extra = (char *)instance + instanceSize + extraAlignment;
|
>
>
>
>
|
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
|
exceptionWithClass: class];
}
#endif
instance = (OFObject *)(void *)((char *)instance + PRE_IVARS_ALIGN);
if (!objc_constructInstance(class, instance)) {
#if !defined(OF_HAVE_ATOMIC_OPS) && !defined(OF_AMIGAOS)
OFSpinlockFree(&((struct PreIvars *)(void *)
((char *)instance - PRE_IVARS_ALIGN))->retainCountSpinlock);
#endif
free((char *)instance - PRE_IVARS_ALIGN);
@throw [OFInitializationFailedException
exceptionWithClass: class];
}
if OF_UNLIKELY (extra != NULL)
*extra = (char *)instance + instanceSize + extraAlignment;
|
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
|
{
uintptr_t ptr = (uintptr_t)self;
unsigned long hash;
OFHashInit(&hash);
for (size_t i = 0; i < sizeof(ptr); i++) {
OFHashAdd(&hash, ptr & 0xFF);
ptr >>= 8;
}
OFHashFinalize(&hash);
return hash;
}
|
|
|
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
|
{
uintptr_t ptr = (uintptr_t)self;
unsigned long hash;
OFHashInit(&hash);
for (size_t i = 0; i < sizeof(ptr); i++) {
OFHashAddByte(&hash, ptr & 0xFF);
ptr >>= 8;
}
OFHashFinalize(&hash);
return hash;
}
|
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
|
return true;
}
- (void)dealloc
{
objc_destructInstance(self);
free((char *)self - PRE_IVARS_ALIGN);
}
/* Required to use properties with the Apple runtime */
- (id)copyWithZone: (void *)zone
{
|
>
>
>
>
|
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
|
return true;
}
- (void)dealloc
{
objc_destructInstance(self);
#if !defined(OF_HAVE_ATOMIC_OPS) && !defined(OF_AMIGAOS)
OFSpinlockFree(&PRE_IVARS->retainCountSpinlock);
#endif
free((char *)self - PRE_IVARS_ALIGN);
}
/* Required to use properties with the Apple runtime */
- (id)copyWithZone: (void *)zone
{
|