ObjFW  Diff

Differences From Artifact [66f93123ef]:

To Artifact [2e1d6a6c76]:


12
13
14
15
16
17
18


19
20
21

22

23
24
25
26
27
28
29
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33







+
+



+

+







 * Public License, either version 2 or 3, which can be found in the file
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#include "config.h"

#define __NO_EXT_QNX

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <unistd.h>

#include <assert.h>

#import "OFObject.h"
#import "OFAutoreleasePool.h"

#import "OFAllocFailedException.h"
#import "OFEnumerationMutationException.h"
37
38
39
40
41
42
43

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







+







#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
252
253
254
255
256
257
258

259
260
261
262
263
264
265
266







-
+







	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
365
366
367
368
369
370
371

372
373
374
375
376
377
378
379







-
+







	 */
	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
423
424
425
426
427
428
429

430
431
432
433
434
435
436
437







-
+








	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
681
682
683
684
685
686
687

688
689
690
691
692
693
694
695







-
+







	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;