ObjFW  Check-in [d07c56a8bb]

Overview
Comment:Add OF_CONSTRUCTOR() / OF_DESTRUCTOR()
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: d07c56a8bb7b0d628ef609305d2ce723aa882b0fbabd460eea531855aa2b4192
User & Date: js on 2017-04-02 01:06:35
Other Links: manifest | tags
Context
2017-04-02
02:02
Add OF_WEAK_REF() check-in: 126632e200 user: js tags: trunk
01:06
Add OF_CONSTRUCTOR() / OF_DESTRUCTOR() check-in: d07c56a8bb user: js tags: trunk
00:43
OFTimer: Add "repeating" property check-in: 13967106a5 user: js tags: trunk
Changes

Modified src/OFBlock.m from [9a8524cb7e] to [0163c4920f].

115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130

static struct objc_abi_module module = {
	8, sizeof(module), NULL, (struct objc_abi_symtab*)&symtab
};

extern void __objc_exec_class(struct objc_abi_module*);

static void __attribute__((__constructor__))
constructor(void)
{
	__objc_exec_class(&module);
}
/* End of ObjC module */
#elif defined(OF_APPLE_RUNTIME)
extern Class objc_initializeClassPair(Class, const char*, Class, Class);








|
<







115
116
117
118
119
120
121
122

123
124
125
126
127
128
129

static struct objc_abi_module module = {
	8, sizeof(module), NULL, (struct objc_abi_symtab*)&symtab
};

extern void __objc_exec_class(struct objc_abi_module*);

OF_CONSTRUCTOR()

{
	__objc_exec_class(&module);
}
/* End of ObjC module */
#elif defined(OF_APPLE_RUNTIME)
extern Class objc_initializeClassPair(Class, const char*, Class, Class);

Modified src/autorelease.m from [93f43616e8] to [1e49675760].

35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#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)
static void __attribute__((__constructor__))
init(void)
{
	OF_ENSURE(of_tlskey_new(&objectsKey));
	OF_ENSURE(of_tlskey_new(&topKey));
	OF_ENSURE(of_tlskey_new(&sizeKey));
}
#endif








|
<







35
36
37
38
39
40
41
42

43
44
45
46
47
48
49
#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

Modified src/exceptions/OFException.m from [860e2e36ac] to [8fabc728f2].

84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
extern int _Unwind_VRS_Get(struct _Unwind_Context*, int, uint32_t, int, void*);
# endif
#endif

#if !defined(HAVE_STRERROR_R) && defined(OF_HAVE_THREADS)
static of_mutex_t mutex;

static void __attribute__((__constructor__))
init(void)
{
	if (!of_mutex_new(&mutex))
		@throw [OFInitializationFailedException exception];
}
#endif

OFString*







|
<







84
85
86
87
88
89
90
91

92
93
94
95
96
97
98
extern int _Unwind_VRS_Get(struct _Unwind_Context*, int, uint32_t, int, void*);
# endif
#endif

#if !defined(HAVE_STRERROR_R) && defined(OF_HAVE_THREADS)
static of_mutex_t mutex;

OF_CONSTRUCTOR()

{
	if (!of_mutex_new(&mutex))
		@throw [OFInitializationFailedException exception];
}
#endif

OFString*

Modified src/foundation-compat.m from [4b59534eae] to [b70a21b331].

51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
autorelease(id self, SEL _cmd)
{
	[OFAutoreleasePool addObject: self];

	return self;
}

