ObjFW  Check-in [5164cbc576]

Overview
Comment:Document a lot of undocumented functions & macros

Also fixes Doxygen not creating documentation for `static OF_INLINE`
functions.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | 1.1
Files: files | file ages | folders
SHA3-256: 5164cbc5764087d6ca0dc0698399065b3e6ba5c58a98fcac2e202a9caf5559bd
User & Date: js on 2024-05-01 15:20:29
Other Links: branch diff | manifest | tags
Context
2024-05-05
09:43
Fix +[OFSystemInfo networkInterfaces] on NetBSD check-in: 6f0bb25b4e user: js tags: 1.1
2024-05-01
15:20
Document a lot of undocumented functions & macros check-in: 5164cbc576 user: js tags: 1.1
15:19
Document a lot of undocumented functions & macros check-in: 0c3c3b6efa user: js tags: trunk
2024-04-29
23:12
Properly hide private symbols check-in: efb77e8878 user: js tags: 1.1
Changes

Modified Doxyfile from [75514e9314] to [ea0872cd8b].

46
47
48
49
50
51
52

	     OF_WEAK_UNAVAILABLE=				\
	     SIGHUP						\
	     SIGUSR1						\
	     SIGUSR2
MACRO_EXPANSION = YES
EXPAND_ONLY_PREDEF = YES
IGNORE_PREFIX = OF OF_ OT OT_








>
46
47
48
49
50
51
52
53
	     OF_WEAK_UNAVAILABLE=				\
	     SIGHUP						\
	     SIGUSR1						\
	     SIGUSR2
MACRO_EXPANSION = YES
EXPAND_ONLY_PREDEF = YES
IGNORE_PREFIX = OF OF_ OT OT_
EXTRACT_STATIC = yes

Modified src/OFDate.m from [7229a07ea7] to [ddae0ab707].

275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
	if (seconds == 0) {
		static OFOnceControl once = OFOnceControlInitValue;
		OFOnce(&once, initZeroDate);
		return (id)zeroDate;
	}

#if defined(OF_OBJFW_RUNTIME) && UINTPTR_MAX == UINT64_MAX
	value = OFFromBigEndian64(OFDoubleToRawUInt64(OFToBigEndianDouble(
	    seconds)));

	/* Almost all dates fall into this range. */
	if (value & (UINT64_C(4) << 60)) {
		id ret = [OFTaggedPointerDate
		    dateWithUInt64TimeIntervalSince1970: value];

		if (ret != nil)







|
|







275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
	if (seconds == 0) {
		static OFOnceControl once = OFOnceControlInitValue;
		OFOnce(&once, initZeroDate);
		return (id)zeroDate;
	}

#if defined(OF_OBJFW_RUNTIME) && UINTPTR_MAX == UINT64_MAX
	value = OFFromBigEndian64(OFBitConvertDoubleToUInt64(
	    OFToBigEndianDouble(seconds)));

	/* Almost all dates fall into this range. */
	if (value & (UINT64_C(4) << 60)) {
		id ret = [OFTaggedPointerDate
		    dateWithUInt64TimeIntervalSince1970: value];

		if (ret != nil)

Modified src/OFMatrix4x4.m from [a90d32dcbf] to [c9b2db710c].

314
315
316
317
318
319
320
321

322
323
324
325
326
327
328
{
	unsigned long hash;

	OFHashInit(&hash);

	for (uint_fast8_t i = 0; i < 4; i++)
		for (uint_fast8_t j = 0; j < 4; j++)
			OFHashAddHash(&hash, OFFloatToRawUInt32(_values[i][j]));


	OFHashFinalize(&hash);

	return hash;
}

- (void)multiplyWithMatrix: (OFMatrix4x4 *)matrix







|
>







314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
{
	unsigned long hash;

	OFHashInit(&hash);

	for (uint_fast8_t i = 0; i < 4; i++)
		for (uint_fast8_t j = 0; j < 4; j++)
			OFHashAddHash(&hash,
			    OFBitConvertFloatToUInt32(_values[i][j]));

	OFHashFinalize(&hash);

	return hash;
}

- (void)multiplyWithMatrix: (OFMatrix4x4 *)matrix

Modified src/OFObject.h from [08353423b4] to [7b8537b8d6].

1478
1479
1480
1481
1482
1483
1484













1485
1486























1487
1488
1489
1490
1491
1492
1493
    const void *_Nonnull key, id _Nullable value,
    objc_associationPolicy policy);
extern id _Nullable objc_getAssociatedObject(id _Nonnull object,
    const void *_Nonnull key);
extern void objc_removeAssociatedObjects(id _Nonnull object);
# endif
#endif













extern id OFAllocObject(Class class_, size_t extraSize, size_t extraAlignment,
    void *_Nullable *_Nullable extra);























extern void OF_NO_RETURN_FUNC OFMethodNotFound(id self, SEL _cmd);

/**
 * @brief Initializes the specified hash.
 *
 * @param hash A pointer to the hash to initialize
 */







>
>
>
>
>
>
>
>
>
>
>
>
>


>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
    const void *_Nonnull key, id _Nullable value,
    objc_associationPolicy policy);
extern id _Nullable objc_getAssociatedObject(id _Nonnull object,
    const void *_Nonnull key);
extern void objc_removeAssociatedObjects(id _Nonnull object);
# endif
#endif

/**
 * @brief Allocates a new object.
 *
 * This is useful to override @ref OFObject#alloc in a subclass that can then
 * allocate extra memory in the same memory allocation.
 *
 * @param class_ The class of which to allocate an object
 * @param extraSize Extra space after the ivars to allocate
 * @param extraAlignment Alignment of the extra space after the ivars
 * @param extra A pointer to set to a pointer to the extra space
 * @return The allocated object
 */
extern id OFAllocObject(Class class_, size_t extraSize, size_t extraAlignment,
    void *_Nullable *_Nullable extra);

/**
 * @brief This function is called when a method is not found.
 *
 * It can also be called intentionally to indicate that a method is not
 * implemetned, for example in an abstract method. However, instead of calling
 * OFMethodNotFound directly, it is preferred to do the following:
 *
 *     - (void)abstractMethod
 *     {
 *     	OF_UNRECOGNIZED_SELECTOR
 *     }
 *
 * However, do not use this for init methods. Instead, use the following:
 *
 *     - (instancetype)init
 *     {
 *     	OF_INVALID_INIT_METHOD
 *     }
 *
 * @param self The object which does not have the method
 * @param _cmd The selector of the method that does not exist
 */
extern void OF_NO_RETURN_FUNC OFMethodNotFound(id self, SEL _cmd);

/**
 * @brief Initializes the specified hash.
 *
 * @param hash A pointer to the hash to initialize
 */

Modified src/OFPlainCondition.h from [c4030c17c8] to [2b26bbac16].

25
26
27
28
29
30
31


32
33
34
35
36
37
38
    (!defined(OF_HAVE_PTHREADS) && !defined(OF_WINDOWS) && !defined(OF_AMIGAOS))
# error No conditions available!
#endif

/* For OFTimeInterval */
#import "OFObject.h"
#import "OFPlainMutex.h"



#if defined(OF_HAVE_PTHREADS)
# include <pthread.h>
typedef pthread_cond_t OFPlainCondition;
#elif defined(OF_WINDOWS)
# include <windows.h>
typedef struct {







>
>







25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
    (!defined(OF_HAVE_PTHREADS) && !defined(OF_WINDOWS) && !defined(OF_AMIGAOS))
# error No conditions available!
#endif

/* For OFTimeInterval */
#import "OFObject.h"
#import "OFPlainMutex.h"

/** @file */

#if defined(OF_HAVE_PTHREADS)
# include <pthread.h>
typedef pthread_cond_t OFPlainCondition;
#elif defined(OF_WINDOWS)
# include <windows.h>
typedef struct {
49
50
51
52
53
54
55









56







57








58








59
60










61
62

63









64
65











66
67
68







69
70
71
72
	} *waitingTasks;
} OFPlainCondition;
#endif

