compat: bless C23-style auto
for type inference
C23 auto standardizes GCC's __auto_type semantics, so we can start using it already.
This commit is contained in:
parent
4b71ebf170
commit
a025ea5251
5 changed files with 14 additions and 9 deletions
|
@ -160,7 +160,7 @@ INLINE void unlock_audio(void) {
|
|||
|
||||
#define WITH_AUDIO_LOCK(...) ({ \
|
||||
lock_audio(); \
|
||||
__auto_type _result = __VA_ARGS__; \
|
||||
auto _result = __VA_ARGS__; \
|
||||
unlock_audio(); \
|
||||
_result; \
|
||||
})
|
||||
|
|
|
@ -387,7 +387,7 @@ DECLARE_EXTERN_TASK(_cancel_task_helper, { BoxedTask task; });
|
|||
#define AWAIT_SUBTASKS cotask_wait_subtasks()
|
||||
|
||||
#define NOT_NULL_OR_DIE(expr) ({ \
|
||||
__auto_type _not_null_ptr = (expr); \
|
||||
auto _not_null_ptr = (expr); \
|
||||
if(_not_null_ptr == NULL) { \
|
||||
cotask_cancel(NOT_NULL(cotask_active())); \
|
||||
UNREACHABLE; \
|
||||
|
|
|
@ -79,7 +79,7 @@ dynarray_size_t _dynarray_prepare_append_with_min_capacity(dynarray_size_t sizeo
|
|||
dynarray_get_ptr(darr, _dynarray_dispatch_func(prepare_append_with_min_capacity, darr, min_capacity))
|
||||
|
||||
#define dynarray_append_with_min_capacity(darr, min_capacity) ({ \
|
||||
__auto_type _darr2 = NOT_NULL(darr); \
|
||||
auto _darr2 = NOT_NULL(darr); \
|
||||
dynarray_get_ptr(_darr2, _dynarray_dispatch_func(prepare_append_with_min_capacity, _darr2, min_capacity)); \
|
||||
})
|
||||
|
||||
|
@ -99,7 +99,7 @@ void _dynarray_compact(dynarray_size_t sizeof_element, DynamicArray *darr) attr_
|
|||
|
||||
#define dynarray_get_ptr(darr, idx) ({ \
|
||||
DYNARRAY_ASSERT_VALID(darr); \
|
||||
__auto_type _darr = NOT_NULL(darr); \
|
||||
auto _darr = NOT_NULL(darr); \
|
||||
dynarray_size_t _darr_idx = (idx); \
|
||||
assume(_darr_idx >= 0); \
|
||||
assume(_darr_idx < _darr->num_elements); \
|
||||
|
@ -129,8 +129,8 @@ void _dynarray_filter(
|
|||
|
||||
#define dynarray_indexof(darr, pelem) ({ \
|
||||
DYNARRAY_ASSERT_VALID(darr); \
|
||||
__auto_type _darr = NOT_NULL(darr); \
|
||||
__auto_type _darr_pelem = NOT_NULL(pelem); \
|
||||
auto _darr = NOT_NULL(darr); \
|
||||
auto _darr_pelem = NOT_NULL(pelem); \
|
||||
DYNARRAY_CHECK_ELEMENT_TYPE(_darr, *(_darr_pelem)); \
|
||||
intptr_t _darr_idx = (intptr_t)(_darr_pelem - _darr->data); \
|
||||
assume(_darr_idx >= 0); \
|
||||
|
|
|
@ -124,7 +124,7 @@ INLINE const char *ent_type_name(EntityType type) {
|
|||
}
|
||||
|
||||
#define ENT_CAST(ent, typename) ({ \
|
||||
__auto_type _ent = ent; \
|
||||
auto _ent = ent; \
|
||||
assert(_ent->type == ENT_TYPE_ID(typename)); \
|
||||
UNION_CAST(EntityInterface*, typename*, _ent); \
|
||||
})
|
||||
|
|
|
@ -292,7 +292,7 @@ typedef _Complex double cmplx;
|
|||
|
||||
#define ASSUME_ALIGNED(expr, alignment) ({ \
|
||||
static_assert(__builtin_constant_p(alignment), ""); \
|
||||
__auto_type _assume_aligned_ptr = (expr); \
|
||||
auto _assume_aligned_ptr = (expr); \
|
||||
assert(((uintptr_t)_assume_aligned_ptr & ((alignment) - 1)) == 0); \
|
||||
__builtin_assume_aligned(_assume_aligned_ptr, (alignment)); \
|
||||
})
|
||||
|
@ -303,7 +303,7 @@ typedef _Complex double cmplx;
|
|||
#define CASTPTR_ASSUME_ALIGNED(expr, type) ((type*)ASSUME_ALIGNED((expr), alignof(type)))
|
||||
|
||||
#define NOT_NULL(expr) ({ \
|
||||
__auto_type _assume_not_null_ptr = (expr); \
|
||||
auto _assume_not_null_ptr = (expr); \
|
||||
assume(_assume_not_null_ptr != NULL); \
|
||||
_assume_not_null_ptr; \
|
||||
})
|
||||
|
@ -322,3 +322,8 @@ typedef _Complex double cmplx;
|
|||
#if defined(__SANITIZE_ADDRESS__) || __has_feature(address_sanitizer)
|
||||
#define ADDRESS_SANITIZER
|
||||
#endif
|
||||
|
||||
// `auto` for type inference is standardized in C23 based on GCC's __auto_type semantics.
|
||||
// We want to have it now, and we don't care about the useless original purpose of C's `auto`.
|
||||
// from __future__ import auto
|
||||
#define auto __auto_type
|
||||
|
|
Loading…
Reference in a new issue