ObjFW  Check-in [3687c35784]

Overview
Comment:Make use of the fact that -[retain] and -[release] must not throw.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 3687c35784dc81f2c007c2a9d283d7e9e2a02c87e14ed35d458b052dcf1a520f
User & Date: js on 2011-09-10 23:54:57
Other Links: manifest | tags
Context
2011-09-11
00:03
Make use of the fact that -[retain] and -[release] must not throw. check-in: 74eeea199c user: js tags: trunk
2011-09-10
23:54
Make use of the fact that -[retain] and -[release] must not throw. check-in: 3687c35784 user: js tags: trunk
22:27
Add -[removeChild:] to OFXMLElement. check-in: 4369d4c8fb user: js tags: trunk
Changes

Modified src/OFDictionary_hashtable.m from [2751804ef6] to [8e095b45a0].

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
		for (i = 0; i < hashtable->size; i++)
			data[i] = NULL;

		size = hashtable->size;
		count = hashtable->count;

		for (i = 0; i < size; i++) {
			id key;
			struct of_dictionary_hashtable_bucket *bucket;

			if (hashtable->data[i] == NULL ||
			    hashtable->data[i] == DELETED)
				continue;

			bucket = [self allocMemoryWithSize: sizeof(*bucket)];
			key = (copyKeys
			    ? [hashtable->data[i]->key copy]
			    : [hashtable->data[i]->key retain]);

			@try {
				[hashtable->data[i]->object retain];
			} @catch (id e) {
				[key release];
				@throw e;
			}

			bucket->key = key;
			bucket->object = hashtable->data[i]->object;
			bucket->hash = hashtable->data[i]->hash;

			data[i] = bucket;
		}
	} @catch (id e) {
		[self release];
		@throw e;







<







|


<
<
|
<
<
<
<
<
<
<







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
		for (i = 0; i < hashtable->size; i++)
			data[i] = NULL;

		size = hashtable->size;
		count = hashtable->count;

		for (i = 0; i < size; i++) {

			struct of_dictionary_hashtable_bucket *bucket;

			if (hashtable->data[i] == NULL ||
			    hashtable->data[i] == DELETED)
				continue;

			bucket = [self allocMemoryWithSize: sizeof(*bucket)];
			bucket->key = (copyKeys
			    ? [hashtable->data[i]->key copy]
			    : [hashtable->data[i]->key retain]);


			bucket->object = [hashtable->data[i]->object retain];







			bucket->hash = hashtable->data[i]->hash;

			data[i] = bucket;
		}
	} @catch (id e) {
		[self release];
		@throw e;
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
			}

			if (data[i] != NULL)
				@throw [OFOutOfRangeException
				    newWithClass: isa];

			bucket = [self allocMemoryWithSize: sizeof(*bucket)];
			key = [key copy];

			@try {
				object = [dictionary objectForKey: key];
				[object retain];
			} @catch (id e) {
				[key release];
				@throw e;
			}

			bucket->key = key;
			bucket->object = object;
			bucket->hash = hash;

			data[i] = bucket;
		}

		[pool release];
	} @catch (id e) {







<

<
|
<
<
<
<
|
<
|
|







167
168
169
170
171
172
173

174

175




176

177
178
179
180
181
182
183
184
185
			}

			if (data[i] != NULL)
				@throw [OFOutOfRangeException
				    newWithClass: isa];

			bucket = [self allocMemoryWithSize: sizeof(*bucket)];



			object = [dictionary objectForKey: key];






			bucket->key = [key copy];
			bucket->object = [object retain];
			bucket->hash = hash;

			data[i] = bucket;
		}

		[pool release];
	} @catch (id e) {
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
					 withSize: sizeof(*data)];

		size = 2;
		for (i = 0; i < size; i++)
			data[i] = NULL;

		i = [key hash] & 1;
		bucket = [self allocMemoryWithSize: sizeof(*bucket)];
		key = [key copy];

		@try {
			[object retain];
		} @catch (id e) {
			[key release];
			@throw e;
		}

		bucket->key = key;
		bucket->object = object;
		bucket->hash = [key hash];

		data[i] = bucket;
		count = 1;
	} @catch (id e) {
		[self release];
		@throw e;







<
<

<
<
<
<
<
<
|
|
|







207
208
209
210
211
212
213


214






215
216
217
218
219
220
221
222
223
224
					 withSize: sizeof(*data)];

		size = 2;
		for (i = 0; i < size; i++)
			data[i] = NULL;

		i = [key hash] & 1;









		bucket = [self allocMemoryWithSize: sizeof(*bucket)];
		bucket->key = [key copy];
		bucket->object = [object retain];
		bucket->hash = [key hash];

		data[i] = bucket;
		count = 1;
	} @catch (id e) {
		[self release];
		@throw e;
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
					@throw [OFOutOfRangeException
					    newWithClass: isa];

				bucket =
				    [self allocMemoryWithSize: sizeof(*bucket)];
				key = [keysCArray[i] copy];

				@try {
					[objectsCArray[i] retain];
				} @catch (id e) {
					[key release];
					@throw e;
				}

				bucket->key = key;
				bucket->object = objectsCArray[i];
				bucket->hash = hash;

				data[j] = bucket;

				continue;
			}

			/*
			 * The key is already in the dictionary. However, we
			 * just replace it so that the programmer gets the same
			 * behavior as if he'd call setObject:forKey: for each
			 * key/object pair.
			 */
			[objectsCArray[i] retain];

			@try {
				[data[j]->object release];
			} @catch (id e) {
				[objectsCArray[i] release];
				@throw e;
			}

			data[j]->object = objectsCArray[i];
		}
	} @catch (id e) {
		[self release];
		@throw e;
	}