#ifdef __cplusplus
extern "C" {
#endif









extern int OFPlainConditionNew(OFPlainCondition *condition);







extern int OFPlainConditionSignal(OFPlainCondition *condition);








extern int OFPlainConditionBroadcast(OFPlainCondition *condition);








extern int OFPlainConditionWait(OFPlainCondition *condition,
    OFPlainMutex *mutex);










extern int OFPlainConditionTimedWait(OFPlainCondition *condition,
    OFPlainMutex *mutex, OFTimeInterval timeout);

#if defined(OF_AMIGAOS) || defined(DOXYGEN)









extern int OFPlainConditionWaitOrExecSignal(OFPlainCondition *condition,
    OFPlainMutex *mutex, ULONG *signalMask);











extern int OFPlainConditionTimedWaitOrExecSignal(OFPlainCondition *condition,
    OFPlainMutex *mutex, OFTimeInterval timeout, ULONG *signalMask);
#endif







extern int OFPlainConditionFree(OFPlainCondition *condition);
#ifdef __cplusplus
}
#endif







>
>
>
>
>
>
>
>
>

>
>
>
>
>
>
>

>
>
>
>
>
>
>
>

>
>
>
>
>
>
>
>


>
>
>
>
>
>
>
>
>
>


>

>
>
>
>
>
>
>
>
>


>
>
>
>
>
>
>
>
>
>
>



>
>
>
>
>
>
>




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
136
137
138
139
140
141
142
143
144
	} *waitingTasks;
} OFPlainCondition;
#endif

#ifdef __cplusplus
extern "C" {
#endif
/**
 * @brief Creates a new plain condition.
 *
 * A plain condition is similar to an @ref OFCondition, but does not use
 * exceptions and can be used from pure C code.
 *
 * @param condition A pointer to the condition to create
 * @return 0 on success, or an error number from `<errno.h>` on error
 */
extern int OFPlainConditionNew(OFPlainCondition *condition);

/**
 * @brief Signals the specified condition.
 *
 * @param condition A pointer to the condition to signal
 * @return 0 on success, or an error number from `<errno.h>` on error
 */
extern int OFPlainConditionSignal(OFPlainCondition *condition);

/**
 * @brief Broadcasts the specified condition, meaning it will be signaled to
 *	  everyone waiting.
 *
 * @param condition A pointer to the condition to broadcast
 * @return 0 on success, or an error number from `<errno.h>` on error
 */
extern int OFPlainConditionBroadcast(OFPlainCondition *condition);

/**
 * @brief Waits on the specified condition with the specified mutex.
 *
 * @param condition A pointer to the condition to wait on
 * @param mutex The mutex to wait with
 * @return 0 on success, or an error number from `<errno.h>` on error
 */
extern int OFPlainConditionWait(OFPlainCondition *condition,
    OFPlainMutex *mutex);

/**
 * @brief Waits on the specified condition with the specified mutex with a
 *	  timeout.
 *
 * @param condition A pointer to the condition to wait on
 * @param mutex The mutex to wait with
 * @param timeout The timeout after which to give up
 * @return 0 on success, or an error number from `<errno.h>` on error
 */
extern int OFPlainConditionTimedWait(OFPlainCondition *condition,
    OFPlainMutex *mutex, OFTimeInterval timeout);

#if defined(OF_AMIGAOS) || defined(DOXYGEN)
/**
 * @brief Waits on the specified condition with the specified mutex or the
 *	  specified Exec signal.
 *
 * @param condition A pointer to the condition to wait on
 * @param mutex The mutex to wait with
 * @param signalMask The Exec signal mask to wait for
 * @return 0 on success, or an error number from `<errno.h>` on error
 */
extern int OFPlainConditionWaitOrExecSignal(OFPlainCondition *condition,
    OFPlainMutex *mutex, ULONG *signalMask);

/**
 * @brief Waits on the specified condition with the specified mutex or the
 *	  specified Exec signal, up until the timeout is reached.
 *
 * @param condition A pointer to the condition to wait on
 * @param mutex The mutex to wait with
 * @param signalMask The Exec signal mask to wait for
 * @param timeout The timeout after which to give up
 * @return 0 on success, or an error number from `<errno.h>` on error
 */
extern int OFPlainConditionTimedWaitOrExecSignal(OFPlainCondition *condition,
    OFPlainMutex *mutex, OFTimeInterval timeout, ULONG *signalMask);
#endif

/**
 * @brief Destroys the specified plain condition.
 *
 * @param condition A pointer to the condition to destroy
 * @return 0 on success, or an error number from `<errno.h>` on error
 */
extern int OFPlainConditionFree(OFPlainCondition *condition);
#ifdef __cplusplus
}
#endif

Modified src/OFPlainMutex.h from [b1091dda6a] to [31506d7dcf].

25
26
27
28
29
30
31


32
33
34
35
36
37
38

#if !defined(OF_HAVE_THREADS) || \
    (!defined(OF_HAVE_PTHREADS) && !defined(OF_WINDOWS) && !defined(OF_AMIGAOS))
# error No mutexes available!
#endif

#import "macros.h"



#if defined(OF_HAVE_PTHREADS)
# include <pthread.h>
typedef pthread_mutex_t OFPlainMutex;
#elif defined(OF_WINDOWS)
# include <windows.h>
typedef CRITICAL_SECTION OFPlainMutex;







>
>







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

#if !defined(OF_HAVE_THREADS) || \
    (!defined(OF_HAVE_PTHREADS) && !defined(OF_WINDOWS) && !defined(OF_AMIGAOS))
# error No mutexes available!
#endif

#import "macros.h"

/** @file */

#if defined(OF_HAVE_PTHREADS)
# include <pthread.h>
typedef pthread_mutex_t OFPlainMutex;
#elif defined(OF_WINDOWS)
# include <windows.h>
typedef CRITICAL_SECTION OFPlainMutex;
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
	OFTLSKey count;
} OFPlainRecursiveMutex;
#endif

#ifdef __cplusplus
extern "C" {
#endif









extern int OFPlainMutexNew(OFPlainMutex *mutex);







extern int OFPlainMutexLock(OFPlainMutex *mutex);







extern int OFPlainMutexTryLock(OFPlainMutex *mutex);







extern int OFPlainMutexUnlock(OFPlainMutex *mutex);







extern int OFPlainMutexFree(OFPlainMutex *mutex);












extern int OFPlainRecursiveMutexNew(OFPlainRecursiveMutex *rmutex);







extern int OFPlainRecursiveMutexLock(OFPlainRecursiveMutex *rmutex);







extern int OFPlainRecursiveMutexTryLock(OFPlainRecursiveMutex *rmutex);







extern int OFPlainRecursiveMutexUnlock(OFPlainRecursiveMutex *rmutex);







extern int OFPlainRecursiveMutexFree(OFPlainRecursiveMutex *rmutex);
#ifdef __cplusplus
}
#endif

/* Spinlocks are inlined for performance. */





static OF_INLINE void
OFYieldThread(void)
{
#if defined(OF_HAVE_SCHED_YIELD)
	sched_yield();
#elif defined(OF_WINDOWS)
	Sleep(0);
#endif
}







