tree-wide: replace __alignof__() with alignof()

Addresses https://github.com/systemd/systemd/pull/27254#discussion_r1165267046.
This commit is contained in:
Yu Watanabe 2023-04-14 13:55:31 +09:00
parent 4db752e4aa
commit 1113e50796
5 changed files with 14 additions and 13 deletions

View file

@ -184,7 +184,7 @@ int flush_accept(int fd);
#define CMSG_TYPED_DATA(cmsg, type) \
({ \
struct cmsghdr *_cmsg = (cmsg); \
assert_cc(__alignof__(type) <= __alignof__(struct cmsghdr)); \
assert_cc(alignof(type) <= alignof(struct cmsghdr)); \
_cmsg ? CAST_ALIGN_PTR(type, CMSG_DATA(_cmsg)) : (type*) NULL; \
})

View file

@ -191,7 +191,7 @@ static uint32_t get_compatibility_entry_address(const DosFileHeader *dos, const
uint32_t entry_point;
} _packed_ LinuxPeCompat1;
while (size >= sizeof(LinuxPeCompat1) && addr % __alignof__(LinuxPeCompat1) == 0) {
while (size >= sizeof(LinuxPeCompat1) && addr % alignof(LinuxPeCompat1) == 0) {
LinuxPeCompat1 *compat = (LinuxPeCompat1 *) ((uint8_t *) dos + addr);
if (compat->type == 0 || compat->size == 0 || compat->size > size)

View file

@ -6,12 +6,13 @@
#endif
#include <limits.h>
#include <stdalign.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#define _align_(x) __attribute__((__aligned__(x)))
#define _alignas_(x) __attribute__((__aligned__(__alignof__(x))))
#define _alignas_(x) __attribute__((__aligned__(alignof(x))))
#define _alignptr_ __attribute__((__aligned__(sizeof(void *))))
#define _cleanup_(x) __attribute__((__cleanup__(x)))
#define _const_ __attribute__((__const__))
@ -343,9 +344,9 @@ static inline size_t ALIGN_TO(size_t l, size_t ali) {
#define ALIGN_PTR(p) ((void*) ALIGN((uintptr_t) (p)))
/* Checks if the specified pointer is aligned as appropriate for the specific type */
#define IS_ALIGNED16(p) (((uintptr_t) p) % __alignof__(uint16_t) == 0)
#define IS_ALIGNED32(p) (((uintptr_t) p) % __alignof__(uint32_t) == 0)
#define IS_ALIGNED64(p) (((uintptr_t) p) % __alignof__(uint64_t) == 0)
#define IS_ALIGNED16(p) (((uintptr_t) p) % alignof(uint16_t) == 0)
#define IS_ALIGNED32(p) (((uintptr_t) p) % alignof(uint32_t) == 0)
#define IS_ALIGNED64(p) (((uintptr_t) p) % alignof(uint64_t) == 0)
/* Same as ALIGN_TO but callable in constant contexts. */
#define CONST_ALIGN_TO(l, ali) \
@ -363,7 +364,7 @@ static inline size_t ALIGN_TO(size_t l, size_t ali) {
#define CAST_ALIGN_PTR(t, p) \
({ \
const void *_p = (p); \
assert(((uintptr_t) _p) % __alignof__(t) == 0); \
assert(((uintptr_t) _p) % alignof(t) == 0); \
(t *) _p; \
})

View file

@ -894,7 +894,7 @@ int manager_rtnl_process_nexthop(sd_netlink *rtnl, sd_netlink_message *message,
return 0;
}
assert((uintptr_t) group % __alignof__(struct nexthop_grp) == 0);
assert((uintptr_t) group % alignof(struct nexthop_grp) == 0);
n_group = raw_group_size / sizeof(struct nexthop_grp);
for (size_t i = 0; i < n_group; i++) {

View file

@ -17,16 +17,16 @@
DISABLE_WARNING_TYPE_LIMITS;
#define info_no_sign(t) \
printf("%s → %zu bits, %zu byte alignment\n", STRINGIFY(t), \
printf("%s → %zu bits, %zu byte alignment\n", STRINGIFY(t), \
sizeof(t)*CHAR_BIT, \
__alignof__(t))
alignof(t))
#define info(t) \
printf("%s → %zu bits%s, %zu byte alignment\n", STRINGIFY(t), \
printf("%s → %zu bits%s, %zu byte alignment\n", STRINGIFY(t), \
sizeof(t)*CHAR_BIT, \
strstr(STRINGIFY(t), "signed") ? "" : \
(t)-1 < (t)0 ? ", signed" : ", unsigned", \
__alignof__(t))
alignof(t))
enum Enum {
enum_value,
@ -44,7 +44,7 @@ enum BigEnum2 {
int main(void) {
int (*function_pointer)(void);
info_no_sign(function_pointer);
info_no_sign(typeof(function_pointer));
info_no_sign(void*);
info(char*);