ObjFW  Check-in [e2b06423e0]

Overview
Comment:Replace OFObject* with id in many places.

We assume now that every object understands retain, release, etc. so
that we can weaken the type from OFObject* to id. This makes it
possible to use different root object classes.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: e2b06423e04383ebc0c5cfe31afe47107923a8080f7ac58bcb166765dbb0e7c2
User & Date: js on 2010-09-05 23:19:08
Other Links: manifest | tags
Context
2010-09-05
23:23
Rename -[enumerator] to -[objectEnumerator] for consistency. check-in: ddb15601a2 user: js tags: trunk
23:19
Replace OFObject* with id in many places. check-in: e2b06423e0 user: js tags: trunk
15:10
ObjFW works on Win64 using MinGW64 now. check-in: 90e1488c24 user: js tags: trunk
Changes

Modified src/OFApplication.h from [8f191a6ed6] to [c960316ed3].

44
45
46
47
48
49
50
51

52
53
54
55
56
57
58

59
60
61
62
63
64
65
44
45
46
47
48
49
50

51
52
53
54
55
56
57

58
59
60
61
62
63
64
65







-
+






-
+







 * \brief Represents the application as an object.
 */
@interface OFApplication: OFObject
{
	OFString *programName;
	OFMutableArray *arguments;
	OFMutableDictionary *environment;
	OFObject <OFApplicationDelegate> *delegate;
	id <OFApplicationDelegate> delegate;
}

#ifdef OF_HAVE_PROPERTIES
@property (readonly, retain) OFString *programName;
@property (readonly, retain) OFArray *arguments;
@property (readonly, retain) OFDictionary *environment;
@property (retain) OFObject <OFApplicationDelegate> *delegate;
@property (retain) id <OFApplicationDelegate> delegate;
#endif

/**
 * \return The only OFApplication instance in the application
 */
+ sharedApplication;

115
116
117
118
119
120
121
122

123
124
125
126
127
128
129

130
131
132
133
134
135
136
115
116
117
118
119
120
121

122
123
124
125
126
127
128

129
130
131
132
133
134
135
136







-
+






-
+







 * \return The environment of the application
 */
- (OFDictionary*)environment;

/**
 * \return The delegate of the application
 */
- (OFObject <OFApplicationDelegate>*)delegate;
- (id <OFApplicationDelegate>)delegate;

/**
 * Sets the delegate of the application.
 *
 * \param delegate The delegate for the application
 */
- (void)setDelegate: (OFObject <OFApplicationDelegate>*)delegate;
- (void)setDelegate: (id <OFApplicationDelegate>)delegate;

/**
 * Starts the application after everything has been initialized.
 */
- (void)run;

/**

Modified src/OFApplication.m from [792653c017] to [4cc1491a54].

29
30
31
32
33
34
35
36

37
38
39
40
41
42
43
44
45

46
47
48
49
50
51
52
53
54
55
56

57
58
59
60
61
62
63
29
30
31
32
33
34
35

36
37
38
39
40
41
42
43
44

45
46
47
48
49
50
51
52
53
54
55

56
57
58
59
60
61
62
63







-
+








-
+










-
+







#endif

static OFApplication *app = nil;

static void
atexit_handler()
{
	id delegate = [app delegate];
	id <OFApplicationDelegate> delegate = [app delegate];

	[delegate applicationWillTerminate];
}

int
of_application_main(int argc, char *argv[], Class cls)
{
	OFApplication *app;
	OFObject <OFApplicationDelegate> *delegate = nil;
	id <OFApplicationDelegate> delegate = nil;

	if (cls != Nil)
		delegate = [[cls alloc] init];

	app = [OFApplication sharedApplication];

	[app setArgumentCount: argc
	    andArgumentValues: argv];

	[app setDelegate: delegate];
	[delegate release];
	[(id)delegate release];

	[app run];

	return 0;
}

@implementation OFApplication
164
165
166
167
168
169
170
171

172
173

174
175
176

177
178
179


180
181
182
183
184
185
186
164
165
166
167
168
169
170

171
172

173
174
175

176
177


178
179
180
181
182
183
184
185
186







-
+

-
+


-
+

-
-
+
+







}

- (OFDictionary*)environment
{
	return [[environment retain] autorelease];
}

- (OFObject <OFApplicationDelegate>*)delegate
- (id <OFApplicationDelegate>)delegate
{
	return [[delegate retain] autorelease];
	return [[(id)delegate retain] autorelease];
}

- (void)setDelegate: (OFObject <OFApplicationDelegate>*)delegate_
- (void)setDelegate: (id <OFApplicationDelegate>)delegate_
{
	[delegate_ retain];
	[delegate release];
	[(id)delegate_ retain];
	[(id)delegate release];
	delegate = delegate_;
}

- (void)run
{
	[delegate applicationDidFinishLaunching];
}
195
196
197
198
199
200
201
202

203
204
205
206
207
208
209
195
196
197
198
199
200
201

202
203
204
205
206
207
208
209







-
+







	exit(status);
}

- (void)dealloc
{
	[arguments release];
	[environment release];
	[delegate release];
	[(id)delegate release];

	[super dealloc];
}
@end

@implementation OFObject (OFApplicationDelegate)
- (void)applicationDidFinishLaunching

Modified src/OFArray.h from [695e6c2270] to [dc04fe21ab].

36
37
38
39
40
41
42
43

44
45
46
47
48
49
50
51

52
53
54
55
56
57
58
59

60
61
62
63
64
65
66
67
68
69

70
71
72
73
74
75
76
77
78

79
80
81
82
83
84
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
120
121
36
37
38
39
40
41
42

43
44
45
46
47
48
49
50

51
52
53
54
55
56
57
58

59
60
61
62
63
64
65
66
67
68

69
70
71
72
73
74
75
76
77

78
79
80
81
82
83
84
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
120
121







-
+







-
+







-
+









-
+








-
+







-
+








-
+








-
+









-
+








/**
 * Creates a new OFArray with the specified object.
 *
 * \param obj An object
 * \return A new autoreleased OFArray
 */
+ arrayWithObject: (OFObject*)obj;
+ arrayWithObject: (id)obj;

/**
 * Creates a new OFArray with the specified objects, terminated by nil.
 *
 * \param first The first object in the array
 * \return A new autoreleased OFArray
 */
+ arrayWithObjects: (OFObject*)first, ...;
+ arrayWithObjects: (id)first, ...;

/**
 * Creates a new OFArray with the objects from the specified C array.
 *
 * \param objs A C array of objects, terminated with nil
 * \return A new autoreleased OFArray
 */
+ arrayWithCArray: (OFObject**)objs;
+ arrayWithCArray: (id*)objs;

/**
 * Creates a new OFArray with the objects from the specified C array of the
 * specified length.
 *
 * \param objs A C array of objects
 * \param len The length of the C array
 * \return A new autoreleased OFArray
 */
+ arrayWithCArray: (OFObject**)objs
+ arrayWithCArray: (id*)objs
	   length: (size_t)length;

/**
 * Initializes an OFArray with the specified object.
 *
 * \param obj An object
 * \return An initialized OFArray
 */
- initWithObject: (OFObject*)obj;
- initWithObject: (id)obj;

/**
 * Initializes an OFArray with the specified objects.
 *
 * \param first The first object
 * \return An initialized OFArray
 */
- initWithObjects: (OFObject*)first, ...;
- initWithObjects: (id)first, ...;

/**
 * Initializes an OFArray with the specified object and a va_list.
 *
 * \param first The first object
 * \param args A va_list
 * \return An initialized OFArray
 */
- initWithObject: (OFObject*)first
- initWithObject: (id)first
	 argList: (va_list)args;

/**
 * Initializes an OFArray with the objects from the specified C array.
 *
 * \param objs A C array of objects, terminated with nil
 * \return An initialized OFArray
 */
- initWithCArray: (OFObject**)objs;
- initWithCArray: (id*)objs;

/**
 * Initializes an OFArray with the objects from the specified C array of the
 * specified length.
 *
 * \param objs A C array of objects
 * \param len The length of the C array
 * \return An initialized OFArray
 */