static OF_INLINE int
OFSpinlockNew(OFSpinlock *spinlock)
{
#if defined(OF_HAVE_ATOMIC_OPS)
	*spinlock = 0;
	return 0;
#elif defined(OF_HAVE_PTHREAD_SPINLOCKS)
	return pthread_spin_init(spinlock, 0);
#else
	return OFPlainMutexNew(spinlock);
#endif
}







static OF_INLINE int
OFSpinlockTryLock(OFSpinlock *spinlock)
{
#if defined(OF_HAVE_ATOMIC_OPS)
	if (OFAtomicIntCompareAndSwap(spinlock, 0, 1)) {
		OFAcquireMemoryBarrier();
		return 0;
	}

	return EBUSY;
#elif defined(OF_HAVE_PTHREAD_SPINLOCKS)
	return pthread_spin_trylock(spinlock);
#else
	return OFPlainMutexTryLock(spinlock);
#endif
}







static OF_INLINE int
OFSpinlockLock(OFSpinlock *spinlock)
{
#if defined(OF_HAVE_ATOMIC_OPS)
	size_t i;

	for (i = 0; i < 10; i++)







>
>
>
>
>
>
>
>
>

>
>
>
>
>
>
>

>
>
>
>
>
>
>

>
>
>
>
>
>
>

>
>
>
>
>
>
>

>
>
>
>
>
>
>
>
>
>
>
>

>
>
>
>
>
>
>

>
>
>
>
>
>
>

>
>
>
>
>
>
>

>
>
>
>
>
>
>







>
>
>
>










>
>
>
>
>
>













>
>
>
>
>
>

















>
>
>
>
>
>







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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
	OFTLSKey count;
} OFPlainRecursiveMutex;
#endif

#ifdef __cplusplus
extern "C" {
#endif
/**
 * @brief Creates a new plain mutex.
 *
 * A plain mutex is similar to an @ref OFMutex, but does not use exceptions and
 * is just a lightweight wrapper around the system's mutex implementation.
 *
 * @param mutex A pointer to the mutex to create
 * @return 0 on success, or an error number from `<errno.h>` on error
 */
extern int OFPlainMutexNew(OFPlainMutex *mutex);

/**
 * @brief Locks the specified mutex.
 *
 * @param mutex A pointer to the mutex to lock
 * @return 0 on success, or an error number from `<errno.h>` on error
 */
extern int OFPlainMutexLock(OFPlainMutex *mutex);

/**
 * @brief Tries to lock the specified mutex without blocking.
 *
 * @param mutex A pointer to the mutex to try to lock
 * @return 0 on success, or an error number from `<errno.h>` on error
 */
extern int OFPlainMutexTryLock(OFPlainMutex *mutex);

/**
 * @brief Unlocks the specified mutex.
 *
 * @param mutex A pointer to the mutex to unlock
 * @return 0 on success, or an error number from `<errno.h>` on error
 */
extern int OFPlainMutexUnlock(OFPlainMutex *mutex);

/**
 * @brief Destroys the specified mutex
 *
 * @param mutex A pointer to the mutex to destruct
 * @return 0 on success, or an error number from `<errno.h>` on error
 */
extern int OFPlainMutexFree(OFPlainMutex *mutex);

/**
 * @brief Creates a new plain recursive mutex.
 *
 * A plain recursive mutex is similar to an @ref OFRecursiveMutex, but does not
 * use exceptions and is just a lightweight wrapper around the system's
 * recursive mutex implementation (or lacking that, a simple implementation of
 * recursive mutexes via regular mutexes).
 *
 * @param rmutex A pointer to the recursive mutex to create
 * @return 0 on success, or an error number from `<errno.h>` on error
 */
extern int OFPlainRecursiveMutexNew(OFPlainRecursiveMutex *rmutex);

/**
 * @brief Locks the specified recursive mutex.
 *
 * @param rmutex A pointer to the recursive mutex to lock
 * @return 0 on success, or an error number from `<errno.h>` on error
 */
extern int OFPlainRecursiveMutexLock(OFPlainRecursiveMutex *rmutex);

/**
 * @brief Tries to lock the specified recursive mutex without blocking.
 *
 * @param rmutex A pointer to the recursive mutex to try to lock
 * @return 0 on success, or an error number from `<errno.h>` on error
 */
extern int OFPlainRecursiveMutexTryLock(OFPlainRecursiveMutex *rmutex);

/**
 * @brief Unlocks the specified recursive mutex.
 *
 * @param rmutex A pointer to the recursive mutex to unlock
 * @return 0 on success, or an error number from `<errno.h>` on error
 */
extern int OFPlainRecursiveMutexUnlock(OFPlainRecursiveMutex *rmutex);

/**
 * @brief Destroys the specified recursive mutex
 *
 * @param rmutex A pointer to the recursive mutex to destruct
 * @return 0 on success, or an error number from `<errno.h>` on error
 */
extern int OFPlainRecursiveMutexFree(OFPlainRecursiveMutex *rmutex);
#ifdef __cplusplus
}
#endif

/* Spinlocks are inlined for performance. */

/**
 * @brief Yield the current thread, indicating to the OS that another thread
 *	  should execute instead.
 */
static OF_INLINE void
OFYieldThread(void)
{
#if defined(OF_HAVE_SCHED_YIELD)
	sched_yield();
#elif defined(OF_WINDOWS)
	Sleep(0);
#endif
}

/**
 * @brief Creates a new spinlock.
 *
 * @param spinlock A pointer to the spinlock to create
 * @return 0 on success, or an error number from `<errno.h>` on error
 */
static OF_INLINE int
OFSpinlockNew(OFSpinlock *spinlock)
{
#if defined(OF_HAVE_ATOMIC_OPS)
	*spinlock = 0;
	return 0;
#elif defined(OF_HAVE_PTHREAD_SPINLOCKS)
	return pthread_spin_init(spinlock, 0);
#else
	return OFPlainMutexNew(spinlock);
#endif
}

/**
 * @brief Tries to lock a spinlock.
 *
 * @param spinlock A pointer to the spinlock to try to lock
 * @return 0 on success, or an error number from `<errno.h>` on error
 */
static OF_INLINE int
OFSpinlockTryLock(OFSpinlock *spinlock)
{
#if defined(OF_HAVE_ATOMIC_OPS)
	if (OFAtomicIntCompareAndSwap(spinlock, 0, 1)) {
		OFAcquireMemoryBarrier();
		return 0;
	}

	return EBUSY;
#elif defined(OF_HAVE_PTHREAD_SPINLOCKS)
	return pthread_spin_trylock(spinlock);
#else
	return OFPlainMutexTryLock(spinlock);
#endif
}

/**
 * @brief Locks a spinlock.
 *
 * @param spinlock A pointer to the spinlock to lock
 * @return 0 on success, or an error number from `<errno.h>` on error
 */
static OF_INLINE int
OFSpinlockLock(OFSpinlock *spinlock)
{
#if defined(OF_HAVE_ATOMIC_OPS)
	size_t i;

	for (i = 0; i < 10; i++)
141
142
143
144
145
146
147






148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163






164
165
166
167
168
169
170
171
172
173
174
#elif defined(OF_HAVE_PTHREAD_SPINLOCKS)
	return pthread_spin_lock(spinlock);
#else
	return OFPlainMutexLock(spinlock);
#endif
}







