ObjFW  Diff

Differences From Artifact [a34fd71e38]:

To Artifact [9d67fa5621]:

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


101
102
103
104
105
106
107
108
109


110
111
112
113
114
115
116
101
102
103
104
105
106
107


108
109
110
111
112
113
114
115
116







-
-
+
+








- (void)release
{
}

- (void)dealloc
{
	@throw [OFNotImplementedException newWithClass: isa
					      selector: _cmd];
	@throw [OFNotImplementedException exceptionWithClass: isa
						    selector: _cmd];
	[super dealloc];	/* Get rid of a stupid warning */
}
@end

@implementation OFArray
+ (void)initialize
{
167
168
169
170
171
172
173
174
175


176
177
178
179
180
181
182
167
168
169
170
171
172
173


174
175
176
177
178
179
180
181
182







-
-
+
+







}

- init
{
	if (isa == [OFArray class]) {
		Class c = isa;
		[self release];
		@throw [OFNotImplementedException newWithClass: c
						      selector: _cmd];
		@throw [OFNotImplementedException exceptionWithClass: c
							    selector: _cmd];
	}

	return [super init];
}

- initWithObject: (id)object
{
197
198
199
200
201
202
203
204
205


206
207
208
209
210
211
212
213


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
197
198
199
200
201
202
203


204
205
206
207
208
209
210
211


212
213
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







-
-
+
+






-
-
+
+






-
-
+
+







-
-
+
+






-
-
+
+




-
-
+
+







}

- initWithObject: (id)firstObject
       arguments: (va_list)arguments
{
	Class c = isa;
	[self release];
	@throw [OFNotImplementedException newWithClass: c
					      selector: _cmd];
	@throw [OFNotImplementedException exceptionWithClass: c
						    selector: _cmd];
}

- initWithArray: (OFArray*)array
{
	Class c = isa;
	[self release];
	@throw [OFNotImplementedException newWithClass: c
					      selector: _cmd];
	@throw [OFNotImplementedException exceptionWithClass: c
						    selector: _cmd];
}

- initWithCArray: (id*)objects
{
	Class c = isa;
	[self release];
	@throw [OFNotImplementedException newWithClass: c
					      selector: _cmd];
	@throw [OFNotImplementedException exceptionWithClass: c
						    selector: _cmd];
}

- initWithCArray: (id*)objects
	  length: (size_t)length
{
	Class c = isa;
	[self release];
	@throw [OFNotImplementedException newWithClass: c
					      selector: _cmd];
	@throw [OFNotImplementedException exceptionWithClass: c
						    selector: _cmd];
}

- initWithSerialization: (OFXMLElement*)element
{
	Class c = isa;
	[self release];
	@throw [OFNotImplementedException newWithClass: c
					      selector: _cmd];
	@throw [OFNotImplementedException exceptionWithClass: c
						    selector: _cmd];
}

- (size_t)count
{
	@throw [OFNotImplementedException newWithClass: isa
					      selector: _cmd];
	@throw [OFNotImplementedException exceptionWithClass: isa
						    selector: _cmd];
}

- (void)getObjects: (id*)buffer
	   inRange: (of_range_t)range
{
	size_t i;

278
279
280
281
282
283
284
285
286


287
288
289
290
291
292
293
278
279
280
281
282
283
284


285
286
287
288
289
290
291
292
293







-
-
+
+







- mutableCopy
{
	return [[OFMutableArray alloc] initWithArray: self];
}

- (id)objectAtIndex: (size_t)index
{
	@throw [OFNotImplementedException newWithClass: isa
					      selector: _cmd];
	@throw [OFNotImplementedException exceptionWithClass: isa
						    selector: _cmd];
}

- (size_t)indexOfObject: (id)object
{
	size_t i, count = [self count];

	for (i = 0; i < count; i++)
527
528
529
530
531
532
533
534

535
536
537
538
539
540
541
527
528
529
530
531
532
533

534
535
536
537
538
539
540
541







-
+







			   objects: (id*)objects
			     count: (int)count_
{
	/* FIXME: Use -[getObjects:inRange:] on the passed objects */
	size_t count = [self count];

	if (count > INT_MAX)
		@throw [OFOutOfRangeException newWithClass: isa];
		@throw [OFOutOfRangeException exceptionWithClass: isa];

	if (state->state >= count)
		return 0;

	state->state = count;
	state->itemsPtr = [self cArray];
	state->mutationsPtr = (unsigned long*)self;
664
665
666
667
668
669
670
671
672



673
674
675
676
677
678
679
680
681
682
683
684



685
686
687
688
664
665
666
667
668
669
670


671
672
673
674
675
676
677
678
679
680
681
682
683


684
685
686
687
688
689
690







-
-
+
+
+










-
-
+
+
+





	[super dealloc];
}

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

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

	return nil;
}

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

	position = 0;
}
@end