ObjFW  Diff

Differences From Artifact [3ddd9aa2f7]:

To Artifact [1b7e4a8b63]:

  • File src/OFArray.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: 16114) [annotate] [blame] [check-ins using]


179
180
181
182
183
184
185
186
187
188

189
190
191
192
193
194
195
179
180
181
182
183
184
185

186

187
188
189
190
191
192
193
194







-

-
+








	return [super init];
}

- initWithObject: (id)object
{
	if (object == nil) {
		Class c = [self class];
		[self release];
		@throw [OFInvalidArgumentException exceptionWithClass: c];
		@throw [OFInvalidArgumentException exception];
	}

	return [self initWithObjects: object, nil];
}

- initWithObjects: (id)firstObject, ...
{
370
371
372
373
374
375
376
377

378
379
380
381
382
383
384
369
370
371
372
373
374
375

376
377
378
379
380
381
382
383







-
+







- (OFArray*)objectsInRange: (of_range_t)range
{
	OFArray *ret;
	id *buffer;

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

	if (![self isKindOfClass: [OFMutableArray class]])
		return [OFArray_subarray arrayWithArray: self
						  range: range];

	buffer = [self allocMemoryWithSize: sizeof(*buffer)
				     count: range.length];
408
409
410
411
412
413
414
415

416
417
418
419
420
421
422
423
407
408
409
410
411
412
413

414

415
416
417
418
419
420
421







-
+
-







	void *pool;
	OFMutableString *ret;
	id *objects;
	size_t i, count;
	IMP append;

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

	count = [self count];

	if (count == 0)
		return @"";
	if (count == 1)
		return [[self firstObject] performSelector: selector];
588
589
590
591
592
593
594
595

596
597
598
599
600
601
602
586
587
588
589
590
591
592

593
594
595
596
597
598
599
600







-
+







		uint8_t type = 0xDC;
		uint32_t tmp = OF_BSWAP32_IF_LE((uint32_t)count);

		[data addItem: &type];
		[data addItems: &tmp
			 count: sizeof(tmp)];
	} else
		@throw [OFOutOfRangeException exceptionWithClass: [self class]];
		@throw [OFOutOfRangeException exception];

	pool = objc_autoreleasePoolPush();

	i = 0;
	enumerator = [self objectEnumerator];
	while ((object = [enumerator nextObject]) != nil) {
		void *pool2 = objc_autoreleasePoolPush();
675
676
677
678
679
680
681
682

683
684
685
686
687
688
689
673
674
675
676
677
678
679

680
681
682
683
684
685
686
687







-
+







- (int)countByEnumeratingWithState: (of_fast_enumeration_state_t*)state
			   objects: (id*)objects
			     count: (int)count
{
	of_range_t range = of_range(state->state, count);

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

	if (range.location + range.length > [self count])
		range.length = [self count] - range.location;

	[self getObjects: objects
		 inRange: range];

716
717
718
719
720
721
722
723

724
725
726
727
728
729
730
731
714
715
716
717
718
719
720

721

722
723
724
725
726
727
728







-
+
-







#endif

- (OFArray*)arrayByAddingObject: (id)object
{
	OFMutableArray *ret;

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

	ret = [[self mutableCopy] autorelease];

	[ret addObject: object];
	[ret makeImmutable];

	return ret;
852
853
854
855
856
857
858
859
860

861
862
863
864
865
866
867
868
869
870
871
872
873

874
875
876
877
849
850
851
852
853
854
855


856
857
858
859
860
861
862
863
864
865
866
867


868
869
870
871
872







-
-
+











-
-
+




	[super dealloc];
}

- (id)nextObject
{
	if (mutationsPtr != NULL && *mutationsPtr != mutations)
		@throw [OFEnumerationMutationException
		    exceptionWithClass: [self class]
				object: array];
		    exceptionWithObject: array];

	if (position < count)
		return [array objectAtIndex: position++];

	return nil;
}

- (void)reset
{
	if (mutationsPtr != NULL && *mutationsPtr != mutations)
		@throw [OFEnumerationMutationException
		    exceptionWithClass: [self class]
				object: array];
		    exceptionWithObject: array];

	position = 0;
}
@end