From 50679dba044f37ed4aeae5c6b58550baefe968dd Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Mon, 6 Jul 2020 11:25:32 +0100 Subject: [PATCH 1/3] build: Add feature test flags to project-wide preprocessor flags MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Rather than defining them piecemeal in each C and H file, and having problems with headers being included in different orders so that `_POSIX_C_SOURCE` gets a value which is too low, just define the feature test flags in `meson.build`. See `man 7 feature_test_macros`. This is useful for when building sysprof as a subproject beneath a project which doesn’t define these macros, or which targets an older C standard than `gnu11`. Signed-off-by: Philip Withnall --- meson.build | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/meson.build b/meson.build index e1e9b42d..26f289f0 100644 --- a/meson.build +++ b/meson.build @@ -87,7 +87,10 @@ add_project_arguments([ '-I' + meson.build_root(), # config.h ], language: 'c') -global_c_args = [] +global_c_args = [ + '-D_GNU_SOURCE', + '-D_POSIX_C_SOURCE=200809L', +] test_c_args = [ '-Wcast-align', '-Wdeclaration-after-statement', From eae4eb4ad759d833050c3bf4050efd5901939316 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Mon, 6 Jul 2020 11:27:28 +0100 Subject: [PATCH 2/3] build: Drop redundant _GNU_SOURCE definitions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It’s defined in `meson.build` now. See the previous commit. Signed-off-by: Philip Withnall --- src/libsysprof-capture/sysprof-capture-writer.c | 4 ---- src/libsysprof-capture/sysprof-collector.c | 4 ---- src/libsysprof-ui/sysprof-details-page.c | 4 ---- src/libsysprof-ui/sysprof-profiler-assistant.c | 4 ---- src/libsysprof/preload/backtrace-helper.h | 4 ---- src/libsysprof/preload/sysprof-memory-collector.c | 2 -- src/libsysprof/preload/sysprof-speedtrack-collector.c | 2 -- src/libsysprof/sysprof-kallsyms.c | 4 ---- src/sysprofd/sysprof-turbostat.c | 2 -- 9 files changed, 30 deletions(-) diff --git a/src/libsysprof-capture/sysprof-capture-writer.c b/src/libsysprof-capture/sysprof-capture-writer.c index f890da98..14577aaf 100644 --- a/src/libsysprof-capture/sysprof-capture-writer.c +++ b/src/libsysprof-capture/sysprof-capture-writer.c @@ -56,10 +56,6 @@ #include "config.h" -#ifndef _GNU_SOURCE -# define _GNU_SOURCE -#endif - #include #include #include diff --git a/src/libsysprof-capture/sysprof-collector.c b/src/libsysprof-capture/sysprof-collector.c index 6d9e6b1c..9ffa9aae 100644 --- a/src/libsysprof-capture/sysprof-collector.c +++ b/src/libsysprof-capture/sysprof-collector.c @@ -54,10 +54,6 @@ * SPDX-License-Identifier: BSD-2-Clause-Patent */ -#ifndef _GNU_SOURCE -# define _GNU_SOURCE -#endif - #include #include #include diff --git a/src/libsysprof-ui/sysprof-details-page.c b/src/libsysprof-ui/sysprof-details-page.c index 0c41ec46..8755f0e9 100644 --- a/src/libsysprof-ui/sysprof-details-page.c +++ b/src/libsysprof-ui/sysprof-details-page.c @@ -18,10 +18,6 @@ * SPDX-License-Identifier: GPL-3.0-or-later */ -#ifndef _GNU_SOURCE -# define _GNU_SOURCE -#endif - #define G_LOG_DOMAIN "sysprof-details-page" #include "config.h" diff --git a/src/libsysprof-ui/sysprof-profiler-assistant.c b/src/libsysprof-ui/sysprof-profiler-assistant.c index 069f3c91..89e35137 100644 --- a/src/libsysprof-ui/sysprof-profiler-assistant.c +++ b/src/libsysprof-ui/sysprof-profiler-assistant.c @@ -20,10 +20,6 @@ #define G_LOG_DOMAIN "sysprof-profiler-assistant" -#ifndef _GNU_SOURCE -# define _GNU_SOURCE -#endif - #include "config.h" #include diff --git a/src/libsysprof/preload/backtrace-helper.h b/src/libsysprof/preload/backtrace-helper.h index 1915a420..92792a56 100644 --- a/src/libsysprof/preload/backtrace-helper.h +++ b/src/libsysprof/preload/backtrace-helper.h @@ -20,10 +20,6 @@ #pragma once -#ifndef _GNU_SOURCE -# define _GNU_SOURCE -#endif - #ifdef HAVE_EXECINFO_H # include #endif diff --git a/src/libsysprof/preload/sysprof-memory-collector.c b/src/libsysprof/preload/sysprof-memory-collector.c index 72cf0515..19cf2c60 100644 --- a/src/libsysprof/preload/sysprof-memory-collector.c +++ b/src/libsysprof/preload/sysprof-memory-collector.c @@ -18,8 +18,6 @@ * SPDX-License-Identifier: GPL-3.0-or-later */ -#define _GNU_SOURCE - #include "config.h" #include diff --git a/src/libsysprof/preload/sysprof-speedtrack-collector.c b/src/libsysprof/preload/sysprof-speedtrack-collector.c index 223dea91..62f75a68 100644 --- a/src/libsysprof/preload/sysprof-speedtrack-collector.c +++ b/src/libsysprof/preload/sysprof-speedtrack-collector.c @@ -18,8 +18,6 @@ * SPDX-License-Identifier: GPL-3.0-or-later */ -#define _GNU_SOURCE - #include "config.h" #include diff --git a/src/libsysprof/sysprof-kallsyms.c b/src/libsysprof/sysprof-kallsyms.c index 965d1cca..4545fba0 100644 --- a/src/libsysprof/sysprof-kallsyms.c +++ b/src/libsysprof/sysprof-kallsyms.c @@ -22,10 +22,6 @@ #include "config.h" -#ifndef _GNU_SOURCE -# define _GNU_SOURCE -#endif - #include #include #include diff --git a/src/sysprofd/sysprof-turbostat.c b/src/sysprofd/sysprof-turbostat.c index 5c80a534..72d6d674 100644 --- a/src/sysprofd/sysprof-turbostat.c +++ b/src/sysprofd/sysprof-turbostat.c @@ -18,8 +18,6 @@ * SPDX-License-ntifier: GPL-3.0-or-later */ -#define _GNU_SOURCE - #include "sysprof-turbostat.h" #include From 1c32c1ece500bba3826c72afcb6e751abe034605 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Mon, 6 Jul 2020 11:27:44 +0100 Subject: [PATCH 3/3] libsysprof-capture: Add a missing string.h include MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It’s needed for `strdup()` which is now used in a macro in this header. Signed-off-by: Philip Withnall --- src/libsysprof-capture/sysprof-macros-internal.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libsysprof-capture/sysprof-macros-internal.h b/src/libsysprof-capture/sysprof-macros-internal.h index cf814dad..7162d3dc 100644 --- a/src/libsysprof-capture/sysprof-macros-internal.h +++ b/src/libsysprof-capture/sysprof-macros-internal.h @@ -59,6 +59,8 @@ #pragma once +#include + #define sysprof_assert_not_reached() assert (false) #define SYSPROF_N_ELEMENTS(a) (sizeof (a) / sizeof (*a))