- initWithCArray: (OFObject**)objs
- initWithCArray: (id*)objs
	  length: (size_t)len;

/**
 * \return The number of objects in the array
 */
- (size_t)count;

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







-
+









-
+







/**
 * Returns the index of the first object that is equivalent to the specified
 * object.
 *
 * \param obj The object whose index is returned
 * \return The index of the first object equivalent to the specified object
 */
- (size_t)indexOfObject: (OFObject*)obj;
- (size_t)indexOfObject: (id)obj;

/**
 * Returns the index of the first object that has the same address as the
 * specified object.
 *
 * \param obj The object whose index is returned
 * \return The index of the first object that has the same aaddress as
 *	   the specified object
 */
- (size_t)indexOfObjectIdenticalTo: (OFObject*)obj;
- (size_t)indexOfObjectIdenticalTo: (id)obj;

/**
 * Returns the first object of the array or nil.
 *
 * The returned object is <i>not</i> retained and autoreleased for performance
 * reasons!
 *

Modified src/OFArray.m from [9bd99c7ed0] to [1e2bb24ba2].

21
22
23
24
25
26
27
28

29
30
31
32
33

34
35
36
37
38
39
40
41
42
43
44
45
46

47
48
49
50
51

52
53
54
55
56
57
58
59
60
61
62
63

64
65
66
67
68
69
70
71
72
73
74
75
76
77

78
79
80
81
82
83
84
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
120
121
122
123
124
125
126
127

128
129
130
131
132
133
134
21
22
23
24
25
26
27

28
29
30
31
32

33
34
35
36
37
38
39
40
41
42
43
44
45

46
47
48
49
50

51
52
53
54
55
56
57
58
59
60
61
62

63

64
65
66
67
68
69
70
71
72
73
74
75

76
77
78
79
80
81
82
83
84
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
120
121
122
123
124
125

126
127
128
129
130
131
132
133







-
+




-
+












-
+




-
+











-
+
-












-
+















-
+












-
+




















-
+








@implementation OFArray
+ array
{
	return [[[self alloc] init] autorelease];
}

+ arrayWithObject: (OFObject*)obj
+ arrayWithObject: (id)obj
{
	return [[[self alloc] initWithObject: obj] autorelease];
}

+ arrayWithObjects: (OFObject*)first, ...
+ arrayWithObjects: (id)first, ...
{
	id ret;
	va_list args;

	va_start(args, first);
	ret = [[[self alloc] initWithObject: first
				    argList: args] autorelease];
	va_end(args);

	return ret;
}

+ arrayWithCArray: (OFObject**)objs
+ arrayWithCArray: (id*)objs
{
	return [[[self alloc] initWithCArray: objs] autorelease];
}

+ arrayWithCArray: (OFObject**)objs
+ arrayWithCArray: (id*)objs
	   length: (size_t)len
{
	return [[[self alloc] initWithCArray: objs
				      length: len] autorelease];
}

- init
{
	self = [super init];

	@try {
		array = [[OFDataArray alloc]
		array = [[OFDataArray alloc] initWithItemSize: sizeof(id)];
		    initWithItemSize: sizeof(OFObject*)];
	} @catch (OFException *e) {
		/*
		 * We can't use [super dealloc] on OS X here. Compiler bug?
		 * [self dealloc] will do here as we check for nil in dealloc.
		 */
		[self dealloc];
		@throw e;
	}

	return self;
}

- initWithObject: (OFObject*)obj
- initWithObject: (id)obj
{
	self = [self init];

	@try {
		[array addItem: &obj];
	} @catch (OFException *e) {
		[self dealloc];
		@throw e;
	}

	[obj retain];

	return self;
}

- initWithObjects: (OFObject*)first, ...
- initWithObjects: (id)first, ...
{
	id ret;
	va_list args;

	va_start(args, first);
	ret = [self initWithObject: first
			   argList: args];
	va_end(args);

	return ret;
}

- initWithObject: (OFObject*)first
- initWithObject: (id)first
	 argList: (va_list)args
{
	id obj;

	self = [self init];

	@try {
		[array addItem: &first];
		while ((obj = va_arg(args, id)) != nil) {
			[array addItem: &obj];
			[obj retain];
		}
	} @catch (OFException *e) {
		[self dealloc];
		@throw e;
	}

	return self;
}

- initWithCArray: (OFObject**)objs
- initWithCArray: (id*)objs
{
	id *obj;
	size_t count;

	self = [self init];

	count = 0;
148
149
150
151
152
153
154
155

156
157
158
159
160
161
162
147
148
149
150
151
152
153

154
155
156
157
158
159
160
161







-
+







		[self dealloc];
		@throw e;
	}

	return self;
}

- initWithCArray: (OFObject**)objs
- initWithCArray: (id*)objs
	  length: (size_t)len
{
	size_t i;

	self = [self init];

	for (i = 0; i < len; i++)
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
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







-
+



















-
+














-
+







{
	return [self retain];
}

- mutableCopy
{
	OFArray *new = [[OFMutableArray alloc] init];
	OFObject **objs;
	id *objs;
	size_t count, i;

	objs = [array cArray];
	count = [array count];

	[new->array addNItems: count
		   fromCArray: objs];

	for (i = 0; i < count; i++)
		[objs[i] retain];

	return new;
}

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

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

	if (objs == NULL)
		return SIZE_MAX;

	for (i = 0; i < count; i++)
		if ([objs[i] isEqual: obj])
			return i;

	return SIZE_MAX;
}

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

	if (objs == NULL)
		return SIZE_MAX;

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







+








+



+
+
+
+








-
+

-
+







}

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

	if (count == 0)
		return @"";
	if (count == 1)
		return [objs[0] retain];

	str = [OFMutableString string];
	cls = [OFString class];
	append = [str methodForSelector: @selector(appendString:)];

	for (i = 0; i < count - 1; i++) {
		if (![objs[i] isKindOfClass: cls])
			@throw [OFInvalidArgumentException newWithClass: isa
							       selector: _cmd];

		append(str, @selector(appendString:), objs[i]);
		append(str, @selector(appendString:), separator);
	}
	append(str, @selector(appendString:), objs[i]);

	return str;
}

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

	if (![obj isKindOfClass: [OFArray class]])
		return NO;

	count = [array count];
	count2 = [(OFArray*)obj count];
304
305
306
307
308
309
310
311

312
313
314
315
316
317
318
309
310
311
312
313
314
315

316
317
318
319
320
321
322
323







-
+







			return NO;

	return YES;
}

- (uint32_t)hash
{
	OFObject **objs = [array cArray];
	id *objs = [array cArray];
	size_t i, count = [array count];
	uint32_t hash;

	OF_HASH_INIT(hash);

	for (i = 0; i < count; i++) {
		uint32_t h = [objs[i] hash];
350
351
352
353
354
355
356
357

358
359
360
361
362
363
364
365
366
367
368

369
370
371
372
373
374
375
355
356
357
358
359
360
361

362
363
364
365
366
367
368
369
370
371
372

373
374
375
376
377
378
379
380







-
+










-
+







	    initWithDataArray: array
	     mutationsPointer: NULL] autorelease];
}

#ifdef OF_HAVE_BLOCKS
- (void)enumerateObjectsUsingBlock: (of_array_enumeration_block_t)block
{
	OFObject **objs = [array cArray];
	id *objs = [array cArray];
	size_t i, count = [array count];
	BOOL stop = NO;

	for (i = 0; i < count && !stop; i++)
		block(objs[i], i, &stop);
}
#endif

- (void)dealloc
{
	OFObject **objs = [array cArray];
	id *objs = [array cArray];
	size_t i, count = [array count];

	for (i = 0; i < count; i++)
		[objs[i] release];

	[array release];

394
395
396
397
398
399
400
401

402
403
404
405
406
407
408
409
410
411
412
413
414
399
400
401
402
403
404
405

406
407
408
409
410
411
412
413
414
415
416
417
418
419







-
+














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

	if (pos < count)
		return *(OFObject**)[array itemAtIndex: pos++];
		return *(id*)[array itemAtIndex: pos++];

	return nil;
}

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

	pos = 0;
}
@end
/// \endcond

