ObjFW  Check-in [2fee820b5d]

Overview
Comment:runtime: Make object_isTaggedPointer() a function

If it is an inline, changing how tagged pointers work internally would
break the ABI and require recompiling everything, making future changes
harder.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 2fee820b5d52d27ccebe1ecee37383e3449382541df4488ca2c235eb0b7db53d
User & Date: js on 2020-09-29 22:21:14
Other Links: manifest | tags
Context
2020-09-29
22:28
OFDate: Use more autorelease pools check-in: 83f4c928a6 user: js tags: trunk
22:21
runtime: Make object_isTaggedPointer() a function check-in: 2fee820b5d user: js tags: trunk
21:36
Merge support for tagged pointers check-in: b4039f9a85 user: js tags: trunk
Changes

Modified src/runtime/ObjFWRT.h from [f60148ac98] to [17cc5dfe7d].

625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647

/*!
 * @brief Returns whether the specified object is a tagged pointer.
 *
 * @param object The object to inspect
 * @return Whether the specified object is a tagged pointer
 */
static inline bool
object_isTaggedPointer(id _Nullable object)
{
	uintptr_t pointer = (uintptr_t)object;

	return pointer & 1;
}

extern Class _Nullable object_getTaggedPointerClass(id _Nonnull object);

/*!
 * @brief Returns the value of the specified tagged pointer.
 *
 * @param object The object whose tagged pointer value should be returned
 * @return The tagged pointer value of the object
 */







<
|
<
<
<
<
<
<
<







625
626
627
628
629
630
631

632







633
634
635
636
637
638
639

/*!
 * @brief Returns whether the specified object is a tagged pointer.
 *
 * @param object The object to inspect
 * @return Whether the specified object is a tagged pointer
 */

extern bool object_isTaggedPointer(id _Nullable object);








/*!
 * @brief Returns the value of the specified tagged pointer.
 *
 * @param object The object whose tagged pointer value should be returned
 * @return The tagged pointer value of the object
 */

Modified src/runtime/amiga-glue.m from [d21e9a60b6] to [896aceecb7].

811
812
813
814
815
816
817








818
819
820
821
822
823
824
int __saveds
glue_objc_registerTaggedPointerClass PPC_PARAMS(Class class)
{
	M68K_ARG(Class, class, a0)

	return objc_registerTaggedPointerClass(class);
}









