ObjFW  Diff

Differences From Artifact [5040476f6b]:

To Artifact [122354a46f]:


13
14
15
16
17
18
19




20
21
22



23
24
25
26
27
28
29
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#include "config.h"

#include <stdlib.h>





#import "OFException.h"
#import "OFString.h"




@implementation OFException
+ (instancetype)exceptionWithClass: (Class)class
{
	return [[[self alloc] initWithClass: class] autorelease];
}








>
>
>
>



>
>
>







13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#include "config.h"

#include <stdlib.h>

#ifdef HAVE_EXECINFO_H
# include <execinfo.h>
#endif

#import "OFException.h"
#import "OFString.h"
#import "OFArray.h"

#import "autorelease.h"

@implementation OFException
+ (instancetype)exceptionWithClass: (Class)class
{
	return [[[self alloc] initWithClass: class] autorelease];
}

40
41
42
43
44
45
46




47
48
49







50
51
52
53
54
55
56
57
58
59
60
61








































62
}

- initWithClass: (Class)class
{
	self = [super init];

	_inClass = class;





	return self;
}








- (Class)inClass
{
	return _inClass;
}

- (OFString*)description
{
	return [OFString stringWithFormat:
	    @"An exception of class %@ occurred in class %@!",
	    object_getClass(self), _inClass];
}








































@end







>
>
>
>



>
>
>
>
>
>
>












>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

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
}

- initWithClass: (Class)class
{
	self = [super init];

	_inClass = class;
#ifdef HAVE_EXECINFO_H
	_backtraceSize = backtrace(_backtraceBuffer,
	    OF_EXCEPTION_MAX_BACKTRACE_SIZE);
#endif

	return self;
}

- (void)dealloc
{
	[_backtrace release];

	[super dealloc];
}

- (Class)inClass
{
	return _inClass;
}

- (OFString*)description
{
	return [OFString stringWithFormat:
	    @"An exception of class %@ occurred in class %@!",
	    object_getClass(self), _inClass];
}

- (OFArray*)backtrace
{
#ifdef HAVE_EXECINFO_H
	char **symbols;

	if (_backtrace != nil)
		return _backtrace;

	if (_backtraceSize < 1)
		return nil;

	symbols = backtrace_symbols(_backtraceBuffer, _backtraceSize);
	@try {
		int i;

		_backtrace = [[OFMutableArray alloc] init];

		for (i = 0; i < _backtraceSize; i++) {
			void *pool = objc_autoreleasePoolPush();
			OFString *symbol;

			symbol = [OFString
			    stringWithCString: symbols[i]
				     encoding: OF_STRING_ENCODING_NATIVE];
			[_backtrace addObject: symbol];

			objc_autoreleasePoolPop(pool);
		}
	} @finally {
		free(symbols);
	}

	[_backtrace makeImmutable];

	return _backtrace;
#else
	return nil;
#endif
}
@end