ObjFW  Diff

Differences From Artifact [66f93123ef]:

To Artifact [bd7981a871]:


37
38
39
40
41
42
43

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







+







#import "macros.h"

#if defined(OF_OBJFW_RUNTIME)
# import <objfw-rt.h>
#elif defined(OF_OLD_GNU_RUNTIME)
# import <objc/objc-api.h>
# import <objc/sarray.h>
# import <objc/Protocol.h>
#else
# import <objc/runtime.h>
#endif

#ifdef _WIN32
# include <windows.h>
#endif
247
248
249
250
251
252
253
254

255
256
257
258
259
260
261
248
249
250
251
252
253
254

255
256
257
258
259
260
261
262







-
+







	Class c;
	struct objc_protocol_list *pl;
	size_t i;

	for (c = self; c != Nil; c = class_get_super_class(c))
		for (pl = c->protocols; pl != NULL; pl = pl->next)
			for (i = 0; i < pl->count; i++)
				if ([pl->list[i] conformsToProtocol: protocol])
				if ([pl->list[i] conformsTo: protocol])
					return YES;

	return NO;
#else
	Class c;

	for (c = self; c != Nil; c = class_getSuperclass(c))
360
361
362
363
364
365
366
367

368
369
370
371
372
373
374
361
362
363
364
365
366
367

368
369
370
371
372
373
374
375







-
+







	 */
	return class_replaceMethod(((OFObject*)self)->isa, selector, newimp,
	    method_getTypeEncoding(method));
#endif
}

+ (IMP)replaceClassMethod: (SEL)selector
      withMethodFromClass: (Class)class;
      withMethodFromClass: (Class)class
{
	IMP newimp;

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

418
419
420
421
422
423
424
425

426
427
428
429
430
431
432
419
420
421
422
423
424
425

426
427
428
429
430
431
432
433







-
+








	return class_replaceMethod(self, selector, newimp,
	    method_getTypeEncoding(method));
#endif
}

+ (IMP)replaceInstanceMethod: (SEL)selector
	 withMethodFromClass: (Class)class;
	 withMethodFromClass: (Class)class
{
	IMP newimp;

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

676
677
678
679
680
681
682
683

684
685
686
687
688
689
690
677
678
679
680
681
682
683

684
685
686
687
688
689
690
691







-
+







	if (nitems > SIZE_MAX / size)
		@throw [OFOutOfRangeException newWithClass: isa];

	return [self resizeMemory: ptr
			   toSize: nitems * size];
}

- (void)freeMemory: (void*)ptr;
- (void)freeMemory: (void*)ptr
{
	void **iter, *last, **memchunks;
	size_t i, memchunks_size;

	if (ptr == NULL)
		return;