Class __saveds
glue_object_getTaggedPointerClass PPC_PARAMS(id object)
{
	M68K_ARG(id, object, a0)

	return object_getTaggedPointerClass(object);







>
>
>
>
>
>
>
>







811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
int __saveds
glue_objc_registerTaggedPointerClass PPC_PARAMS(Class class)
{
	M68K_ARG(Class, class, a0)

	return objc_registerTaggedPointerClass(class);
}

bool __saveds
glue_object_isTaggedPointer PPC_PARAMS(id object)
{
	M68K_ARG(id, object, a0)

	return object_isTaggedPointer(object);
}

Class __saveds
glue_object_getTaggedPointerClass PPC_PARAMS(id object)
{
	M68K_ARG(id, object, a0)

	return object_getTaggedPointerClass(object);

Modified src/runtime/amiga-library.m from [8a86d7c3a3] to [3b48513197].

145
146
147
148
149
150
151

152
153
154
155
156
157
158
159
160
161
extern struct objc_hashtable *glue_objc_hashtable_new(void);
extern void glue_objc_hashtable_set(void);
extern void *glue_objc_hashtable_get(void);
extern void glue_objc_hashtable_delete(void);
extern void glue_objc_hashtable_free(void);
extern void glue_objc_setTaggedPointerSecret(void);
extern int glue_objc_registerTaggedPointerClass(void);

extern Class _Nullable glue_object_getTaggedPointerClass(void);
extern uintptr_t glue_object_getTaggedPointerValue(void);
extern id _Nullable glue_objc_createTaggedPointer(void);

#ifdef OF_MORPHOS
const ULONG __abox__ = 1;
#endif
struct ExecBase *SysBase;
struct objc_libc libc;
FILE *stdout;







>
|

|







145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
extern struct objc_hashtable *glue_objc_hashtable_new(void);
extern void glue_objc_hashtable_set(void);
extern void *glue_objc_hashtable_get(void);
extern void glue_objc_hashtable_delete(void);
extern void glue_objc_hashtable_free(void);
extern void glue_objc_setTaggedPointerSecret(void);
extern int glue_objc_registerTaggedPointerClass(void);
extern bool glue_object_isTaggedPointer(void);
extern Class glue_object_getTaggedPointerClass(void);
extern uintptr_t glue_object_getTaggedPointerValue(void);
extern id glue_objc_createTaggedPointer(void);

#ifdef OF_MORPHOS
const ULONG __abox__ = 1;
#endif
struct ExecBase *SysBase;
struct objc_libc libc;
FILE *stdout;
676
677
678
679
680
681
682

683
684
685
686
687
688
689
	(CONST_APTR)glue_objc_hashtable_new,
	(CONST_APTR)glue_objc_hashtable_set,
	(CONST_APTR)glue_objc_hashtable_get,
	(CONST_APTR)glue_objc_hashtable_delete,
	(CONST_APTR)glue_objc_hashtable_free,
	(CONST_APTR)glue_objc_setTaggedPointerSecret,
	(CONST_APTR)glue_objc_registerTaggedPointerClass,

	(CONST_APTR)glue_object_getTaggedPointerClass,
	(CONST_APTR)glue_object_getTaggedPointerValue,
	(CONST_APTR)glue_objc_createTaggedPointer,
	(CONST_APTR)-1,
#ifdef OF_MORPHOS
	(CONST_APTR)FUNCARRAY_END
#endif







>







677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
	(CONST_APTR)glue_objc_hashtable_new,
	(CONST_APTR)glue_objc_hashtable_set,
	(CONST_APTR)glue_objc_hashtable_get,
	(CONST_APTR)glue_objc_hashtable_delete,
	(CONST_APTR)glue_objc_hashtable_free,
	(CONST_APTR)glue_objc_setTaggedPointerSecret,
	(CONST_APTR)glue_objc_registerTaggedPointerClass,
	(CONST_APTR)glue_object_isTaggedPointer,
	(CONST_APTR)glue_object_getTaggedPointerClass,
	(CONST_APTR)glue_object_getTaggedPointerValue,
	(CONST_APTR)glue_objc_createTaggedPointer,
	(CONST_APTR)-1,
#ifdef OF_MORPHOS
	(CONST_APTR)FUNCARRAY_END
#endif

Modified src/runtime/amigaos3.sfd from [5fcef80cc6] to [7f54fc7db5].

88
89
90
91
92
93
94

95
96
97
98
void glue_objc_hashtable_set(struct objc_hashtable *_Nonnull table, const void *_Nonnull key, const void *_Nonnull object)(a0,a1,a2)
void *_Nullable glue_objc_hashtable_get(struct objc_hashtable *_Nonnull table, const void *_Nonnull key)(a0,a1)
void glue_objc_hashtable_delete(struct objc_hashtable *_Nonnull table, const void *_Nonnull key)(a0,a1)
void glue_objc_hashtable_free(struct objc_hashtable *_Nonnull table)(a0)
* Public functions again
void glue_objc_setTaggedPointerSecret(uintptr_t secret)(d0)
int glue_objc_registerTaggedPointerClass(Class _Nonnull class_)(a0)

Class _Nullable glue_object_getTaggedPointerClass(id _Nonnull object)(a0)
uintptr_t glue_object_getTaggedPointerValue(id _Nonnull object)(a0)
id _Nullable glue_objc_createTaggedPointer(int class_, uintptr_t value)(d0,d1)
==end







>




88
89
90
91
92
93
94
95
96
97
98
99
void glue_objc_hashtable_set(struct objc_hashtable *_Nonnull table, const void *_Nonnull key, const void *_Nonnull object)(a0,a1,a2)
void *_Nullable glue_objc_hashtable_get(struct objc_hashtable *_Nonnull table, const void *_Nonnull key)(a0,a1)
void glue_objc_hashtable_delete(struct objc_hashtable *_Nonnull table, const void *_Nonnull key)(a0,a1)
void glue_objc_hashtable_free(struct objc_hashtable *_Nonnull table)(a0)
* Public functions again
void glue_objc_setTaggedPointerSecret(uintptr_t secret)(d0)
int glue_objc_registerTaggedPointerClass(Class _Nonnull class_)(a0)
bool glue_object_isTaggedPointer(id _Nullable object)(a0)
Class _Nullable glue_object_getTaggedPointerClass(id _Nonnull object)(a0)
uintptr_t glue_object_getTaggedPointerValue(id _Nonnull object)(a0)
id _Nullable glue_objc_createTaggedPointer(int class_, uintptr_t value)(d0,d1)
==end

Modified src/runtime/linklib/linklib.m from [674c07dbdb] to [f6ecf9cc72].

715
716
717
718
719
720
721






722
723
724
725
726
727
728
}

int
objc_registerTaggedPointerClass(Class class)
{
	return glue_objc_registerTaggedPointerClass(class);
}







Class
object_getTaggedPointerClass(id object)
{
	return glue_object_getTaggedPointerClass(object);
}








>
>
>
>
>
>







715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
}