static void __attribute__((__constructor__))
init(void)
{
	Class NSAutoreleasePool = objc_getClass("NSAutoreleasePool");
	Class NSObject = objc_getClass("NSObject");
	Method allocMethod;
	Method addObjectMethod;
	Method autoreleaseMethod;








|
<







51
52
53
54
55
56
57
58

59
60
61
62
63
64
65
autorelease(id self, SEL _cmd)
{
	[OFAutoreleasePool addObject: self];

	return self;
}

OF_CONSTRUCTOR()

{
	Class NSAutoreleasePool = objc_getClass("NSAutoreleasePool");
	Class NSObject = objc_getClass("NSObject");
	Method allocMethod;
	Method addObjectMethod;
	Method autoreleaseMethod;

Modified src/macros.h from [db7b5a88fe] to [35fb899dee].

334
335
336
337
338
339
340







341
342
343
344
345
346
347
# define OF_DEALLOC_UNSUPPORTED						\
	[self doesNotRecognizeSelector: _cmd];				\
									\
	abort();							\
									\
	[super dealloc];	/* Get rid of a stupid warning */
#endif








static OF_INLINE uint16_t OF_CONST_FUNC
OF_BSWAP16_CONST(uint16_t i)
{
	return (i & UINT16_C(0xFF00)) >> 8 |
	    (i & UINT16_C(0x00FF)) << 8;
}







>
>
>
>
>
>
>







334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
# define OF_DEALLOC_UNSUPPORTED						\
	[self doesNotRecognizeSelector: _cmd];				\
									\
	abort();							\
									\
	[super dealloc];	/* Get rid of a stupid warning */
#endif

#define OF_CONSTRUCTOR(prio)					\
	static void __attribute__((__constructor__(prio)))	\
	constructor##__LINE__(void)
#define OF_DESTRUCTOR(prio)					\
	static void __attribute__((__destructor__(prio)))	\
	destructor##__LINE__(void)

static OF_INLINE uint16_t OF_CONST_FUNC
OF_BSWAP16_CONST(uint16_t i)
{
	return (i & UINT16_C(0xFF00)) >> 8 |
	    (i & UINT16_C(0x00FF)) << 8;
}

Modified src/of_asprintf.m from [c0ebec1591] to [81c730c736].

78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
	} lengthModifier;
	bool useLocale;
};

#ifdef HAVE_ASPRINTF_L
static locale_t cLocale;

static void __attribute__((constructor))
init(void)
{
	if ((cLocale = newlocale(LC_ALL_MASK, "C", NULL)) == NULL)
		@throw [OFInitializationFailedException exception];
}
#endif

#ifndef HAVE_ASPRINTF







|
<







78
79
80
81
82
83
84
85

86
87
88
89
90
91
92
	} lengthModifier;
	bool useLocale;
};

#ifdef HAVE_ASPRINTF_L
static locale_t cLocale;

OF_CONSTRUCTOR()

{
	if ((cLocale = newlocale(LC_ALL_MASK, "C", NULL)) == NULL)
		@throw [OFInitializationFailedException exception];
}
#endif

#ifndef HAVE_ASPRINTF

Modified src/resolver.m from [9302e3897c] to [e5254d8f80].

42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#endif

#import "socket_helpers.h"

#if !defined(HAVE_THREADSAFE_GETADDRINFO) && defined(OF_HAVE_THREADS)
static of_mutex_t mutex;

static void __attribute__((__constructor__))
init(void)
{
	if (!of_mutex_new(&mutex))
		@throw [OFInitializationFailedException exception];
}
#endif

of_resolver_result_t**







|
<







42
43
44
45
46
47
48
49

50
51
52
53
54
55
56
#endif

#import "socket_helpers.h"

#if !defined(HAVE_THREADSAFE_GETADDRINFO) && defined(OF_HAVE_THREADS)
static of_mutex_t mutex;

OF_CONSTRUCTOR()

{
	if (!of_mutex_new(&mutex))
		@throw [OFInitializationFailedException exception];
}
#endif

of_resolver_result_t**

Modified src/runtime/arc.m from [20660be952] to [120ac4ff9d].

44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59

static bool
obj_equal(const void *obj1, const void *obj2)
{
	return (obj1 == obj2);
}

