ObjFW  Check-in [120caad331]

Overview
Comment:Make runtime API more similar to Apple's.

This makes it easier to use runtime functions in portable code.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 120caad33130c217c839a2c619f841c4f4302aef747492de3d2eb041f1c0a5ab
User & Date: js on 2012-11-30 16:09:39
Other Links: manifest | tags
Context
2012-12-01
17:26
Add OFMapTable. check-in: 6f081c14f9 user: js tags: trunk
2012-11-30
16:09
Make runtime API more similar to Apple's. check-in: 120caad331 user: js tags: trunk
15:40
Remove inline that lead to a missing symbol. check-in: 3b58706d32 user: js tags: trunk
Changes

Modified src/macros.h from [1ed7809f51] to [f956fa931a].

114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#define OF_ENSURE(cond)							\
	if (!(cond)) {							\
		fprintf(stderr, "Failed to ensure condition in "	\
		    __FILE__ ":%d:\n" #cond "\n", __LINE__);		\
		abort();						\
	}

#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_PATH_PARENT_DIR @".."








<
<
<
<







114
115
116
117
118
119
120




121
122
123
124
125
126
127
#define OF_ENSURE(cond)							\
	if (!(cond)) {							\
		fprintf(stderr, "Failed to ensure condition in "	\
		    __FILE__ ":%d:\n" #cond "\n", __LINE__);		\
		abort();						\
	}





#ifndef _WIN32
# define OF_PATH_DELIMITER '/'
#else
# define OF_PATH_DELIMITER '\\'
#endif
#define OF_PATH_PARENT_DIR @".."

Modified src/runtime/class.m from [fb20a2022a] to [72c72347b1].

350
351
352
353
354
355
356
357

358
359
360
361
362
363
364
365

			if (load_queue == NULL)
				OBJC_ERROR("Not enough memory for load queue!");
		}
	}
}

Class

objc_lookup_class(const char *name)
{
	Class cls = objc_classname_to_class(name);

	if (cls == NULL)
		return Nil;

	if (cls->info & OBJC_CLASS_INFO_SETUP)







<
>
|







350
351
352
353
354
355
356

357
358
359
360
361
362
363
364
365

			if (load_queue == NULL)
				OBJC_ERROR("Not enough memory for load queue!");
		}
	}
}


id
objc_lookUpClass(const char *name)
{
	Class cls = objc_classname_to_class(name);

	if (cls == NULL)
		return Nil;

	if (cls->info & OBJC_CLASS_INFO_SETUP)
373
374
375
376
377
378
379





380

381
382
383
384
385
386
387
388
389












390
391
392
393
394
395
396

	if (!(cls->info & OBJC_CLASS_INFO_SETUP))
		return Nil;

	return cls;
}






Class

objc_get_class(const char *name)
{
	Class cls;

	if ((cls = objc_lookup_class(name)) == Nil)
		OBJC_ERROR("Class %s not found!", name);

	return cls;
}













const char*
class_getName(Class cls)
{
	return cls->name;
}








>
>
>
>
>
|
>
|



|




>
>
>
>
>
>
>
>
>
>
>
>







373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
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

	if (!(cls->info & OBJC_CLASS_INFO_SETUP))
		return Nil;

	return cls;
}

id
objc_getClass(const char *name)
{
	return objc_lookUpClass(name);
}

id
objc_getRequiredClass(const char *name)
{
	Class cls;

	if ((cls = objc_getClass(name)) == Nil)
		OBJC_ERROR("Class %s not found!", name);

	return cls;
}

Class
objc_lookup_class(const char *name)
{
	return objc_getClass(name);
}

Class
objc_get_class(const char *name)
{
	return objc_getRequiredClass(name);
}

const char*
class_getName(Class cls)
{
	return cls->name;
}

Modified src/runtime/exception.m from [e345b72019] to [d52bb65783].

433
434
435
436
437
438
439



440
441
442
443
444
445
446
447
			i = filter * size_for_encoding(lsda->typestable_enc);
			tmp = lsda->typestable - i;
			c = (uintptr_t)read_value(lsda->typestable_enc, &tmp);
			c = (uintptr_t)resolve_value(c, lsda->typestable_enc,
			    lsda->typestable - i, lsda->typestable_base);
#endif




			class = (c != 0 ? objc_get_class((const char*)c) : Nil);

			if (class_matches(class, e->object)) {
				*filtervalue = filter;
				return HANDLER_FOUND;
			}
		} else if (filter == 0)
			return CLEANUP_FOUND;







>
>
>
|







433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
			i = filter * size_for_encoding(lsda->typestable_enc);
			tmp = lsda->typestable - i;
			c = (uintptr_t)read_value(lsda->typestable_enc, &tmp);
			c = (uintptr_t)resolve_value(c, lsda->typestable_enc,
			    lsda->typestable - i, lsda->typestable_base);