Modified src/OFAutoreleasePool.h from [20042a6dbe] to [219e7884ea].

28
29
30
31
32
33
34
35

36
37
38
39
40
41
42
43
44

45
46
47
48
49
50
51
28
29
30
31
32
33
34

35
36
37
38
39
40
41
42
43

44
45
46
47
48
49
50
51







-
+








-
+








/**
 * Adds an object to the autorelease pool at the top of the thread-specific
 * stack.
 *
 * \param obj The object to add to the autorelease pool
 */
+ (void)addObjectToTopmostPool: (OFObject*)obj;
+ (void)addObjectToTopmostPool: (id)obj;

+ (void)releaseAll;

/**
 * Adds an object to the specific autorelease pool.
 *
 * \param obj The object to add to the autorelease pool
 */
- (void)addObject: (OFObject*)obj;
- (void)addObject: (id)obj;

/**
 * Releases all objects in the autorelease pool.
 *
 * This does not free the memory allocated to store pointers to the objects in
 * the pool, so reusing the pool does not allocate any memory until the previous
 * number of objects is exceeded. It behaves this way to optimize loops that

Modified src/OFAutoreleasePool.m from [14bd700788] to [0e3d14e495].

35
36
37
38
39
40
41
42

43
44
45
46
47
48
49
35
36
37
38
39
40
41

42
43
44
45
46
47
48
49







-
+







		return;

	if (!of_tlskey_new(&first_key) || !of_tlskey_new(&last_key))
		@throw [OFInitializationFailedException newWithClass: self];
}
#endif

+ (void)addObjectToTopmostPool: (OFObject*)obj
+ (void)addObjectToTopmostPool: (id)obj
{
#ifdef OF_THREADS
	id last = of_tlskey_get(last_key);
#endif

	if (last == nil) {
		@try {
129
130
131
132
133
134
135
136

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

136
137
138
139
140
141
142
143







-
+







		[self dealloc];
		@throw e;
	}

	return self;
}

- (void)addObject: (OFObject*)obj
- (void)addObject: (id)obj
{
	if (count + 1 > size) {
		objects = [self resizeMemory: objects
				    toNItems: size + GROW_SIZE
				    withSize: sizeof(id)];
		size += GROW_SIZE;
	}

Modified src/OFDictionary.h from [49adfd1a99] to [63820ae3f4].

19
20
21
22
23
24
25
26
27


28
29
30
31
32
33
34
19
20
21
22
23
24
25


26
27
28
29
30
31
32
33
34







-
-
+
+







#ifdef OF_HAVE_BLOCKS
typedef void (^of_dictionary_enumeration_block_t)(id key, id obj, BOOL *stop);
#endif

/// \cond internal
struct of_dictionary_bucket
{
	OFObject <OFCopying> *key;
	OFObject *object;
	id <OFCopying> key;
	id object;
	uint32_t hash;
};
/// \endcond

/**
 * \brief A class for storing objects in a hash table.
 */
62
63
64
65
66
67
68
69
70


71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88

89
90
91
92
93
94
95
62
63
64
65
66
67
68


69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87

88
89
90
91
92
93
94
95







-
-
+
+

















-
+







/**
 * Creates a new OFDictionary with the specified key and object.
 *
 * \param key The key
 * \param obj The object
 * \return A new autoreleased OFDictionary
 */
+ dictionaryWithObject: (OFObject*)obj
		forKey: (OFObject <OFCopying>*)key;
+ dictionaryWithObject: (id)obj
		forKey: (id <OFCopying>)key;

/**
 * Creates a new OFDictionary with the specified keys and objects.
 *
 * \param keys An array of keys
 * \param objs An array of objects
 * \return A new autoreleased OFDictionary
 */
+ dictionaryWithObjects: (OFArray*)objs
		forKeys: (OFArray*)keys;

/**
 * Creates a new OFDictionary with the specified keys objects.
 *
 * \param key The first key
 * \return A new autoreleased OFDictionary
 */
+ dictionaryWithKeysAndObjects: (OFObject <OFCopying>*)key, ...;
+ dictionaryWithKeysAndObjects: (id <OFCopying>)key, ...;

/**
 * Initializes an already allocated OFDictionary.
 *
 * \return An initialized OFDictionary
 */
- init;
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
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







-
-
+
+



















-
+









-
+











-
+







 * Initializes an already allocated OFDictionary with the specified key and
 * object.
 *
 * \param key The key
 * \param obj The object
 * \return A new initialized OFDictionary
 */
- initWithObject: (OFObject*)obj
	  forKey: (OFObject <OFCopying>*)key;
- initWithObject: (id)obj
	  forKey: (id <OFCopying>)key;

/**
 * Initializes an already allocated OFDictionary with the specified keys and
 * objects.
 *
 * \param keys An array of keys
 * \param objs An array of objects
 * \return A new initialized OFDictionary
 */
- initWithObjects: (OFArray*)objs
	  forKeys: (OFArray*)keys;

/**
 * Initializes an already allocated OFDictionary with the specified keys and
 * objects.
 *
 * \param first The first key
 * \return A new initialized OFDictionary
 */
- initWithKeysAndObjects: (OFObject <OFCopying>*)first, ...;
- initWithKeysAndObjects: (id <OFCopying>)first, ...;

/**
 * Initializes an already allocated OFDictionary with the specified key and
 * va_list.
 *
 * \param first The first key
 * \param args A va_list of the other arguments
 * \return A new initialized OFDictionary
 */
- initWithKey: (OFObject <OFCopying>*)first
- initWithKey: (id <OFCopying>)first
      argList: (va_list)args;

/**
 * Returns the object for the given key or nil if the key was not found.
 *
 * The returned object is <i>not</i> retained and autoreleased for performance
 * reasons!
 *
 * \param key The key whose object should be returned
 * \return The object for the given key or nil if the key was not found
 */
- (id)objectForKey: (OFObject <OFCopying>*)key;
- (id)objectForKey: (id)key;

/**
 * \return The number of objects in the dictionary
 */
- (size_t)count;

/**

Modified src/OFDictionary.m from [bf50d5443a] to [f2f7830f20].

32
33
34
35
36
37
38
39
40


41
42
43
44
45
46
47
48
49
50
51
52
53

54
55
56
57
58
59
60
32
33
34
35
36
37
38


39
40
41
42
43
44
45
46
47
48
49
50
51
52

53
54
55
56
57
58
59
60







-
-
+
+












-
+







}

+ dictionaryWithDictionary: (OFDictionary*)dict
{
	return [[[self alloc] initWithDictionary: dict] autorelease];
}

+ dictionaryWithObject: (OFObject*)obj
		forKey: (OFObject <OFCopying>*)key
+ dictionaryWithObject: (id)obj
		forKey: (id <OFCopying>)key
{
	return [[[self alloc] initWithObject: obj
				      forKey: key] autorelease];
}

+ dictionaryWithObjects: (OFArray*)objs
		forKeys: (OFArray*)keys
{
	return [[[self alloc] initWithObjects: objs
				      forKeys: keys] autorelease];
}

+ dictionaryWithKeysAndObjects: (OFObject <OFCopying>*)first, ...
+ dictionaryWithKeysAndObjects: (id <OFCopying>)first, ...
{
	id ret;
	va_list args;

	va_start(args, first);
	ret = [[[self alloc] initWithKey: first
				 argList: args] autorelease];
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
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







-
+
















-
+













-
-
+
+







		@throw e;
	}

	size = dict->size;
	count = dict->count;

	for (i = 0; i < size; i++) {
		OFObject <OFCopying> *key;
		id <OFCopying> key;
		BUCKET *b;

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

		@try {
			b = [self allocMemoryWithSize: sizeof(BUCKET)];
			key = [dict->data[i]->key copy];
		} @catch (OFException *e) {
			[self dealloc];
			@throw e;
		}

		@try {
			[dict->data[i]->object retain];
		} @catch (OFException *e) {
			[key release];
			[(id)key release];
			[self dealloc];
			@throw e;
		}

		b->key = key;
		b->object = dict->data[i]->object;
		b->hash = dict->data[i]->hash;
		data[i] = b;
	}

	return self;
}

- initWithObject: (OFObject*)obj
	  forKey: (OFObject <OFCopying>*)key
- initWithObject: (id)obj
	  forKey: (id <OFCopying>)key
{
	uint32_t i;
	BUCKET *b;

	self = [self init];

	@try {
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
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







-
+












-
+






-
+







		 * Anyway, we didn't do anything yet anyway, so [self dealloc]
		 * works.
		 */
		[self dealloc];
		@throw e;
	}

	i = [key hash] & 1;
	i = [(id)key hash] & 1;

	@try {
		b = [self allocMemoryWithSize: sizeof(BUCKET)];
		key = [key copy];
	} @catch (OFException *e) {
		[self dealloc];
		@throw e;
	}

	@try {
		[obj retain];
	} @catch (OFException *e) {
		[key release];
		[(id)key release];
		[self dealloc];
		@throw e;
	}

	b->key = key;
	b->object = obj;
	b->hash = [key hash];
	b->hash = [(id)key hash];
	data[i] = b;
	count = 1;

	return self;
}

