ObjFW  Check-in [f2fe8f96d5]

Overview
Comment:Move autorelease pools to runtime
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: f2fe8f96d5512dcd960b70921d36a0f9319c3b5cf3d8dddc2dd69a1761205d96
User & Date: js on 2020-01-02 22:16:48
Other Links: manifest | tags
Context
2020-01-03
00:23
OFSecureData: Remove duplicate methods check-in: 2e910c40f1 user: js tags: trunk
2020-01-02
22:16
Move autorelease pools to runtime check-in: f2fe8f96d5 user: js tags: trunk
01:51
Update copyright check-in: c7f0229795 user: js tags: trunk
Changes

Modified src/Makefile from [3a17fda84f] to [73e066fe5a].

174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
	    OFKernelEventObserver.h		\
	    OFKeyValueCoding.h			\
	    OFLocking.h				\
	    OFMessagePackRepresentation.h	\
	    OFSerialization.h			\
	    OFTLSSocket.h			\
	    ObjFW.h				\
	    autorelease.h			\
	    block.h				\
	    macros.h				\
	    objfw-defs.h			\
	    platform.h				\
	    ${USE_INCLUDES_ATOMIC}

SRCS += OFAdjacentArray.m		\







<







174
175
176
177
178
179
180

181
182
183
184
185
186
187
	    OFKernelEventObserver.h		\
	    OFKeyValueCoding.h			\
	    OFLocking.h				\
	    OFMessagePackRepresentation.h	\
	    OFSerialization.h			\
	    OFTLSSocket.h			\
	    ObjFW.h				\

	    block.h				\
	    macros.h				\
	    objfw-defs.h			\
	    platform.h				\
	    ${USE_INCLUDES_ATOMIC}

SRCS += OFAdjacentArray.m		\
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
	OFPointValue.m			\
	OFPointerValue.m		\
	OFRangeCharacterSet.m		\
	OFRangeValue.m			\
	OFRectangleValue.m		\
	OFSubarray.m			\
	OFUTF8String.m			\
	${AUTORELEASE_M}		\
	${LIBBASES_M}
SRCS_FILES += OFFileURLHandler.m	\
	      OFINIFileSettings.m
SRCS_SOCKETS += OFDNSResolverSettings.m			\
		OFHTTPURLHandler.m			\
		OFHostAddressResolver.m			\
		OFKernelEventObserver.m			\







<







202
203
204
205
206
207
208

209
210
211
212
213
214
215
	OFPointValue.m			\
	OFPointerValue.m		\
	OFRangeCharacterSet.m		\
	OFRangeValue.m			\
	OFRectangleValue.m		\
	OFSubarray.m			\
	OFUTF8String.m			\

	${LIBBASES_M}
SRCS_FILES += OFFileURLHandler.m	\
	      OFINIFileSettings.m
SRCS_SOCKETS += OFDNSResolverSettings.m			\
		OFHTTPURLHandler.m			\
		OFHostAddressResolver.m			\
		OFKernelEventObserver.m			\

Modified src/OFObject.h from [8e7d1bdd71] to [67744f52d1].

26
27
28
29
30
31
32
33
34
35
36
37
38
39
40

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

#import "macros.h"
#import "autorelease.h"
#import "block.h"

/*
 * Some versions of MinGW require <winsock2.h> to be included before
 * <windows.h>. Do this here to make sure this is always done in the correct
 * order, even if another header includes just <windows.h>.
 */







<







26
27
28
29
30
31
32

33
34
35
36
37
38
39

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

#import "macros.h"

#import "block.h"

/*
 * Some versions of MinGW require <winsock2.h> to be included before
 * <windows.h>. Do this here to make sure this is always done in the correct
 * order, even if another header includes just <windows.h>.
 */
1273
1274
1275
1276
1277
1278
1279




1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
 */
- (of_comparison_result_t)compare: (id <OFComparing>)object;
@end

#ifdef __cplusplus
extern "C" {
#endif




extern id of_alloc_object(Class class_, size_t extraSize,
    size_t extraAlignment, void *_Nullable *_Nullable extra);
extern void OF_NO_RETURN_FUNC of_method_not_found(id self, SEL _cmd);
extern uint32_t of_hash_seed;
#ifdef __cplusplus
}
#endif

