ObjFW  Check-in [98f171212d]

Overview
Comment:Backport a few fixes from default branch to 0.1.

This includes the following revisions:
* f91d3a18db7b
* dbe7a578af42
* 95545a36ed0e
* 7806af1b171a
* cacc8353b5c2

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | 0.1
Files: files | file ages | folders
SHA3-256: 98f171212dd4ecf9a7fbcd405b93ac2459e3dc7145c71d9e38cdada6cf5dab40
User & Date: js on 2010-01-04 14:29:43
Other Links: branch diff | manifest | tags
Context
2010-01-04
14:36
Add ChangeLog. check-in: 292eaf1b86 user: js tags: 0.1, 0.1.1-release
14:29
Backport a few fixes from default branch to 0.1. check-in: 98f171212d user: js tags: 0.1
2009-12-24
09:19
Merge latest changes from default branch to 0.1 branch. check-in: 80820d91b3 user: js tags: 0.1, 0.1-release
Changes

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

165
166
167
168
169
170
171
172

173
174
175
176
177
178
179
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]);
	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
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 : nil);
	return (first != NULL ? [[*first retain] autorelease] : nil);
}

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

	return (last != NULL ? *last : nil);
	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 [OFString string];
		return @"";

	str = [[OFMutableString alloc] init];
	str = [OFMutableString string];
	@try {
		append = [str methodForSelector: @selector(appendString:)];
	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]);
	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];
	return str;
}

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

Modified src/OFDictionary.m from [67a9356465] to [7dfec004d5].

471
472
473
474
475
476
477
478

479
480
481
482
483
484
485
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;
	return [[data[i].object retain] autorelease];
}

- (size_t)count
{
	return count;
}

Modified src/OFMutableArray.m from [3bbaec8fd0] to [d5e78125eb].

1
2
3
4
5
6
7
8
9
10
11
12


13
14
15
16
17
18
19
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21












+
+







/*
 * Copyright (c) 2008 - 2009
 *   Jonathan Schleifer <js@webkeks.org>
 *
 * All rights reserved.
 *
 * This file is part of ObjFW. It may be distributed under the terms of the
 * Q Public License 1.0, which can be found in the file LICENSE included in
 * the packaging of this file.
 */

#include "config.h"

#include <string.h>

#import "OFMutableArray.h"
#import "OFExceptions.h"

@implementation OFMutableArray
- (id)copy
{
103
104
105
106
107
108
109
110

111

112
113
114
115
116
117
118
119
120
121
122
123
124
125
126

127
128
129
130
131
132
133
134
135
136
137
138
139
140
141

142
143
144
145
146
147
148



149

150







151
152
153
154
155
156
157
158

159
160
161

162
163
164
165



166

167
168








169
170
171
172
105
106
107
108
109
110
111

112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127

128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143

144
145
146
147
148
149


150
151
152
153
154

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
187
188
189
190
191







-
+

+













-

+














-
+





-
-
+
+
+

+
-
+
+
+
+
+
+
+







-
+


-
+


-
-
+
+
+

+
-
-
+
+
+
+
+
+
+
+




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

	for (i = 0; i < count; i++) {
		if ([objs[i] isEqual: obj]) {
			[objs[i] release];
			OFObject *obj = objs[i];
			[array removeItemAtIndex: i];
			[obj release];
		}
	}

	return self;
}

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

	for (i = 0; i < count; i++) {
		if (objs[i] == obj) {
			[obj release];
			[array removeItemAtIndex: i];
			[obj release];
		}
	}

	return self;
}

- removeObjectAtIndex: (size_t)index
{
	return [self removeNObjects: 1
			    atIndex: index];
}

- removeNObjects: (size_t)nobjects
{
	OFObject **objs = [array cArray];
	OFObject **objs = [array cArray], **copy;
	size_t i, count = [array count];

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

	for (i = count - nobjects; i < count; i++)
		[objs[i] release];
	copy = [self allocMemoryForNItems: nobjects
				 withSize: sizeof(OFObject*)];
	memcpy(copy, objs + (count - nobjects), nobjects * sizeof(OFObject*));

	@try {
	[array removeNItems: nobjects];
		[array removeNItems: nobjects];

		for (i = 0; i < nobjects; i++)
			[copy[i] release];
	} @finally {
		[self freeMemory: copy];
	}

	return self;
}

- removeNObjects: (size_t)nobjects
	 atIndex: (size_t)index
{
	OFObject **objs = [array cArray];
	OFObject **objs = [array cArray], **copy;
	size_t i, count = [array count];

	if (nobjects > count)
	if (nobjects > count - index)
		@throw [OFOutOfRangeException newWithClass: isa];

	for (i = index; i < count && i < index + nobjects; i++)
		[objs[i] release];
	copy = [self allocMemoryForNItems: nobjects
				 withSize: sizeof(OFObject*)];
	memcpy(copy, objs + index, nobjects * sizeof(OFObject*));

	@try {
	[array removeNItems: nobjects
		    atIndex: index];
		[array removeNItems: nobjects
			    atIndex: index];

		for (i = 0; i < nobjects; i++)
			[copy[i] release];
	} @finally {
		[self freeMemory: copy];
	}

	return self;
}
@end

Modified src/OFObject.m from [ff3d52f1b1] to [186b25418e].

552
553
554
555
556
557
558


559
560
552
553
554
555
556
557
558
559
560
561
562







+
+



+ (void)release
{
}

+ (void)dealloc
{
	@throw [OFNotImplementedException newWithClass: self
					      selector: _cmd];
}
@end

