Skip to content

Commit 9509c9d

Browse files
Chris Morinsofar
authored andcommitted
fix circular header dependency (macro.h and log.h)
1 parent dd09753 commit 9509c9d

3 files changed

Lines changed: 46 additions & 46 deletions

File tree

src/attributes.h

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#define _printf_(a,b) __attribute__ ((format (printf, a, b)))
2+
#define _alloc_(...) __attribute__ ((alloc_size(__VA_ARGS__)))
3+
#define _sentinel_ __attribute__ ((sentinel))
4+
#define _unused_ __attribute__ ((unused))
5+
#define _destructor_ __attribute__ ((destructor))
6+
#define _pure_ __attribute__ ((pure))
7+
#define _const_ __attribute__ ((const))
8+
#define _deprecated_ __attribute__ ((deprecated))
9+
#define _packed_ __attribute__ ((packed))
10+
#define _malloc_ __attribute__ ((malloc))
11+
#define _weak_ __attribute__ ((weak))
12+
#define _likely_(x) (__builtin_expect(!!(x),1))
13+
#define _unlikely_(x) (__builtin_expect(!!(x),0))
14+
#define _public_ __attribute__ ((visibility("default")))
15+
#define _hidden_ __attribute__ ((visibility("hidden")))
16+
#define _weakref_(x) __attribute__((weakref(#x)))
17+
#define _alignas_(x) __attribute__((aligned(__alignof(x))))
18+
#define _cleanup_(x) __attribute__((cleanup(x)))
19+
20+
/* Define C11 thread_local attribute even on older gcc compiler
21+
* version */
22+
#ifndef thread_local
23+
/*
24+
* Don't break on glibc < 2.16 that doesn't define __STDC_NO_THREADS__
25+
* see http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53769
26+
*/
27+
#if __STDC_VERSION__ >= 201112L && !(defined(__STDC_NO_THREADS__) || (defined(__GNU_LIBRARY__) && __GLIBC__ == 2 && __GLIBC_MINOR__ < 16))
28+
#define thread_local _Thread_local
29+
#else
30+
#define thread_local __thread
31+
#endif
32+
#endif
33+
34+
/* Define C11 noreturn without <stdnoreturn.h> and even on older gcc
35+
* compiler versions */
36+
#ifndef noreturn
37+
#if __STDC_VERSION__ >= 201112L
38+
#define noreturn _Noreturn
39+
#else
40+
#define noreturn __attribute__((noreturn))
41+
#endif
42+
#endif

src/log.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,15 @@
2121

2222
#include <errno.h>
2323
#include <stdarg.h>
24-
#include <stdbool.h>
2524
#include <stdlib.h>
2625
#include <syslog.h>
27-
#include <sys/uio.h>
2826

2927
#include <systemd/sd-id128.h>
3028

3129
#include "alloc-util.h"
32-
#include "macro.h"
30+
#include "attributes.h"
3331

34-
int log_get_max_level(void);
32+
int log_get_max_level(void) _pure_;
3533

3634
int log_internal(
3735
int level,

src/macro.h

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,8 @@
2525
#include <sys/param.h>
2626
#include <sys/types.h>
2727

28-
#define _printf_(a,b) __attribute__ ((format (printf, a, b)))
29-
#define _alloc_(...) __attribute__ ((alloc_size(__VA_ARGS__)))
30-
#define _sentinel_ __attribute__ ((sentinel))
31-
#define _unused_ __attribute__ ((unused))
32-
#define _destructor_ __attribute__ ((destructor))
33-
#define _pure_ __attribute__ ((pure))
34-
#define _const_ __attribute__ ((const))
35-
#define _deprecated_ __attribute__ ((deprecated))
36-
#define _packed_ __attribute__ ((packed))
37-
#define _malloc_ __attribute__ ((malloc))
38-
#define _weak_ __attribute__ ((weak))
39-
#define _likely_(x) (__builtin_expect(!!(x),1))
40-
#define _unlikely_(x) (__builtin_expect(!!(x),0))
41-
#define _public_ __attribute__ ((visibility("default")))
42-
#define _hidden_ __attribute__ ((visibility("hidden")))
43-
#define _weakref_(x) __attribute__((weakref(#x)))
44-
#define _alignas_(x) __attribute__((aligned(__alignof(x))))
45-
#define _cleanup_(x) __attribute__((cleanup(x)))
28+
#include "attributes.h"
29+
#include "log.h"
4630

4731
/* Temporarily disable some warnings */
4832
#define DISABLE_WARNING_DECLARATION_AFTER_STATEMENT \
@@ -361,30 +345,6 @@ static inline unsigned long ALIGN_POWER2(unsigned long u) {
361345
_found; \
362346
})
363347

364-
/* Define C11 thread_local attribute even on older gcc compiler
365-
* version */
366-
#ifndef thread_local
367-
/*
368-
* Don't break on glibc < 2.16 that doesn't define __STDC_NO_THREADS__
369-
* see http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53769
370-
*/
371-
#if __STDC_VERSION__ >= 201112L && !(defined(__STDC_NO_THREADS__) || (defined(__GNU_LIBRARY__) && __GLIBC__ == 2 && __GLIBC_MINOR__ < 16))
372-
#define thread_local _Thread_local
373-
#else
374-
#define thread_local __thread
375-
#endif
376-
#endif
377-
378-
/* Define C11 noreturn without <stdnoreturn.h> and even on older gcc
379-
* compiler versions */
380-
#ifndef noreturn
381-
#if __STDC_VERSION__ >= 201112L
382-
#define noreturn _Noreturn
383-
#else
384-
#define noreturn __attribute__((noreturn))
385-
#endif
386-
#endif
387-
388348
#define DEFINE_TRIVIAL_CLEANUP_FUNC(type, func) \
389349
static inline void func##p(type *p) { \
390350
if (*p) \

0 commit comments

Comments
 (0)