ObjFW  Diff

Differences From Artifact [2a9a3f450d]:

To Artifact [3bfea8ea41]:


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







-
+





-
+



-
+







		char *name;

		if ((keyLength = key.UTF8StringLength) < 1) {
			objc_autoreleasePoolPop(pool);
			return [self valueForUndefinedKey: key];
		}

		name = of_alloc(keyLength + 3, 1);
		name = OFAllocMemory(keyLength + 3, 1);
		@try {
			memcpy(name, "is", 2);
			memcpy(name + 2, key.UTF8String, keyLength);
			name[keyLength + 2] = '\0';

			name[2] = of_ascii_toupper(name[2]);
			name[2] = OFASCIIToUpper(name[2]);

			selector = sel_registerName(name);
		} @finally {
			free(name);
			OFFreeMemory(name);
		}

		methodSignature = [self methodSignatureForSelector: selector];

		if (methodSignature == NULL) {
			objc_autoreleasePoolPop(pool);
			return [self valueForUndefinedKey: key];
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
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







-
+
-


-
+
-










-
-
+



-
+





-
+



-
+










-
-
+







	objc_autoreleasePoolPop(pool);

	return [ret autorelease];
}

- (id)valueForUndefinedKey: (OFString *)key
{
	@throw [OFUndefinedKeyException exceptionWithObject: self
	@throw [OFUndefinedKeyException exceptionWithObject: self key: key];
							key: key];
}

- (void)setValue: (id)value
- (void)setValue: (id)value forKey: (OFString *)key
	  forKey: (OFString *)key
{
	void *pool = objc_autoreleasePoolPush();
	size_t keyLength;
	char *name;
	SEL selector;
	OFMethodSignature *methodSignature;
	const char *valueType;

	if ((keyLength = key.UTF8StringLength) < 1) {
		objc_autoreleasePoolPop(pool);
		[self	   setValue: value
		    forUndefinedKey: key];
		[self setValue: value forUndefinedKey: key];
		return;
	}

	name = of_alloc(keyLength + 5, 1);
	name = OFAllocMemory(keyLength + 5, 1);
	@try {
		memcpy(name, "set", 3);
		memcpy(name + 3, key.UTF8String, keyLength);
		memcpy(name + keyLength + 3, ":", 2);

		name[3] = of_ascii_toupper(name[3]);
		name[3] = OFASCIIToUpper(name[3]);

		selector = sel_registerName(name);
	} @finally {
		free(name);
		OFFreeMemory(name);
	}

	methodSignature = [self methodSignatureForSelector: selector];

	if (methodSignature == nil ||
	    methodSignature.numberOfArguments != 3 ||
	    *methodSignature.methodReturnType != 'v' ||
	    *[methodSignature argumentTypeAtIndex: 0] != '@' ||
	    *[methodSignature argumentTypeAtIndex: 1] != ':') {
		objc_autoreleasePoolPop(pool);
		[self	   setValue: value
		    forUndefinedKey: key];
		[self setValue: value forUndefinedKey: key];
		return;
	}

	valueType = [methodSignature argumentTypeAtIndex: 2];

	if (*valueType != '@' && *valueType != '#' && value == nil) {
		objc_autoreleasePoolPop(pool);
224
225
226
227
228
229
230
231
232

233
234
235
236
237
238
239

240
241
242
243
244
245
246
247
248
249
250

251
252
253
254
255
256
257
258
259

260
261
262
263
264
265
266
267
268
269
270
271
220
221
222
223
224
225
226


227
228
229
230
231
232
233

234

235
236
237
238
239
240
241
242
243

244

245
246
247
248
249
250
251

252

253
254
255
256
257
258
259
260
261
262
263







-
-
+






-
+
-









-
+
-







-
+
-











	CASE('L', unsigned long, unsignedLongValue)
	CASE('Q', unsigned long long, unsignedLongLongValue)
	CASE('f', float, floatValue)
	CASE('d', double, doubleValue)
#undef CASE
	default:
		objc_autoreleasePoolPop(pool);
		[self	   setValue: value
		    forUndefinedKey: key];
		[self setValue: value forUndefinedKey: key];
		return;
	}

	objc_autoreleasePoolPop(pool);
}

- (void)setValue: (id)value
- (void)setValue: (id)value forKeyPath: (OFString *)keyPath
      forKeyPath: (OFString *)keyPath
{
	void *pool = objc_autoreleasePoolPush();
	OFArray *keys = [keyPath componentsSeparatedByString: @"."];
	size_t keysCount = keys.count;
	id object = self;
	size_t i = 0;

	for (OFString *key in keys) {
		if (++i == keysCount)
			[object setValue: value
			[object setValue: value forKey: key];
				  forKey: key];
		else
			object = [object valueForKey: key];
	}

	objc_autoreleasePoolPop(pool);
}

-  (void)setValue: (id)value
-  (void)setValue: (id)value forUndefinedKey: (OFString *)key
  forUndefinedKey: (OFString *)key
{
	@throw [OFUndefinedKeyException exceptionWithObject: self
							key: key
						      value: value];
}

- (void)setNilValueForKey: (OFString *)key
{
	@throw [OFInvalidArgumentException exception];
}
@end