static OF_INLINE int
OFSpinlockUnlock(OFSpinlock *spinlock)
{
#if defined(OF_HAVE_ATOMIC_OPS)
	bool ret = OFAtomicIntCompareAndSwap(spinlock, 1, 0);

	OFReleaseMemoryBarrier();

	return (ret ? 0 : EINVAL);
#elif defined(OF_HAVE_PTHREAD_SPINLOCKS)
	return pthread_spin_unlock(spinlock);
#else
	return OFPlainMutexUnlock(spinlock);
#endif
}







static OF_INLINE int
OFSpinlockFree(OFSpinlock *spinlock)
{
#if defined(OF_HAVE_ATOMIC_OPS)
	return 0;
#elif defined(OF_HAVE_PTHREAD_SPINLOCKS)
	return pthread_spin_destroy(spinlock);
#else
	return OFPlainMutexFree(spinlock);
#endif
}







>
>
>
>
>
>
















>
>
>
>
>
>











242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
#elif defined(OF_HAVE_PTHREAD_SPINLOCKS)
	return pthread_spin_lock(spinlock);
#else
	return OFPlainMutexLock(spinlock);
#endif
}

/**
 * @brief Unlocks a spinlock.
 *
 * @param spinlock A pointer to the spinlock to unlock
 * @return 0 on success, or an error number from `<errno.h>` on error
 */
static OF_INLINE int
OFSpinlockUnlock(OFSpinlock *spinlock)
{
#if defined(OF_HAVE_ATOMIC_OPS)
	bool ret = OFAtomicIntCompareAndSwap(spinlock, 1, 0);

	OFReleaseMemoryBarrier();

	return (ret ? 0 : EINVAL);
#elif defined(OF_HAVE_PTHREAD_SPINLOCKS)
	return pthread_spin_unlock(spinlock);
#else
	return OFPlainMutexUnlock(spinlock);
#endif
}

/**
 * @brief Destroys a spinlock.
 *
 * @param spinlock A pointer to the spinlock to destroy
 * @return 0 on success, or an error number from `<errno.h>` on error
 */
static OF_INLINE int
OFSpinlockFree(OFSpinlock *spinlock)
{
#if defined(OF_HAVE_ATOMIC_OPS)
	return 0;
#elif defined(OF_HAVE_PTHREAD_SPINLOCKS)
	return pthread_spin_destroy(spinlock);
#else
	return OFPlainMutexFree(spinlock);
#endif
}

Modified src/OFPlainThread.h from [3654325ef3] to [3b3df80df6].

23
24
25
26
27
28
29


30
31
32
33
34
35
36

#if !defined(OF_HAVE_THREADS) || \
    (!defined(OF_HAVE_PTHREADS) && !defined(OF_WINDOWS) && !defined(OF_AMIGAOS))
# error No threads available!
#endif

#import "OFObject.h"



#if defined(OF_HAVE_PTHREADS)
# include <pthread.h>
typedef pthread_t OFPlainThread;
#elif defined(OF_WINDOWS)
# include <windows.h>
typedef HANDLE OFPlainThread;







>
>







23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38

#if !defined(OF_HAVE_THREADS) || \
    (!defined(OF_HAVE_PTHREADS) && !defined(OF_WINDOWS) && !defined(OF_AMIGAOS))
# error No threads available!
#endif

#import "OFObject.h"

/** @file */

#if defined(OF_HAVE_PTHREADS)
# include <pthread.h>
typedef pthread_t OFPlainThread;
#elif defined(OF_WINDOWS)
# include <windows.h>
typedef HANDLE OFPlainThread;
49
50
51
52
53
54
55
56





57
58
59
60
61
62






63
64
65
66
67
68
69
#endif

typedef struct {
	float priority;
	size_t stackSize;
} OFPlainThreadAttributes;

#if defined(OF_HAVE_PTHREADS)





static OF_INLINE OFPlainThread
OFCurrentPlainThread(void)
{
	return pthread_self();
}







static OF_INLINE bool
OFPlainThreadIsCurrent(OFPlainThread thread)
{
	return pthread_equal(thread, pthread_self());
}
#elif defined(OF_WINDOWS)
static OF_INLINE OFPlainThread







|
>
>
>
>
>






>
>
>
>
>
>







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
#endif

typedef struct {
	float priority;
	size_t stackSize;
} OFPlainThreadAttributes;

#if defined(OF_HAVE_PTHREADS) || defined(DOXYGEN)
/**
 * @brief Returns the current plain thread.
 *
 * @return The current plain thread
 */
static OF_INLINE OFPlainThread
OFCurrentPlainThread(void)
{
	return pthread_self();
}

/**
 * @brief Returns whether the specified plain thread is the current thread.
 *
 * @param thread The thread to check
 * @return Whether the specified plain thread is the current thread
 */
static OF_INLINE bool
OFPlainThreadIsCurrent(OFPlainThread thread)
{
	return pthread_equal(thread, pthread_self());
}
#elif defined(OF_WINDOWS)
static OF_INLINE OFPlainThread
81
82
83
84
85
86
87






88














89
90






91







92







93
94
95
96
extern OFPlainThread OFCurrentPlainThread(void);
extern bool OFPlainThreadIsCurrent(OFPlainThread);
#endif

#ifdef __cplusplus
extern "C" {
#endif






extern int OFPlainThreadAttributesInit(OFPlainThreadAttributes *attr);














extern int OFPlainThreadNew(OFPlainThread *thread, const char *name,
    void (*function)(id), id object, const OFPlainThreadAttributes *attr);






extern void OFSetThreadName(const char *name);







extern int OFPlainThreadJoin(OFPlainThread thread);







extern int OFPlainThreadDetach(OFPlainThread thread);
#ifdef __cplusplus
}
#endif







>
>
>
>
>
>

>
>
>
>
>
>
>
>
>
>
>
>
>
>


>
>
>
>
>
>

>
>
>
>
>
>
>

>
>
>
>
>
>
>




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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
extern OFPlainThread OFCurrentPlainThread(void);
extern bool OFPlainThreadIsCurrent(OFPlainThread);
#endif

#ifdef __cplusplus
extern "C" {
#endif
/**
 * @brief Initializes the specified thread attributes.
 *
 * @param attr A pointer to the thread attributes to initialize
 * @return 0 on success, or an error number from `<errno.h>` on error
 */
extern int OFPlainThreadAttributesInit(OFPlainThreadAttributes *attr);

/**
 * @brief Creates a new plain thread.
 *
 * A plain thread is similar to @ref OFThread, but does not use exceptions and
 * is just a lightweight wrapper around the system's thread implementation.
 *
 * @param thread A pointer to the thread to create
 * @param name A name for the thread
 * @param function The function the thread should execute
 * @param object The object to pass to the thread as an argument
 * @param attr Thread attributes
 * @return 0 on success, or an error number from `<errno.h>` on error
 */
extern int OFPlainThreadNew(OFPlainThread *thread, const char *name,
    void (*function)(id), id object, const OFPlainThreadAttributes *attr);

/**
 * @brief Sets the name of the current thread.
 *
 * @param name The name for the current thread
 */
extern void OFSetThreadName(const char *name);

/**
 * @brief Joins the specified thread.
 *
 * @param thread The thread to join
 * @return 0 on success, or an error number from `<errno.h>` on error
 */
extern int OFPlainThreadJoin(OFPlainThread thread);

/**
 * @brief Detaches the specified thread.
 *
 * @param thread The thread to detach
 * @return 0 on success, or an error number from `<errno.h>` on error
 */
extern int OFPlainThreadDetach(OFPlainThread thread);
#ifdef __cplusplus
}
#endif

Modified src/OFString.h from [6dd49c2942] to [5ec6a2e4f7].

1331
1332
1333
1334
1335
1336
1337
















