ObjFW  Diff

Differences From Artifact [8a9fc8e1ab]:

To Artifact [9c33438270]:


1
2
3
4

5
6
7
8
9
10
11
1



2
3
4
5
6
7
8
9

-
-
-
+







/*
 * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
 *               2018, 2019, 2020
 *   Jonathan Schleifer <js@nil.im>
 * Copyright (c) 2008-2021 Jonathan Schleifer <js@nil.im>
 *
 * 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.QPL included in
 * the packaging of this file.
 *
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
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







-
+
-


-
+
-










-
-
+







	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);
	@try {
		memcpy(name, "set", 3);
		memcpy(name + 3, key.UTF8String, keyLength);
179
180
181
182
183
184
185
186
187

188
189
190
191
192
193
194
174
175
176
177
178
179
180


181
182
183
184
185
186
187
188







-
-
+








	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);
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
272
273
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