ObjFW  Check-in [fdcb2a71e4]

Overview
Comment:Clean up method replacing.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: fdcb2a71e4bc2790db7438d44f055db6c655e2c0b90d6e0d084da3f90de42531
User & Date: js on 2010-07-08 10:04:04
Other Links: manifest | tags
Context
2010-07-08
18:49
Resolve attribute namespaces after all attributes have been parsed. check-in: 4c57833cfa user: js tags: trunk
10:04
Clean up method replacing. check-in: fdcb2a71e4 user: js tags: trunk
09:44
Cache OFAutoreleasePool class. check-in: 3c5eb0ddb6 user: js tags: trunk
Changes

Modified src/OFObject.m from [85afaae721] to [b60749cd23].

230
231
232
233
234
235
236




237
238







239
240
241
242
243
244
245
246
247
#endif
}

+ (IMP)setImplementation: (IMP)newimp
	  forClassMethod: (SEL)selector
{
#if defined(OF_OBJFW_RUNTIME)




	return objc_replace_class_method(self, selector, newimp);
#elif defined(OF_APPLE_RUNTIME)







	return class_replaceMethod(self->isa, selector, newimp,
	    method_getTypeEncoding(class_getClassMethod(self, selector)));
#else
	Method_t method;
	IMP oldimp;

	/* The class method is the instance method of the meta class */
	if ((method = class_get_instance_method(self->class_pointer,
	    selector)) == NULL)







>
>
>
>


>
>
>
>
>
>
>

|







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
#endif
}

+ (IMP)setImplementation: (IMP)newimp
	  forClassMethod: (SEL)selector
{
#if defined(OF_OBJFW_RUNTIME)
	if (newimp == (IMP)0 || !class_respondsToSelector(self->isa, selector))
		@throw [OFInvalidArgumentException newWithClass: self
						       selector: _cmd];

	return objc_replace_class_method(self, selector, newimp);
#elif defined(OF_APPLE_RUNTIME)
	Method method;

	if (newimp == (IMP)0 ||
	    (method = class_getClassMethod(self, selector)) == NULL)
		@throw [OFInvalidArgumentException newWithClass: self
						       selector: _cmd];

	return class_replaceMethod(self->isa, selector, newimp,
	    method_getTypeEncoding(method));
#else
	Method_t method;
	IMP oldimp;

	/* The class method is the instance method of the meta class */
	if ((method = class_get_instance_method(self->class_pointer,
	    selector)) == NULL)
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
300
301
302
303
304
305
{
	IMP newimp;

	if (![class isSubclassOfClass: self])
		@throw [OFInvalidArgumentException newWithClass: self
						       selector: _cmd];

#if defined(OF_OBJFW_RUNTIME)
	newimp = objc_get_class_method(class, selector);
#elif defined(OF_APPLE_RUNTIME)
	newimp = method_getImplementation(class_getClassMethod(class,
	    selector));
#else
	/* The class method is the instance method of the meta class */
	newimp = method_get_imp(class_get_instance_method(class->class_pointer,
	    selector));
#endif

	return [self setImplementation: newimp
			forClassMethod: selector];
}

+ (IMP)setImplementation: (IMP)newimp
       forInstanceMethod: (SEL)selector
{
#if defined(OF_OBJFW_RUNTIME)




	return objc_replace_instance_method(self, selector, newimp);
#elif defined(OF_APPLE_RUNTIME)







	return class_replaceMethod(self, selector, newimp,
	    method_getTypeEncoding(class_getInstanceMethod(self, selector)));
#else
	Method_t method = class_get_instance_method(self, selector);
	IMP oldimp;

	if (method == NULL)
		@throw [OFInvalidArgumentException newWithClass: self
						       selector: _cmd];







<
<
<
<
|
<
<
<
<
<









>
>
>
>


>
>
>
>
>
>
>

|







280
281
282
283
284
285
286




287





288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
{
	IMP newimp;

	if (![class isSubclassOfClass: self])
		@throw [OFInvalidArgumentException newWithClass: self
						       selector: _cmd];





	newimp = [class methodForSelector: selector];






	return [self setImplementation: newimp
			forClassMethod: selector];
}

+ (IMP)setImplementation: (IMP)newimp
       forInstanceMethod: (SEL)selector
{
#if defined(OF_OBJFW_RUNTIME)
	if (newimp == (IMP)0 || !class_respondsToSelector(self, selector))
		@throw [OFInvalidArgumentException newWithClass: self
						       selector: _cmd];

	return objc_replace_instance_method(self, selector, newimp);
#elif defined(OF_APPLE_RUNTIME)
	Method method;

	if (newimp == (IMP)0 ||
	    (method = class_getInstanceMethod(self, selector)) == NULL)
		@throw [OFInvalidArgumentException newWithClass: self
						       selector: _cmd];

	return class_replaceMethod(self, selector, newimp,
	    method_getTypeEncoding(method));
#else
	Method_t method = class_get_instance_method(self, selector);
	IMP oldimp;

	if (method == NULL)
		@throw [OFInvalidArgumentException newWithClass: self
						       selector: _cmd];
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
{
	IMP newimp;

	if (![class isSubclassOfClass: self])
		@throw [OFInvalidArgumentException newWithClass: self
						       selector: _cmd];

#if defined(OF_OBJFW_RUNTIME)
	newimp = objc_get_instance_method(class, selector);
#elif defined(OF_APPLE_RUNTIME)
	newimp = class_getMethodImplementation(class, selector);
#else
	newimp = method_get_imp(class_get_instance_method(class, selector));
#endif

	return [self setImplementation: newimp
		     forInstanceMethod: selector];
}

- init
{







<
|
<
<
<
<
<







338
339
340
341
342
343
344

345





346
347
348
349
350
351
352
{
	IMP newimp;

	if (![class isSubclassOfClass: self])
		@throw [OFInvalidArgumentException newWithClass: self
						       selector: _cmd];


	newimp = [class instanceMethodForSelector: selector];






	return [self setImplementation: newimp
		     forInstanceMethod: selector];
}

- init
{