1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
 * @brief Returns the name of the specified OFStringEncoding.
 *
 * @param encoding The encoding for which to return the name
 * @return The name of the specified OFStringEncoding
 */
extern OFString *_Nullable OFStringEncodingName(OFStringEncoding encoding);

















extern char *_Nullable _OFStrDup(const char *_Nonnull) OF_VISIBILITY_HIDDEN;
extern size_t _OFUTF8StringEncode(OFUnichar, char *) OF_VISIBILITY_HIDDEN;
extern ssize_t _OFUTF8StringDecode(const char *, size_t, OFUnichar *)
    OF_VISIBILITY_HIDDEN;
extern size_t OFUTF16StringLength(const OFChar16 *);
extern size_t OFUTF32StringLength(const OFChar32 *);
#ifdef __cplusplus
}
#endif

OF_ASSUME_NONNULL_END

#import "OFConstantString.h"







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>




<
<







1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357


1358
1359
1360
1361
1362
1363
1364
 * @brief Returns the name of the specified OFStringEncoding.
 *
 * @param encoding The encoding for which to return the name
 * @return The name of the specified OFStringEncoding
 */
extern OFString *_Nullable OFStringEncodingName(OFStringEncoding encoding);

/**
 * @brief Returns the length of the specified UTF-16 string.
 *
 * @param string The UTF-16 string
 * @return The length of the specified UTF-16 string
 */
extern size_t OFUTF16StringLength(const OFChar16 *string);

/**
 * @brief Returns the length of the specified UTF-32 string.
 *
 * @param string The UTF-32 string
 * @return The length of the specified UTF-32 string
 */
extern size_t OFUTF32StringLength(const OFChar32 *string);

extern char *_Nullable _OFStrDup(const char *_Nonnull) OF_VISIBILITY_HIDDEN;
extern size_t _OFUTF8StringEncode(OFUnichar, char *) OF_VISIBILITY_HIDDEN;
extern ssize_t _OFUTF8StringDecode(const char *, size_t, OFUnichar *)
    OF_VISIBILITY_HIDDEN;


#ifdef __cplusplus
}
#endif

OF_ASSUME_NONNULL_END

#import "OFConstantString.h"

Modified src/OFTLSKey.h from [0f3980a25d] to [4742ef8bb4].

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

#if !defined(OF_HAVE_THREADS) || \
    (!defined(OF_HAVE_PTHREADS) && !defined(OF_WINDOWS) && !defined(OF_AMIGAOS))
# error No thread-local storage available!
#endif

#import "macros.h"



#if defined(OF_HAVE_PTHREADS)
# include <pthread.h>
typedef pthread_key_t OFTLSKey;
#elif defined(OF_WINDOWS)
# include <windows.h>
typedef DWORD OFTLSKey;
#elif defined(OF_MORPHOS)
# include <proto/exec.h>
typedef ULONG OFTLSKey;
#elif defined(OF_AMIGAOS)
typedef struct _OFTLSKey {
	struct objc_hashtable *table;
	struct _OFTLSKey *next, *previous;
} *OFTLSKey;
#endif

#ifdef __cplusplus
extern "C" {
#endif






extern int OFTLSKeyNew(OFTLSKey *key);







extern int OFTLSKeyFree(OFTLSKey key);
#ifdef __cplusplus
}
#endif

/* TLS keys are inlined for performance. */

#if defined(OF_HAVE_PTHREADS)






static OF_INLINE void *
OFTLSKeyGet(OFTLSKey key)
{
	return pthread_getspecific(key);
}







static OF_INLINE int
OFTLSKeySet(OFTLSKey key, void *ptr)
{
	return pthread_setspecific(key, ptr);
}
#elif defined(OF_WINDOWS)
static OF_INLINE void *
OFTLSKeyGet(OFTLSKey key)
{
	return TlsGetValue(key);
}

static OF_INLINE int
OFTLSKeySet(OFTLSKey key, void *ptr)
{
	return (TlsSetValue(key, ptr) ? 0 : EINVAL);
}
#elif defined(OF_MORPHOS)
static OF_INLINE void *
OFTLSKeyGet(OFTLSKey key)
{
	return (void *)TLSGetValue(key);
}

static OF_INLINE int
OFTLSKeySet(OFTLSKey key, void *ptr)
{
	return (TLSSetValue(key, (APTR)ptr) ? 0 : EINVAL);
}
#elif defined(OF_AMIGAOS)
/* Those are too big too inline. */
# ifdef __cplusplus
extern "C" {
# endif
extern void *OFTLSKeyGet(OFTLSKey key);
extern int OFTLSKeySet(OFTLSKey key, void *ptr);
# ifdef __cplusplus
}
# endif
#endif







>
>




















>
>
>
>
>
>

>
>
>
>
>
>
>







|
>
>
>
>
>
>






>
>
>
>
>
>

|

|









|

|









|

|







|




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

#if !defined(OF_HAVE_THREADS) || \
    (!defined(OF_HAVE_PTHREADS) && !defined(OF_WINDOWS) && !defined(OF_AMIGAOS))
# error No thread-local storage available!
#endif

#import "macros.h"

/** @file */

#if defined(OF_HAVE_PTHREADS)
# include <pthread.h>
typedef pthread_key_t OFTLSKey;
#elif defined(OF_WINDOWS)
# include <windows.h>
typedef DWORD OFTLSKey;
#elif defined(OF_MORPHOS)
# include <proto/exec.h>
typedef ULONG OFTLSKey;
#elif defined(OF_AMIGAOS)
typedef struct _OFTLSKey {
	struct objc_hashtable *table;
	struct _OFTLSKey *next, *previous;
} *OFTLSKey;
#endif

#ifdef __cplusplus
extern "C" {
#endif
/**
 * @brief Creates a new Thread Local Storage key.
 *
 * @param key A pointer to the key to create
 * @return 0 on success, or an error number from `<errno.h>` on error
 */
extern int OFTLSKeyNew(OFTLSKey *key);

/**
 * @brief Destroys the specified Thread Local Storage key.
 *
 * @param key A pointer to the key to destroy
 * @return 0 on success, or an error number from `<errno.h>` on error
 */
extern int OFTLSKeyFree(OFTLSKey key);
#ifdef __cplusplus
}
#endif

/* TLS keys are inlined for performance. */

#if defined(OF_HAVE_PTHREADS) || defined(DOXYGEN)
/**
 * @brief Returns the current value for the specified Thread Local Storage key.
 *
 * @param key A pointer to the key whose value to return
 * @return The current value for the specified Thread Local Storage key
 */
static OF_INLINE void *
OFTLSKeyGet(OFTLSKey key)
{
	return pthread_getspecific(key);
}

/**
 * @brief Sets the current value for the specified Thread Local Storage key.
 *
 * @param key A pointer to the key whose value to set
 * @param value The new value for the key
 */
static OF_INLINE int
OFTLSKeySet(OFTLSKey key, void *value)
{
	return pthread_setspecific(key, value);
}
#elif defined(OF_WINDOWS)
static OF_INLINE void *
OFTLSKeyGet(OFTLSKey key)
{
	return TlsGetValue(key);
}

static OF_INLINE int
OFTLSKeySet(OFTLSKey key, void *value)
{
	return (TlsSetValue(key, value) ? 0 : EINVAL);
}
#elif defined(OF_MORPHOS)
static OF_INLINE void *
OFTLSKeyGet(OFTLSKey key)
{
	return (void *)TLSGetValue(key);
}

