ObjFW  Check-in [e1586f4dce]

Overview
Comment:A few casts to make Clang happy.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | runtime
Files: files | file ages | folders
SHA3-256: e1586f4dcec53985c3d2d94b3aa48c2794e6551972c53d8cab7f36b8d24a163e
User & Date: js on 2012-04-22 12:15:08
Other Links: branch diff | manifest | tags
Context
2012-04-22
15:56
Add class_registerAlias_np(). check-in: 8525f9600e user: js tags: runtime
12:15
A few casts to make Clang happy. check-in: e1586f4dce user: js tags: runtime
2012-04-21
13:47
Ensure all selectors are registered before load. check-in: d5236bb40e user: js tags: runtime
Changes

Modified src/runtime/lookup.m from [40605ab2a2] to [035f3dccce].

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
76
77
78
79
80
81

BOOL
class_respondsToSelector(Class cls, SEL sel)
{
	if (cls == Nil)
		return NO;

	return (objc_sparsearray_get(cls->dtable, sel->uid) != NULL ? YES : NO);

}

#if !defined(__ELF__) || (!defined(OF_X86_ASM) && !defined(OF_AMD64_ASM))
static id
nil_method(id self, SEL _cmd)
{
	return nil;
}

IMP
objc_msg_lookup(id obj, SEL sel)
{
	IMP imp;

	if (obj == nil)
		return (IMP)nil_method;

	if ((imp = objc_sparsearray_get(obj->isa->dtable, sel->uid)) == NULL)


		return objc_forward_handler(obj, sel);

	return imp;
}

IMP
objc_msg_lookup_super(struct objc_super *super, SEL sel)
{
	IMP imp;

	if (super->self == nil)
		return (IMP)nil_method;

	imp = objc_sparsearray_get(super->class->dtable, sel->uid);

	if (imp == NULL)
		return objc_forward_handler(super->self, sel);

	return imp;
}
#endif







|
>

















|
>
>













|







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
76
77
78
79
80
81
82
83
84

BOOL
class_respondsToSelector(Class cls, SEL sel)
{
	if (cls == Nil)
		return NO;

	return (objc_sparsearray_get(cls->dtable, (uint32_t)sel->uid) != NULL
	    ? YES : NO);
}

#if !defined(__ELF__) || (!defined(OF_X86_ASM) && !defined(OF_AMD64_ASM))
static id
nil_method(id self, SEL _cmd)
{
	return nil;
}

IMP
objc_msg_lookup(id obj, SEL sel)
{
	IMP imp;

	if (obj == nil)
		return (IMP)nil_method;

	imp = objc_sparsearray_get(obj->isa->dtable, (uint32_t)sel->uid);

	if (imp == NULL)
		return objc_forward_handler(obj, sel);

	return imp;
}

IMP
objc_msg_lookup_super(struct objc_super *super, SEL sel)
{
	IMP imp;

	if (super->self == nil)
		return (IMP)nil_method;

	imp = objc_sparsearray_get(super->class->dtable, (uint32_t)sel->uid);

	if (imp == NULL)
		return objc_forward_handler(super->self, sel);

	return imp;
}
#endif

Modified src/runtime/selector.m from [c0f228fae6] to [e0ff7d4f75].

101
102
103
104
105
106
107
108
109
110
111
112
113
114
115

const char*
sel_getName(SEL sel)
{
	const char *ret;

	objc_global_mutex_lock();
	ret = objc_sparsearray_get(selectors, sel->uid);
	objc_global_mutex_unlock();

	return ret;
}

BOOL
sel_isEqual(SEL sel1, SEL sel2)







|







101
102
103
104
105
106
107
108
109
110
111
112
113
114
115

const char*
sel_getName(SEL sel)
{
	const char *ret;

	objc_global_mutex_lock();
	ret = objc_sparsearray_get(selectors, (uint32_t)sel->uid);
	objc_global_mutex_unlock();

	return ret;
}

BOOL
sel_isEqual(SEL sel1, SEL sel2)

Modified src/runtime/sparsearray.m from [c1a8aea676] to [676c05892e].

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
76
77

static struct objc_sparsearray_level2 *empty_level2 = NULL;
static struct objc_sparsearray_level3 *empty_level3 = NULL;

static void
init(void)
{
	size_t i;

	empty_level2 = malloc(sizeof(struct objc_sparsearray_level2));
	empty_level3 = malloc(sizeof(struct objc_sparsearray_level3));

	if (empty_level2 == NULL || empty_level3 == NULL)
		ERROR("Not enough memory to allocate sparse array!");

	empty_level2->empty = YES;
	empty_level3->empty = YES;

	for (i = 0; i < 256; i++) {
		empty_level2->buckets[i] = empty_level3;
		empty_level3->buckets[i] = NULL;
	}
}

