From 343628d8c0f1848b968930f6dbabdd1174404b14 Mon Sep 17 00:00:00 2001 From: Maria Matejka Date: Fri, 20 Jan 2023 14:07:38 +0100 Subject: Fixed various build problems on FreeBSD and/or CLang --- lib/birdlib.h | 9 +++++++++ lib/settle.h | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/birdlib.h b/lib/birdlib.h index d743ecdf..5ecd19ca 100644 --- a/lib/birdlib.h +++ b/lib/birdlib.h @@ -9,13 +9,22 @@ #ifndef _BIRD_BIRDLIB_H_ #define _BIRD_BIRDLIB_H_ +#include + #include "sysdep/config.h" #include "lib/alloca.h" /* 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) +#endif + #define SKIP_BACK(s, i, p) ({ s *_ptr = ((s *)((char *)p - OFFSETOF(s, i))); SAME_TYPE(&_ptr->i, p); _ptr; }) #define BIRD_ALIGN(s, a) (((s)+a-1)&~(a-1)) #define CPU_STRUCT_ALIGN (MAX_(_Alignof(void*), _Alignof(u64))) diff --git a/lib/settle.h b/lib/settle.h index d274599d..e721f21f 100644 --- a/lib/settle.h +++ b/lib/settle.h @@ -32,7 +32,7 @@ struct settle { STATIC_ASSERT(OFFSETOF(struct settle, hook) == OFFSETOF(struct settle, tm) + OFFSETOF(timer, hook)); -#define SETTLE_INIT(_cfp, _hook, _data) (struct settle) { .tm = { .data = (_data), }, .hook = (_hook), .cf = ({ASSERT_DIE((_cfp)->min <= (_cfp)->max); *(_cfp); }), } +#define SETTLE_INIT(_cfp, _hook, _data) (struct settle) { .tm = { .data = (_data), .hook = TYPE_CAST(void (*)(struct settle *), void (*)(struct timer *), (_hook)), }, .cf = ({ASSERT_DIE((_cfp)->min <= (_cfp)->max); *(_cfp); }), } static inline void settle_init(struct settle *s, struct settle_config *cf, void (*hook)(struct settle *), void *data) -- cgit v1.2.3