static OF_INLINE int
OFTLSKeySet(OFTLSKey key, void *value)
{
	return (TLSSetValue(key, (APTR)value) ? 0 : EINVAL);
}
#elif defined(OF_AMIGAOS)
/* Those are too big too inline. */
# ifdef __cplusplus
extern "C" {
# endif
extern void *OFTLSKeyGet(OFTLSKey key);
extern int OFTLSKeySet(OFTLSKey key, void *value);
# ifdef __cplusplus
}
# endif
#endif

Modified src/OFTaggedPointerDate.m from [3a7c65c57a] to [d646100367].

36
37
38
39
40
41
42
43
44
45
46
47
48
49

- (OFTimeInterval)timeIntervalSince1970
{
	uint64_t value = (uint64_t)object_getTaggedPointerValue(self);

	value |= UINT64_C(4) << 60;

	return OFFromBigEndianDouble(OFRawUInt64ToDouble(OFToBigEndian64(
	    value)));
}

OF_SINGLETON_METHODS
@end
#endif







|






36
37
38
39
40
41
42
43
44
45
46
47
48
49

- (OFTimeInterval)timeIntervalSince1970
{
	uint64_t value = (uint64_t)object_getTaggedPointerValue(self);

	value |= UINT64_C(4) << 60;

	return OFFromBigEndianDouble(OFBitConvertUInt64ToDouble(OFToBigEndian64(
	    value)));
}

OF_SINGLETON_METHODS
@end
#endif

Modified src/exceptions/OFException.h from [d9742d9115] to [5970277a67].

20
21
22
23
24
25
26


27
28
29
30
31
32
33
#import "OFObject.h"

#ifdef OF_WINDOWS
# include <windows.h>
#endif

OF_ASSUME_NONNULL_BEGIN



@class OFArray OF_GENERIC(ObjectType);
@class OFString;
@class OFValue;

#define OFStackTraceSize 16








>
>







20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#import "OFObject.h"

#ifdef OF_WINDOWS
# include <windows.h>
#endif

OF_ASSUME_NONNULL_BEGIN

/** @file */

@class OFArray OF_GENERIC(ObjectType);
@class OFString;
@class OFValue;

#define OFStackTraceSize 16

188
189
190
191
192
193
194











195

196
197
198
199
200
201
202
203
 */
- (nullable OFArray OF_GENERIC(OFString *) *)stackTraceSymbols;
@end

#ifdef __cplusplus
extern "C" {
#endif











extern OFString *OFStrError(int errNo);

#ifdef OF_WINDOWS
extern OFString *_OFWindowsStatusToString(LSTATUS status) OF_VISIBILITY_HIDDEN;
#endif
#ifdef __cplusplus
}
#endif

OF_ASSUME_NONNULL_END







>
>
>
>
>
>
>
>
>
>
>

>








190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
 */
- (nullable OFArray OF_GENERIC(OFString *) *)stackTraceSymbols;
@end

#ifdef __cplusplus
extern "C" {
#endif
/**
 * @brief Converts the specified error number (from `<errno.h>`) to a string.
 *
 * Unlike the system function `strerror`, this function is always thread-safe.
 *
 * As an addition, on Windows, it is also able to convert socket error numbers
 * to string.
 *
 * @param errNo The error number to convert to a string
 * @return A string describing the error
 */
extern OFString *OFStrError(int errNo);

#ifdef OF_WINDOWS
extern OFString *_OFWindowsStatusToString(LSTATUS status) OF_VISIBILITY_HIDDEN;
#endif
#ifdef __cplusplus
}
#endif

OF_ASSUME_NONNULL_END

Modified src/macros.h from [b827bb1ce0] to [e71e68e9ff].

34
35
36
37
38
39
40


41
42
43
44
45
46
47
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <sys/time.h>



#include "platform.h"

#ifdef OF_OBJFW_RUNTIME
# ifdef OF_COMPILING_OBJFW
#  include "ObjFWRT.h"
# else







>
>







34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <sys/time.h>

/** @file */

#include "platform.h"

#ifdef OF_OBJFW_RUNTIME
# ifdef OF_COMPILING_OBJFW
#  include "ObjFWRT.h"
# else
585
586
587
588
589
590
591
592






593
594







595
596







597
598
599
600
601
602
603
604






605
606
607
608
609
610
611
612






613
614
615
616
617
618
619
620






621
622
623
624
625
626
627
628






629
630
631
632
633
634
635
636






637
638
639
640

641
642






643
644
645
646

647
648
649







650








651








652








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






678







679







680







681







682







683







684







685
686
687
688
689
690
691
692
693
694
695
696







697
698
699
700
701








702
703
704
705
706
707







708
709
710
711
712
713
714
	i = (uint64_t)_OFByteSwap32NonConst(
	    (uint32_t)(i & UINT32_C(0xFFFFFFFF))) << 32 |
	    _OFByteSwap32NonConst((uint32_t)(i >> 32));
#endif
	return i;
}

#ifdef __GNUC__






# define OFByteSwap16(i) \
    (__builtin_constant_p(i) ? _OFByteSwap16Const(i) : _OFByteSwap16NonConst(i))







# define OFByteSwap32(i) \
    (__builtin_constant_p(i) ? _OFByteSwap32Const(i) : _OFByteSwap32NonConst(i))







# define OFByteSwap64(i) \
    (__builtin_constant_p(i) ? _OFByteSwap64Const(i) : _OFByteSwap64NonConst(i))
#else
# define OFByteSwap16(i) _OFByteSwap16Const(i)
# define OFByteSwap32(i) _OFByteSwap32Const(i)
# define OFByteSwap64(i) _OFByteSwap64Const(i)
#endif







static OF_INLINE uint32_t
OFFloatToRawUInt32(float f)
{
	uint32_t ret;
	memcpy(&ret, &f, 4);
	return ret;
}







static OF_INLINE float
OFRawUInt32ToFloat(uint32_t uInt32)
{
	float ret;
	memcpy(&ret, &uInt32, 4);
	return ret;
}







static OF_INLINE uint64_t
OFDoubleToRawUInt64(double d)
{
	uint64_t ret;
	memcpy(&ret, &d, 8);
	return ret;
}







static OF_INLINE double
OFRawUInt64ToDouble(uint64_t uInt64)
{
	double ret;
	memcpy(&ret, &uInt64, 8);
	return ret;
}







static OF_INLINE float OF_CONST_FUNC
OFByteSwapFloat(float f)
{
	return OFRawUInt32ToFloat(OFByteSwap32(OFFloatToRawUInt32(f)));

}







static OF_INLINE double OF_CONST_FUNC
OFByteSwapDouble(double d)
{
	return OFRawUInt64ToDouble(OFByteSwap64(OFDoubleToRawUInt64(d)));

}

#ifdef OF_BIG_ENDIAN







# define OFFromBigEndian16(i) (i)








# define OFFromBigEndian32(i) (i)








# define OFFromBigEndian64(i) (i)








# define OFFromLittleEndian16(i) OFByteSwap16(i)








# define OFFromLittleEndian32(i) OFByteSwap32(i)








# define OFFromLittleEndian64(i) OFByteSwap64(i)








# define OFToBigEndian16(i) (i)








# define OFToBigEndian32(i) (i)








# define OFToBigEndian64(i) (i)








# define OFToLittleEndian16(i) OFByteSwap16(i)








# define OFToLittleEndian32(i) OFByteSwap32(i)