int
objc_registerTaggedPointerClass(Class class)
{
	return glue_objc_registerTaggedPointerClass(class);
}

bool
object_isTaggedPointer(id object)
{
	return glue_object_isTaggedPointer(object);
}

Class
object_getTaggedPointerClass(id object)
{
	return glue_object_getTaggedPointerClass(object);
}

Modified src/runtime/morphos-clib.h from [f477f1a478] to [252cb36e71].

83
84
85
86
87
88
89

90
91
92
void glue_objc_hashtable_set(struct objc_hashtable *, const void *, const void *);
void *glue_objc_hashtable_get(struct objc_hashtable *, const void *);
void glue_objc_hashtable_delete(struct objc_hashtable *, const void *);
void glue_objc_hashtable_free(struct objc_hashtable *);
/* Public functions again */
void glue_objc_setTaggedPointerSecret(uintptr_t);
int glue_objc_registerTaggedPointerClass(Class);

Class _Nullable glue_object_getTaggedPointerClass(id);
uintptr_t glue_object_getTaggedPointerValue(id);
id glue_objc_createTaggedPointer(int, uintptr_t);







>



83
84
85
86
87
88
89
90
91
92
93
void glue_objc_hashtable_set(struct objc_hashtable *, const void *, const void *);
void *glue_objc_hashtable_get(struct objc_hashtable *, const void *);
void glue_objc_hashtable_delete(struct objc_hashtable *, const void *);
void glue_objc_hashtable_free(struct objc_hashtable *);
/* Public functions again */
void glue_objc_setTaggedPointerSecret(uintptr_t);
int glue_objc_registerTaggedPointerClass(Class);
bool glue_object_isTaggedPointer(id);
Class _Nullable glue_object_getTaggedPointerClass(id);
uintptr_t glue_object_getTaggedPointerValue(id);
id glue_objc_createTaggedPointer(int, uintptr_t);

Modified src/runtime/morphos.fd from [43f04663ca] to [881a580162].

86
87
88
89
90
91
92

93
94
95
96
glue_objc_hashtable_set(table,key,object)(sysv,r12base)
glue_objc_hashtable_get(table,key)(sysv,r12base)
glue_objc_hashtable_delete(table,key)(sysv,r12base)
glue_objc_hashtable_free(table)(sysv,r12base)
* Public functions again
glue_objc_setTaggedPointerSecret(secret)(sysv,r12base)
glue_objc_registerTaggedPointerClass(class_)(sysv,r12base)

glue_object_getTaggedPointerClass(object)(sysv,r12base)
glue_object_getTaggedPointerValue(object)(sysv,r12base)
glue_objc_createTaggedPointer(class_,value)(sysv,r12base)
##end







>




86
87
88
89
90
91
92
93
94
95
96
97
glue_objc_hashtable_set(table,key,object)(sysv,r12base)
glue_objc_hashtable_get(table,key)(sysv,r12base)
glue_objc_hashtable_delete(table,key)(sysv,r12base)
glue_objc_hashtable_free(table)(sysv,r12base)
* Public functions again
glue_objc_setTaggedPointerSecret(secret)(sysv,r12base)
glue_objc_registerTaggedPointerClass(class_)(sysv,r12base)
glue_object_isTaggedPointer(object)(sysv,r12base)
glue_object_getTaggedPointerClass(object)(sysv,r12base)
glue_object_getTaggedPointerValue(object)(sysv,r12base)
glue_objc_createTaggedPointer(class_,value)(sysv,r12base)
##end

Modified src/runtime/private.h from [44543549b6] to [7f0c22271c].

