From: Maria Matejka Date: Thu, 9 Jan 2025 17:55:26 +0000 (+0100) Subject: Merge commit 'abecb5bb408f253cd24345ba94940ea0f7b59f4f' into HEAD X-Git-Tag: v3.0.1~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=000ba7e960ef744910d684c749c0a8d796a49694;p=thirdparty%2Fbird.git Merge commit 'abecb5bb408f253cd24345ba94940ea0f7b59f4f' into HEAD --- 000ba7e960ef744910d684c749c0a8d796a49694 diff --cc lib/birdlib.h index 442bf6004,8209a108d..bc7c334cb --- a/lib/birdlib.h +++ b/lib/birdlib.h @@@ -21,41 -16,10 +21,41 @@@ /* Ugly structure offset handling macros */ +#define SAME_TYPE(a, b) ({ int _ = ((a) != (b)); !_; }) +#define TYPE_CAST(from, to, what) ( SAME_TYPE(((from) NULL), (what)), ((to) (what))) + +#ifdef offsetof +#define OFFSETOF offsetof +#else #define OFFSETOF(s, i) ((size_t) &((s *)0)->i) -#define SKIP_BACK(s, i, p) ((s *)((char *)p - OFFSETOF(s, i))) +#endif + +#define SKIP_BACK(s, i, p) ({ \ + typeof(p) _orig = p; \ + s *_ptr = ((s *)((char *)_orig - OFFSETOF(s, i))); \ + SAME_TYPE(&_ptr->i, _orig); \ + _ptr; }) +#define SKIP_BACK_DECLARE(s, n, i, p) s *n = SKIP_BACK(s, i, p) #define BIRD_ALIGN(s, a) (((s)+a-1)&~(a-1)) +#define BIRD_SET_ALIGNED_POINTER(ptr, val) do { \ + size_t _alignment = _Alignof(typeof(*ptr)); \ + ptr = (typeof(ptr)) BIRD_ALIGN((uintptr_t)(val), _alignment); \ +} while (0) - #define CPU_STRUCT_ALIGN (MAX_(_Alignof(void*), _Alignof(u64))) + #define CPU_STRUCT_ALIGN (alignof(max_align_t)) +#define BIRD_CPU_ALIGN(s) BIRD_ALIGN((s), CPU_STRUCT_ALIGN) + +/* Structure item alignment macros */ + +#define PADDING_NAME(id) _padding_##id +#define PADDING_(id, sz) u8 PADDING_NAME(id)[sz] + +#if CPU_POINTER_ALIGNMENT == 4 +#define PADDING(id, n32, n64) PADDING_(id, n32) +#elif CPU_POINTER_ALIGNMENT == 8 +#define PADDING(id, n32, n64) PADDING_(id, n64) +#else +#error "Strange CPU pointer alignment: " CPU_POINTER_ALIGNMENT +#endif /* Utility macros */ diff --cc lib/mempool.c index 1ca6d03b6,525eee8fc..b88bc1227 --- a/lib/mempool.c +++ b/lib/mempool.c @@@ -27,9 -27,7 +27,8 @@@ struct lp_chunk { struct lp_chunk *next; + struct linpool *lp; - uintptr_t data_align[0]; - _Atomic u64 data_align_atomic[0]; + max_align_t data_align[0]; byte data[0]; };