ObjFW  Check-in [0d9f732af1]

Overview
Comment:Fix missing retain + autorelease on return.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 0d9f732af17b4991fe5901465d127e5d1709aae172a34ef812ae4e307f2e24e2
User & Date: js on 2010-01-03 17:28:29
Other Links: manifest | tags
Context
2010-01-03
17:36
OFMutableArray: Safer removing of objects. check-in: 0c9d2a8ce9 user: js tags: trunk
17:28
Fix missing retain + autorelease on return. check-in: 0d9f732af1 user: js tags: trunk
17:28
OFMutableArray: Fix out of range check for -[removeNItems:atIndex:]. check-in: 14fe09e7fa user: js tags: trunk
Changes

Modified src/OFArray.m from [1587b7303a] to [7844cdc05f].

165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
		[objs[i] retain];

	return new;
}

- (id)objectAtIndex: (size_t)index
{
	return *((OFObject**)[array itemAtIndex: index]);
}

- (size_t)indexOfObject: (OFObject*)obj
{
	id *objs = [array cArray];
	size_t i, count = [array count];








|







165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
		[objs[i] retain];

	return new;
}

- (id)objectAtIndex: (size_t)index
{
	return [[*((OFObject**)[array itemAtIndex: index]) retain] autorelease];
}

- (size_t)indexOfObject: (OFObject*)obj
{
	id *objs = [array cArray];
	size_t i, count = [array count];

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
	return SIZE_MAX;
}

- (id)firstObject
{
	id *first = [array firstItem];

	return (first != NULL ? *first : nil);
}

- (id)lastObject
{
	id *last = [array lastItem];

	return (last != NULL ? *last : nil);
}

- (OFString*)componentsJoinedByString: (OFString*)separator
{
	OFString *str;
	OFString **objs = [array cArray];
	size_t i, count = [array count];
	IMP append;

	if (count == 0)
		return [OFString string];

	str = [[OFMutableString alloc] init];
	@try {
		append = [str methodForSelector: @selector(appendString:)];

		for (i = 0; i < count - 1; i++) {
			append(str, @selector(appendString:), objs[i]);
			append(str, @selector(appendString:), separator);
		}
		append(str, @selector(appendString:), objs[i]);
	} @catch (OFException *e) {
		[str release];
		@throw e;
	}

	return [str autorelease];
}

- (BOOL)isEqual: (OFObject*)obj
{
	OFObject **objs, **objs2;
	size_t i, count, count2;








|






|










|

|
<
|

|
|
|
|
|
<
<
<
|
<
|







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
	return SIZE_MAX;
}

- (id)firstObject
{
	id *first = [array firstItem];

	return (first != NULL ? [[*first retain] autorelease] : nil);
}

- (id)lastObject
{
	id *last = [array lastItem];

	return (last != NULL ? [[*last retain] autorelease] : nil);
}

- (OFString*)componentsJoinedByString: (OFString*)separator
{
	OFString *str;
	OFString **objs = [array cArray];
	size_t i, count = [array count];
	IMP append;

	if (count == 0)
		return @"";

	str = [OFMutableString string];

	append = [str methodForSelector: @selector(appendString:)];

	for (i = 0; i < count - 1; i++) {
		append(str, @selector(appendString:), objs[i]);
		append(str, @selector(appendString:), separator);
	}
	append(str, @selector(appendString:), objs[i]);





	return str;
}

- (BOOL)isEqual: (OFObject*)obj
{
	OFObject **objs, **objs2;
	size_t i, count, count2;

Modified src/OFDictionary.m from [e62d24d536] to [c0653a92e6].

471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
		for (i = 0; i < size && data[i].key != nil &&
		    ![data[i].key isEqual: key]; i++);

	/* Key not in dictionary */
	if (i >= size || ![data[i].key isEqual: key])
		return nil;

	return data[i].object;
}

- (size_t)count
{
	return count;
}








|







471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
		for (i = 0; i < size && data[i].key != nil &&
		    ![data[i].key isEqual: key]; i++);

	/* Key not in dictionary */
	if (i >= size || ![data[i].key isEqual: key])
		return nil;

	return [[data[i].object retain] autorelease];
}

- (size_t)count
{
	return count;
}