OF_ASSUME_NONNULL_END

#import "OFObject+KeyValueCoding.h"
#import "OFObject+Serialization.h"







>
>
>
>












1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
 */
- (of_comparison_result_t)compare: (id <OFComparing>)object;
@end

#ifdef __cplusplus
extern "C" {
#endif
#ifdef OF_APPLE_RUNTIME
extern void *_Null_unspecified objc_autoreleasePoolPush(void);
extern void objc_autoreleasePoolPop(void *_Null_unspecified pool);
#endif
extern id of_alloc_object(Class class_, size_t extraSize,
    size_t extraAlignment, void *_Nullable *_Nullable extra);
extern void OF_NO_RETURN_FUNC of_method_not_found(id self, SEL _cmd);
extern uint32_t of_hash_seed;
#ifdef __cplusplus
}
#endif

OF_ASSUME_NONNULL_END

#import "OFObject+KeyValueCoding.h"
#import "OFObject+Serialization.h"

Modified src/OFObject.m from [b21ded3e9c] to [d6b3535b02].

62
63
64
65
66
67
68



69
70
71
72
73
74
75

#if defined(OF_HAVE_ATOMIC_OPS)
# import "atomic.h"
#elif defined(OF_HAVE_THREADS)
# import "mutex.h"
#endif




#if defined(OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR)
extern id of_forward(id, SEL, ...);
extern struct stret of_forward_stret(id, SEL, ...);
#else
# define of_forward of_method_not_found
# define of_forward_stret of_method_not_found_stret
#endif







>
>
>







62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78

#if defined(OF_HAVE_ATOMIC_OPS)
# import "atomic.h"
#elif defined(OF_HAVE_THREADS)
# import "mutex.h"
#endif

#ifdef OF_APPLE_RUNTIME
extern id _Nullable _objc_rootAutorelease(id _Nullable object);
#endif
#if defined(OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR)
extern id of_forward(id, SEL, ...);
extern struct stret of_forward_stret(id, SEL, ...);
#else
# define of_forward of_method_not_found
# define of_forward_stret of_method_not_found_stret
#endif

Deleted src/autorelease.h version [4417be87e8].

1
2
3
4
5
6
7
8
9
10
11
12
13
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
/*
 * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
 *               2018, 2019, 2020
 *   Jonathan Schleifer <js@nil.im>
 *
 * All rights reserved.
 *
 * This file is part of ObjFW. It may be distributed under the terms of the
 * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
 * the packaging of this file.
 *
 * Alternatively, it may be distributed under the terms of the GNU General
 * Public License, either version 2 or 3, which can be found in the file
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#import "macros.h"

OF_ASSUME_NONNULL_BEGIN

/*! @file */

#ifdef __cplusplus
extern "C" {
#endif
/*!
 * @brief Creates a new autorelease pool.
 *
 * @return An identifier for the created autorelease pool
 */
extern void *objc_autoreleasePoolPush(void);

/*!
 * @brief Drains an autorelease pool.
 *
 * @param pool An identifier for the pool to drain
 */
extern void objc_autoreleasePoolPop(void *pool);

/*!
 * @brief Autoreleases an object.
 *
 * @param object The object to autorelease
 * @return The autoreleased object
 */
extern id _objc_rootAutorelease(id object);
#ifdef __cplusplus
}
#endif

OF_ASSUME_NONNULL_END
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<








































































































Deleted src/autorelease.m version [b12aba3e31].