<
<
<
<
<
<
<

|














<
<
|
<
<
<
<
<







300
301
302
303
304
305
306







307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322


323





324
325
326
327
328
329
330
					@throw [OFOutOfRangeException
					    newWithClass: isa];

				bucket =
				    [self allocMemoryWithSize: sizeof(*bucket)];
				key = [keysCArray[i] copy];








				bucket->key = key;
				bucket->object = [objectsCArray[i] retain];
				bucket->hash = hash;

				data[j] = bucket;

				continue;
			}

			/*
			 * The key is already in the dictionary. However, we
			 * just replace it so that the programmer gets the same
			 * behavior as if he'd call setObject:forKey: for each
			 * key/object pair.
			 */
			[objectsCArray[i] retain];


			[data[j]->object release];





			data[j]->object = objectsCArray[i];
		}
	} @catch (id e) {
		[self release];
		@throw e;
	}

414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
		size = newSize;

		/* Add first key / object pair */
		hash = [key hash];
		j = hash & (size - 1);

		bucket = [self allocMemoryWithSize: sizeof(*bucket)];
		key = [key copy];

		@try {
			[object retain];
		} @catch (id e) {
			[key release];
			@throw e;
		}

		bucket->key = key;
		bucket->object = object;
		bucket->hash = hash;

		data[j] = bucket;

		for (i = 1; i < count; i++) {
			uint32_t last;








<
<
<
<
<
<
<
<
<
|
|







375
376
377
378
379
380
381









382
383
384
385
386
387
388
389
390
		size = newSize;

		/* Add first key / object pair */
		hash = [key hash];
		j = hash & (size - 1);

		bucket = [self allocMemoryWithSize: sizeof(*bucket)];









		bucket->key = [key copy];
		bucket->object = [object retain];
		bucket->hash = hash;

		data[j] = bucket;

		for (i = 1; i < count; i++) {
			uint32_t last;

479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525

				if (j >= last)
					@throw [OFOutOfRangeException
					    newWithClass: isa];

				bucket =
				    [self allocMemoryWithSize: sizeof(*bucket)];
				key = [key copy];

				@try {
					[object retain];
				} @catch (id e) {
					[key release];
					@throw e;
				}

				bucket->key = key;
				bucket->object = object;
				bucket->hash = hash;

				data[j] = bucket;

				continue;
			}

			/*
			 * The key is already in the dictionary. However, we
			 * just replace it so that the programmer gets the same
			 * behavior as if he'd call setObject:forKey: for each
			 * key/object pair.
			 */
			[object retain];

			@try {
				[data[j]->object release];
			} @catch (id e) {
				[object release];
				@throw e;
			}

			data[j]->object = object;
			count--;
		}
	} @catch (id e) {
		[self release];
		@throw e;
	}







<
<
<
<
<
<
<
<
<
|
|














<
<
|
<
<
<
<
<







431
432
433
434
435
436
437









438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453


454





455
456
457
458
459
460
461

				if (j >= last)
					@throw [OFOutOfRangeException
					    newWithClass: isa];

				bucket =
				    [self allocMemoryWithSize: sizeof(*bucket)];









				bucket->key = [key copy];
				bucket->object = [object retain];
				bucket->hash = hash;

				data[j] = bucket;

				continue;
			}

			/*
			 * The key is already in the dictionary. However, we
			 * just replace it so that the programmer gets the same
			 * behavior as if he'd call setObject:forKey: for each
			 * key/object pair.
			 */
			[object retain];


			[data[j]->object release];





			data[j]->object = object;
			count--;
		}
	} @catch (id e) {
		[self release];
		@throw e;
	}

Modified src/OFMutableDictionary_hashtable.m from [ba31392df4] to [7aba881118].

155
156
157
158
159
160
161

162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179

180
181
182
183
184
185
186
		}

		if (i >= last)
			@throw [OFOutOfRangeException newWithClass: isa];

		bucket = [self allocMemoryWithSize: sizeof(*bucket)];


		@try {
			key = (copyKey ? [key copy] : [key retain]);
		} @catch (id e) {
			[self freeMemory: bucket];
			@throw e;
		}

		@try {
			[object retain];
		} @catch (id e) {
			[self freeMemory: bucket];
			[key release];
			@throw e;
		}

		bucket->key = key;
		bucket->object = object;
		bucket->hash = hash;

		data[i] = bucket;
		count++;

		return;
	}

	old = data[i]->object;