struct objc_sparsearray*
objc_sparsearray_new(void)
{
	struct objc_sparsearray *s;
	size_t i;

	if (empty_level2 == NULL || empty_level3 == NULL)
		init();

	if ((s = malloc(sizeof(struct objc_sparsearray))) == NULL)
		ERROR("Not enough memory to allocate sparse array!");

	for (i = 0; i < 256; i++)
		s->buckets[i] = empty_level2;

	return s;
}

void
objc_sparsearray_copy(struct objc_sparsearray *dst,
    struct objc_sparsearray *src)
{
	size_t i, j, k;
	uint32_t idx;

	for (i = 0; i < 256; i++) {
		if (src->buckets[i]->empty)
			continue;

		for (j = 0; j < 256; j++) {







|




















|

















|







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
76
77

static struct objc_sparsearray_level2 *empty_level2 = NULL;
static struct objc_sparsearray_level3 *empty_level3 = NULL;

static void
init(void)
{
	uint_fast16_t i;

	empty_level2 = malloc(sizeof(struct objc_sparsearray_level2));
	empty_level3 = malloc(sizeof(struct objc_sparsearray_level3));

	if (empty_level2 == NULL || empty_level3 == NULL)
		ERROR("Not enough memory to allocate sparse array!");

	empty_level2->empty = YES;
	empty_level3->empty = YES;

	for (i = 0; i < 256; i++) {
		empty_level2->buckets[i] = empty_level3;
		empty_level3->buckets[i] = NULL;
	}
}

struct objc_sparsearray*
objc_sparsearray_new(void)
{
	struct objc_sparsearray *s;
	uint_fast16_t i;

	if (empty_level2 == NULL || empty_level3 == NULL)
		init();

	if ((s = malloc(sizeof(struct objc_sparsearray))) == NULL)
		ERROR("Not enough memory to allocate sparse array!");

	for (i = 0; i < 256; i++)
		s->buckets[i] = empty_level2;

	return s;
}

void
objc_sparsearray_copy(struct objc_sparsearray *dst,
    struct objc_sparsearray *src)
{
	uint_fast16_t i, j, k;
	uint32_t idx;

	for (i = 0; i < 256; i++) {
		if (src->buckets[i]->empty)
			continue;

		for (j = 0; j < 256; j++) {
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
144
145
146
147
148
149
150
{
	uint8_t i = idx >> 16;
	uint8_t j = idx >>  8;
	uint8_t k = idx;

	if (s->buckets[i]->empty) {
		struct objc_sparsearray_level2 *t;
		size_t l;

		t = malloc(sizeof(struct objc_sparsearray_level2));

		if (t == NULL)
			ERROR("Not enough memory to insert into sparse array!");

		t->empty = NO;

		for (l = 0; l < 256; l++)
			t->buckets[l] = empty_level3;

		s->buckets[i] = t;
	}

	if (s->buckets[i]->buckets[j]->empty) {
		struct objc_sparsearray_level3 *t;
		size_t l;

		t = malloc(sizeof(struct objc_sparsearray_level3));

		if (t == NULL)
			ERROR("Not enough memory to insert into sparse array!");

		t->empty = NO;

		for (l = 0; l < 256; l++)
			t->buckets[l] = NULL;

		s->buckets[i]->buckets[j] = t;
	}

	s->buckets[i]->buckets[j]->buckets[k] = obj;
}

void
objc_sparsearray_free(struct objc_sparsearray *s)
{
	size_t i, j;

	for (i = 0; i < 256; i++) {
		if (s->buckets[i]->empty)
			continue;

		for (j = 0; j < 256; j++)
			if (!s->buckets[i]->buckets[j]->empty)







|
















|




















|







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
144
145
146
147
148
149
150
{
	uint8_t i = idx >> 16;
	uint8_t j = idx >>  8;
	uint8_t k = idx;

	if (s->buckets[i]->empty) {
		struct objc_sparsearray_level2 *t;
		uint_fast16_t l;

		t = malloc(sizeof(struct objc_sparsearray_level2));

		if (t == NULL)
			ERROR("Not enough memory to insert into sparse array!");

		t->empty = NO;

		for (l = 0; l < 256; l++)
			t->buckets[l] = empty_level3;

		s->buckets[i] = t;
	}

	if (s->buckets[i]->buckets[j]->empty) {
		struct objc_sparsearray_level3 *t;
		uint_fast16_t l;

		t = malloc(sizeof(struct objc_sparsearray_level3));

		if (t == NULL)
			ERROR("Not enough memory to insert into sparse array!");

		t->empty = NO;

		for (l = 0; l < 256; l++)
			t->buckets[l] = NULL;

		s->buckets[i]->buckets[j] = t;
	}

	s->buckets[i]->buckets[j]->buckets[k] = obj;
}

void
objc_sparsearray_free(struct objc_sparsearray *s)
{
	uint_fast16_t i, j;

	for (i = 0; i < 256; i++) {
		if (s->buckets[i]->empty)
			continue;

		for (j = 0; j < 256; j++)
			if (!s->buckets[i]->buckets[j]->empty)