1
2
3
4
5
6
7
8
9
10
11
12
13
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
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
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
/*
 * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
 *               2018, 2019, 2020
 *   Jonathan Schleifer <js@nil.im>
 *
 * All rights reserved.
 *
 * This file is part of ObjFW. It may be distributed under the terms of the
 * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
 * the packaging of this file.
 *
 * Alternatively, it may be distributed under the terms of the GNU General
 * Public License, either version 2 or 3, which can be found in the file
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#include "config.h"

#include <stdio.h>
#include <stdlib.h>

#import "OFObject.h"
#import "OFSystemInfo.h"

#if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS)
# import "tlskey.h"
#endif

#if defined(OF_HAVE_COMPILER_TLS)
static thread_local id *objects = NULL;
static thread_local id *top = NULL;
static thread_local size_t size = 0;
#elif defined(OF_HAVE_THREADS)
static of_tlskey_t objectsKey, topKey, sizeKey;
#else
static id *objects = NULL;
static id *top = NULL;
static size_t size = 0;
#endif

#if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS)
OF_CONSTRUCTOR()
{
	OF_ENSURE(of_tlskey_new(&objectsKey));
	OF_ENSURE(of_tlskey_new(&topKey));
	OF_ENSURE(of_tlskey_new(&sizeKey));
}
#endif

void *
objc_autoreleasePoolPush()
{
#if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS)
	id *top = of_tlskey_get(topKey);
	id *objects = of_tlskey_get(objectsKey);
#endif
	ptrdiff_t offset = top - objects;

	return (void *)offset;
}

void
objc_autoreleasePoolPop(void *offset)
{
#if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS)
	id *top = of_tlskey_get(topKey);
	id *objects = of_tlskey_get(objectsKey);
#endif
	id *pool = objects + (ptrdiff_t)offset;
	id *iter;

	for (iter = pool; iter < top; iter++)
		[*iter release];

	top = pool;

	if (top == objects) {
		free(objects);

		objects = NULL;
		top = NULL;
	}

#if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS)
	OF_ENSURE(of_tlskey_set(topKey, top));
	OF_ENSURE(of_tlskey_set(objectsKey, objects));
#endif
}

id
_objc_rootAutorelease(id object)
{
#if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS)
	id *top = of_tlskey_get(topKey);
	id *objects = of_tlskey_get(objectsKey);
	size_t size = (size_t)(uintptr_t)of_tlskey_get(sizeKey);
#endif

	if (objects == NULL) {
		size = [OFSystemInfo pageSize];

		OF_ENSURE((objects = malloc(size)) != NULL);

		top = objects;

#if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS)
		OF_ENSURE(of_tlskey_set(objectsKey, objects));
		OF_ENSURE(of_tlskey_set(sizeKey, (void *)(uintptr_t)size));
#endif
	}

	if ((uintptr_t)top >= (uintptr_t)objects + size) {
		ptrdiff_t diff = top - objects;

		size += [OFSystemInfo pageSize];
		OF_ENSURE((objects = realloc(objects, size)) != NULL);

#if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS)
		OF_ENSURE(of_tlskey_set(objectsKey, objects));
		OF_ENSURE(of_tlskey_set(sizeKey, (void *)(uintptr_t)size));
#endif

		top = objects + diff;
	}

	*top = object;
	top++;

#if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS)
	OF_ENSURE(of_tlskey_set(topKey, top));
#endif

	return object;
}
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<














































































































































































































































































Modified src/runtime/Makefile from [c147b029c7] to [c796547f2c].

8
9
10
11
12
13
14

15
16
17
18
19
20
21
STATIC_LIB = ${OBJFWRT_STATIC_LIB}
FRAMEWORK = ${OBJFWRT_FRAMEWORK}
AMIGA_LIB = ${OBJFWRT_AMIGA_LIB}
LIB_MAJOR = ${OBJFWRT_LIB_MAJOR}
LIB_MINOR = ${OBJFWRT_LIB_MINOR}

SRCS = arc.m			\

       category.m		\
       class.m			\
       dtable.m			\
       exception.m		\
       hashtable.m		\
       init.m			\
       instance.m		\







>







8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
STATIC_LIB = ${OBJFWRT_STATIC_LIB}
FRAMEWORK = ${OBJFWRT_FRAMEWORK}
AMIGA_LIB = ${OBJFWRT_AMIGA_LIB}
LIB_MAJOR = ${OBJFWRT_LIB_MAJOR}
LIB_MINOR = ${OBJFWRT_LIB_MINOR}

SRCS = arc.m			\
       autorelease.m		\
       category.m		\
       class.m			\
       dtable.m			\
       exception.m		\
       hashtable.m		\
       init.m			\
       instance.m		\

Modified src/runtime/ObjFWRT.h from [72c497c1d6] to [ce979e873f].

147
148
149
150
151
152
153



154
155
156
157
158
159
160
extern void objc_setForwardHandler(IMP _Nullable forward,
    IMP _Nullable stretForward);
extern void objc_setEnumerationMutationHandler(
    objc_enumeration_mutation_handler_t _Nullable handler);
extern id _Nullable objc_constructInstance(Class _Nullable class_,
    void *_Nullable bytes);
extern void *_Nullable objc_destructInstance(id _Nullable object);




/*
 * Used by the compiler, but can also be called manually.
 *
 * These declarations are also required to prevent Clang's implicit
 * declarations which include __declspec(dllimport) on Windows.
 */