static void __attribute__((__constructor__))
init(void)
{
	hashtable = objc_hashtable_new(obj_hash, obj_equal, 2);

#ifdef OF_HAVE_THREADS
	if (!of_spinlock_new(&spinlock))
		OBJC_ERROR("Failed to create spinlock!")
#endif







|
<







44
45
46
47
48
49
50
51

52
53
54
55
56
57
58

static bool
obj_equal(const void *obj1, const void *obj2)
{
	return (obj1 == obj2);
}

OF_CONSTRUCTOR()

{
	hashtable = objc_hashtable_new(obj_hash, obj_equal, 2);

#ifdef OF_HAVE_THREADS
	if (!of_spinlock_new(&spinlock))
		OBJC_ERROR("Failed to create spinlock!")
#endif

Modified src/runtime/exception.m from [e1815049b3] to [b2da8e6383].

695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
}

#ifdef HAVE_SEH_EXCEPTIONS
typedef EXCEPTION_DISPOSITION (*seh_personality_fn)(PEXCEPTION_RECORD, void*,
    PCONTEXT, PDISPATCHER_CONTEXT);
static seh_personality_fn __gxx_personality_seh0 = NULL;

static void __attribute__((__constructor__))
gxx_personality_init(void)
{
	/*
	 * This only works if the application uses libstdc++-6.dll.
	 * There is unfortunately no other way, as Windows does not support
	 * proper weak linking.
	 */








|
<







695
696
697
698
699
700
701
702

703
704
705
706
707
708
709
}

#ifdef HAVE_SEH_EXCEPTIONS
typedef EXCEPTION_DISPOSITION (*seh_personality_fn)(PEXCEPTION_RECORD, void*,
    PCONTEXT, PDISPATCHER_CONTEXT);
static seh_personality_fn __gxx_personality_seh0 = NULL;

OF_CONSTRUCTOR()

{
	/*
	 * This only works if the application uses libstdc++-6.dll.
	 * There is unfortunately no other way, as Windows does not support
	 * proper weak linking.
	 */

Modified src/runtime/property.m from [ec5df4b0c7] to [79dd5a258d].

27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# import "threading.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

#ifdef OF_HAVE_THREADS
static void __attribute__((__constructor__))
init(void)
{
	for (size_t i = 0; i < NUM_SPINLOCKS; i++)
		if (!of_spinlock_new(&spinlocks[i]))
			OBJC_ERROR("Failed to initialize spinlocks!")
}
#endif








|
<







27
28
29
30
31
32
33
34

35
36
37
38
39
40
41
# import "threading.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

#ifdef OF_HAVE_THREADS
OF_CONSTRUCTOR()

{
	for (size_t i = 0; i < NUM_SPINLOCKS; i++)
		if (!of_spinlock_new(&spinlocks[i]))
			OBJC_ERROR("Failed to initialize spinlocks!")
}
#endif

Modified src/runtime/synchronized.m from [985b7a3ea1] to [675119db68].

30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
	int	      count;
	of_rmutex_t   rmutex;
	struct lock_s *next;
} *locks = NULL;

static of_mutex_t mutex;

static void __attribute__((__constructor__))
init(void)
{
	if (!of_mutex_new(&mutex))
		OBJC_ERROR("Failed to create mutex!")
}
#endif

int







|
<







30
31
32
33
34
35
36
37

38
39
40
41
42
43
44
	int	      count;
	of_rmutex_t   rmutex;
	struct lock_s *next;
} *locks = NULL;

static of_mutex_t mutex;

OF_CONSTRUCTOR()

{
	if (!of_mutex_new(&mutex))
		OBJC_ERROR("Failed to create mutex!")
}
#endif

int

Modified src/threading_pthread.m from [7669b743f6] to [430c90cbfe].

33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
	id object;
};

/*
 * This is done here to make sure this is done as early as possible in the main
 * thread.
 */
static void __attribute__((constructor))
init(void)
{
	pthread_attr_t pattr;
	int policy;
	struct sched_param param;

	OF_ENSURE(pthread_attr_init(&pattr) == 0);
	OF_ENSURE(pthread_attr_getschedpolicy(&pattr, &policy) == 0);







|
<







33
34
35
36
37
38
39
40

41
42
43
44
45
46
47
	id object;
};

/*
 * This is done here to make sure this is done as early as possible in the main
 * thread.
 */
OF_CONSTRUCTOR()

{
	pthread_attr_t pattr;
	int policy;
	struct sched_param param;

	OF_ENSURE(pthread_attr_init(&pattr) == 0);
	OF_ENSURE(pthread_attr_getschedpolicy(&pattr, &policy) == 0);

Modified tests/plugin/TestPlugin.m from [9a203f8488] to [591fb14b83].

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

#import "TestPlugin.h"

#ifdef OF_OBJFW_RUNTIME
# import "runtime-private.h"

static void __attribute__((destructor))
unload(void)
{
	objc_unregister_class(objc_getClass("TestPlugin"));
}
#endif

@implementation TestPlugin
- (int)test: (int)num







|
<







17
18
19
20
21
22
23
24

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

#import "TestPlugin.h"

#ifdef OF_OBJFW_RUNTIME
# import "runtime-private.h"

OF_DESTRUCTOR()

{
	objc_unregister_class(objc_getClass("TestPlugin"));
}
#endif

@implementation TestPlugin
- (int)test: (int)num