- initWithObjects: (OFArray*)objs
243
244
245
246
247
248
249
250

251
252
253
254
255
256
257
258

259
260
261
262
263
264

265
266

267
268
269
270
271
272
273
243
244
245
246
247
248
249

250
251
252
253
254
255
256
257

258
259
260
261
262
263

264
265

266
267
268
269
270
271
272
273







-
+







-
+





-
+

-
+







	for (i = 0; i < count; i++) {
		uint32_t j, hash, last;

		hash = [keys_carray[i] hash];
		last = size;

		for (j = hash & (size - 1); j < last && data[j] != NULL; j++)
			if ([data[j]->key isEqual: keys_carray[i]])
			if ([(id)data[j]->key isEqual: keys_carray[i]])
				break;

		/* In case the last bucket is already used */
		if (j >= last) {
			last = hash & (size - 1);

			for (j = 0; j < last && data[j] != NULL; j++)
				if ([data[j]->key isEqual: keys_carray[i]])
				if ([(id)data[j]->key isEqual: keys_carray[i]])
					break;
		}

		/* Key not in dictionary */
		if (j >= last || data[j] == NULL ||
		    ![data[j]->key isEqual: keys_carray[i]]) {
		    ![(id)data[j]->key isEqual: keys_carray[i]]) {
			BUCKET *b;
			OFObject <OFCopying> *key;
			id <OFCopying> key;

			last = size;

			j = hash & (size - 1);
			for (; j < last && data[j] != NULL; j++);

			/* In case the last bucket is already used */
290
291
292
293
294
295
296
297

298
299
300
301
302
303
304
290
291
292
293
294
295
296

297
298
299
300
301
302
303
304







-
+







				[self dealloc];
				@throw e;
			}

			@try {
				[objs_carray[i] retain];
			} @catch (OFException *e) {
				[key release];
				[(id)key release];
				[self dealloc];
				@throw e;
			}

			b->key = key;
			b->object = objs_carray[i];
			b->hash = hash;
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
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







-
+












-
+



-
+







-
+








		data[j]->object = objs_carray[i];
	}

	return self;
}

- initWithKeysAndObjects: (OFObject <OFCopying>*)first, ...
- initWithKeysAndObjects: (id <OFCopying>)first, ...
{
	id ret;
	va_list args;

	va_start(args, first);
	ret = [self initWithKey: first
			argList: args];
	va_end(args);

	return ret;
}

- initWithKey: (OFObject <OFCopying>*)key
- initWithKey: (id <OFCopying>)key
      argList: (va_list)args
{
	BUCKET *b;
	OFObject *obj;
	id obj;
	size_t i;
	uint32_t j, hash;
	va_list args2;

	self = [super init];

	count = 1;
	for (va_copy(args2, args); va_arg(args2, OFObject*) != nil; count++);
	for (va_copy(args2, args); va_arg(args2, id) != nil; count++);
	count >>= 1;

	if (count > UINT32_MAX) {
		Class c = isa;
		[self dealloc];
		@throw [OFOutOfRangeException newWithClass: c];
	}
395
396
397
398
399
400
401
402

403
404
405
406
407
408
409
410

411
412
413
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


439
440
441
442
443
444
445
446
447

448
449
450
451

452
453
454
455
456
457
458
459

460
461
462
463
464
465

466
467
468
469
470
471
472
395
396
397
398
399
400
401

402
403
404
405
406
407
408
409

410
411
412
413
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
439
440
441
442
443
444
445
446

447
448
449
450

451
452
453
454
455
456
457
458

459
460
461
462
463
464

465
466
467
468
469
470
471
472







-
+







-
+













-
+












-
-
+
+








-
+



-
+







-
+





-
+







		Class c = isa;
		size = 0;
		[self dealloc];
		@throw [OFInvalidArgumentException newWithClass: c
						       selector: _cmd];
	}

	if ((obj = va_arg(args, OFObject*)) == nil) {
	if ((obj = va_arg(args, id)) == nil) {
		Class c = isa;
		[self dealloc];
		@throw [OFInvalidArgumentException newWithClass: c
						       selector: _cmd];
	}

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

	@try {
		b = [self allocMemoryWithSize: sizeof(BUCKET)];
		key = [key copy];
	} @catch (OFException *e) {
		[self dealloc];
		@throw e;
	}

	@try {
		[obj retain];
	} @catch (OFException *e) {
		[key release];
		[(id)key release];
		[self dealloc];
		@throw e;
	}

	b->key = key;
	b->object = obj;
	b->hash = hash;
	data[j] = b;

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

		key = va_arg(args, OFObject <OFCopying>*);
		obj = va_arg(args, OFObject*);
		key = va_arg(args, id <OFCopying>);
		obj = va_arg(args, id);

		if (key == nil || obj == nil) {
			Class c = isa;
			[self dealloc];
			@throw [OFInvalidArgumentException newWithClass: c
							       selector: _cmd];
		}

		hash = [key hash];
		hash = [(id)key hash];
		last = size;

		for (j = hash & (size - 1); j < last && data[j] != NULL; j++)
			if ([data[j]->key isEqual: key])
			if ([(id)data[j]->key isEqual: key])
				break;

		/* In case the last bucket is already used */
		if (j >= last) {
			last = hash & (size - 1);

			for (j = 0; j < last && data[j] != NULL; j++)
				if ([data[j]->key isEqual: key])
				if ([(id)data[j]->key isEqual: key])
					break;
		}

		/* Key not in dictionary */
		if (j >= last || data[j] == NULL ||
		    ![data[j]->key isEqual: key]) {
		    ![(id)data[j]->key isEqual: key]) {
			last = size;

			j = hash & (size - 1);
			for (; j < last && data[j] != NULL; j++);

			/* In case the last bucket is already used */
			if (j >= last) {
488
489
490
491
492
493
494
495

496
497
498
499
500
501
502
488
489
490
491
492
493
494

495
496
497
498
499
500
501
502







-
+







				[self dealloc];
				@throw e;
			}

			@try {
				[obj retain];
			} @catch (OFException *e) {
				[key release];
				[(id)key release];
				[self dealloc];
				@throw e;
			}

			b->key = key;
			b->object = obj;
			b->hash = hash;
527
528
529
530
531
532
533
534

535
536
537
538
539
540
541
542
543
544
545
546
547
548
549

550
551
552
553
554
555
556
557
558
559
560
561
562
563

564
565
566
567
568
569
570
527
528
529
530
531
532
533

534
535
536
537
538
539
540
541
542
543
544
545
546
547
548

549
550
551
552
553
554
555
556
557
558
559
560
561
562

563
564
565
566
567
568
569
570







-
+














-
+













-
+








		data[j]->object = obj;
	}

	return self;
}