>
>
>







147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
extern void objc_setForwardHandler(IMP _Nullable forward,
    IMP _Nullable stretForward);
extern void objc_setEnumerationMutationHandler(
    objc_enumeration_mutation_handler_t _Nullable handler);
extern id _Nullable objc_constructInstance(Class _Nullable class_,
    void *_Nullable bytes);
extern void *_Nullable objc_destructInstance(id _Nullable object);
extern void *_Null_unspecified objc_autoreleasePoolPush(void);
extern void objc_autoreleasePoolPop(void *_Null_unspecified pool);
extern id _Nullable _objc_rootAutorelease(id _Nullable object);

/*
 * Used by the compiler, but can also be called manually.
 *
 * These declarations are also required to prevent Clang's implicit
 * declarations which include __declspec(dllimport) on Windows.
 */

Modified src/runtime/amiga-glue.m from [c9d4372ce7] to [67a0ee932e].

723
724
725
726
727
728
729






















void *__saveds
glue_objc_destructInstance PPC_PARAMS(id object)
{
	M68K_ARG(id, object, a0)

	return objc_destructInstance(object);
}





























>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
void *__saveds
glue_objc_destructInstance PPC_PARAMS(id object)
{
	M68K_ARG(id, object, a0)

	return objc_destructInstance(object);
}

void *__saveds
glue_objc_autoreleasePoolPush(void)
{
	return objc_autoreleasePoolPush();
}

void __saveds
glue_objc_autoreleasePoolPop PPC_PARAMS(void *pool)
{
	M68K_ARG(void *, pool, a0)

	objc_autoreleasePoolPop(pool);
}

id __saveds
glue__objc_rootAutorelease PPC_PARAMS(id object)
{
	M68K_ARG(id, object, a0)

	return _objc_rootAutorelease(object);
}

Modified src/runtime/amiga-library.m from [a349e70338] to [e964a079fa].

135
136
137
138
139
140
141



142
143
144
145
146
147
148
extern Method *glue_class_copyMethodList(void);
extern SEL glue_method_getName(void);
extern const char *glue_method_getTypeEncoding(void);
extern objc_property_t *glue_class_copyPropertyList(void);
extern const char *glue_property_getName(void);
extern char *glue_property_copyAttributeValue(void);
extern void *glue_objc_destructInstance(void);




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







>
>
>







135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
extern Method *glue_class_copyMethodList(void);
extern SEL glue_method_getName(void);
extern const char *glue_method_getTypeEncoding(void);
extern objc_property_t *glue_class_copyPropertyList(void);
extern const char *glue_property_getName(void);
extern char *glue_property_copyAttributeValue(void);
extern void *glue_objc_destructInstance(void);
extern void *glue_objc_autoreleasePoolPush(void);
extern void glue_objc_autoreleasePoolPop(void);
extern id glue__objc_rootAutorelease(void);

#ifdef OF_MORPHOS
const ULONG __abox__ = 1;
#endif
struct ExecBase *SysBase;
struct objc_libc libc;
FILE *stdout;
653
654
655
656
657
658
659



660
661
662
663
664
665
666
	(CONST_APTR)glue_class_copyMethodList,
	(CONST_APTR)glue_method_getName,
	(CONST_APTR)glue_method_getTypeEncoding,
	(CONST_APTR)glue_class_copyPropertyList,
	(CONST_APTR)glue_property_getName,
	(CONST_APTR)glue_property_copyAttributeValue,
	(CONST_APTR)glue_objc_destructInstance,



	(CONST_APTR)-1,
