ObjFW  Check-in [7f0b0c9811]

Overview
Comment:Remove all code for the GNU runtime.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | runtime
Files: files | file ages | folders
SHA3-256: 7f0b0c9811a95e6e2a1799549d08088066127598cfb76d002e522747e81607eb
User & Date: js on 2012-03-04 19:42:56
Other Links: branch diff | manifest | tags
Context
2012-03-04
20:20
Import and integrate ObjFW-RT. check-in: 129f90b580 user: js tags: runtime
19:42
Remove all code for the GNU runtime. check-in: 7f0b0c9811 user: js tags: runtime
19:28
Change includes of objfw-rt.h to include local runtime.h. check-in: 1664513cf6 user: js tags: runtime
Changes

Modified src/OFBlock.m from [26addffed9] to [41dec8a8ba].

69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103

104
105
106
107
108
109
110
};

@protocol RetainRelease
- retain;
- (void)release;
@end

#if defined(OF_OBJFW_RUNTIME) || defined(OF_GNU_RUNTIME) || \
    defined(OF_OLD_GNU_RUNTIME)
struct objc_abi_class {
	struct objc_abi_metaclass *metaclass;
	const char *superclass, *name;
	unsigned long version, info, instance_size;
	void *ivars, *methodlist, *dtable, *subclass_list, *sibling_class;
	void *protocols, *gc_object_type;
	long abi_version;
	void *ivar_offsets, *properties;
};

struct objc_abi_metaclass {
	const char *metaclass, *superclass, *name;
	unsigned long version, info, instance_size;
	void *ivars, *methodlist, *dtable, *subclass_list, *sibling_class;
	void *protocols, *gc_object_type;
	long abi_version;
	void *ivar_offsets, *properties;
};

#ifndef OF_OBJFW_RUNTIME
enum objc_abi_class_info {
	OBJC_CLASS_INFO_CLASS	  = 0x01,
	OBJC_CLASS_INFO_METACLASS = 0x02
};
#endif


extern void __objc_exec_class(void*);

/* Begin of ObjC module */
static struct objc_abi_metaclass _NSConcreteStackBlock_metaclass = {
	"OFBlock", "OFBlock", "OFStackBlock", 8, OBJC_CLASS_INFO_METACLASS,
	sizeof(struct objc_abi_class), NULL, NULL
};







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







>







69
70
71
72
73
74
75





















76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
};

@protocol RetainRelease
- retain;
- (void)release;
@end






















#ifndef OF_OBJFW_RUNTIME
enum objc_abi_class_info {
	OBJC_CLASS_INFO_CLASS	  = 0x01,
	OBJC_CLASS_INFO_METACLASS = 0x02
};
#endif

#if defined(OF_OBJFW_RUNTIME)
extern void __objc_exec_class(void*);

/* Begin of ObjC module */
static struct objc_abi_metaclass _NSConcreteStackBlock_metaclass = {
	"OFBlock", "OFBlock", "OFStackBlock", 8, OBJC_CLASS_INFO_METACLASS,
	sizeof(struct objc_abi_class), NULL, NULL
};

Modified src/OFIntrospection.m from [3e6c8b04d5] to [e4635330ec].

14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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
69
70
71
72
73
74
75
 * file.
 */

#include "config.h"

#include <stdlib.h>

#if defined(OF_APPLE_RUNTIME) || defined(OF_GNU_RUNTIME)
# import <objc/runtime.h>
#elif defined(OF_OLD_GNU_RUNTIME)
# import <objc/objc-api.h>
#endif

#import "OFIntrospection.h"
#import "OFString.h"
#import "OFArray.h"
#import "OFAutoreleasePool.h"

#import "macros.h"

