From d287c76f4f2e1ffd275da41b84f9e08ea7f74344 Mon Sep 17 00:00:00 2001 From: Fred Wright Date: Tue, 24 Jan 2017 16:18:50 -0800 Subject: [PATCH] Fixes some issues with C++11. In compiler.h, it adds the missing "std::" namespace prefixes to the memory_barrier() definition. In gpsd.h it: 1) Moves the include of compiler.h outside the conditional 'extern "C"', since the "atomic" stuff in the former is incompatible with the latter. 2) Fixes DEVICEHOOKPATH for C++11 (C++11 requires spaces between literals and string macros). 3) Cleans up some ordering of system includes left over from the former head/tail setup. TESTED: Ran "scons build-all check" on OSX 10.5-10.12, Ubuntu 14, CentOS 7, Fedora 25, FreeBSD 10.3, OpenBSD 5.6 (32- and 64-bit), and NetBSD 6.1.5. Also tested Qt builds with OSX 10.9 (Qt4 and Qt5), OSX 10.12 (Qt5), and Fedora 25 (Qt5). Observed the correct DEVICEHOOKPATH in the log on OSX. --- compiler.h | 2 +- gpsd.h | 15 +++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/compiler.h b/compiler.h index 7d664b18..71d26f68 100644 --- a/compiler.h +++ b/compiler.h @@ -90,7 +90,7 @@ static inline void memory_barrier(void) /* we are C++ */ #if __cplusplus >= 201103L /* C++11 and later has atomics, earlier do not */ - atomic_thread_fence(memory_order_seq_cst); + std::atomic_thread_fence(std::memory_order_seq_cst); #endif #elif defined HAVE_STDATOMIC_H /* we are C and atomics are in C98 and newer */ diff --git a/gpsd.h b/gpsd.h index c69facd0..b3dc3c97 100644 --- a/gpsd.h +++ b/gpsd.h @@ -7,22 +7,21 @@ #ifndef _GPSD_H_ #define _GPSD_H_ +#include "compiler.h" /* Must be outside extern "C" for "atomic" */ + # ifdef __cplusplus extern "C" { # endif +#include #include -#include -#include /* for time_t */ - -#include "gpsd_config.h" - #include -#include +#include #include +#include /* for time_t */ #include "gps.h" -#include "compiler.h" +#include "gpsd_config.h" #include "os_compat.h" /* @@ -991,7 +990,7 @@ PRINTF_FUNC(3, 4) void gpsd_log(const struct gpsd_errout_t *, const int, const c void cfmakeraw(struct termios *); #endif /* defined(__CYGWIN__) */ -#define DEVICEHOOKPATH "/"SYSCONFDIR"/gpsd/device-hook" +#define DEVICEHOOKPATH "/" SYSCONFDIR "/gpsd/device-hook" # ifdef __cplusplus }