- (id)objectForKey: (OFObject <OFCopying>*)key
- (id)objectForKey: (id)key
{
	uint32_t i, hash, last;

	if (key == nil)
		@throw [OFInvalidArgumentException newWithClass: isa
						       selector: _cmd];

	hash = [key hash];
	last = size;

	for (i = hash & (size - 1); i < last && data[i] != NULL; i++) {
		if (data[i] == DELETED)
			continue;

		if ([data[i]->key isEqual: key])
		if ([(id)data[i]->key isEqual: key])
			return data[i]->object;
	}

	if (i < last)
		return nil;

	/* In case the last bucket is already used */
	last = hash & (size - 1);

	for (i = 0; i < last && data[i] != NULL; i++) {
		if (data[i] == DELETED)
			continue;

		if ([data[i]->key isEqual: key])
		if ([(id)data[i]->key isEqual: key])
			return data[i]->object;
	}

	return nil;
}

- (size_t)count
652
653
654
655
656
657
658
659

660
661
662
663
664
665
666
652
653
654
655
656
657
658

659
660
661
662
663
664
665
666







-
+








- (void)dealloc
{
	uint32_t i;

	for (i = 0; i < size; i++) {
		if (data[i] != NULL && data[i] != DELETED) {
			[data[i]->key release];
			[(id)data[i]->key release];
			[data[i]->object release];
		}
	}

	[super dealloc];
}

Modified src/OFList.h from [44738d18b3] to [12c31cb041].

61
62
63
64
65
66
67
68

69
70
71
72
73
74
75
76
77
78

79
80
81
82
83
84
85
86
87
88
89

90
91
92
93
94
95
96
97
98
99
100
101

102
103
104
105
106
107
108
61
62
63
64
65
66
67

68
69
70
71
72
73
74
75
76
77

78
79
80
81
82
83
84
85
86
87
88

89
90
91
92
93
94
95
96
97
98
99
100

101
102
103
104
105
106
107
108







-
+









-
+










-
+











-
+







 * Appends an object to the list.
 *
 * \param obj The object to append
 * \return An of_list_object_t, needed to identify the object inside the list.
 *	   For example, if you want to remove an object from the list, you need
 *	   its of_list_object_t.
 */
- (of_list_object_t*)appendObject: (OFObject*)obj;
- (of_list_object_t*)appendObject: (id)obj;

/**
 * Prepends an object to the list.
 *
 * \param obj The object to prepend
 * \return An of_list_object_t, needed to identify the object inside the list.
 *	   For example, if you want to remove an object from the list, you need
 *	   its of_list_object_t.
 */
- (of_list_object_t*)prependObject: (OFObject*)obj;
- (of_list_object_t*)prependObject: (id)obj;

/**
 * Inserts an object before another object.
 * \param obj The object to insert
 * \param listobj The of_list_object_t of the object before which it should be
 *	  inserted
 * \return An of_list_object_t, needed to identify the object inside the list.
 *	   For example, if you want to remove an object from the list, you need
 *	   its of_list_object_t.
 */
- (of_list_object_t*)insertObject: (OFObject*)obj
- (of_list_object_t*)insertObject: (id)obj
		 beforeListObject: (of_list_object_t*)listobj;

/**
 * Inserts an object after another object.
 * \param obj The object to insert
 * \param listobj The of_list_object_t of the object after which it should be
 *	  inserted
 * \return An of_list_object_t, needed to identify the object inside the list.
 *	   For example, if you want to remove an object from the list, you need
 *	   its of_list_object_t.
 */
- (of_list_object_t*)insertObject: (OFObject*)obj
- (of_list_object_t*)insertObject: (id)obj
		  afterListObject: (of_list_object_t*)listobj;

/**
 * Removes the object with the specified list object from the list.
 *
 * \param listobj The list object returned by append / prepend
 */

Modified src/OFList.m from [4b2ea9b8f4] to [156d215610].

49
50
51
52
53
54
55
56

57
58
59
60
61
62
63
49
50
51
52
53
54
55

56
57
58
59
60
61
62
63







-
+







}

- (of_list_object_t*)lastListObject;
{
	return lastListObject;
}

- (of_list_object_t*)appendObject: (OFObject*)obj
- (of_list_object_t*)appendObject: (id)obj
{
	of_list_object_t *o;

	o = [self allocMemoryWithSize: sizeof(of_list_object_t)];
	o->object = [obj retain];
	o->next = NULL;
	o->prev = lastListObject;
72
73
74
75
76
77
78
79

80
81
82
83
84
85
86
72
73
74
75
76
77
78

79
80
81
82
83
84
85
86







-
+







	count++;

	[obj retain];

	return o;
}

- (of_list_object_t*)prependObject: (OFObject*)obj
- (of_list_object_t*)prependObject: (id)obj
{
	of_list_object_t *o;

	o = [self allocMemoryWithSize: sizeof(of_list_object_t)];
	o->object = [obj retain];
	o->next = firstListObject;
	o->prev = NULL;
95
96
97
98
99
100
101
102

103
104
105
106
107
108
109
95
96
97
98
99
100
101

102
103
104
105
106
107
108
109







-
+







	count++;

	[obj retain];

	return o;
}

- (of_list_object_t*)insertObject: (OFObject*)obj
- (of_list_object_t*)insertObject: (id)obj
		 beforeListObject: (of_list_object_t*)listobj
{
	of_list_object_t *o;

	o = [self allocMemoryWithSize: sizeof(of_list_object_t)];
	o->object = [obj retain];
	o->next = listobj;
120
121
122
123
124
125
126
127

128
129
130
131
132
133
134
120
121
122
123
124
125
126

127
128
129
130
131
132
133
134







-
+







	count++;

	[obj retain];

	return o;
}

- (of_list_object_t*)insertObject: (OFObject*)obj
- (of_list_object_t*)insertObject: (id)obj
		  afterListObject: (of_list_object_t*)listobj
{
	of_list_object_t *o;

	o = [self allocMemoryWithSize: sizeof(of_list_object_t)];
	o->object = [obj retain];
	o->next = listobj->next;
169
170
171
172
173
174
175
176

177
178
179
180
181
182
183
169
170
171
172
173
174
175

176
177
178
179
180
181
182
183







-
+







}

- (size_t)count
{
	return count;
}

- (BOOL)isEqual: (OFObject*)obj
- (BOOL)isEqual: (id)obj
{
	of_list_object_t *iter, *iter2;

	if (![obj isKindOfClass: [OFList class]])
		return NO;

	if ([(OFList*)obj count] != count)

Modified src/OFMutableArray.h from [a6aa74e205] to [103c29de74].

24
25
26
27
28
29
30
31

32
33
34
35
36
37
38
39

40
41
42
43
44
45
46
47
48
49
50


51
52
53
54
55
56
57
58
59
60

61
62
63
64
65
66
67
68
69
70


71
72
73
74
75
76
77

78
79
80
81
82
83
84

85
86
87
88
89
90
91
24
25
26
27
28
29
30

31
32
33
34
35
36
37
38

39
40
41
42
43
44
45
46
47
48


49
50
51
52
53
54
55
56
57
58
59

60
61
62
63
64
65
66
67
68


69
70
71
72
73
74
75
76

77
78
79
80
81
82
83

84
85
86
87
88
89
90
91







-
+







-
+









-
-
+
+









-
+








-
-
+
+






-
+






-
+







}

/**
 * Adds an object to the OFArray.
 *
 * \param obj An object to add
 */
- (void)addObject: (OFObject*)obj;
- (void)addObject: (id)obj;

/**
 * Adds an object to the OFArray at the specified index.
 *
 * \param obj An object to add
 * \param index The index where the object should be added
 */
- (void)addObject: (OFObject*)obj
- (void)addObject: (id)obj
	  atIndex: (size_t)index;

/**
 * Replaces all objects equivalent to the first specified object with the
 * second specified object.
 *
 * \param old The object to replace
 * \param new The replacement object
 */
- (void)replaceObject: (OFObject*)old
	   withObject: (OFObject*)new;
- (void)replaceObject: (id)old
	   withObject: (id)new;

/**
 * Replaces the object at the specified index with the specified object.
 *
 * \param index The index of the object to replace
 * \param obj The replacement object
 * \return The old object, autoreleased
 */
- (id)replaceObjectAtIndex: (size_t)index
		withObject: (OFObject*)obj;
		withObject: (id)obj;

/**
 * Replaces all objects that have the same address as the first specified object
 * with the second specified object.
 *
 * \param old The object to replace
 * \param new The replacement object
 */
