20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
#import "private.h"
#define TAGGED_POINTER_BITS 4
#define NUM_TAGGED_POINTER_CLASSES (1 << (TAGGED_POINTER_BITS - 1))
Class objc_tagged_pointer_classes[NUM_TAGGED_POINTER_CLASSES];
static int taggedPointerClassesCount;
int
objc_registerTaggedPointerClass(Class class)
{
int i;
objc_global_mutex_lock();
|
>
>
>
>
>
>
>
|
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
#import "private.h"
#define TAGGED_POINTER_BITS 4
#define NUM_TAGGED_POINTER_CLASSES (1 << (TAGGED_POINTER_BITS - 1))
Class objc_tagged_pointer_classes[NUM_TAGGED_POINTER_CLASSES];
static int taggedPointerClassesCount;
uintptr_t objc_tagged_pointer_secret;
void
objc_setTaggedPointerSecret(uintptr_t secret)
{
objc_tagged_pointer_secret = secret & ~(uintptr_t)1;
}
int
objc_registerTaggedPointerClass(Class class)
{
int i;
objc_global_mutex_lock();
|
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
85
86
87
|
return i;
}
Class
object_getTaggedPointerClass(id object)
{
uintptr_t pointer = (uintptr_t)object;
pointer &= (1 << TAGGED_POINTER_BITS) - 1;
pointer >>= 1;
if (pointer >= NUM_TAGGED_POINTER_CLASSES)
return Nil;
return objc_tagged_pointer_classes[pointer];
}
uintptr_t
object_getTaggedPointerValue(id object)
{
uintptr_t pointer = (uintptr_t)object;
pointer >>= TAGGED_POINTER_BITS;
return pointer;
}
id
objc_createTaggedPointer(int class, uintptr_t value)
{
uintptr_t pointer;
if (class < 0 || class >= NUM_TAGGED_POINTER_CLASSES)
return nil;
if (value > (UINTPTR_MAX >> TAGGED_POINTER_BITS))
return nil;
pointer = (class << 1) | 1;
pointer |= (value << TAGGED_POINTER_BITS);
return (id)pointer;
}
|
|
|
|
|
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
85
86
87
88
89
90
91
92
93
94
|
return i;
}
Class
object_getTaggedPointerClass(id object)
{
uintptr_t pointer = (uintptr_t)object ^ objc_tagged_pointer_secret;
pointer &= (1 << TAGGED_POINTER_BITS) - 1;
pointer >>= 1;
if (pointer >= NUM_TAGGED_POINTER_CLASSES)
return Nil;
return objc_tagged_pointer_classes[pointer];
}
uintptr_t
object_getTaggedPointerValue(id object)
{
uintptr_t pointer = (uintptr_t)object ^ objc_tagged_pointer_secret;
pointer >>= TAGGED_POINTER_BITS;
return pointer;
}
id
objc_createTaggedPointer(int class, uintptr_t value)
{
uintptr_t pointer;
if (class < 0 || class >= NUM_TAGGED_POINTER_CLASSES)
return nil;
if (value > (UINTPTR_MAX >> TAGGED_POINTER_BITS))
return nil;
pointer = (class << 1) | 1;
pointer |= (value << TAGGED_POINTER_BITS);
return (id)(pointer ^ objc_tagged_pointer_secret);
}
|