#ifdef OF_MORPHOS
	(CONST_APTR)FUNCARRAY_END
#endif
};
#pragma GCC diagnostic pop








>
>
>







656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
	(CONST_APTR)glue_class_copyMethodList,
	(CONST_APTR)glue_method_getName,
	(CONST_APTR)glue_method_getTypeEncoding,
	(CONST_APTR)glue_class_copyPropertyList,
	(CONST_APTR)glue_property_getName,
	(CONST_APTR)glue_property_copyAttributeValue,
	(CONST_APTR)glue_objc_destructInstance,
	(CONST_APTR)glue_objc_autoreleasePoolPush,
	(CONST_APTR)glue_objc_autoreleasePoolPop,
	(CONST_APTR)glue__objc_rootAutorelease,
	(CONST_APTR)-1,
#ifdef OF_MORPHOS
	(CONST_APTR)FUNCARRAY_END
#endif
};
#pragma GCC diagnostic pop

Modified src/runtime/amigaos3.sfd from [4e4fca08ce] to [c02a06707d].

78
79
80
81
82
83
84



85
Method _Nullable *_Nullable glue_class_copyMethodList(Class _Nullable class_, unsigned int *_Nullable outCount)(a0,a1)
SEL _Nonnull glue_method_getName(Method _Nonnull method)(a0)
const char *_Nullable glue_method_getTypeEncoding(Method _Nonnull method)(a0)
objc_property_t _Nullable *_Nullable glue_class_copyPropertyList(Class _Nullable class_, unsigned int *_Nullable outCount)(a0,a1)
const char *_Nonnull glue_property_getName(objc_property_t _Nonnull property)(a0)
char *_Nullable glue_property_copyAttributeValue(objc_property_t _Nonnull property, const char *_Nonnull name)(a0,a1)
void *_Nullable glue_objc_destructInstance(id _Nullable object)(a0)



==end







>
>
>

78
79
80
81
82
83
84
85
86
87
88
Method _Nullable *_Nullable glue_class_copyMethodList(Class _Nullable class_, unsigned int *_Nullable outCount)(a0,a1)
SEL _Nonnull glue_method_getName(Method _Nonnull method)(a0)
const char *_Nullable glue_method_getTypeEncoding(Method _Nonnull method)(a0)
objc_property_t _Nullable *_Nullable glue_class_copyPropertyList(Class _Nullable class_, unsigned int *_Nullable outCount)(a0,a1)
const char *_Nonnull glue_property_getName(objc_property_t _Nonnull property)(a0)
char *_Nullable glue_property_copyAttributeValue(objc_property_t _Nonnull property, const char *_Nonnull name)(a0,a1)
void *_Nullable glue_objc_destructInstance(id _Nullable object)(a0)
void *_Null_unspecified glue_objc_autoreleasePoolPush(void)()
void glue_objc_autoreleasePoolPop(void *_Null_unspecified pool)(a0)
id _Nullable glue__objc_rootAutorelease(id _Nullable object)(a0)
==end

Modified src/runtime/arc.m from [7e83394958] to [7f174d7d34].

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

#include "config.h"

#import "ObjFWRT.h"
#import "private.h"

#import "OFObject.h"
#import "OFBlock.h"

#ifdef OF_HAVE_THREADS
# import "mutex.h"
#endif