- (void)replaceObjectIdenticalTo: (OFObject*)old
		      withObject: (OFObject*)new;
- (void)replaceObjectIdenticalTo: (id)old
		      withObject: (id)new;

/**
 * Removes all objects equivalent to the specified object.
 *
 * \param obj The object to remove
 */
- (void)removeObject: (OFObject*)obj;
- (void)removeObject: (id)obj;

/**
 * Removes all objects that have the same address as the specified object.
 *
 * \param obj The object to remove
 */
- (void)removeObjectIdenticalTo: (OFObject*)obj;
- (void)removeObjectIdenticalTo: (id)obj;

/**
 * Removes the object at the specified index.
 *
 * \param index The index of the object to remove
 * \return The object that was at the index, autoreleased
 */

Modified src/OFMutableArray.m from [fc5290b53c] to [6ea5171a82].

17
18
19
20
21
22
23
24

25
26
27
28
29
30
31
32
33
34
35
36
37
38
39

40
41
42
43
44
45
46
47

48
49
50
51
52
53
54
55
56
57
58


59
60

61
62
63
64
65
66
67
68
69
70
71
72
73

74
75

76
77
78
79
80
81
82
83
84
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
17
18
19
20
21
22
23

24
25
26
27
28
29
30
31
32
33
34
35
36
37
38

39
40
41
42
43
44
45
46

47
48
49
50
51
52
53
54
55
56


57
58
59

60
61
62
63
64
65
66
67
68
69
70
71
72

73
74

75
76
77
78
79
80
81
82
83
84
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







-
+














-
+







-
+









-
-
+
+

-
+












-
+

-
+











-
-
+
+

-
+











-
+

-
+




-
+







#import "OFDataArray.h"
#import "OFExceptions.h"

@implementation OFMutableArray
- copy
{
	OFArray *new = [[OFArray alloc] init];
	OFObject **objs;
	id *objs;
	size_t count, i;

	objs = [array cArray];
	count = [array count];

	[new->array addNItems: count
		   fromCArray: objs];

	for (i = 0; i < count; i++)
		[objs[i] retain];

	return new;
}

- (void)addObject: (OFObject*)obj
- (void)addObject: (id)obj
{
	[array addItem: &obj];
	[obj retain];

	mutations++;
}

- (void)addObject: (OFObject*)obj
- (void)addObject: (id)obj
	  atIndex: (size_t)index
{
	[array addItem: &obj
	       atIndex: index];
	[obj retain];

	mutations++;
}

- (void)replaceObject: (OFObject*)old
	   withObject: (OFObject*)new
- (void)replaceObject: (id)old
	   withObject: (id)new
{
	OFObject **objs = [array cArray];
	id *objs = [array cArray];
	size_t i, count = [array count];

	for (i = 0; i < count; i++) {
		if ([objs[i] isEqual: old]) {
			[new retain];
			[objs[i] release];
			objs[i] = new;
		}
	}
}

- (id)replaceObjectAtIndex: (size_t)index
		withObject: (OFObject*)obj
		withObject: (id)obj
{
	OFObject **objs = [array cArray];
	id *objs = [array cArray];
	id old;

	if (index >= [array count])
		@throw [OFOutOfRangeException newWithClass: isa];

	old = objs[index];
	objs[index] = [obj retain];

	return [old autorelease];
}

- (void)replaceObjectIdenticalTo: (OFObject*)old
		      withObject: (OFObject*)new
- (void)replaceObjectIdenticalTo: (id)old
		      withObject: (id)new
{
	OFObject **objs = [array cArray];
	id *objs = [array cArray];
	size_t i, count = [array count];

	for (i = 0; i < count; i++) {
		if (objs[i] == old) {
			[new retain];
			[objs[i] release];
			objs[i] = new;
		}
	}
}

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

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

			[array removeItemAtIndex: i];
			mutations++;

			[obj release];

			/*
124
125
126
127
128
129
130
131

132
133

134
135
136
137
138
139
140
124
125
126
127
128
129
130

131
132

133
134
135
136
137
138
139
140







-
+

-
+







			objs = [array cArray];
			count--;
			i--;
		}
	}
}

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

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

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







-
+






-
-
+
+















-
+






-
-
+
+







		     atIndex: index];

	return old;
}

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

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

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

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

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

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

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

	copy = [self allocMemoryForNItems: nobjects
				 withSize: sizeof(OFObject*)];
	memcpy(copy, objs + index, nobjects * sizeof(OFObject*));
				 withSize: sizeof(id)];
	memcpy(copy, objs + index, nobjects * sizeof(id));

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

		for (i = 0; i < nobjects; i++)
235
236
237
238
239
240
241
242

243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258

259
260
261
262
263
264
265
235
236
237
238
239
240
241

242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257

258
259
260
261
262
263
264
265







-
+















-
+







	    initWithDataArray: array
	     mutationsPointer: &mutations] autorelease];
}

#ifdef OF_HAVE_BLOCKS
- (void)enumerateObjectsUsingBlock: (of_array_enumeration_block_t)block
{
	OFObject **objs = [array cArray];
	id *objs = [array cArray];
	size_t i, count = [array count];
	BOOL stop = NO;
	unsigned long mutations2 = mutations;

	for (i = 0; i < count && !stop; i++) {
		if (mutations != mutations2)
			@throw [OFEnumerationMutationException
			    newWithClass: isa];

		block(objs[i], i, &stop);
	}
}

- (void)replaceObjectsUsingBlock: (of_array_replace_block_t)block
{
	OFObject **objs = [array cArray];
	id *objs = [array cArray];
	size_t i, count = [array count];
	BOOL stop = NO;
	unsigned long mutations2 = mutations;

	for (i = 0; i < count && !stop; i++) {
		if (mutations != mutations2)
			@throw [OFEnumerationMutationException

Modified src/OFMutableDictionary.h from [8e6d4d0e2c] to [fdc610a5c4].

26
27
28
29
30
31
32
33
34


35
36
37
38
39
40
41

42
43
44
45
46
47
48
49
50
51
26
27
28
29
30
31
32


33
34
35
36
37
38
39
40

41
42
43
44
45
46
47
48
49
50
51







-
-
+
+






-
+










/**
 * Sets an object for a key.
 * A key can be any object.
 *
 * \param key The key to set
 * \param obj The object to set the key to
 */
- (void)setObject: (OFObject*)obj
	   forKey: (OFObject <OFCopying>*)key;
- (void)setObject: (id)obj
	   forKey: (id <OFCopying>)key;

/**
 * Remove the object with the given key from the dictionary.
 *
 * \param key The key whose object should be removed
 */
- (void)removeObjectForKey: (OFObject*)key;
- (void)removeObjectForKey: (id)key;

#ifdef OF_HAVE_BLOCKS
/**
 * Replaces each object with the object returned by the block.
 *
 * \param block The block which returns a new object for each object
 */
- (void)replaceObjectsUsingBlock: (of_dictionary_replace_block_t)block;
#endif
@end

Modified src/OFMutableDictionary.m from [9fd6867bb8] to [078edcac44].

75
76
77
78
79
80
81
82
83


84
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
120
121
122
123
124
125
75
76
77
78
79
80
81


82
83
84
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
120
121
122
123
124
125







-
-
+
+








-
+






-
+











-
+






-
+







	}

	[self freeMemory: data];
	data = newdata;
	size = newsize;
}

- (void)setObject: (OFObject*)obj
	   forKey: (OFObject <OFCopying>*)key