# define OFToLittleEndian64(i) OFByteSwap64(i)
#else
# define OFFromBigEndian16(i) OFByteSwap16(i)
# define OFFromBigEndian32(i) OFByteSwap32(i)
# define OFFromBigEndian64(i) OFByteSwap64(i)
# define OFFromLittleEndian16(i) (i)
# define OFFromLittleEndian32(i) (i)
# define OFFromLittleEndian64(i) (i)
# define OFToBigEndian16(i) OFByteSwap16(i)
# define OFToBigEndian32(i) OFByteSwap32(i)
# define OFToBigEndian64(i) OFByteSwap64(i)
# define OFToLittleEndian16(i) (i)
# define OFToLittleEndian32(i) (i)
# define OFToLittleEndian64(i) (i)
#endif

#ifdef OF_FLOAT_BIG_ENDIAN






# define OFFromBigEndianFloat(f) (f)







# define OFFromBigEndianDouble(d) (d)







# define OFFromLittleEndianFloat(f) OFByteSwapFloat(f)







# define OFFromLittleEndianDouble(d) OFByteSwapDouble(d)







# define OFToBigEndianFloat(f) (f)







# define OFToBigEndianDouble(d) (d)







# define OFToLittleEndianFloat(f) OFByteSwapFloat(f)







# define OFToLittleEndianDouble(d) OFByteSwapDouble(d)
#else
# define OFFromBigEndianFloat(f) OFByteSwapFloat(f)
# define OFFromBigEndianDouble(d) OFByteSwapDouble(d)
# define OFFromLittleEndianFloat(f) (f)
# define OFFromLittleEndianDouble(d) (d)
# define OFToBigEndianFloat(f) OFByteSwapFloat(f)
# define OFToBigEndianDouble(d) OFByteSwapDouble(d)
# define OFToLittleEndianFloat(f) (f)
# define OFToLittleEndianDouble(d) (d)
#endif








#define OFRotateLeft(value, bits)					\
    (((bits) % (sizeof(value) * 8)) > 0					\
    ? ((value) << ((bits) % (sizeof(value) * 8))) |			\
    ((value) >> (sizeof(value) * 8 - ((bits) % (sizeof(value) * 8))))	\
    : (value))








#define OFRotateRight(value, bits)					\
    (((bits) % (sizeof(value) * 8)) > 0					\
    ? ((value) >> ((bits) % (sizeof(value) * 8))) |			\
    ((value) << (sizeof(value) * 8 - ((bits) % (sizeof(value) * 8))))	\
    : (value))








#define OFRoundUpToPowerOf2(pow2, value)	\
    (((value) + (pow2) - 1) & ~((pow2) - 1))

static OF_INLINE bool
OFBitsetIsSet(unsigned char *_Nonnull storage, size_t idx)
{
	return storage[idx / CHAR_BIT] & (1u << (idx % CHAR_BIT));







|
>
>
>
>
>
>


>
>
>
>
>
>
>


>
>
>
>
>
>
>








>
>
>
>
>
>
|
|






>
>
>
>
>
>
|
|






>
>
>
>
>
>
|
|






>
>
>
>
>
>
|
|






>
>
>
>
>
>



|
>


>
>
>
>
>
>



|
>


|
>
>
>
>
>
>
>

>
>
>
>
>
>
>
>

>
>
>
>
>
>
>
>

>
>
>
>
>
>
>
>

>
>
>
>
>
>
>
>

>
>
>
>
>
>
>
>

>
>
>
>
>
>
>
>

>
>
>
>
>
>
>
>

>
>
>
>
>
>
>
>

>
>
>
>
>
>
>
>

>
>
>
>
>
>
>
>

>
>
>
>
>
>
>
>
















|
>
>
>
>
>
>

>
>
>
>
>
>
>

>
>
>
>
>
>
>

>
>
>
>
>
>
>

>
>
>
>
>
>
>

>
>
>
>
>
>
>

>
>
>
>
>
>
>

>
>
>
>
>
>
>












>
>
>
>
>
>
>





>
>
>
>
>
>
>
>






>
>
>
>
>
>
>







587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
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
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
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
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
	i = (uint64_t)_OFByteSwap32NonConst(
	    (uint32_t)(i & UINT32_C(0xFFFFFFFF))) << 32 |
	    _OFByteSwap32NonConst((uint32_t)(i >> 32));
#endif
	return i;
}

#if defined(__GNUC__) || defined(DOXYGEN)
/**
 * @brief Byte swaps the specified 16 bit integer.
 *
 * @param i The integer to byte swap
 * @return The byte swapped integer
 */
# define OFByteSwap16(i) \
    (__builtin_constant_p(i) ? _OFByteSwap16Const(i) : _OFByteSwap16NonConst(i))

/**
 * @brief Byte swaps the specified 32 bit integer.
 *
 * @param i The integer to byte swap
 * @return The byte swapped integer
 */
# define OFByteSwap32(i) \
    (__builtin_constant_p(i) ? _OFByteSwap32Const(i) : _OFByteSwap32NonConst(i))

/**
 * @brief Byte swaps the specified 64 bit integer.
 *
 * @param i The integer to byte swap
 * @return The byte swapped integer
 */
# define OFByteSwap64(i) \
    (__builtin_constant_p(i) ? _OFByteSwap64Const(i) : _OFByteSwap64NonConst(i))
#else
# define OFByteSwap16(i) _OFByteSwap16Const(i)
# define OFByteSwap32(i) _OFByteSwap32Const(i)
# define OFByteSwap64(i) _OFByteSwap64Const(i)
#endif

/**
 * @brief Bit-converts the specified float to a uint32_t.
 *
 * @param f The float to bit-convert
 * @return The float bit-converted to a uint32_t
 */
static OF_INLINE uint32_t OF_CONST_FUNC
OFBitConvertFloatToUInt32(float f)
{
	uint32_t ret;
	memcpy(&ret, &f, 4);
	return ret;
}

/**
 * @brief Bit-converts the specified uint32_t to a float.
 *
 * @param uInt32 The uint32_t to bit-convert
 * @return The uint32_t bit-converted to a float
 */
static OF_INLINE float OF_CONST_FUNC
OFBitConvertUInt32ToFloat(uint32_t uInt32)
{
	float ret;
	memcpy(&ret, &uInt32, 4);
	return ret;
}

/**
 * @brief Bit-converts the specified double to a uint64_t.
 *
 * @param d The double to bit-convert
 * @return The double bit-converted to a uint64_t
 */
static OF_INLINE uint64_t OF_CONST_FUNC
OFBitConvertDoubleToUInt64(double d)
{
	uint64_t ret;
	memcpy(&ret, &d, 8);
	return ret;
}

/**
 * @brief Bit-converts the specified uint64_t to a double.
 *
 * @param uInt64 The uint64_t to bit-convert
 * @return The uint64_t bit-converted to a double
 */
static OF_INLINE double OF_CONST_FUNC
OFBitConvertUInt64ToDouble(uint64_t uInt64)
{
	double ret;
	memcpy(&ret, &uInt64, 8);
	return ret;
}

/**
 * @brief Byte swaps the specified float.
 *
 * @param f The float to byte swap
 * @return The byte swapped float
 */
static OF_INLINE float OF_CONST_FUNC
OFByteSwapFloat(float f)
{
	return OFBitConvertUInt32ToFloat(OFByteSwap32(
	    OFBitConvertFloatToUInt32(f)));
}

/**
 * @brief Byte swaps the specified double.
 *
 * @param d The double to byte swap
 * @return The byte swapped double
 */
static OF_INLINE double OF_CONST_FUNC
OFByteSwapDouble(double d)
{
	return OFBitConvertUInt64ToDouble(OFByteSwap64(
	    OFBitConvertDoubleToUInt64(d)));
}