Modified src/OFStream.m from [dff3658c98] to [a1881748df].

9
10
11
12
13
14
15

16
17
18
19
20
21
22
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23







+







 * the packaging of this file.
 */

#include "config.h"

#include <string.h>
#include <unistd.h>
#include <assert.h>

#import "OFStream.h"
#import "OFExceptions.h"
#import "OFMacros.h"

#ifdef _WIN32
#include <windows.h>
133
134
135
136
137
138
139

140
141


142
143
144
145


146
147
148
149



150
151
152
153



154
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
187
188
189
190
191


192
193
194
195
196
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
134
135
136
137
138
139
140
141


142
143




144
145
146



147
148
149
150



151
152
153
154


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
187
188








189
190
191
192
193
194
195
196

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







+
-
-
+
+
-
-
-
-
+
+

-
-
-
+
+
+

-
-
-
+
+
+

-
-
+
+

-


-
-
-
-
+
-
-
-
-
-
+
+
+
+
+
-


-
-
-
-
-
-
-
+
+
+
+

-

+
+
+
+
+
+
+
+
+



-
-
-
-
-
-
+
+

-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
-

-
-
-
-
-
-
-
-
-
-
-
+
+
+

-
+
-


-
-
-
-
+
-
-
-
-
-
-
-
+
+
+
+
+
+

-
-
+
+
+
+
+
+
+
+







			}
		}
	}

	/* Read until we get a newline or \0 */
	tmp = [self allocMemoryWithSize: pagesize];

	@try {
	for (;;) {
		if ([self atEndOfStreamWithoutCache]) {
		for (;;) {
			if ([self atEndOfStreamWithoutCache]) {
			[self freeMemory: tmp];

			if (cache == NULL)
				return nil;
				if (cache == NULL)
					return nil;

			ret = [OFString stringWithCString: cache
						 encoding: encoding
						   length: cache_len];
				ret = [OFString stringWithCString: cache
							 encoding: encoding
							   length: cache_len];

			[self freeMemory: cache];
			cache = NULL;
			cache_len = 0;
				[self freeMemory: cache];
				cache = NULL;
				cache_len = 0;

			return ret;
		}
				return ret;
			}

		@try {
			len = [self readNBytesWithoutCache: pagesize
						intoBuffer: tmp];
		} @catch (OFException *e) {
			[self freeMemory: tmp];
			@throw e;
		}


		/* Look if there's a newline or \0 */
		for (i = 0; i < len; i++) {
			if (OF_UNLIKELY(tmp[i] == '\n' || tmp[i] == '\0')) {
				ret_len = cache_len + i;
			/* Look if there's a newline or \0 */
			for (i = 0; i < len; i++) {
				if (OF_UNLIKELY(tmp[i] == '\n' ||
				    tmp[i] == '\0')) {
					ret_len = cache_len + i;
				@try {
					ret_c = [self
					    allocMemoryWithSize: ret_len];
				} @catch (OFException *e) {
					[self freeMemory: tmp];
					@throw e;
				}
				if (cache != NULL)
					memcpy(ret_c, cache, cache_len);
				memcpy(ret_c + cache_len, tmp, i);

					if (cache != NULL)
						memcpy(ret_c, cache, cache_len);
					memcpy(ret_c + cache_len, tmp, i);

				if (i < len) {
					@try {
						ret = [OFString
						    stringWithCString: ret_c
							     encoding: encoding
							       length: ret_len];
					} @finally {
						[self freeMemory: ret_c];
					}

					if (i < len) {
						tmp2 = [self
						    allocMemoryWithSize: len -
									 i - 1];
					} @catch (OFException *e) {
						[self freeMemory: ret_c];
						[self freeMemory: tmp];
						@throw e;
					}
					memcpy(tmp2, tmp + i + 1, len - i - 1);
						memcpy(tmp2, tmp + i + 1,
						    len - i - 1);

					[self freeMemory: cache];
					cache = tmp2;
					cache_len = len - i - 1;
				} else {
					[self freeMemory: cache];
					cache = NULL;
					cache_len = 0;
				}
						[self freeMemory: cache];
						cache = tmp2;
						cache_len = len - i - 1;
					} else {
						[self freeMemory: cache];
						cache = NULL;
						cache_len = 0;
					}
				[self freeMemory: tmp];

				@try {
					ret = [OFString
					    stringWithCString: ret_c
						     encoding: encoding
						       length: ret_len];
				} @finally {
					[self freeMemory: ret_c];
				}
				return ret;
			}
		}
					return ret;
				}
			}

		/* There was no newline or \0 */
			/* There was no newline or \0 */
		@try {
			cache = [self resizeMemory: cache
					    toSize: cache_len + len];
		} @catch (OFException *e) {
			[self freeMemory: tmp];
			@throw e;
		}


		/*
		 * It's possible that cache_len + len is 0 and thus cache was
		 * set to NULL by resizeMemory:toSize:.
		 */
		if (cache != NULL)
			memcpy(cache + cache_len, tmp, len);
			/*
			 * It's possible that cache_len + len is 0 and thus
			 * cache was set to NULL by resizeMemory:toSize:.
			 */
			if (cache != NULL)
				memcpy(cache + cache_len, tmp, len);

		cache_len += len;
	}
			cache_len += len;
		}
	} @finally {
		[self freeMemory: tmp];
	}

	/* Get rid of a warning, never reached anyway */
	assert(0);
}

- (size_t)writeNBytes: (size_t)size
	   fromBuffer: (const char*)buf
{
	@throw [OFNotImplementedException newWithClass: isa
					      selector: _cmd];