#endif

			if (c != 0)
				class = objc_getRequiredClass((const char*)c);
			else
				class = Nil;

			if (class_matches(class, e->object)) {
				*filtervalue = filter;
				return HANDLER_FOUND;
			}
		} else if (filter == 0)
			return CLEANUP_FOUND;

Modified src/runtime/runtime.h from [865d6eebac] to [d874182359].

165
166
167
168
169
170
171
172
173

174
175
176
177
178
179
180
#define NO  (BOOL)0

typedef void (*objc_uncaught_exception_handler)(id);

extern SEL sel_registerName(const char*);
extern const char* sel_getName(SEL);
extern BOOL sel_isEqual(SEL, SEL);
extern Class objc_get_class(const char*);
extern Class objc_lookup_class(const char*);

extern const char* class_getName(Class);
extern Class class_getSuperclass(Class);
extern BOOL class_isKindOfClass(Class, Class);
extern unsigned long class_getInstanceSize(Class);
extern BOOL class_respondsToSelector(Class, SEL);
extern BOOL class_conformsToProtocol(Class, Protocol*);
extern IMP class_getMethodImplementation(Class, SEL);







|
|
>







165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#define NO  (BOOL)0

typedef void (*objc_uncaught_exception_handler)(id);

extern SEL sel_registerName(const char*);
extern const char* sel_getName(SEL);
extern BOOL sel_isEqual(SEL, SEL);
extern id objc_lookUpClass(const char*);
extern id objc_getClass(const char*);
extern id objc_getRequiredClass(const char*);
extern const char* class_getName(Class);
extern Class class_getSuperclass(Class);
extern BOOL class_isKindOfClass(Class, Class);
extern unsigned long class_getInstanceSize(Class);
extern BOOL class_respondsToSelector(Class, SEL);
extern BOOL class_conformsToProtocol(Class, Protocol*);
extern IMP class_getMethodImplementation(Class, SEL);

Modified src/runtime/static-instances.m from [f95b35ea0d] to [7e14b89af0].

29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
objc_init_static_instances(struct objc_abi_symtab *symtab)
{
	struct objc_abi_static_instances **si;
	size_t i;

	/* Check if the class for a static instance became available */
	for (i = 0; i < static_instances_cnt; i++) {
		Class cls = objc_lookup_class(static_instances[i]->class_name);

		if (cls != Nil) {
			id *instances;

			for (instances = static_instances[i]->instances;
			    *instances != nil; instances++)
				object_setClass(*instances, cls);







|







29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
objc_init_static_instances(struct objc_abi_symtab *symtab)
{
	struct objc_abi_static_instances **si;
	size_t i;

	/* Check if the class for a static instance became available */
	for (i = 0; i < static_instances_cnt; i++) {
		Class cls = objc_lookUpClass(static_instances[i]->class_name);

		if (cls != Nil) {
			id *instances;

			for (instances = static_instances[i]->instances;
			    *instances != nil; instances++)
				object_setClass(*instances, cls);
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
	si = (struct objc_abi_static_instances**)
	    symtab->defs[symtab->cls_def_cnt + symtab->cat_def_cnt];

	if (si == NULL)
		return;

	for (; *si != NULL; si++) {
		Class cls = objc_lookup_class((*si)->class_name);

		if (cls != Nil) {
			id *instances;

			for (instances = (*si)->instances; *instances != nil;
			    instances++)
				object_setClass(*instances, cls);







|







66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
	si = (struct objc_abi_static_instances**)
	    symtab->defs[symtab->cls_def_cnt + symtab->cat_def_cnt];

	if (si == NULL)
		return;

	for (; *si != NULL; si++) {
		Class cls = objc_lookUpClass((*si)->class_name);

		if (cls != Nil) {
			id *instances;

			for (instances = (*si)->instances; *instances != nil;
			    instances++)
				object_setClass(*instances, cls);

Modified tests/OFBlockTests.m from [b8c56f759a] to [7a082a1b83].

21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#import "OFAutoreleasePool.h"

#if defined(OF_OBJFW_RUNTIME)
# include "runtime.h"
#elif defined(OF_APPLE_RUNTIME)
# include <objc/runtime.h>
#endif
#ifdef OF_OBJFW_RUNTIME
# define objc_getClass objc_get_class
#endif

#import "TestsAppDelegate.h"

static OFString *module = @"OFBlock";

extern void *_NSConcreteStackBlock;
extern void *_NSConcreteGlobalBlock;







<
<
<







21
22
23
24
25
26
27



28
29
30
31
32
33
34
#import "OFAutoreleasePool.h"

#if defined(OF_OBJFW_RUNTIME)
# include "runtime.h"
#elif defined(OF_APPLE_RUNTIME)
# include <objc/runtime.h>
#endif




#import "TestsAppDelegate.h"

static OFString *module = @"OFBlock";

extern void *_NSConcreteStackBlock;
extern void *_NSConcreteGlobalBlock;