16 #ifndef OBJFW_MACROS_H
17 #define OBJFW_MACROS_H
19 #include "objfw-defs.h"
21 #ifndef __STDC_LIMIT_MACROS
22 # define __STDC_LIMIT_MACROS
24 #ifndef __STDC_CONSTANT_MACROS
25 # define __STDC_CONSTANT_MACROS
40 #ifdef OF_OBJFW_RUNTIME
41 # ifdef OF_COMPILING_OBJFW
44 # include <ObjFWRT/ObjFWRT.h>
47 #ifdef OF_APPLE_RUNTIME
48 # include <objc/objc.h>
49 # include <objc/runtime.h>
50 # include <objc/message.h>
54 # define restrict __restrict__
55 #elif __STDC_VERSION__ < 199901L
59 #if __STDC_VERSION__ >= 201112L && !defined(static_assert)
61 # define static_assert _Static_assert
64 #if defined(OF_HAVE__THREAD_LOCAL)
65 # define OF_HAVE_COMPILER_TLS
66 # ifdef OF_HAVE_THREADS_H
71 # define thread_local _Thread_local
74 # define thread_local _Thread_local
76 #elif defined(OF_HAVE___THREAD)
77 # define OF_HAVE_COMPILER_TLS
78 # define thread_local __thread
85 #if defined(OF_HAVE_COMPILER_TLS) && defined(OF_IOS) && defined(OF_X86)
86 # undef OF_HAVE_COMPILER_TLS
90 # define OF_INLINE inline __attribute__((__always_inline__))
91 # define OF_LIKELY(cond) (__builtin_expect(!!(cond), 1))
92 # define OF_UNLIKELY(cond) (__builtin_expect(!!(cond), 0))
93 # define OF_CONST_FUNC __attribute__((__const__))
94 # define OF_NO_RETURN_FUNC __attribute__((__noreturn__))
95 # define OF_WEAK_REF(sym) __attribute__((__weakref__(sym)))
97 # define OF_INLINE inline
98 # define OF_LIKELY(cond) (cond)
99 # define OF_UNLIKELY(cond) (cond)
100 # define OF_CONST_FUNC
101 # define OF_NO_RETURN_FUNC
102 # define OF_WEAK_REF(sym)
106 # define OF_BYTE_ORDER_NATIVE OF_BYTE_ORDER_BIG_ENDIAN
108 # define OF_BYTE_ORDER_NATIVE OF_BYTE_ORDER_LITTLE_ENDIAN
111 #if __STDC_VERSION__ >= 201112L
112 # define OF_ALIGNOF(type) _Alignof(type)
113 # define OF_ALIGNAS(type) _Alignas(type)
115 # define OF_ALIGNOF(type) __alignof__(type)
116 # define OF_ALIGNAS(type) __attribute__((__aligned__(__alignof__(type))))
119 #if __STDC_VERSION__ >= 201112L && defined(OF_HAVE_MAX_ALIGN_T)
120 # define OF_BIGGEST_ALIGNMENT _Alignof(max_align_t)
122 # ifdef __BIGGEST_ALIGNMENT__
123 # define OF_BIGGEST_ALIGNMENT __BIGGEST_ALIGNMENT__
126 # define OF_BIGGEST_ALIGNMENT 16
130 #define OF_PREPROCESSOR_CONCAT2(a, b) a##b
131 #define OF_PREPROCESSOR_CONCAT(a, b) OF_PREPROCESSOR_CONCAT2(a, b)
133 #if __OBJFW_RUNTIME_ABI__ || (defined(OF_APPLE_RUNTIME) && defined(__OBJC2__))
134 # define OF_HAVE_NONFRAGILE_IVARS
137 #ifdef OF_HAVE_NONFRAGILE_IVARS
138 # define OF_RESERVE_IVARS(cls, num)
140 # define OF_RESERVE_IVARS(cls, num) \
142 void *OF_PREPROCESSOR_CONCAT(_reserved_, cls)[num];
146 # define OF_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
148 # define OF_GCC_VERSION 0
151 #define OF_STRINGIFY(s) OF_STRINGIFY2(s)
152 #define OF_STRINGIFY2(s) #s
154 #ifndef __has_feature
155 # define __has_feature(x) 0
158 #ifndef __has_attribute
159 # define __has_attribute(x) 0
162 #if __has_feature(objc_bool)
164 # define YES __objc_yes
166 # define NO __objc_no
169 # define true ((bool)1)
171 # define false ((bool)0)
175 #if !__has_feature(objc_instancetype)
176 # define instancetype id
179 #if __has_feature(blocks)
180 # define OF_HAVE_BLOCKS
183 #if __has_feature(objc_arc)
184 # define OF_RETURNS_RETAINED __attribute__((__ns_returns_retained__))
185 # define OF_RETURNS_NOT_RETAINED __attribute__((__ns_returns_not_retained__))
186 # define OF_RETURNS_INNER_POINTER \
187 __attribute__((__objc_returns_inner_pointer__))
188 # define OF_CONSUMED __attribute__((__ns_consumed__))
189 # define OF_WEAK_UNAVAILABLE __attribute__((__objc_arc_weak_unavailable__))
191 # define OF_RETURNS_RETAINED
192 # define OF_RETURNS_NOT_RETAINED
193 # define OF_RETURNS_INNER_POINTER
195 # define OF_WEAK_UNAVAILABLE
200 # undef __unsafe_unretained
202 # undef __autoreleasing
203 # define __unsafe_unretained
205 # define __autoreleasing
208 #if __has_feature(objc_generics)
209 # define OF_HAVE_GENERICS
210 # define OF_GENERIC(...) <__VA_ARGS__>
212 # define OF_GENERIC(...)
215 #if __has_feature(nullability)
216 # define OF_ASSUME_NONNULL_BEGIN _Pragma("clang assume_nonnull begin")
217 # define OF_ASSUME_NONNULL_END _Pragma("clang assume_nonnull end")
218 # define OF_NULLABLE_PROPERTY(...) (__VA_ARGS__, nullable)
219 # define OF_NULL_RESETTABLE_PROPERTY(...) (__VA_ARGS__, null_resettable)
221 # define OF_ASSUME_NONNULL_BEGIN
222 # define OF_ASSUME_NONNULL_END
225 # define _Null_unspecified
226 # define OF_NULLABLE_PROPERTY
227 # define OF_NULL_RESETTABLE_PROPERTY
230 # define null_unspecified
233 #if __has_feature(objc_kindof)
234 # define OF_KINDOF(class_) __kindof class_
236 # define OF_KINDOF(class_) id
239 #if __has_feature(objc_class_property)
240 # define OF_HAVE_CLASS_PROPERTIES
243 #if defined(__clang__) || OF_GCC_VERSION >= 405
244 # define OF_UNREACHABLE __builtin_unreachable();
246 # define OF_UNREACHABLE abort();
249 #if defined(__clang__) || OF_GCC_VERSION >= 406
250 # define OF_SENTINEL __attribute__((__sentinel__))
251 # define OF_NO_RETURN __attribute__((__noreturn__))
254 # define OF_NO_RETURN
258 # define OF_WARN_UNUSED_RESULT __attribute__((__warn_unused_result__))
260 # define OF_WARN_UNUSED_RESULT
263 #if __has_attribute(__unavailable__)
264 # define OF_UNAVAILABLE __attribute__((__unavailable__))
265 # define OF_HAVE_UNAVAILABLE
267 # define OF_UNAVAILABLE
270 #if __has_attribute(__objc_requires_super__)
271 # define OF_REQUIRES_SUPER __attribute__((__objc_requires_super__))
273 # define OF_REQUIRES_SUPER
276 #if __has_attribute(__objc_root_class__)
277 # define OF_ROOT_CLASS __attribute__((__objc_root_class__))
279 # define OF_ROOT_CLASS
282 #if __has_attribute(__objc_subclassing_restricted__)
283 # define OF_SUBCLASSING_RESTRICTED \
284 __attribute__((__objc_subclassing_restricted__))
286 # define OF_SUBCLASSING_RESTRICTED
289 #if __has_attribute(__objc_method_family__)
290 # define OF_METHOD_FAMILY(f) __attribute__((__objc_method_family__(f)))
292 # define OF_METHOD_FAMILY(f)
295 #if __has_attribute(__objc_designated_initializer__)
296 # define OF_DESIGNATED_INITIALIZER \
297 __attribute__((__objc_designated_initializer__))
299 # define OF_DESIGNATED_INITIALIZER
302 #if __has_attribute(__objc_boxable__)
303 # define OF_BOXABLE __attribute__((__objc_boxable__))
308 #if __has_attribute(__swift_name__)
309 # define OF_SWIFT_NAME(name) __attribute__((__swift_name__(name)))
311 # define OF_SWIFT_NAME(name)
314 #if __has_attribute(__objc_direct__) && defined(OF_APPLE_RUNTIME)
315 # define OF_DIRECT __attribute__((__objc_direct__))
319 #if __has_attribute(__objc_direct_members__) && defined(OF_APPLE_RUNTIME)
320 # define OF_DIRECT_MEMBERS __attribute__((__objc_direct_members__))
322 # define OF_DIRECT_MEMBERS
325 #ifdef OF_APPLE_RUNTIME
326 # if defined(OF_X86_64) || defined(OF_X86) || defined(OF_ARM64) || \
327 defined(OF_ARM) || defined(OF_POWERPC)
328 # define OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR
329 # define OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR_STRET
333 # if defined(OF_X86_64) || defined(OF_X86) || \
334 defined(OF_ARM64) || defined(OF_ARM) || defined(OF_POWERPC) || \
335 defined(OF_MIPS) || defined(OF_SPARC64) || defined(OF_SPARC)
336 # define OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR
337 # if __OBJFW_RUNTIME_ABI__ >= 800
338 # define OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR_STRET
341 # elif defined(OF_MACH_O)
342 # if defined(OF_X86_64)
343 # define OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR
344 # if __OBJFW_RUNTIME_ABI__ >= 800
345 # define OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR_STRET
348 # elif defined(OF_WINDOWS)
349 # if defined(OF_X86_64) || defined(OF_X86)
350 # define OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR
351 # if __OBJFW_RUNTIME_ABI__ >= 800
352 # define OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR_STRET
358 #define OF_RETAIN_COUNT_MAX UINT_MAX
359 #define OF_NOT_FOUND SIZE_MAX
361 #ifdef OBJC_COMPILING_RUNTIME
362 # define OF_ENSURE(cond) \
364 if OF_UNLIKELY (!(cond)) \
365 objc_error("ObjFWRT @ " __FILE__ ":" \
366 OF_STRINGIFY(__LINE__), \
367 "Failed to ensure condition:\n" #cond); \
370 # define OF_ENSURE(cond) \
372 if OF_UNLIKELY (!(cond)) { \
373 fprintf(stderr, "Failed to ensure condition " \
374 "in " __FILE__ ":%d:\n" #cond "\n", \
381 #define OF_UNRECOGNIZED_SELECTOR of_method_not_found(self, _cmd);
382 #if __has_feature(objc_arc)
383 # define OF_INVALID_INIT_METHOD of_method_not_found(self, _cmd);
385 # define OF_INVALID_INIT_METHOD \
387 of_method_not_found(self, _cmd); \
396 # define OF_DEALLOC_UNSUPPORTED \
397 [self doesNotRecognizeSelector: _cmd]; \
401 _Pragma("clang diagnostic push ignored \"-Wunreachable-code\""); \
403 _Pragma("clang diagnostic pop");
405 # define OF_DEALLOC_UNSUPPORTED \
406 [self doesNotRecognizeSelector: _cmd]; \
413 #define OF_CONSTRUCTOR(prio) \
414 static void __attribute__((__constructor__(prio))) \
415 OF_PREPROCESSOR_CONCAT(constructor, __LINE__)(void)
416 #define OF_DESTRUCTOR(prio) \
417 static void __attribute__((__destructor__(prio))) \
418 OF_PREPROCESSOR_CONCAT(destructor, __LINE__)(void)
420 static OF_INLINE uint16_t OF_CONST_FUNC
421 OF_BSWAP16_CONST(uint16_t i)
423 return (i & 0xFF00) >> 8 | (i & 0x00FF) << 8;
426 static OF_INLINE uint32_t OF_CONST_FUNC
427 OF_BSWAP32_CONST(uint32_t i)
429 return (i & 0xFF000000) >> 24 | (i & 0x00FF0000) >> 8 |
430 (i & 0x0000FF00) << 8 | (i & 0x000000FF) << 24;
433 static OF_INLINE uint64_t OF_CONST_FUNC
434 OF_BSWAP64_CONST(uint64_t i)
436 return (i & 0xFF00000000000000) >> 56 | (i & 0x00FF000000000000) >> 40 |
437 (i & 0x0000FF0000000000) >> 24 | (i & 0x000000FF00000000) >> 8 |
438 (i & 0x00000000FF000000) << 8 | (i & 0x0000000000FF0000) << 24 |
439 (i & 0x000000000000FF00) << 40 | (i & 0x00000000000000FF) << 56;
442 static OF_INLINE uint16_t OF_CONST_FUNC
443 OF_BSWAP16_NONCONST(uint16_t i)
445 #if defined(OF_HAVE_BUILTIN_BSWAP16)
446 return __builtin_bswap16(i);
447 #elif (defined(OF_X86_64) || defined(OF_X86)) && defined(__GNUC__)
453 #elif defined(OF_POWERPC) && defined(__GNUC__)
459 #elif defined(OF_ARMV6) && defined(__GNUC__)
466 i = (i & UINT16_C(0xFF00)) >> 8 |
467 (i & UINT16_C(0x00FF)) << 8;
472 static OF_INLINE uint32_t OF_CONST_FUNC
473 OF_BSWAP32_NONCONST(uint32_t i)
475 #if defined(OF_HAVE_BUILTIN_BSWAP32)
476 return __builtin_bswap32(i);
477 #elif (defined(OF_X86_64) || defined(OF_X86)) && defined(__GNUC__)
483 #elif defined(OF_POWERPC) && defined(__GNUC__)
489 #elif defined(OF_ARMV6) && defined(__GNUC__)
496 i = (i & UINT32_C(0xFF000000)) >> 24 |
497 (i & UINT32_C(0x00FF0000)) >> 8 |
498 (i & UINT32_C(0x0000FF00)) << 8 |
499 (i & UINT32_C(0x000000FF)) << 24;
504 static OF_INLINE uint64_t OF_CONST_FUNC
505 OF_BSWAP64_NONCONST(uint64_t i)
507 #if defined(OF_HAVE_BUILTIN_BSWAP64)
508 return __builtin_bswap64(i);
509 #elif defined(OF_X86_64) && defined(__GNUC__)
515 #elif defined(OF_X86) && defined(__GNUC__)
524 i = (uint64_t)OF_BSWAP32_NONCONST((uint32_t)(i & 0xFFFFFFFF)) << 32 |
525 OF_BSWAP32_NONCONST((uint32_t)(i >> 32));
531 # define OF_BSWAP16(i) \
532 (__builtin_constant_p(i) ? OF_BSWAP16_CONST(i) : OF_BSWAP16_NONCONST(i))
533 # define OF_BSWAP32(i) \
534 (__builtin_constant_p(i) ? OF_BSWAP32_CONST(i) : OF_BSWAP32_NONCONST(i))
535 # define OF_BSWAP64(i) \
536 (__builtin_constant_p(i) ? OF_BSWAP64_CONST(i) : OF_BSWAP64_NONCONST(i))
538 # define OF_BSWAP16(i) OF_BSWAP16_CONST(i)
539 # define OF_BSWAP32(i) OF_BSWAP32_CONST(i)
540 # define OF_BSWAP64(i) OF_BSWAP64_CONST(i)
543 static OF_INLINE uint32_t
544 OF_FLOAT_TO_INT_RAW(
float f)
551 static OF_INLINE
float
552 OF_INT_TO_FLOAT_RAW(uint32_t uInt32)
555 memcpy(&ret, &uInt32, 4);
559 static OF_INLINE uint64_t
560 OF_DOUBLE_TO_INT_RAW(
double d)
567 static OF_INLINE
double
568 OF_INT_TO_DOUBLE_RAW(uint64_t uInt64)
571 memcpy(&ret, &uInt64, 8);
575 static OF_INLINE
float OF_CONST_FUNC
576 OF_BSWAP_FLOAT(
float f)
578 return OF_INT_TO_FLOAT_RAW(OF_BSWAP32(OF_FLOAT_TO_INT_RAW(f)));
581 static OF_INLINE
double OF_CONST_FUNC
582 OF_BSWAP_DOUBLE(
double d)
584 return OF_INT_TO_DOUBLE_RAW(OF_BSWAP64(OF_DOUBLE_TO_INT_RAW(d)));
588 # define OF_BSWAP16_IF_BE(i) OF_BSWAP16(i)
589 # define OF_BSWAP32_IF_BE(i) OF_BSWAP32(i)
590 # define OF_BSWAP64_IF_BE(i) OF_BSWAP64(i)
591 # define OF_BSWAP16_IF_LE(i) (i)
592 # define OF_BSWAP32_IF_LE(i) (i)
593 # define OF_BSWAP64_IF_LE(i) (i)
595 # define OF_BSWAP16_IF_BE(i) (i)
596 # define OF_BSWAP32_IF_BE(i) (i)
597 # define OF_BSWAP64_IF_BE(i) (i)
598 # define OF_BSWAP16_IF_LE(i) OF_BSWAP16(i)
599 # define OF_BSWAP32_IF_LE(i) OF_BSWAP32(i)
600 # define OF_BSWAP64_IF_LE(i) OF_BSWAP64(i)
603 #ifdef OF_FLOAT_BIG_ENDIAN
604 # define OF_BSWAP_FLOAT_IF_BE(i) OF_BSWAP_FLOAT(i)
605 # define OF_BSWAP_DOUBLE_IF_BE(i) OF_BSWAP_DOUBLE(i)
606 # define OF_BSWAP_FLOAT_IF_LE(i) (i)
607 # define OF_BSWAP_DOUBLE_IF_LE(i) (i)
609 # define OF_BSWAP_FLOAT_IF_BE(i) (i)
610 # define OF_BSWAP_DOUBLE_IF_BE(i) (i)
611 # define OF_BSWAP_FLOAT_IF_LE(i) OF_BSWAP_FLOAT(i)
612 # define OF_BSWAP_DOUBLE_IF_LE(i) OF_BSWAP_DOUBLE(i)
615 static OF_INLINE uint16_t
616 of_be16_ptr_read(
void *_Nonnull ptr)
619 memcpy(&value, ptr,
sizeof(value));
620 return OF_BSWAP16_IF_LE(value);
623 static OF_INLINE uint32_t
624 of_be32_ptr_read(
void *_Nonnull ptr)
627 memcpy(&value, ptr,
sizeof(value));
628 return OF_BSWAP32_IF_LE(value);
631 static OF_INLINE uint64_t
632 of_be64_ptr_read(
void *_Nonnull ptr)
635 memcpy(&value, ptr,
sizeof(value));
636 return OF_BSWAP64_IF_LE(value);
639 static OF_INLINE
float
640 of_be_float_ptr_read(
void *_Nonnull ptr)
643 memcpy(&value, ptr,
sizeof(value));
644 return OF_BSWAP_FLOAT_IF_LE(value);
647 static OF_INLINE
double
648 of_be_double_ptr_read(
void *_Nonnull ptr)
651 memcpy(&value, ptr,
sizeof(value));
652 return OF_BSWAP_DOUBLE_IF_LE(value);
655 static OF_INLINE uint16_t
656 of_le16_ptr_read(
void *_Nonnull ptr)
659 memcpy(&value, ptr,
sizeof(value));
660 return OF_BSWAP16_IF_BE(value);
663 static OF_INLINE uint32_t
664 of_le32_ptr_read(
void *_Nonnull ptr)
667 memcpy(&value, ptr,
sizeof(value));
668 return OF_BSWAP32_IF_BE(value);
671 static OF_INLINE uint64_t
672 of_le64_ptr_read(
void *_Nonnull ptr)
675 memcpy(&value, ptr,
sizeof(value));
676 return OF_BSWAP64_IF_BE(value);
679 static OF_INLINE
float
680 of_le_float_ptr_read(
void *_Nonnull ptr)
683 memcpy(&value, ptr,
sizeof(value));
684 return OF_BSWAP_FLOAT_IF_BE(value);
687 static OF_INLINE
double
688 of_le_double_ptr_read(
void *_Nonnull ptr)
691 memcpy(&value, ptr,
sizeof(value));
692 return OF_BSWAP_DOUBLE_IF_BE(value);
695 static OF_INLINE
void
696 of_be16_ptr_write(
void *_Nonnull ptr, uint16_t value)
698 value = OF_BSWAP16_IF_LE(value);
699 memcpy(ptr, &value,
sizeof(value));
702 static OF_INLINE
void
703 of_be32_ptr_write(
void *_Nonnull ptr, uint32_t value)
705 value = OF_BSWAP32_IF_LE(value);
706 memcpy(ptr, &value,
sizeof(value));
709 static OF_INLINE
void
710 of_be64_ptr_write(
void *_Nonnull ptr, uint64_t value)
712 value = OF_BSWAP64_IF_LE(value);
713 memcpy(ptr, &value,
sizeof(value));
716 static OF_INLINE
void
717 of_be_float_ptr_write(
void *_Nonnull ptr,
float value)
719 value = OF_BSWAP_FLOAT_IF_LE(value);
720 memcpy(ptr, &value,
sizeof(value));
723 static OF_INLINE
void
724 of_be_double_ptr_write(
void *_Nonnull ptr,
double value)
726 value = OF_BSWAP_DOUBLE_IF_LE(value);
727 memcpy(ptr, &value,
sizeof(value));
730 static OF_INLINE
void
731 of_le16_ptr_write(
void *_Nonnull ptr, uint16_t value)
733 value = OF_BSWAP16_IF_BE(value);
734 memcpy(ptr, &value,
sizeof(value));
737 static OF_INLINE
void
738 of_le32_ptr_write(
void *_Nonnull ptr, uint32_t value)
740 value = OF_BSWAP32_IF_BE(value);
741 memcpy(ptr, &value,
sizeof(value));
744 static OF_INLINE
void
745 of_le64_ptr_write(
void *_Nonnull ptr, uint64_t value)
747 value = OF_BSWAP64_IF_BE(value);
748 memcpy(ptr, &value,
sizeof(value));
751 static OF_INLINE
void
752 of_le_float_ptr_write(
void *_Nonnull ptr,
float value)
754 value = OF_BSWAP_FLOAT_IF_BE(value);
755 memcpy(ptr, &value,
sizeof(value));
758 static OF_INLINE
void
759 of_le_double_ptr_write(
void *_Nonnull ptr,
double value)
761 value = OF_BSWAP_DOUBLE_IF_BE(value);
762 memcpy(ptr, &value,
sizeof(value));
765 #define OF_ROL(value, bits) \
766 (((bits) % (sizeof(value) * 8)) > 0 \
767 ? ((value) << ((bits) % (sizeof(value) * 8))) | \
768 ((value) >> (sizeof(value) * 8 - ((bits) % (sizeof(value) * 8)))) \
770 #define OF_ROR(value, bits) \
771 (((bits) % (sizeof(value) * 8)) > 0 \
772 ? ((value) >> ((bits) % (sizeof(value) * 8))) | \
773 ((value) << (sizeof(value) * 8 - ((bits) % (sizeof(value) * 8)))) \
776 #define OF_ROUND_UP_POW2(pow2, value) (((value) + (pow2) - 1) & ~((pow2) - 1))
778 #define OF_HASH_INIT(hash) hash = of_hash_seed;
779 #define OF_HASH_ADD(hash, byte) \
781 hash += (uint8_t)(byte); \
782 hash += (hash << 10); \
783 hash ^= (hash >> 6); \
785 #define OF_HASH_FINALIZE(hash) \
787 hash += (hash << 3); \
788 hash ^= (hash >> 11); \
789 hash += (hash << 15); \
791 #define OF_HASH_ADD_HASH(hash, other) \
793 uint32_t otherCopy = (uint32_t)other; \
794 OF_HASH_ADD(hash, (otherCopy >> 24) & 0xFF); \
795 OF_HASH_ADD(hash, (otherCopy >> 16) & 0xFF); \
796 OF_HASH_ADD(hash, (otherCopy >> 8) & 0xFF); \
797 OF_HASH_ADD(hash, otherCopy & 0xFF); \
800 static OF_INLINE
bool
801 of_bitset_isset(
unsigned char *_Nonnull storage,
size_t idx)
803 return storage[idx / CHAR_BIT] & (1u << (idx % CHAR_BIT));
806 static OF_INLINE
void
807 of_bitset_set(
unsigned char *_Nonnull storage,
size_t idx)
809 storage[idx / CHAR_BIT] |= (1u << (idx % CHAR_BIT));
812 static OF_INLINE
void
813 of_bitset_clear(
unsigned char *_Nonnull storage,
size_t idx)
815 storage[idx / CHAR_BIT] &= ~(1u << (idx % CHAR_BIT));
818 static OF_INLINE
char *_Nullable
819 of_strdup(
const char *_Nonnull
string)
822 size_t length = strlen(
string);
824 if ((copy = (
char *)malloc(length + 1)) == NULL)
827 memcpy(copy,
string, length + 1);
832 static OF_INLINE
void
833 of_explicit_memset(
void *_Nonnull buffer_,
int character,
size_t length)
835 volatile unsigned char *buffer = (
volatile unsigned char *)buffer_;
837 while (buffer < (
unsigned char *)buffer_ + length)
838 *buffer++ = character;
841 static OF_INLINE
bool
842 of_ascii_isalpha(
char c)
844 return ((c >=
'a' && c <=
'z') || (c >=
'A' && c <=
'Z'));
847 static OF_INLINE
bool
848 of_ascii_isdigit(
char c)
850 return (c >=
'0' && c <=
'9');
853 static OF_INLINE
bool
854 of_ascii_isalnum(
char c)
856 return (of_ascii_isalpha(c) || of_ascii_isdigit(c));
859 static OF_INLINE
bool
860 of_ascii_isspace(
char c)
862 return (c ==
' ' || c ==
'\t' || c ==
'\n' || c ==
'\r' || c ==
'\f' ||
866 static OF_INLINE
char
867 of_ascii_toupper(
char c)
869 return (c >=
'a' && c <=
'z' ?
'A' + (c -
'a') : c);
872 static OF_INLINE
char
873 of_ascii_tolower(
char c)
875 return (c >=
'A' && c <=
'Z' ?
'a' + (c -
'A') : c);