- (void)setObject: (id)obj
	   forKey: (id <OFCopying>)key
{
	uint32_t i, hash, last;
	id old;

	if (key == nil || obj == nil)
		@throw [OFInvalidArgumentException newWithClass: isa
						       selector: _cmd];

	hash = [key hash];
	hash = [(id)key hash];
	last = size;

	for (i = hash & (size - 1); i < last && data[i] != NULL; i++) {
		if (data[i] == DELETED)
			continue;

		if ([data[i]->key isEqual: key])
		if ([(id)data[i]->key isEqual: key])
			break;
	}

	/* In case the last bucket is already used */
	if (i >= last) {
		last = hash & (size - 1);

		for (i = 0; i < last && data[i] != NULL; i++) {
			if (data[i] == DELETED)
				continue;

			if ([data[i]->key isEqual: key])
			if ([(id)data[i]->key isEqual: key])
				break;
		}
	}

	/* Key not in dictionary */
	if (i >= last || data[i] == NULL || data[i] == DELETED ||
	    ![data[i]->key isEqual: key]) {
	    ![(id)data[i]->key isEqual: key]) {
		BUCKET *b;

		[self _resizeForCount: count + 1];

		mutations++;
		last = size;

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







-
+

















-
+














-
-
+
+







			[self freeMemory: b];
		}

		@try {
			[obj retain];
		} @catch (OFException *e) {
			[self freeMemory: b];
			[key release];
			[(id)key release];
			@throw e;
		}

		b->key = key;
		b->object = obj;
		b->hash = hash;
		data[i] = b;
		count++;

		return;
	}

	old = data[i]->object;
	data[i]->object = [obj retain];
	[old release];
}

