From b609f8ee96bac031e30970215bb625a99dc01a68 Mon Sep 17 00:00:00 2001 From: Christopher Dykes Date: Wed, 27 Apr 2016 14:34:33 -0700 Subject: [PATCH] Have the GFlags portability header stick things in namespaces Summary: Just like the real thing does. This was causing some issues when trying to link against glog, which expects the flags to be namespaced like this. Reviewed By: mzlee Differential Revision: D3230630 fb-gh-sync-id: a73ab3044560d561a39eb91ceee1588c147a46c5 fbshipit-source-id: a73ab3044560d561a39eb91ceee1588c147a46c5 --- folly/portability/GFlags.h | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/folly/portability/GFlags.h b/folly/portability/GFlags.h index 846bdc1e..6f0b1d51 100644 --- a/folly/portability/GFlags.h +++ b/folly/portability/GFlags.h @@ -27,25 +27,35 @@ #define DECLARE_VARIABLE() \ static_assert(false, "You shouldn't be using GFlags internals."); -#define FOLLY_DECLARE_FLAG(_type, _name) extern _type FLAGS_##_name -#define DECLARE_bool(_name) FOLLY_DECLARE_FLAG(bool, _name) -#define DECLARE_double(_name) FOLLY_DECLARE_FLAG(double, _name) -#define DECLARE_int32(_name) FOLLY_DECLARE_FLAG(int, _name) -#define DECLARE_int64(_name) FOLLY_DECLARE_FLAG(long long, _name) -#define DECLARE_uint64(_name) FOLLY_DECLARE_FLAG(unsigned long long, _name) -#define DECLARE_string(_name) FOLLY_DECLARE_FLAG(std::string, _name) +#define FOLLY_DECLARE_FLAG(_type, _shortType, _name) \ + namespace fL##_shortType { \ + extern _type FLAGS_##_name; \ + } \ + using fL##_shortType::FLAGS_##_name + +#define DECLARE_bool(_name) FOLLY_DECLARE_FLAG(bool, B, _name) +#define DECLARE_double(_name) FOLLY_DECLARE_FLAG(double, D, _name) +#define DECLARE_int32(_name) FOLLY_DECLARE_FLAG(int, I, _name) +#define DECLARE_int64(_name) FOLLY_DECLARE_FLAG(long long, I64, _name) +#define DECLARE_uint64(_name) FOLLY_DECLARE_FLAG(unsigned long long, U64, _name) +#define DECLARE_string(_name) FOLLY_DECLARE_FLAG(std::string, S, _name) + +#define FOLLY_DEFINE_FLAG(_type, _shortType, _name, _default) \ + namespace fL##_shortType { \ + _type FLAGS_##_name = _default; \ + } \ + using fL##_shortType::FLAGS_##_name -#define FOLLY_DEFINE_FLAG(_type, _name, _default) _type FLAGS_##_name = _default #define DEFINE_bool(_name, _default, _description) \ - FOLLY_DEFINE_FLAG(bool, _name, _default) + FOLLY_DEFINE_FLAG(bool, B, _name, _default) #define DEFINE_double(_name, _default, _description) \ - FOLLY_DEFINE_FLAG(double, _name, _default) + FOLLY_DEFINE_FLAG(double, D, _name, _default) #define DEFINE_int32(_name, _default, _description) \ - FOLLY_DEFINE_FLAG(int, _name, _default) + FOLLY_DEFINE_FLAG(int, I, _name, _default) #define DEFINE_int64(_name, _default, _description) \ - FOLLY_DEFINE_FLAG(long long, _name, _default) + FOLLY_DEFINE_FLAG(long long, I64, _name, _default) #define DEFINE_uint64(_name, _default, _description) \ - FOLLY_DEFINE_FLAG(unsigned long long, _name, _default) + FOLLY_DEFINE_FLAG(unsigned long long, U64, _name, _default) #define DEFINE_string(_name, _default, _description) \ - FOLLY_DEFINE_FLAG(std::string, _name, _default) + FOLLY_DEFINE_FLAG(std::string, S, _name, _default) #endif -- 2.34.1