305
306
307
308
309
310
311

312
313
314
315
316
317
318
extern void objc_dtable_set(struct objc_dtable *_Nonnull, uint32_t,
    IMP _Nullable);
extern void objc_dtable_free(struct objc_dtable *_Nonnull);
extern void objc_dtable_cleanup(void);
extern void objc_init_static_instances(struct objc_symtab *_Nonnull);
extern void objc_forget_pending_static_instances(void);
extern void objc_zero_weak_references(id _Nonnull);

#ifdef OF_HAVE_THREADS
extern void objc_global_mutex_lock(void);
extern void objc_global_mutex_unlock(void);
extern void objc_global_mutex_free(void);
#else
# define objc_global_mutex_lock()
# define objc_global_mutex_unlock()







>







305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
extern void objc_dtable_set(struct objc_dtable *_Nonnull, uint32_t,
    IMP _Nullable);
extern void objc_dtable_free(struct objc_dtable *_Nonnull);
extern void objc_dtable_cleanup(void);
extern void objc_init_static_instances(struct objc_symtab *_Nonnull);
extern void objc_forget_pending_static_instances(void);
extern void objc_zero_weak_references(id _Nonnull);
extern Class _Nullable object_getTaggedPointerClass(id _Nonnull);
#ifdef OF_HAVE_THREADS
extern void objc_global_mutex_lock(void);
extern void objc_global_mutex_unlock(void);
extern void objc_global_mutex_free(void);
#else
# define objc_global_mutex_lock()
# define objc_global_mutex_unlock()

Modified src/runtime/tagged-pointer.m from [696420866c] to [347f048030].

47
48
49
50
51
52
53








54
55
56
57
58
59
60
	i = taggedPointerClassesCount++;
	objc_tagged_pointer_classes[i] = class;

	objc_global_mutex_unlock();

	return i;
}









Class
object_getTaggedPointerClass(id object)
{
	uintptr_t pointer = (uintptr_t)object ^ objc_tagged_pointer_secret;

	pointer &= (1 << TAGGED_POINTER_BITS) - 1;







>
>
>
>
>
>
>
>







47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
	i = taggedPointerClassesCount++;
	objc_tagged_pointer_classes[i] = class;

	objc_global_mutex_unlock();

	return i;
}

bool
object_isTaggedPointer(id object)
{
	uintptr_t pointer = (uintptr_t)object;

	return pointer & 1;
}

Class
object_getTaggedPointerClass(id object)
{
	uintptr_t pointer = (uintptr_t)object ^ objc_tagged_pointer_secret;

	pointer &= (1 << TAGGED_POINTER_BITS) - 1;

Modified tests/RuntimeTests.m from [33b8900615] to [eff11f992f].

97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
	else
		abort();

	TEST(@"Tagged pointers",
	    (cid1 = objc_registerTaggedPointerClass([OFString class])) != -1 &&
	    (cid2 = objc_registerTaggedPointerClass([OFNumber class])) != -1 &&
	    (object = objc_createTaggedPointer(cid2, (uintptr_t)value)) &&
	    object_getTaggedPointerClass(object) == [OFNumber class] &&
	    [object class] == [OFNumber class] &&
	    object_getTaggedPointerValue(object) == value &&
	    objc_createTaggedPointer(cid2, UINTPTR_MAX >> 4) != nil &&
	    objc_createTaggedPointer(cid2, (UINTPTR_MAX >> 4) + 1) == nil)
#endif

	objc_autoreleasePoolPop(pool);
}
@end







|









97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
	else
		abort();

	TEST(@"Tagged pointers",
	    (cid1 = objc_registerTaggedPointerClass([OFString class])) != -1 &&
	    (cid2 = objc_registerTaggedPointerClass([OFNumber class])) != -1 &&
	    (object = objc_createTaggedPointer(cid2, (uintptr_t)value)) &&
	    object_getClass(object) == [OFNumber class] &&
	    [object class] == [OFNumber class] &&
	    object_getTaggedPointerValue(object) == value &&
	    objc_createTaggedPointer(cid2, UINTPTR_MAX >> 4) != nil &&
	    objc_createTaggedPointer(cid2, (UINTPTR_MAX >> 4) + 1) == nil)
#endif

	objc_autoreleasePoolPop(pool);
}
@end