@implementation OFMethod
#if defined(OF_APPLE_RUNTIME) || defined(OF_GNU_RUNTIME)
- _initWithMethod: (Method)method
{
	self = [super init];

	@try {
		selector = method_getName(method);
		name = [[OFString alloc]
		    initWithCString: sel_getName(selector)
			   encoding: OF_STRING_ENCODING_ASCII];
		typeEncoding = method_getTypeEncoding(method);
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}
#elif defined(OF_OLD_GNU_RUNTIME)
- _initWithMethod: (Method_t)method
{
	self = [super init];

	@try {
		selector = method->method_name;
		name = [[OFString alloc]
		    initWithCString: sel_get_name(selector)
			   encoding: OF_STRING_ENCODING_ASCII];
		typeEncoding = method->method_types;
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}
#endif

- (void)dealloc
{
	[name release];







|

<
<










|















<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







14
15
16
17
18
19
20
21
22


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48


















49
50
51
52
53
54
55
 * file.
 */

#include "config.h"

#include <stdlib.h>

#if defined(OF_APPLE_RUNTIME)
# import <objc/runtime.h>


#endif

#import "OFIntrospection.h"
#import "OFString.h"
#import "OFArray.h"
#import "OFAutoreleasePool.h"

#import "macros.h"

@implementation OFMethod
#if defined(OF_APPLE_RUNTIME)
- _initWithMethod: (Method)method
{
	self = [super init];

	@try {
		selector = method_getName(method);
		name = [[OFString alloc]
		    initWithCString: sel_getName(selector)
			   encoding: OF_STRING_ENCODING_ASCII];
		typeEncoding = method_getTypeEncoding(method);
	} @catch (id e) {
		[self release];
		@throw e;
	}



















	return self;
}
#endif

- (void)dealloc
{
	[name release];
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
{
	return [OFString stringWithFormat: @"<OFMethod: %@ [%s]>",
					   name, typeEncoding];
}
@end

@implementation OFInstanceVariable
#if defined(OF_APPLE_RUNTIME) || defined(OF_GNU_RUNTIME)
- _initWithIvar: (Ivar)ivar
{
	self = [super init];

	@try {
		name = [[OFString alloc]
		    initWithCString: ivar_getName(ivar)
			   encoding: OF_STRING_ENCODING_ASCII];
		offset = ivar_getOffset(ivar);
		typeEncoding = ivar_getTypeEncoding(ivar);
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}
#elif defined(OF_OLD_GNU_RUNTIME)
- _initWithIvar: (Ivar_t)ivar
{
	self = [super init];

	@try {
		name = [[OFString alloc]
		    initWithCString: ivar->ivar_name
			   encoding: OF_STRING_ENCODING_ASCII];
		offset = ivar->ivar_offset;
		typeEncoding = ivar->ivar_type;
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}
#endif

- (void)dealloc
{
	[name release];







|















<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98


















99
100
101
102
103
104
105
{
	return [OFString stringWithFormat: @"<OFMethod: %@ [%s]>",
					   name, typeEncoding];
}
@end

@implementation OFInstanceVariable
#if defined(OF_APPLE_RUNTIME)
- _initWithIvar: (Ivar)ivar
{
	self = [super init];

	@try {
		name = [[OFString alloc]
		    initWithCString: ivar_getName(ivar)
			   encoding: OF_STRING_ENCODING_ASCII];
		offset = ivar_getOffset(ivar);
		typeEncoding = ivar_getTypeEncoding(ivar);
	} @catch (id e) {
		[self release];
		@throw e;
	}



















	return self;
}
#endif

- (void)dealloc
{
	[name release];
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
}
@end

#ifdef OF_HAVE_PROPERTIES
@implementation OFProperty
@synthesize name, attributes;

#if defined(OF_APPLE_RUNTIME) || defined(OF_GNU_RUNTIME)
- _initWithProperty: (objc_property_t)property
{
	self = [super init];

	@try {
		name = [[OFString alloc]
		    initWithCString: property_getName(property)







|







130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
}
@end

#ifdef OF_HAVE_PROPERTIES
@implementation OFProperty
@synthesize name, attributes;

#if defined(OF_APPLE_RUNTIME)
- _initWithProperty: (objc_property_t)property
{
	self = [super init];

	@try {
		name = [[OFString alloc]
		    initWithCString: property_getName(property)
218
219
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

- initWithClass: (Class)class
{
	self = [super init];

	@try {
		OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
#if defined(OF_APPLE_RUNTIME) || defined(OF_GNU_RUNTIME)
		Method *methodList;
		Ivar *ivarList;
# ifdef OF_HAVE_PROPERTIES
		objc_property_t *propertyList;
# endif
		unsigned i, count;
#elif defined(OF_OLD_GNU_RUNTIME)
		MethodList_t methodList;
#endif

		classMethods = [[OFMutableArray alloc] init];
		instanceMethods = [[OFMutableArray alloc] init];
		instanceVariables = [[OFMutableArray alloc] init];
#ifdef OF_HAVE_PROPERTIES
		properties = [[OFMutableArray alloc] init];
#endif

#if defined(OF_APPLE_RUNTIME) || defined(OF_GNU_RUNTIME)
		methodList = class_copyMethodList(((OFObject*)class)->isa,
		    &count);
		@try {
			for (i = 0; i < count; i++) {
				[classMethods addObject: [[[OFMethod alloc]
				    _initWithMethod: methodList[i]]
				    autorelease]];







|






<
<









|







180
181
182
183
184
185
186
187
188
189
190
191
192
193


194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210

- initWithClass: (Class)class
{
	self = [super init];

	@try {
		OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
#if defined(OF_APPLE_RUNTIME)
		Method *methodList;
		Ivar *ivarList;
# ifdef OF_HAVE_PROPERTIES
		objc_property_t *propertyList;
# endif
		unsigned i, count;


#endif

		classMethods = [[OFMutableArray alloc] init];
		instanceMethods = [[OFMutableArray alloc] init];
		instanceVariables = [[OFMutableArray alloc] init];
#ifdef OF_HAVE_PROPERTIES
		properties = [[OFMutableArray alloc] init];
#endif

#if defined(OF_APPLE_RUNTIME)
		methodList = class_copyMethodList(((OFObject*)class)->isa,
		    &count);
		@try {
			for (i = 0; i < count; i++) {
				[classMethods addObject: [[[OFMethod alloc]
				    _initWithMethod: methodList[i]]
				    autorelease]];
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
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
				    _initWithProperty: propertyList[i]]
				    autorelease]];
				[pool releaseObjects];
			}
		} @finally {
			free(propertyList);
		}
#elif defined(OF_OLD_GNU_RUNTIME)
		for (methodList = class->class_pointer->methods;
		    methodList != NULL; methodList = methodList->method_next) {
			int i;

			for (i = 0; i < methodList->method_count; i++) {
				[classMethods addObject: [[[OFMethod alloc]
				    _initWithMethod:
				    &methodList->method_list[i]] autorelease]];
				[pool releaseObjects];
			}
		}

		for (methodList = class->methods; methodList != NULL;
		    methodList = methodList->method_next) {
			int i;

			for (i = 0; i < methodList->method_count; i++) {
				[instanceMethods addObject: [[[OFMethod alloc]
				    _initWithMethod:
				    &methodList->method_list[i]] autorelease]];
				[pool releaseObjects];
			}
		}

		if (class->ivars != NULL) {
			int i;

			for (i = 0; i < class->ivars->ivar_count; i++) {
				[instanceVariables addObject:
				    [[[OFInstanceVariable alloc]
				    _initWithIvar: class->ivars->ivar_list + i]
				    autorelease]];
				[pool releaseObjects];
			}
		}
#endif

		[classMethods makeImmutable];
		[instanceMethods makeImmutable];
		[instanceVariables makeImmutable];
#ifdef OF_HAVE_PROPERTIES
		[properties makeImmutable];







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







246
247
248
249
250
251
252




































253
254
255
256
257
258
259
				    _initWithProperty: propertyList[i]]
				    autorelease]];
				[pool releaseObjects];
			}
		} @finally {
			free(propertyList);
		}




































#endif

		[classMethods makeImmutable];
		[instanceMethods makeImmutable];
		[instanceVariables makeImmutable];
#ifdef OF_HAVE_PROPERTIES
		[properties makeImmutable];

Modified src/OFObject.m from [1328998492] to [ad59fef6e2].

36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#import "OFMemoryNotPartOfObjectException.h"
#import "OFNotImplementedException.h"
#import "OFOutOfMemoryException.h"
#import "OFOutOfRangeException.h"

#import "macros.h"

#if (defined(OF_APPLE_RUNTIME) && __OBJC2__) || defined(OF_GNU_RUNTIME)
# import <objc/objc-exception.h>
#elif defined(OF_OBJFW_RUNTIME)
# import "runtime.h"
#elif defined(OF_OLD_GNU_RUNTIME)
# import <objc/Protocol.h>
#endif

#ifdef _WIN32
# include <windows.h>
#endif

#import "OFString.h"







|



<
<







36
37
38
39
40
41
42
43
44
45
46


47
48
49
50
51
52
53
#import "OFMemoryNotPartOfObjectException.h"
#import "OFNotImplementedException.h"
#import "OFOutOfMemoryException.h"
#import "OFOutOfRangeException.h"

#import "macros.h"

#if (defined(OF_APPLE_RUNTIME) && __OBJC2__)
# import <objc/objc-exception.h>
#elif defined(OF_OBJFW_RUNTIME)
# import "runtime.h"


#endif

#ifdef _WIN32
# include <windows.h>
#endif

#import "OFString.h"
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# define __BIGGEST_ALIGNMENT__ 16
#endif

#define PRE_IVAR_ALIGN ((sizeof(struct pre_ivar) + \
	(__BIGGEST_ALIGNMENT__ - 1)) & ~(__BIGGEST_ALIGNMENT__ - 1))
#define PRE_IVAR ((struct pre_ivar*)(void*)((char*)self - PRE_IVAR_ALIGN))

#ifdef OF_OLD_GNU_RUNTIME
extern void __objc_update_dispatch_table_for_class(Class);
#endif

static struct {
	Class isa;
} alloc_failed_exception;
static Class autoreleasePool = Nil;

static SEL cxx_construct = NULL;
static SEL cxx_destruct = NULL;

size_t of_pagesize;

#ifdef NEED_OBJC_SYNC_INIT
extern BOOL objc_sync_init();
#endif

#ifdef NEED_OBJC_PROPERTIES_INIT
extern BOOL objc_properties_init();
#endif

#if (defined(OF_APPLE_RUNTIME) && __OBJC2__) || defined(OF_GNU_RUNTIME)
static void
uncaught_exception_handler(id exception)
{
	fprintf(stderr, "\nUnhandled exception:\n%s\n",
	    [[exception description] UTF8String]);
}
#endif







<
<
<
<


















|







72
73
74
75
76
77
78




79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# define __BIGGEST_ALIGNMENT__ 16
#endif

#define PRE_IVAR_ALIGN ((sizeof(struct pre_ivar) + \
	(__BIGGEST_ALIGNMENT__ - 1)) & ~(__BIGGEST_ALIGNMENT__ - 1))
#define PRE_IVAR ((struct pre_ivar*)(void*)((char*)self - PRE_IVAR_ALIGN))





static struct {
	Class isa;
} alloc_failed_exception;
static Class autoreleasePool = Nil;

static SEL cxx_construct = NULL;
static SEL cxx_destruct = NULL;

size_t of_pagesize;

#ifdef NEED_OBJC_SYNC_INIT
extern BOOL objc_sync_init();
#endif

#ifdef NEED_OBJC_PROPERTIES_INIT
extern BOOL objc_properties_init();
#endif

#if (defined(OF_APPLE_RUNTIME) && __OBJC2__)
static void
uncaught_exception_handler(id exception)
{
	fprintf(stderr, "\nUnhandled exception:\n%s\n",
	    [[exception description] UTF8String]);
}
#endif
121
122
123
124
125
126
127
128
129
130
131
132
133
134
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
void
objc_enumerationMutation(id object)
{
	enumeration_mutation_handler(object);
}
#endif

#if defined(HAVE_OBJC_ENUMERATIONMUTATION) && defined(OF_OLD_GNU_RUNTIME)
extern void objc_setEnumerationMutationHandler(void(*handler)(id));
#endif

const char*
_NSPrintForDebugger(id object)
{
	return [[object description]
	    cStringWithEncoding: OF_STRING_ENCODING_NATIVE];
}

#ifdef OF_OLD_GNU_RUNTIME
static BOOL
protocol_conformsToProtocol(Protocol *a, Protocol *b)
{
	/*
	 * This function is an ugly workaround for a bug that only happens with
	 * Clang 2.9 together with the libobjc from GCC 4.6.
	 * Since the instance variables of Protocol are @private, we have to
	 * cast them to a struct here in order to access them.
	 */
	struct objc_protocol {
		Class isa;
		const char *protocol_name;
		struct objc_protocol_list *protocol_list;
	} *pa = (struct objc_protocol*)a, *pb = (struct objc_protocol*)b;
	struct objc_protocol_list *pl;
	size_t i;

	if (!strcmp(pa->protocol_name, pb->protocol_name))
		return YES;

	for (pl = pa->protocol_list; pl != NULL; pl = pl->next)
		for (i = 0; i < pl->count; i++)
			if (protocol_conformsToProtocol(pl->list[i], b))
				return YES;

	return NO;
}
#endif

/* References for static linking */
void _references_to_categories_of_OFObject(void)
{
	_OFObject_Serialization_reference = 1;
}

@implementation OFObject







<
<
<
<







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







115
116
117
118
119
120
121




122
123
124
125
126
127
128






























129
130
131
132
133
134
135
void
objc_enumerationMutation(id object)
{
	enumeration_mutation_handler(object);
}
#endif





const char*
_NSPrintForDebugger(id object)
{
	return [[object description]
	    cStringWithEncoding: OF_STRING_ENCODING_NATIVE];
}































/* References for static linking */
void _references_to_categories_of_OFObject(void)
{
	_OFObject_Serialization_reference = 1;
}

@implementation OFObject
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
	if (!objc_properties_init()) {
		fputs("Runtime error: objc_properties_init() failed!\n",
		    stderr);
		abort();
	}
#endif

#if (defined(OF_APPLE_RUNTIME) && __OBJC2__) || defined(OF_GNU_RUNTIME)
	objc_setUncaughtExceptionHandler(uncaught_exception_handler);
#endif

#ifdef HAVE_OBJC_ENUMERATIONMUTATION
	objc_setEnumerationMutationHandler(enumeration_mutation_handler);
#endif








|







146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
	if (!objc_properties_init()) {
		fputs("Runtime error: objc_properties_init() failed!\n",
		    stderr);
		abort();
	}
#endif

#if (defined(OF_APPLE_RUNTIME) && __OBJC2__)
	objc_setUncaughtExceptionHandler(uncaught_exception_handler);
#endif

#ifdef HAVE_OBJC_ENUMERATIONMUTATION
	objc_setEnumerationMutationHandler(enumeration_mutation_handler);
#endif

298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
+ (Class)superclass
{
	return class_getSuperclass(self);
}

+ (BOOL)instancesRespondToSelector: (SEL)selector
{
#ifdef OF_OLD_GNU_RUNTIME
	return class_get_instance_method(self, selector) != METHOD_NULL;
#else
	return class_respondsToSelector(self, selector);
#endif
}

+ (BOOL)conformsToProtocol: (Protocol*)protocol
{
#ifdef OF_OLD_GNU_RUNTIME
	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 (protocol_conformsToProtocol(pl->list[i],
				    protocol))
					return YES;

	return NO;
#else
	Class c;

	for (c = self; c != Nil; c = class_getSuperclass(c))
		if (class_conformsToProtocol(c, protocol))
			return YES;

	return NO;
#endif
}

+ (IMP)instanceMethodForSelector: (SEL)selector
{
#if defined(OF_OBJFW_RUNTIME)
	return objc_get_instance_method(self, selector);
#elif defined(OF_OLD_GNU_RUNTIME)
	return method_get_imp(class_get_instance_method(self, selector));
#else
	return class_getMethodImplementation(self, selector);
#endif
}

+ (const char*)typeEncodingForInstanceSelector: (SEL)selector
{
#if defined(OF_OBJFW_RUNTIME)
	const char *ret;

	if ((ret = objc_get_type_encoding(self, selector)) == NULL)
		@throw [OFNotImplementedException exceptionWithClass: self
							    selector: selector];

	return ret;
#elif defined(OF_OLD_GNU_RUNTIME)
	Method_t m;

	if ((m = class_get_instance_method(self, selector)) == NULL ||
	    m->method_types == NULL)
		@throw [OFNotImplementedException exceptionWithClass: self
							    selector: selector];

	return m->method_types;
#else
	Method m;
	const char *ret;

	if ((m = class_getInstanceMethod(self, selector)) == NULL ||
	    (ret = method_getTypeEncoding(m)) == NULL)
		@throw [OFNotImplementedException exceptionWithClass: self







<
<
<

<




<
<
<
<
<
<
<
<
<
<
<
<
<
<







<






<
<















<
<
<
<
<
<
<
<
<







258
259
260
261
262
263
264



265

266
267
268
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
+ (Class)superclass
{
	return class_getSuperclass(self);
}

+ (BOOL)instancesRespondToSelector: (SEL)selector
{



	return class_respondsToSelector(self, selector);

}

+ (BOOL)conformsToProtocol: (Protocol*)protocol
{














	Class c;

	for (c = self; c != Nil; c = class_getSuperclass(c))
		if (class_conformsToProtocol(c, protocol))
			return YES;

	return NO;

}

+ (IMP)instanceMethodForSelector: (SEL)selector
{
#if defined(OF_OBJFW_RUNTIME)
	return objc_get_instance_method(self, selector);


#else
	return class_getMethodImplementation(self, selector);
#endif
}

+ (const char*)typeEncodingForInstanceSelector: (SEL)selector
{
#if defined(OF_OBJFW_RUNTIME)
	const char *ret;

	if ((ret = objc_get_type_encoding(self, selector)) == NULL)
		@throw [OFNotImplementedException exceptionWithClass: self
							    selector: selector];

	return ret;









#else
	Method m;
	const char *ret;

	if ((m = class_getInstanceMethod(self, selector)) == NULL ||
	    (ret = method_getTypeEncoding(m)) == NULL)
		@throw [OFNotImplementedException exceptionWithClass: self
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
{
#if defined(OF_OBJFW_RUNTIME)
	if (newImp == (IMP)0 || !class_respondsToSelector(self->isa, selector))
		@throw [OFInvalidArgumentException exceptionWithClass: self
							     selector: _cmd];

	return objc_replace_class_method(self, selector, newImp);
#elif defined(OF_OLD_GNU_RUNTIME)
	Method_t method;
	MethodList_t iter;

	method = class_get_class_method(self->class_pointer, selector);

	if (newImp == (IMP)0 || method == METHOD_NULL)
		@throw [OFInvalidArgumentException exceptionWithClass: self
							     selector: _cmd];

	for (iter = ((Class)self->class_pointer)->methods; iter != NULL;
	    iter = iter->method_next) {
		int i;

		for (i = 0; i < iter->method_count; i++)
			if (sel_eq(iter->method_list[i].method_name,
			    selector)) {
				IMP oldImp;

				oldImp = iter->method_list[i].method_imp;
				iter->method_list[i].method_imp = newImp;

				__objc_update_dispatch_table_for_class(
				    (Class)self->class_pointer);

				return oldImp;
			}
	}

	assert([self addClassMethod: selector
		   withTypeEncoding: method->method_types
		     implementation: newImp]);

	return (IMP)0;
#else
	Method method;

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







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







318
319
320
321
322
323
324


































325
326
327
328
329
330
331
{
#if defined(OF_OBJFW_RUNTIME)
	if (newImp == (IMP)0 || !class_respondsToSelector(self->isa, selector))
		@throw [OFInvalidArgumentException exceptionWithClass: self
							     selector: _cmd];

	return objc_replace_class_method(self, selector, newImp);


































#else
	Method method;

	if (newImp == (IMP)0 ||
	    (method = class_getClassMethod(self, selector)) == NULL)
		@throw [OFInvalidArgumentException exceptionWithClass: self
							     selector: _cmd];
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
{
#if defined(OF_OBJFW_RUNTIME)
	if (newImp == (IMP)0 || !class_respondsToSelector(self, selector))
		@throw [OFInvalidArgumentException exceptionWithClass: self
							     selector: _cmd];

	return objc_replace_instance_method(self, selector, newImp);
#elif defined(OF_OLD_GNU_RUNTIME)
	Method_t method;
	MethodList_t iter;

	method = class_get_instance_method(self, selector);

	if (newImp == (IMP)0 || method == METHOD_NULL)
		@throw [OFInvalidArgumentException exceptionWithClass: self
							     selector: _cmd];

	for (iter = ((Class)self)->methods; iter != NULL;
	    iter = iter->method_next) {
		int i;

		for (i = 0; i < iter->method_count; i++)
			if (sel_eq(iter->method_list[i].method_name,
			    selector)) {
				IMP oldImp;

				oldImp = iter->method_list[i].method_imp;
				iter->method_list[i].method_imp = newImp;

				__objc_update_dispatch_table_for_class(self);

				return oldImp;
			}
	}

	assert([self addInstanceMethod: selector
		      withTypeEncoding: method->method_types
			implementation: newImp]);

	return (IMP)0;
#else
	Method method;

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







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







359
360
361
362
363
364
365

































366
367
368
369
370
371
372
{
#if defined(OF_OBJFW_RUNTIME)
	if (newImp == (IMP)0 || !class_respondsToSelector(self, selector))
		@throw [OFInvalidArgumentException exceptionWithClass: self
							     selector: _cmd];

	return objc_replace_instance_method(self, selector, newImp);

































#else
	Method method;

	if (newImp == (IMP)0 ||
	    (method = class_getInstanceMethod(self, selector)) == NULL)
		@throw [OFInvalidArgumentException exceptionWithClass: self
							     selector: _cmd];
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
		     forInstanceMethod: selector];
}

+ (BOOL)addInstanceMethod: (SEL)selector
	 withTypeEncoding: (const char*)typeEncoding
	   implementation: (IMP)implementation
{
#if defined(OF_APPLE_RUNTIME) || defined(OF_GNU_RUNTIME)
	return class_addMethod(self, selector, implementation, typeEncoding);
#elif defined(OF_OLD_GNU_RUNTIME)
	MethodList_t methodList;

	for (methodList = ((Class)self)->methods; methodList != NULL;
	    methodList = methodList->method_next) {
		int i;

		for (i = 0; i < methodList->method_count; i++)
			if (sel_eq(methodList->method_list[i].method_name,
			    selector))
				return NO;
	}

	if ((methodList = malloc(sizeof(*methodList))) == NULL)
		@throw [OFOutOfMemoryException
		    exceptionWithClass: self
			 requestedSize: sizeof(*methodList)];

	methodList->method_next = ((Class)self)->methods;
	methodList->method_count = 1;

	methodList->method_list[0].method_name = selector;
	methodList->method_list[0].method_types = typeEncoding;
	methodList->method_list[0].method_imp = implementation;

	((Class)self)->methods = methodList;

	__objc_update_dispatch_table_for_class(self);

	return YES;
#else
	@throw [OFNotImplementedException exceptionWithClass: self
						    selector: _cmd];
#endif
}

+ (BOOL)addClassMethod: (SEL)selector
      withTypeEncoding: (const char*)typeEncoding
	implementation: (IMP)implementation
{
#if defined(OF_APPLE_RUNTIME) || defined(OF_GNU_RUNTIME)
	return class_addMethod(((OFObject*)self)->isa, selector, implementation,
	    typeEncoding);
#elif defined(OF_OLD_GNU_RUNTIME)
	MethodList_t methodList;

	for (methodList = ((Class)self->class_pointer)->methods;
	    methodList != NULL; methodList = methodList->method_next) {
		int i;

		for (i = 0; i < methodList->method_count; i++)
			if (sel_eq(methodList->method_list[i].method_name,
			    selector))
				return NO;
	}

	if ((methodList = malloc(sizeof(*methodList))) == NULL)
		@throw [OFOutOfMemoryException
		    exceptionWithClass: self
			 requestedSize: sizeof(*methodList)];

	methodList->method_next = ((Class)self->class_pointer)->methods;
	methodList->method_count = 1;

	methodList->method_list[0].method_name = selector;
	methodList->method_list[0].method_types = typeEncoding;
	methodList->method_list[0].method_imp = implementation;

	((Class)self->class_pointer)->methods = methodList;

	__objc_update_dispatch_table_for_class((Class)self->class_pointer);

	return YES;
#else
	@throw [OFNotImplementedException exceptionWithClass: self
						    selector: _cmd];
#endif
}

+ (void)inheritMethodsFromClass: (Class)class
{
	Class superclass = [self superclass];

	if ([self isSubclassOfClass: class])
		return;

#if defined(OF_APPLE_RUNTIME) || defined(OF_GNU_RUNTIME)
	Method *methodList;
	unsigned i, count;

	methodList = class_copyMethodList(((OFObject*)class)->isa, &count);
	@try {
		for (i = 0; i < count; i++) {
			SEL selector = method_getName(methodList[i]);







|

<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







|


<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<










|







391
392
393
394
395
396
397
398
399

































400
401
402
403
404
405
406
407
408
409

































410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
		     forInstanceMethod: selector];
}

+ (BOOL)addInstanceMethod: (SEL)selector
	 withTypeEncoding: (const char*)typeEncoding
	   implementation: (IMP)implementation
{
#if defined(OF_APPLE_RUNTIME)
	return class_addMethod(self, selector, implementation, typeEncoding);

































#endif
}

+ (BOOL)addClassMethod: (SEL)selector
      withTypeEncoding: (const char*)typeEncoding
	implementation: (IMP)implementation
{
#if defined(OF_APPLE_RUNTIME)
	return class_addMethod(((OFObject*)self)->isa, selector, implementation,
	    typeEncoding);

































#endif
}

+ (void)inheritMethodsFromClass: (Class)class
{
	Class superclass = [self superclass];

	if ([self isSubclassOfClass: class])
		return;

#if defined(OF_APPLE_RUNTIME)
	Method *methodList;
	unsigned i, count;

	methodList = class_copyMethodList(((OFObject*)class)->isa, &count);
	@try {
		for (i = 0; i < count; i++) {
			SEL selector = method_getName(methodList[i]);
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
				       withTypeEncoding: typeEncoding
					 implementation: implementation];
			}
		}
	} @finally {
		free(methodList);
	}
#elif defined(OF_OLD_GNU_RUNTIME)
	MethodList_t methodList;

	for (methodList = class->class_pointer->methods;
	    methodList != NULL; methodList = methodList->method_next) {
		int i;

		for (i = 0; i < methodList->method_count; i++) {
			SEL selector = methodList->method_list[i].method_name;
			IMP implementation;

			/*
			 * Don't replace methods implemented in receiving class.
			 */
			if ([self methodForSelector: selector] !=
			    [superclass methodForSelector: selector])
				continue;

			implementation = [class methodForSelector: selector];

			if ([self respondsToSelector: selector])
				     [self setImplementation: implementation
					      forClassMethod: selector];
			else {
				const char *typeEncoding =
				    methodList->method_list[i].method_types;
				[self addClassMethod: selector
				    withTypeEncoding: typeEncoding
				      implementation: implementation];
			}
		}
	}

	for (methodList = class->methods; methodList != NULL;
	    methodList = methodList->method_next) {
		int i;

		for (i = 0; i < methodList->method_count; i++) {
			SEL selector = methodList->method_list[i].method_name;
			IMP implementation;

			/*
			 * Don't replace methods implemented in receiving class.
			 */
			if ([self instanceMethodForSelector: selector] !=
			    [superclass instanceMethodForSelector: selector])
				continue;

			implementation =
			    [class instanceMethodForSelector: selector];

			if ([self instancesRespondToSelector: selector])
				     [self setImplementation: implementation
					   forInstanceMethod: selector];
			else {
				const char *typeEncoding =
				    methodList->method_list[i].method_types;
				[self addInstanceMethod: selector
				       withTypeEncoding: typeEncoding
					 implementation: implementation];
			}
		}
	}
#else
	@throw [OFNotImplementedException exceptionWithClass: self
						    selector: _cmd];
#endif

	[self inheritMethodsFromClass: [class superclass]];
}

- init
{







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
<
<
<
<
<
<
<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







477
478
479
480
481
482
483























484








485

































486
487
488
489
490
491
492
				       withTypeEncoding: typeEncoding
					 implementation: implementation];
			}
		}
	} @finally {
		free(methodList);
	}























#else








	/* FIXME */

































#endif

	[self inheritMethodsFromClass: [class superclass]];
}

- init
{
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
- (BOOL)isMemberOfClass: (Class)class
{
	return (isa == class);
}

- (BOOL)respondsToSelector: (SEL)selector
{
#ifdef OF_OLD_GNU_RUNTIME
	if (object_is_instance(self))
		return class_get_instance_method(isa, selector) != METHOD_NULL;
	else
		return class_get_class_method(isa, selector) != METHOD_NULL;
#else
	return class_respondsToSelector(isa, selector);
#endif
}

- (BOOL)conformsToProtocol: (Protocol*)protocol
{
	return [isa conformsToProtocol: protocol];
}

- (IMP)methodForSelector: (SEL)selector
{
#if defined(OF_OBJFW_RUNTIME) || defined(OF_OLD_GNU_RUNTIME)
	return objc_msg_lookup(self, selector);
#else
	return class_getMethodImplementation(isa, selector);
#endif
}

- (id)performSelector: (SEL)selector







<
<
<
<
<
<

<









|







518
519
520
521
522
523
524






525

526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
- (BOOL)isMemberOfClass: (Class)class
{
	return (isa == class);
}

- (BOOL)respondsToSelector: (SEL)selector
{






	return class_respondsToSelector(isa, selector);

}

- (BOOL)conformsToProtocol: (Protocol*)protocol
{
	return [isa conformsToProtocol: protocol];
}

- (IMP)methodForSelector: (SEL)selector
{
#if defined(OF_OBJFW_RUNTIME)
	return objc_msg_lookup(self, selector);
#else
	return class_getMethodImplementation(isa, selector);
#endif
}

- (id)performSelector: (SEL)selector
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
	const char *ret;

	if ((ret = objc_get_type_encoding(isa, selector)) == NULL)
		@throw [OFNotImplementedException exceptionWithClass: isa
							    selector: selector];

	return ret;
#elif defined(OF_OLD_GNU_RUNTIME)
	Method_t m;

	if ((m = class_get_instance_method(isa, selector)) == NULL ||
	    m->method_types == NULL)
		@throw [OFNotImplementedException exceptionWithClass: isa
							    selector: selector];

	return m->method_types;
#else
	Method m;
	const char *ret;

	if ((m = class_getInstanceMethod(isa, selector)) == NULL ||
	    (ret = method_getTypeEncoding(m)) == NULL)
		@throw [OFNotImplementedException exceptionWithClass: isa







<
<
<
<
<
<
<
<
<







571
572
573
574
575
576
577









578
579
580
581
582
583
584
	const char *ret;

	if ((ret = objc_get_type_encoding(isa, selector)) == NULL)
		@throw [OFNotImplementedException exceptionWithClass: isa
							    selector: selector];

	return ret;









#else
	Method m;
	const char *ret;

	if ((m = class_getInstanceMethod(isa, selector)) == NULL ||
	    (ret = method_getTypeEncoding(m)) == NULL)
		@throw [OFNotImplementedException exceptionWithClass: isa

Modified src/OFThread.m from [ee16dd390b] to [15c3b7304d].

23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#ifndef _WIN32
# include <unistd.h>
# include <sched.h>
#else
# include <windows.h>
#endif

#if defined(OF_GNU_RUNTIME) || defined(OF_OLD_GNU_RUNTIME)
# import <objc/thr.h>
#endif

#import "OFThread.h"
#import "OFList.h"
#import "OFDate.h"
#import "OFAutoreleasePool.h"

#import "OFConditionBroadcastFailedException.h"
#import "OFConditionSignalFailedException.h"







<
<
<
<







23
24
25
26
27
28
29




30
31
32
33
34
35
36
#ifndef _WIN32
# include <unistd.h>
# include <sched.h>
#else
# include <windows.h>
#endif





#import "OFThread.h"
#import "OFList.h"
#import "OFDate.h"
#import "OFAutoreleasePool.h"

#import "OFConditionBroadcastFailedException.h"
#import "OFConditionSignalFailedException.h"
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
static of_tlskey_t threadSelf;

static id
call_main(id object)
{
	OFThread *thread = (OFThread*)object;

#if defined(OF_GNU_RUNTIME) || defined(OF_OLD_GNU_RUNTIME)
	objc_thread_add();
#endif

	if (!of_tlskey_set(threadSelf, thread))
		@throw [OFInitializationFailedException
		    exceptionWithClass: [thread class]];

	/*
	 * Nasty workaround for thread implementations which can't return a
	 * value on join.







<
<
<
<







53
54
55
56
57
58
59




60
61
62
63
64
65
66
static of_tlskey_t threadSelf;

static id
call_main(id object)
{
	OFThread *thread = (OFThread*)object;





	if (!of_tlskey_set(threadSelf, thread))
		@throw [OFInitializationFailedException
		    exceptionWithClass: [thread class]];

	/*
	 * Nasty workaround for thread implementations which can't return a
	 * value on join.
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
	thread->running = OF_THREAD_WAITING_FOR_JOIN;

	[OFTLSKey callAllDestructors];
	[OFAutoreleasePool _releaseAll];

	[thread release];

#if defined(OF_GNU_RUNTIME) || defined(OF_OLD_GNU_RUNTIME)
	objc_thread_remove();
#endif

	return 0;
}

@implementation OFThread
#if defined(OF_HAVE_PROPERTIES) && defined(OF_HAVE_BLOCKS)
@synthesize block;
#endif







<
<
<
<







79
80
81
82
83
84
85




86
87
88
89
90
91
92
	thread->running = OF_THREAD_WAITING_FOR_JOIN;

	[OFTLSKey callAllDestructors];
	[OFAutoreleasePool _releaseAll];

	[thread release];





	return 0;
}

@implementation OFThread
#if defined(OF_HAVE_PROPERTIES) && defined(OF_HAVE_BLOCKS)
@synthesize block;
#endif
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
	}

	[OFTLSKey callAllDestructors];
	[OFAutoreleasePool _releaseAll];

	[thread release];

#if defined(OF_GNU_RUNTIME) || defined(OF_OLD_GNU_RUNTIME)
	objc_thread_remove();
#endif

	of_thread_exit();
}

- initWithObject: (id)object_
{
	self = [super init];








<
<
<
<







211
212
213
214
215
216
217




218
219
220
221
222
223
224
	}

	[OFTLSKey callAllDestructors];
	[OFAutoreleasePool _releaseAll];

	[thread release];





	of_thread_exit();
}

- initWithObject: (id)object_
{
	self = [super init];

Modified src/macros.h from [d255a09914] to [52ea94e401].

15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
 */

#import "OFObject.h"

#include <stddef.h>
#include <stdint.h>

#if defined(OF_APPLE_RUNTIME) || defined(OF_GNU_RUNTIME)
# import <objc/runtime.h>
#elif defined(OF_OLD_GNU_RUNTIME)
# import <objc/objc-api.h>
#endif

#ifdef _PSP
# define INTMAX_MAX LONG_LONG_MAX
#endif

#ifdef __GNUC__







|

<
<







15
16
17
18
19
20
21
22
23


24
25
26
27
28
29
30
 */

#import "OFObject.h"

#include <stddef.h>
#include <stdint.h>

#if defined(OF_APPLE_RUNTIME)
# import <objc/runtime.h>


#endif

#ifdef _PSP
# define INTMAX_MAX LONG_LONG_MAX
#endif

#ifdef __GNUC__
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# elif defined(__ppc__) || defined(__PPC__)
#  define OF_PPC_ASM
# elif defined(__arm__) || defined(__ARM__)
#  define OF_ARM_ASM
# endif
#endif

#if defined(OF_OLD_GNU_RUNTIME) || defined(OF_OBJFW_RUNTIME)
# define objc_lookUpClass objc_lookup_class
#endif

#ifdef OF_OLD_GNU_RUNTIME
# define class_getInstanceSize class_get_instance_size
# define class_getName class_get_class_name
# define class_getSuperclass class_get_super_class
# define sel_getName sel_get_name
# define sel_registerName sel_get_uid
#endif

#ifndef _WIN32
# define OF_PATH_DELIMITER '/'
#else
# define OF_PATH_DELIMITER '\\'
#endif

#define OF_IVAR_OFFSET(ivar) ((intptr_t)&ivar - (intptr_t)self)







|



<
<
<
<
<
<
<
<







70
71
72
73
74
75
76
77
78
79
80








81
82
83
84
85
86
87
# elif defined(__ppc__) || defined(__PPC__)
#  define OF_PPC_ASM
# elif defined(__arm__) || defined(__ARM__)
#  define OF_ARM_ASM
# endif
#endif

#ifdef OF_OBJFW_RUNTIME
# define objc_lookUpClass objc_lookup_class
#endif









#ifndef _WIN32
# define OF_PATH_DELIMITER '/'
#else
# define OF_PATH_DELIMITER '\\'
#endif

#define OF_IVAR_OFFSET(ivar) ((intptr_t)&ivar - (intptr_t)self)