#if defined(OF_BIG_ENDIAN) || defined(DOXYGEN)
/**
 * @brief Converts the specified 16 bit integer from big endian to native
 *	  endian.
 *
 * @param i The 16 bit integer to convert
 * @return The 16 bit integer converted to native endian
 */
# define OFFromBigEndian16(i) (i)

/**
 * @brief Converts the specified 32 bit integer from big endian to native
 *	  endian.
 *
 * @param i The 32 bit integer to convert
 * @return The 32 bit integer converted to native endian
 */
# define OFFromBigEndian32(i) (i)

/**
 * @brief Converts the specified 64 bit integer from big endian to native
 *	  endian.
 *
 * @param i The 64 bit integer to convert
 * @return The 64 bit integer converted to native endian
 */
# define OFFromBigEndian64(i) (i)

/**
 * @brief Converts the specified 16 bit integer from little endian to native
 *	  endian.
 *
 * @param i The 16 bit integer to convert
 * @return The 16 bit integer converted to native endian
 */
# define OFFromLittleEndian16(i) OFByteSwap16(i)

/**
 * @brief Converts the specified 32 bit integer from little endian to native
 *	  endian.
 *
 * @param i The 32 bit integer to convert
 * @return The 32 bit integer converted to native endian
 */
# define OFFromLittleEndian32(i) OFByteSwap32(i)

/**
 * @brief Converts the specified 64 bit integer from little endian to native
 *	  endian.
 *
 * @param i The 64 bit integer to convert
 * @return The 64 bit integer converted to native endian
 */
# define OFFromLittleEndian64(i) OFByteSwap64(i)

/**
 * @brief Converts the specified 16 bit integer from native endian to big
 *	  endian.
 *
 * @param i The 16 bit integer to convert
 * @return The 16 bit integer converted to big endian
 */
# define OFToBigEndian16(i) (i)

/**
 * @brief Converts the specified 32 bit integer from native endian to big
 *	  endian.
 *
 * @param i The 32 bit integer to convert
 * @return The 32 bit integer converted to big endian
 */
# define OFToBigEndian32(i) (i)

/**
 * @brief Converts the specified 64 bit integer from native endian to big
 *	  endian.
 *
 * @param i The 64 bit integer to convert
 * @return The 64 bit integer converted to big endian
 */
# define OFToBigEndian64(i) (i)

/**
 * @brief Converts the specified 16 bit integer from native endian to little
 *	  endian.
 *
 * @param i The 16 bit integer to convert
 * @return The 16 bit integer converted to little endian
 */
# define OFToLittleEndian16(i) OFByteSwap16(i)

/**
 * @brief Converts the specified 32 bit integer from native endian to little
 *	  endian.
 *
 * @param i The 32 bit integer to convert
 * @return The 32 bit integer converted to little endian
 */
# define OFToLittleEndian32(i) OFByteSwap32(i)

/**
 * @brief Converts the specified 64 bit integer from native endian to little
 *	  endian.
 *
 * @param i The 64 bit integer to convert
 * @return The 64 bit integer converted to little endian
 */
# define OFToLittleEndian64(i) OFByteSwap64(i)
#else
# define OFFromBigEndian16(i) OFByteSwap16(i)
# define OFFromBigEndian32(i) OFByteSwap32(i)
# define OFFromBigEndian64(i) OFByteSwap64(i)
# define OFFromLittleEndian16(i) (i)
# define OFFromLittleEndian32(i) (i)
# define OFFromLittleEndian64(i) (i)
# define OFToBigEndian16(i) OFByteSwap16(i)
# define OFToBigEndian32(i) OFByteSwap32(i)
# define OFToBigEndian64(i) OFByteSwap64(i)
# define OFToLittleEndian16(i) (i)
# define OFToLittleEndian32(i) (i)
# define OFToLittleEndian64(i) (i)
#endif

#if defined(OF_FLOAT_BIG_ENDIAN) || defined(DOXYGEN)
/**
 * @brief Converts the specified float from big endian to native endian.
 *
 * @param f The float to convert
 * @return The float converted to native endian
 */
# define OFFromBigEndianFloat(f) (f)

/**
 * @brief Converts the specified double from big endian to native endian.
 *
 * @param d The double to convert
 * @return The double converted to native endian
 */
# define OFFromBigEndianDouble(d) (d)

/**
 * @brief Converts the specified float from little endian to native endian.
 *
 * @param f The float to convert
 * @return The float converted to native endian
 */
# define OFFromLittleEndianFloat(f) OFByteSwapFloat(f)

/**
 * @brief Converts the specified double from little endian to native endian.
 *
 * @param d The double to convert
 * @return The double converted to native endian
 */
# define OFFromLittleEndianDouble(d) OFByteSwapDouble(d)

/**
 * @brief Converts the specified float from native endian to big endian.
 *
 * @param f The float to convert
 * @return The float converted to big endian
 */
# define OFToBigEndianFloat(f) (f)

/**
 * @brief Converts the specified double from native endian to big endian.
 *
 * @param d The double to convert
 * @return The double converted to big endian
 */
# define OFToBigEndianDouble(d) (d)

/**
 * @brief Converts the specified float from native endian to little endian.
 *
 * @param f The float to convert
 * @return The float converted to little endian
 */
# define OFToLittleEndianFloat(f) OFByteSwapFloat(f)

/**
 * @brief Converts the specified double from native endian to little endian.
 *
 * @param d The double to convert
 * @return The double converted to little endian
 */
# define OFToLittleEndianDouble(d) OFByteSwapDouble(d)
#else
# define OFFromBigEndianFloat(f) OFByteSwapFloat(f)
# define OFFromBigEndianDouble(d) OFByteSwapDouble(d)
# define OFFromLittleEndianFloat(f) (f)
# define OFFromLittleEndianDouble(d) (d)
# define OFToBigEndianFloat(f) OFByteSwapFloat(f)
# define OFToBigEndianDouble(d) OFByteSwapDouble(d)
# define OFToLittleEndianFloat(f) (f)
# define OFToLittleEndianDouble(d) (d)
#endif

/**
 * @brief Rotates the specified value left by the specified amount of bits.
 *
 * @param value The value to rotate
 * @param bits The number of bits to rotate left the value by
 * @return The value rotated left by the specified amount of bits
 */
#define OFRotateLeft(value, bits)					\
    (((bits) % (sizeof(value) * 8)) > 0					\
    ? ((value) << ((bits) % (sizeof(value) * 8))) |			\
    ((value) >> (sizeof(value) * 8 - ((bits) % (sizeof(value) * 8))))	\
    : (value))

/**
 * @brief Rotates the specified value right by the specified amount of bits.
 *
 * @param value The value to rotate
 * @param bits The number of bits to rotate right the value by
 * @return The value rotated right by the specified amount of bits
 */
#define OFRotateRight(value, bits)					\
    (((bits) % (sizeof(value) * 8)) > 0					\
    ? ((value) >> ((bits) % (sizeof(value) * 8))) |			\
    ((value) << (sizeof(value) * 8 - ((bits) % (sizeof(value) * 8))))	\
    : (value))

/**
 * @brief Rounds up the specified value to the specified power of two.
 *
 * @param pow2 The power of 2 to round up to
 * @param value The value to round up to the specified power of two
 * @return The specified value rounded up to the specified power of two
 */
#define OFRoundUpToPowerOf2(pow2, value)	\
    (((value) + (pow2) - 1) & ~((pow2) - 1))

static OF_INLINE bool
OFBitsetIsSet(unsigned char *_Nonnull storage, size_t idx)
{
	return storage[idx / CHAR_BIT] & (1u << (idx % CHAR_BIT));