ObjFW  Diff

Differences From Artifact [74a7fa7b2d]:

To Artifact [6cfd14d520]:

  • File src/OFAutoreleasePool.m — part of check-in [e1e7ffa903] at 2011-09-22 23:25:42 on branch trunk — Exceptions are now autoreleased.

    This is safe as an "exception loop" can't happen, since if allocating
    an exception fails, it throws an OFAllocFailedException which is
    preallocated and can always be thrown.

    So, the worst case would be that an autorelease of an exception fails,
    triggering an OFOutOfMemoryException for which there is no memory,
    resulting in an OFAllocFailedException to be thrown. (user: js, size: 4213) [annotate] [blame] [check-ins using]


37
38
39
40
41
42
43
44

45
46
47
48
49
50
51
#ifdef OF_THREADS
+ (void)initialize
{
	if (self != [OFAutoreleasePool class])
		return;

	if (!of_tlskey_new(&firstKey) || !of_tlskey_new(&lastKey))
		@throw [OFInitializationFailedException newWithClass: self];

}
#endif

+ (void)addObject: (id)object
{
#ifdef OF_THREADS
	id lastPool = of_tlskey_get(lastKey);







|
>







37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#ifdef OF_THREADS
+ (void)initialize
{
	if (self != [OFAutoreleasePool class])
		return;

	if (!of_tlskey_new(&firstKey) || !of_tlskey_new(&lastKey))
		@throw [OFInitializationFailedException
		    exceptionWithClass: self];
}
#endif

+ (void)addObject: (id)object
{
#ifdef OF_THREADS
	id lastPool = of_tlskey_get(lastKey);
62
63
64
65
66
67
68
69

70
71
72
73
74
75
76
#ifdef OF_THREADS
		lastPool = of_tlskey_get(lastKey);
#endif
	}

	if (lastPool == nil) {
		[object release];
		@throw [OFInitializationFailedException newWithClass: self];

	}

	@try {
		[lastPool _addObject: object];
	} @catch (id e) {
		[object release];
		@throw e;







|
>







63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#ifdef OF_THREADS
		lastPool = of_tlskey_get(lastKey);
#endif
	}

	if (lastPool == nil) {
		[object release];
		@throw [OFInitializationFailedException
		    exceptionWithClass: self];
	}

	@try {
		[lastPool _addObject: object];
	} @catch (id e) {
		[object release];
		@throw e;
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
	@try {
#ifdef OF_THREADS
		id firstPool = of_tlskey_get(firstKey);
		previousPool = of_tlskey_get(lastKey);

		if (!of_tlskey_set(lastKey, self))
			@throw [OFInitializationFailedException
			    newWithClass: isa];
#else
		previousPool = lastPool;
		lastPool = self;
#endif

		if (firstPool == nil) {
#ifdef OF_THREADS
			if (!of_tlskey_set(firstKey, self)) {
				of_tlskey_set(lastKey, previousPool);
				@throw [OFInitializationFailedException
				    newWithClass: isa];
			}
#else
			firstPool = self;
#endif
		}

		if (previousPool != nil)







|










|







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
	@try {
#ifdef OF_THREADS
		id firstPool = of_tlskey_get(firstKey);
		previousPool = of_tlskey_get(lastKey);

		if (!of_tlskey_set(lastKey, self))
			@throw [OFInitializationFailedException
			    exceptionWithClass: isa];
#else
		previousPool = lastPool;
		lastPool = self;
#endif

		if (firstPool == nil) {
#ifdef OF_THREADS
			if (!of_tlskey_set(firstKey, self)) {
				of_tlskey_set(lastKey, previousPool);
				@throw [OFInitializationFailedException
				    exceptionWithClass: isa];
			}
#else
			firstPool = self;
#endif
		}

		if (previousPool != nil)
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#endif

	[super dealloc];
}

- retain
{
	@throw [OFNotImplementedException newWithClass: isa
					      selector: _cmd];
}

- autorelease
{
	@throw [OFNotImplementedException newWithClass: isa
					      selector: _cmd];
}
@end







|
|




|
|


207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
#endif

	[super dealloc];
}

- retain
{
	@throw [OFNotImplementedException exceptionWithClass: isa
						    selector: _cmd];
}

- autorelease
{
	@throw [OFNotImplementedException exceptionWithClass: isa
						    selector: _cmd];
}
@end