ObjFW  Diff

Differences From Artifact [ad2d762abe]:

To Artifact [213aaaa47c]:

  • File src/OFArray_adjacent.m — part of check-in [3d16a30f41] at 2013-06-22 12:12:36 on branch trunk — Rework exceptions.

    This mostly removes the argument for the class in which the exception
    occurred. As backtraces were recently added for all platforms, the
    passed class does not give any extra information on where the exception
    occurred anymore.

    This also removes a few other arguments which were not too helpful. In
    the past, the idea was to pass as many arguments as possible so that it
    is easier to find the origin of the exception. However, as backtraces
    are a much better way to find the origin, those are not useful anymore
    and just make the exception more cumbersome to use. The rule is now to
    only pass arguments that might help in recovering from the exception or
    provide information that is otherwise not easily accessible. (user: js, size: 6817) [annotate] [blame] [check-ins using]


49
50
51
52
53
54
55
56

57
58
59
60
61
62
63
64
49
50
51
52
53
54
55

56

57
58
59
60
61
62
63







-
+
-








- initWithObject: (id)object
{
	self = [self init];

	@try {
		if (object == nil)
			@throw [OFInvalidArgumentException
			@throw [OFInvalidArgumentException exception];
			    exceptionWithClass: [self class]];

		[_array addItem: &object];
		[object retain];
	} @catch (id e) {
		[self release];
		@throw e;
	}
144
145
146
147
148
149
150
151

152
153
154
155
156
157
158
159
143
144
145
146
147
148
149

150

151
152
153
154
155
156
157







-
+
-







			if (objects[i] == nil)
				ok = false;

			[objects[i] retain];
		}

		if (!ok)
			@throw [OFInvalidArgumentException
			@throw [OFInvalidArgumentException exception];
			    exceptionWithClass: [self class]];

		[_array addItems: objects
			   count: count];
	} @catch (id e) {
		size_t i;

		for (i = 0; i < count; i++)
174
175
176
177
178
179
180
181

182
183
184
185
186
187
188
189
190
172
173
174
175
176
177
178

179


180
181
182
183
184
185
186







-
+
-
-







		void *pool = objc_autoreleasePoolPush();
		OFEnumerator *enumerator;
		OFXMLElement *child;

		if ((![[element name] isEqual: @"OFArray"] &&
		    ![[element name] isEqual: @"OFMutableArray"]) ||
		    ![[element namespace] isEqual: OF_SERIALIZATION_NS])
			@throw [OFInvalidArgumentException
			@throw [OFInvalidArgumentException exception];
			    exceptionWithClass: [self class]
				      selector: _cmd];

		enumerator = [[element elementsForNamespace:
		    OF_SERIALIZATION_NS] objectEnumerator];

		while ((child = [enumerator nextObject]) != nil) {
			void *pool2 = objc_autoreleasePoolPush();
			id object;
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
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







-
+












-
+













-
+







- (id)objectAtIndex: (size_t)index
{
	id ret;

	@try {
		ret = *((id*)[_array itemAtIndex: index]);
	} @catch (OFOutOfRangeException *e) {
		@throw [OFOutOfRangeException exceptionWithClass: [self class]];
		@throw [OFOutOfRangeException exception];
	}

	return ret;
}

- (id)objectAtIndexedSubscript: (size_t)index
{
	id ret;

	@try {
		ret = *((id*)[_array itemAtIndex: index]);
	} @catch (OFOutOfRangeException *e) {
		@throw [OFOutOfRangeException exceptionWithClass: [self class]];
		@throw [OFOutOfRangeException exception];
	}

	return ret;
}

- (void)getObjects: (id*)buffer
	   inRange: (of_range_t)range
{
	id *objects = [_array items];
	size_t i, count = [_array count];

	if (range.length > SIZE_MAX - range.location ||
	    range.location + range.length > count)
		@throw [OFOutOfRangeException exceptionWithClass: [self class]];
		@throw [OFOutOfRangeException exception];

	for (i = 0; i < range.length; i++)
		buffer[i] = objects[range.location + i];
}

- (size_t)indexOfObject: (id)object
{
292
293
294
295
296
297
298
299

300
301
302
303
304
305
306
307
288
289
290
291
292
293
294

295

296
297
298
299
300
301
302







-
+
-







}


- (OFArray*)objectsInRange: (of_range_t)range
{
	if (range.length > SIZE_MAX - range.location ||
	    range.location + range.length > [_array count])
		@throw [OFOutOfRangeException
		@throw [OFOutOfRangeException exception];
		    exceptionWithClass: [self class]];

	if ([self isKindOfClass: [OFMutableArray class]])
		return [OFArray
		    arrayWithObjects: (id*)[_array items] + range.location
			       count: range.length];

	return [OFArray_adjacentSubarray arrayWithArray: self