- (void)removeObjectForKey: (OFObject*)key
- (void)removeObjectForKey: (id)key
{
	uint32_t i, hash, last;

	if (key == nil)
		@throw [OFInvalidArgumentException newWithClass: isa
						       selector: _cmd];

	hash = [key hash];
	last = size;

	for (i = hash & (size - 1); i < last && data[i] != NULL; i++) {
		if (data[i] == DELETED)
			continue;

		if ([data[i]->key isEqual: key]) {
			[data[i]->key release];
		if ([(id)data[i]->key isEqual: key]) {
			[(id)data[i]->key release];
			[data[i]->object release];
			[self freeMemory: data[i]];
			data[i] = DELETED;

			count--;
			mutations++;
			[self _resizeForCount: count];
202
203
204
205
206
207
208
209
210


211
212
213
214
215
216
217
202
203
204
205
206
207
208


209
210
211
212
213
214
215
216
217







-
-
+
+







	/* In case the last bucket is already used */
	last = hash & (size - 1);

	for (i = 0; i < last && data[i] != NULL; i++) {
		if (data[i] == DELETED)
			continue;

		if ([data[i]->key isEqual: key]) {
			[data[i]->key release];
		if ([(id)data[i]->key isEqual: key]) {
			[(id)data[i]->key release];
			[data[i]->object release];
			[self freeMemory: data[i]];
			data[i] = DELETED;

			count--;
			mutations++;
			[self _resizeForCount: count];

Modified src/OFObject.h from [edc7438bce] to [acfaa1e5ed].

214
215
216
217
218
219
220
221

222
223
224
225
226
227
228
214
215
216
217
218
219
220

221
222
223
224
225
226
227
228







-
+







 *
 * Classes containing data (like strings, arrays, lists etc.) should reimplement
 * this!
 *
 * \param obj The object which should be tested for equality
 * \return A boolean whether the object is equal to the specified object
 */
- (BOOL)isEqual: (OFObject*)obj;
- (BOOL)isEqual: (id)obj;

/**
 * Calculates a hash for the object.
 *
 * Classes containing data (like strings, arrays, lists etc.) should reimplement
 * this!
 *

Modified src/OFObject.m from [f4894aef60] to [45b7441d77].

399
400
401
402
403
404
405
406

407
408
409
410
411
412
413
399
400
401
402
403
404
405

406
407
408
409
410
411
412
413







-
+







#ifdef OF_APPLE_RUNTIME
	return class_getMethodImplementation(isa, selector);
#else
	return objc_msg_lookup(self, selector);
#endif
}

- (BOOL)isEqual: (OFObject*)obj
- (BOOL)isEqual: (id)obj
{
	/* Classes containing data should reimplement this! */
	return (self == obj ? YES : NO);
}

- (uint32_t)hash
{

Modified src/OFStreamObserver.h from [31983ae5e4] to [943d945622].

50
51
52
53
54
55
56
57

58
59
60
61
62
63
64
65
66
67
68
69

70
71
72
73
74
75
76
77
78
79
80

81
82
83
84
85
86
87

88
89
90
91
92
93
94
50
51
52
53
54
55
56

57
58
59
60
61
62
63
64
65
66
67
68

69
70
71
72
73
74
75
76
77
78
79

80
81
82
83
84
85
86

87
88
89
90
91
92
93
94







-
+











-
+










-
+






-
+







@end

/**
 * \brief A class that can observe multiple streams at once.
 */
@interface OFStreamObserver: OFObject
{
	OFObject <OFStreamObserverDelegate> *delegate;
	id <OFStreamObserverDelegate> delegate;
#ifdef OF_HAVE_POLL
	OFDataArray *fds;
#else
	fd_set readfds;
	fd_set writefds;
	int nfds;
#endif
	OFMutableDictionary *fdToStream;
}

#ifdef OF_HAVE_PROPERTIES
@property (retain) OFObject <OFStreamObserverDelegate> *delegate;
@property (retain) id <OFStreamObserverDelegate> delegate;
#endif

/**
 * \return A new, autoreleased OFStreamObserver
 */
+ streamObserver;

/**
 * \return The delegate for the OFStreamObserver
 */
- (OFObject <OFStreamObserverDelegate>*)delegate;
- (id <OFStreamObserverDelegate>)delegate;

/**
 * Sets the delegate for the OFStreamObserver.
 *
 * \param delegate The delegate for the OFStreamObserver
 */
- (void)setDelegate: (OFObject <OFStreamObserverDelegate>*)delegate;
- (void)setDelegate: (id <OFStreamObserverDelegate>)delegate;

/**
 * Adds a stream to observe for reading.
 *
 * \param stream The stream to observe for reading
 */
- (void)addStreamToObserveForReading: (OFStream*)stream;

Modified src/OFStreamObserver.m from [282f7af8d3] to [7ad4630322].

44
45
46
47
48
49
50
51

52
53
54
55
56
57
58
59
60

61
62

63
64
65

66
67
68


69
70
71
72
73
74
75
44
45
46
47
48
49
50

51
52
53
54
55
56
57
58
59

60
61

62
63
64

65
66


67
68
69
70
71
72
73
74
75







-
+








-
+

-
+


-
+

-
-
+
+







	fdToStream = [[OFMutableDictionary alloc] init];

	return self;
}

- (void)dealloc
{
	[delegate release];
	[(id)delegate release];
#ifdef OF_HAVE_POLL
	[fds release];
#endif
	[fdToStream release];

	[super dealloc];
}

- (OFObject <OFStreamObserverDelegate>*)delegate
- (id <OFStreamObserverDelegate>)delegate
{
	return [[delegate retain] autorelease];
	return [[(id)delegate retain] autorelease];
}

- (void)setDelegate: (OFObject <OFStreamObserverDelegate>*)delegate_
- (void)setDelegate: (id <OFStreamObserverDelegate>)delegate_
{
	[delegate_ retain];
	[delegate release];
	[(id)delegate_ retain];
	[(id)delegate release];
	delegate = delegate_;
}

#ifdef OF_HAVE_POLL
- (void)_addStream: (OFStream*)stream
	withEvents: (short)events
{

Modified src/OFString+XMLUnescaping.h from [ddb946d7cf] to [1fcc11b4c5].

43
44
45
46
47
48
49
50

51
43
44
45
46
47
48
49

50
51







-
+

/**
 * Unescapes XML in the string and uses the specified handler for unknown
 * entities.
 *
 * \param h An OFXMLUnescapingDelegate as a handler for unknown entities
 */
- (OFString*)stringByXMLUnescapingWithDelegate:
    (OFObject <OFStringXMLUnescapingDelegate>*)delegate;
    (id <OFStringXMLUnescapingDelegate>)delegate;
@end

Modified src/OFString+XMLUnescaping.m from [79011c0f14] to [be2a2ed79d].

71
72
73
74
75
76
77
78

79
80
81
82
83
84
85
71
72
73
74
75
76
77

78
79
80
81
82
83
84
85







-
+







@implementation OFString (XMLUnescaping)
- (OFString*)stringByXMLUnescaping
{
	return [self stringByXMLUnescapingWithDelegate: nil];
}

- (OFString*)stringByXMLUnescapingWithDelegate:
    (OFObject <OFStringXMLUnescapingDelegate>*)delegate
    (id <OFStringXMLUnescapingDelegate>)delegate
{
	size_t i, last;
	BOOL in_entity;
	OFMutableString *ret;

	last = 0;
	in_entity = NO;

Modified src/OFThread.h from [5849ea0fbe] to [cc3937ad7a].

83
84
85
86
87
88
89
90

91
92
93
94
95
96
97
83
84
85
86
87
88
89

90
91
92
93
94
95
96
97







-
+







 * released. You can specify nil as object if you want the old object to be
 * released and don't want any new object for the TLS key.
 *
 * \param key The Thread Local Storage key
 * \param obj The object the Thread Local Storage key will be set to
 * \return The old object, autoreleased
 */
+ (id)setObject: (OFObject*)obj
+ (id)setObject: (id)obj
      forTLSKey: (OFTLSKey*)key;

/**
 * Returns the object for the specified Thread Local Storage key.
 *
 * The returned object is <i>not</i> retained and autoreleased for performance
 * reasons!

Modified src/OFThread.m from [1dfee35b1d] to [4035170a3e].

64
65
66
67
68
69
70
71

72
73
74
75
76
77
78
64
65
66
67
68
69
70

71
72
73
74
75
76
77
78







-
+







}

+ threadWithObject: (id)obj
{
	return [[[self alloc] initWithObject: obj] autorelease];
}

+ (id)setObject: (OFObject*)obj
+ (id)setObject: (id)obj
      forTLSKey: (OFTLSKey*)key
{
	id old = of_tlskey_get(key->key);

	if (!of_tlskey_set(key->key, [obj retain]))
		@throw [OFInvalidArgumentException newWithClass: self
						       selector: _cmd];

Modified src/OFXMLElementBuilder.h from [d870539158] to [3c0e04c5a7].

41
42
43
44
45
46
47
48

49
50
51
52

53
54
55
56
57
58
59
60
61
62
63

64
65
66
67
68
69
70

71
41
42
43
44
45
46
47

48
49
50
51

52
53
54
55
56
57
58
59
60
61
62

63
64
65
66
67
68
69

70
71







-
+



-
+










-
+






-
+

 * It can also be used to build OFXMLElements from parts of the document by
 * first parsing stuff using the OFXMLParser with another delegate and then
 * setting the OFXMLElementBuilder as delegate for the parser.
 */
@interface OFXMLElementBuilder: OFObject
{
	OFMutableArray *stack;
	OFObject <OFXMLElementBuilderDelegate> *delegate;
	id <OFXMLElementBuilderDelegate> delegate;
}

#ifdef OF_HAVE_PROPERTIES
@property (retain) OFObject <OFXMLElementBuilderDelegate> *delegate;
@property (retain) id <OFXMLElementBuilderDelegate> delegate;
#endif

/**
 * \return A new, autoreleased OFXMLElementBuilder
 */
+ elementBuilder;

/**
 * \return The delegate for the OFXMLElementBuilder
 */
- (OFObject <OFXMLElementBuilderDelegate>*)delegate;
- (id <OFXMLElementBuilderDelegate>)delegate;

/**
 * Sets the delegate for the OFXMLElementBuilder.
 *
 * \param delegate The delegate for the OFXMLElementBuilder
 */
- (void)setDelegate: (OFObject <OFXMLElementBuilderDelegate>*)delegate;
- (void)setDelegate: (id <OFXMLElementBuilderDelegate>)delegate;
@end

Modified src/OFXMLElementBuilder.m from [eae2627930] to [59069a8174].

31
32
33
34
35
36
37
38

39
40
41
42
43

44
45

46
47
48

49
50
51


52
53
54
55
56
57
58
31
32
33
34
35
36
37

38
39
40
41
42

43
44

45
46
47

48
49


50
51
52
53
54
55
56
57
58







-
+




-
+

-
+


-
+

-
-
+
+








	return self;
}

- (void)dealloc
{
	[stack release];
	[delegate release];
	[(id)delegate release];

	[super dealloc];
}

- (OFObject <OFXMLElementBuilderDelegate>*)delegate
- (id <OFXMLElementBuilderDelegate>)delegate
{
	return [[delegate retain] autorelease];
	return [[(id)delegate retain] autorelease];
}

- (void)setDelegate: (OFObject <OFXMLElementBuilderDelegate>*)delegate_
- (void)setDelegate: (id <OFXMLElementBuilderDelegate>)delegate_
{
	[delegate_ retain];
	[delegate release];
	[(id)delegate_ retain];
	[(id)delegate release];
	delegate = delegate_;
}

-    (void)parser: (OFXMLParser*)parser
  didStartElement: (OFString*)name
       withPrefix: (OFString*)prefix
	namespace: (OFString*)ns

Modified src/OFXMLParser.h from [bbfb693f5f] to [1fa95b39f4].

97
98
99
100
101
102
103
104

105
106
107
108
109
110
111
97
98
99
100
101
102
103

104
105
106
107
108
109
110
111







-
+







 * \brief An event-based XML parser.
 *
 * OFXMLParser is an event-based XML parser which calls the delegate's callbacks
 * as soon asit finds something, thus suitable for streams as well.
 */
@interface OFXMLParser: OFObject <OFStringXMLUnescapingDelegate>
{
	OFObject <OFXMLParserDelegate> *delegate;
	id <OFXMLParserDelegate> delegate;
	enum {
		OF_XMLPARSER_OUTSIDE_TAG,
		OF_XMLPARSER_TAG_OPENED,
		OF_XMLPARSER_IN_PROLOG,
		OF_XMLPARSER_IN_TAG_NAME,
		OF_XMLPARSER_IN_CLOSE_TAG_NAME,
		OF_XMLPARSER_IN_TAG,
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
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







-
+










-
+






-
+













	OFString *attrName;
	OFString *attrPrefix;
	char delim;
	OFMutableArray *previous;
}

#ifdef OF_HAVE_PROPERTIES
@property (retain) OFObject <OFXMLParserDelegate> *delegate;
@property (retain) id <OFXMLParserDelegate> delegate;
#endif

/**
 * \return A new, autoreleased OFXMLParser
 */
+ parser;

/**
 * \return The delegate that is used by the XML parser
 */
- (OFObject <OFXMLParserDelegate>*)delegate;
- (id <OFXMLParserDelegate>)delegate;

/**
 * Sets the delegate the OFXMLParser should use.
 *
 * \param delegate The delegate to use
 */
- (void)setDelegate: (OFObject <OFXMLParserDelegate>*)delegate;
- (void)setDelegate: (id <OFXMLParserDelegate>)delegate;

/**
 * Parses a buffer with the specified size.
 *
 * \param buf The buffer to parse
 * \param size The size of the buffer
 */
- (void)parseBuffer: (const char*)buf
	   withSize: (size_t)size;
@end

@interface OFObject (OFXMLParserDelegate) <OFXMLParserDelegate>
@end

Modified src/OFXMLParser.m from [0ff2c07a09] to [156503de2d].

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







-
+













-
+

-
+


-
+

-
-
+
+







	}

	return self;
}

- (void)dealloc
{
	[delegate release];
	[(id)delegate release];

	[cache release];
	[name release];
	[prefix release];
	[namespaces release];
	[attrs release];
	[attrName release];
	[attrPrefix release];
	[previous release];

	[super dealloc];
}

- (OFObject <OFXMLParserDelegate>*)delegate
- (id <OFXMLParserDelegate>)delegate
{
	return [[delegate retain] autorelease];
	return [[(id)delegate retain] autorelease];
}

- (void)setDelegate: (OFObject <OFXMLParserDelegate>*)delegate_
- (void)setDelegate: (id <OFXMLParserDelegate>)delegate_
{
	[delegate_ retain];
	[delegate release];
	[(id)delegate_ retain];
	[(id)delegate release];
	delegate = delegate_;
}

- (void)parseBuffer: (const char*)buf
	   withSize: (size_t)size
{
	OFAutoreleasePool *pool;