struct weak_ref {
	id **locations;
	size_t count;







<
<
<







16
17
18
19
20
21
22



23
24
25
26
27
28
29
 */

#include "config.h"

#import "ObjFWRT.h"
#import "private.h"




#ifdef OF_HAVE_THREADS
# import "mutex.h"
#endif

struct weak_ref {
	id **locations;
	size_t count;

Added src/runtime/autorelease.m version [6a15e61b81].















































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
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
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
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
/*
 * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
 *               2018, 2019, 2020
 *   Jonathan Schleifer <js@nil.im>
 *
 * All rights reserved.
 *
 * This file is part of ObjFW. It may be distributed under the terms of the
 * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
 * the packaging of this file.
 *
 * Alternatively, it may be distributed under the terms of the GNU General
 * Public License, either version 2 or 3, which can be found in the file
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#include "config.h"

#include <stdio.h>
#include <stdlib.h>

#import "ObjFWRT.h"
#import "private.h"

#if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS)
# import "tlskey.h"
#endif

#if defined(OF_HAVE_COMPILER_TLS)
static thread_local id *objects = NULL;
static thread_local id *top = NULL;
static thread_local size_t size = 0;
#elif defined(OF_HAVE_THREADS)
static of_tlskey_t objectsKey, topKey, sizeKey;
#else
static id *objects = NULL;
static id *top = NULL;
static size_t size = 0;
#endif

#if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS)
OF_CONSTRUCTOR()
{
	OF_ENSURE(of_tlskey_new(&objectsKey));
	OF_ENSURE(of_tlskey_new(&topKey));
	OF_ENSURE(of_tlskey_new(&sizeKey));
}
#endif

void *
objc_autoreleasePoolPush()
{
#if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS)
	id *top = of_tlskey_get(topKey);
	id *objects = of_tlskey_get(objectsKey);
#endif
	ptrdiff_t offset = top - objects;

	return (void *)offset;
}

void
objc_autoreleasePoolPop(void *offset)
{
#if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS)
	id *top = of_tlskey_get(topKey);
	id *objects = of_tlskey_get(objectsKey);
#endif
	id *pool = objects + (ptrdiff_t)offset;
	id *iter;

	for (iter = pool; iter < top; iter++)
		[*iter release];

	top = pool;

	if (top == objects) {
		free(objects);

		objects = NULL;
		top = NULL;
	}

#if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS)
	OF_ENSURE(of_tlskey_set(topKey, top));
	OF_ENSURE(of_tlskey_set(objectsKey, objects));
#endif
}

id
_objc_rootAutorelease(id object)
{
#if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS)
	id *top = of_tlskey_get(topKey);
	id *objects = of_tlskey_get(objectsKey);
	size_t size = (size_t)(uintptr_t)of_tlskey_get(sizeKey);
#endif

	if (objects == NULL) {
		size = 16 * sizeof(id);

		OF_ENSURE((objects = malloc(size)) != NULL);

		top = objects;

#if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS)
		OF_ENSURE(of_tlskey_set(objectsKey, objects));
		OF_ENSURE(of_tlskey_set(sizeKey, (void *)(uintptr_t)size));
#endif
	}

	if ((uintptr_t)top >= (uintptr_t)objects + size) {
		ptrdiff_t diff = top - objects;

		size *= 2;
		OF_ENSURE((objects = realloc(objects, size)) != NULL);

#if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS)
		OF_ENSURE(of_tlskey_set(objectsKey, objects));
		OF_ENSURE(of_tlskey_set(sizeKey, (void *)(uintptr_t)size));
#endif

		top = objects + diff;
	}

	*top = object;
	top++;

#if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS)
	OF_ENSURE(of_tlskey_set(topKey, top));
#endif

	return object;
}

Modified src/runtime/linklib/linklib.m from [7a6ee768ac] to [af59ade95f].

653
654
655
656
657
658
659


















}

void *
objc_destructInstance(id object)
{
	return glue_objc_destructInstance(object);
}

























>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
}

void *
objc_destructInstance(id object)
{
	return glue_objc_destructInstance(object);
}

void *
objc_autoreleasePoolPush(void)
{
	return glue_objc_autoreleasePoolPush();
}

void
objc_autoreleasePoolPop(void *pool)
{
	glue_objc_autoreleasePoolPop(pool);
}

id
_objc_rootAutorelease(id object)
{
	return glue__objc_rootAutorelease(object);
}

Modified src/runtime/morphos-clib.h from [c45411ce53] to [407871c4d0].

72
73
74
75
76
77
78



Method *glue_class_copyMethodList(Class class_, unsigned int *outCount);
SEL glue_method_getName(Method method);
const char *glue_method_getTypeEncoding(Method method);
objc_property_t *glue_class_copyPropertyList(Class class_, unsigned int *outCount);
const char *glue_property_getName(objc_property_t property);
char *glue_property_copyAttributeValue(objc_property_t property, const char *name);
void *glue_objc_destructInstance(id object);










>
>
>
72
73
74
75
76
77
78
79
80
81
Method *glue_class_copyMethodList(Class class_, unsigned int *outCount);
SEL glue_method_getName(Method method);
const char *glue_method_getTypeEncoding(Method method);
objc_property_t *glue_class_copyPropertyList(Class class_, unsigned int *outCount);
const char *glue_property_getName(objc_property_t property);
char *glue_property_copyAttributeValue(objc_property_t property, const char *name);
void *glue_objc_destructInstance(id object);
void *glue_objc_autoreleasePoolPush(void);
void glue_objc_autoreleasePoolPop(void *pool);
id glue__objc_rootAutorelease(id object);

Modified src/runtime/morphos.fd from [7d9c1b57f3] to [01e9313771].

74
75
76
77
78
79
80



81
glue_class_copyMethodList(class_,outCount)(sysv,r12base)
glue_method_getName(method)(sysv,r12base)
glue_method_getTypeEncoding(method)(sysv,r12base)
glue_class_copyPropertyList(class_,outCount)(sysv,r12base)
glue_property_getName(property)(sysv,r12base)
glue_property_copyAttributeValue(property,name)(sysv,r12base)
glue_objc_destructInstance(object)(sysv,r12base)



##end







>
>
>

74
75
76
77
78
79
80
81
82
83
84
glue_class_copyMethodList(class_,outCount)(sysv,r12base)
glue_method_getName(method)(sysv,r12base)
glue_method_getTypeEncoding(method)(sysv,r12base)
glue_class_copyPropertyList(class_,outCount)(sysv,r12base)
glue_property_getName(property)(sysv,r12base)
glue_property_copyAttributeValue(property,name)(sysv,r12base)
glue_objc_destructInstance(object)(sysv,r12base)
objc_autoreleasePoolPush()(sysv,r12base)
objc_autoreleasePoolPop(pool)(sysv,r12base)
_objc_rootAutorelease(object)(sysv,r12base)
##end

Modified src/runtime/private.h from [feea25df7d] to [a228e75679].

362
363
364
365
366
367
368


369
370
371






372
	}

@interface DummyObject
{
	Class _Nonnull isa;
}



+ (void)initialize;
+ (bool)resolveClassMethod: (nonnull SEL)selector;
+ (bool)resolveInstanceMethod: (nonnull SEL)selector;






@end







>
>



>
>
>
>
>
>

362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
	}

@interface DummyObject
{
	Class _Nonnull isa;
}

@property (readonly, nonatomic) bool allowsWeakReference;

+ (void)initialize;
+ (bool)resolveClassMethod: (nonnull SEL)selector;
+ (bool)resolveInstanceMethod: (nonnull SEL)selector;
- (nonnull id)retain;
- (void)release;
- (nonnull id)autorelease;
- (nonnull id)copy;
- (nonnull id)mutableCopy;
- (bool)retainWeakReference;
@end

Modified src/runtime/property.m from [7a58a24d18] to [f51e3c1883].

18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include "config.h"

#include <string.h>

#import "ObjFWRT.h"
#import "private.h"

#import "OFObject.h"

#ifdef OF_HAVE_THREADS
# import "mutex.h"
# define NUM_SPINLOCKS 8	/* needs to be a power of 2 */
# define SPINLOCK_HASH(p) ((unsigned)((uintptr_t)p >> 4) & (NUM_SPINLOCKS - 1))
static of_spinlock_t spinlocks[NUM_SPINLOCKS];
#endif








<
<







18
19
20
21
22
23
24


25
26
27
28
29
30
31
#include "config.h"

#include <string.h>

#import "ObjFWRT.h"
#import "private.h"



#ifdef OF_HAVE_THREADS
# import "mutex.h"
# define NUM_SPINLOCKS 8	/* needs to be a power of 2 */
# define SPINLOCK_HASH(p) ((unsigned)((uintptr_t)p >> 4) & (NUM_SPINLOCKS - 1))
static of_spinlock_t spinlocks[NUM_SPINLOCKS];
#endif