>
|
|
|
|
|
|
|
<
|
<
<
<
<
|
<
<
|

>







155
156
157
158
159
160
161
162
163
164
165
166
167
168
169

170




171


172
173
174
175
176
177
178
179
180
181
		}

		if (i >= last)
			@throw [OFOutOfRangeException newWithClass: isa];

		bucket = [self allocMemoryWithSize: sizeof(*bucket)];

		if (copyKey) {
			@try {
				bucket->key = [key copy];
			} @catch (id e) {
				[self freeMemory: bucket];
				@throw e;
			}
		} else

			bucket->key = [key retain];







		bucket->object = [object retain];
		bucket->hash = hash;

		data[i] = bucket;
		count++;

		return;
	}

	old = data[i]->object;

Modified src/OFStreamSelectObserver.m from [c9a34f66b3] to [ed43022176].

39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
};

@implementation OFStreamSelectObserver
- init
{
	self = [super init];

	@try {
		FD_ZERO(&readFDs);
		FD_ZERO(&writeFDs);

		FD_SET(cancelFD[0], &readFDs);
		nFDs = cancelFD[0] + 1;
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (void)_addStream: (OFStream*)stream
	 withFDSet: (fd_set*)FDSet
{







<
|
|

|
|
<
<
<
<







39
40
41
42
43
44
45

46
47
48
49
50




51
52
53
54
55
56
57
};

@implementation OFStreamSelectObserver
- init
{
	self = [super init];


	FD_ZERO(&readFDs);
	FD_ZERO(&writeFDs);

	FD_SET(cancelFD[0], &readFDs);
	nFDs = cancelFD[0] + 1;





	return self;
}

- (void)_addStream: (OFStream*)stream
	 withFDSet: (fd_set*)FDSet
{

Modified src/OFThread.m from [28529a39cf] to [f4c5d36434].

257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
	of_thread_exit();
}

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

	@try {
		object = [object_ retain];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

#ifdef OF_HAVE_BLOCKS
- initWithBlock: (of_thread_block_t)block_
{
	return [self initWithBlock: block_
			    object: nil];
}

- initWithBlock: (of_thread_block_t)block_
	 object: (id)object_
{
	self = [super init];

	@try {
		block = [block_ retain];
		object = [object_ retain];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}
#endif

- (id)main
{







<
|
<
<
<
<
















<
|
|
<
<
<
<







257
258
259
260
261
262
263

264




265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280

281
282




283
284
285
286
287
288
289
	of_thread_exit();
}

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


	object = [object_ retain];





	return self;
}

#ifdef OF_HAVE_BLOCKS
- initWithBlock: (of_thread_block_t)block_
{
	return [self initWithBlock: block_
			    object: nil];
}

- initWithBlock: (of_thread_block_t)block_
	 object: (id)object_
{
	self = [super init];


	block = [block_ retain];
	object = [object_ retain];





	return self;
}
#endif

- (id)main
{

Modified src/OFXMLElement.m from [ddafe5133c] to [67c5a15992].

276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295

	if (![parser finishedParsing])
		@throw [OFMalformedXMLException newWithClass: c
						      parser: parser];

	self = [delegate->element retain];

	@try {
		[pool release];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- initWithFile: (OFString*)path
{
	OFAutoreleasePool *pool;







<
|
<
<
<
<







276
277
278
279
280
281
282

283




284
285
286
287
288
289
290

	if (![parser finishedParsing])
		@throw [OFMalformedXMLException newWithClass: c
						      parser: parser];

	self = [delegate->element retain];


	[pool release];





	return self;
}

- initWithFile: (OFString*)path
{
	OFAutoreleasePool *pool;
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334

	if (![parser finishedParsing])
		@throw [OFMalformedXMLException newWithClass: c
						      parser: parser];

	self = [delegate->element retain];

	@try {
		[pool release];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- initWithSerialization: (OFXMLElement*)element
{
	self = [super init];







<
|
<
<
<
<







310
311
312
313
314
315
316

317




318
319
320
321
322
323
324

	if (![parser finishedParsing])
		@throw [OFMalformedXMLException newWithClass: c
						      parser: parser];

	self = [delegate->element retain];


	[pool release];





	return self;
}

- initWithSerialization: (OFXMLElement*)element
{
	self = [super init];
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
{
	return [[attributes copy] autorelease];
}

- (void)setChildren: (OFArray*)children_
{
	OFMutableArray *new = [children_ mutableCopy];

	@try {
		[children release];
	} @catch (id e) {
		[new release];
		@throw e;
	}

	children = new;
}

- (OFArray*)children
{
	return [[children copy] autorelease];
}







<
<
|
<
<
<
<
<







413
414
415
416
417
418
419


420





421
422
423
424
425
426
427
{
	return [[attributes copy] autorelease];
}

- (void)setChildren: (OFArray*)children_
{
	OFMutableArray *new = [children_ mutableCopy];


	[children release];





	children = new;
}

- (OFArray*)children
{
	return [[children copy] autorelease];
}