diff options
author | bungeman <bungeman@google.com> | 2014-10-15 13:53:54 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-10-15 13:53:55 -0700 |
commit | 8dfdfff98dd14b0f3bef465411941e1bab8f0261 (patch) | |
tree | 8c8303ae71ae87326b18092035187e51d967d060 /include | |
parent | 9e4d6d180fcfbbe2ea242196cc0affd45b7ed7ae (diff) |
Don't use 'defined' in macro expansion.
A careful reading of the preprocessor specification indicates that
any use of the 'defined' operator outside the form of 'defined X' or
'defined ( X )' directly in the constant expression of a '#if' or
'#elif' may cause undefined behavior.
In particular, msvc is very unpredictable. The 'defined X' and
'defined ( X )' forms behave differently when created from marco
expansion, with 'defined ( X )' generally evaluating to '0L'. The
'defined X' form generally behaves more the way one would expect,
but still has a number of quirks which should simply be considered
undefined behavior.
BUG=chromium:419245
Review URL: https://codereview.chromium.org/657183002
Diffstat (limited to 'include')
-rw-r--r-- | include/core/SkFloatingPoint.h | 8 | ||||
-rw-r--r-- | include/core/SkPostConfig.h | 4 |
2 files changed, 8 insertions, 4 deletions
diff --git a/include/core/SkFloatingPoint.h b/include/core/SkFloatingPoint.h index 2df8f9bf65..f85c456aa8 100644 --- a/include/core/SkFloatingPoint.h +++ b/include/core/SkFloatingPoint.h @@ -32,8 +32,12 @@ static inline float sk_float_pow(float base, float exp) { static inline float sk_float_copysign(float x, float y) { // c++11 contains a 'float copysign(float, float)' function in <cmath>. // clang-cl reports __cplusplus for clang, not the __cplusplus vc++ version _MSC_VER would report. -#define SK_BUILD_WITH_CLANG_CL (defined(_MSC_VER) && defined(__clang__)) -#if (!SK_BUILD_WITH_CLANG_CL && __cplusplus >= 201103L) || (defined(_MSC_VER) && _MSC_VER >= 1800) +#if (defined(_MSC_VER) && defined(__clang__)) +# define SK_BUILD_WITH_CLANG_CL 1 +#else +# define SK_BUILD_WITH_CLANG_CL 0 +#endif +#if (!SK_BUILD_WITH_CLANG_CL && __cplusplus >= 201103L) || (_MSC_VER >= 1800) return copysign(x, y); // Posix has demanded 'float copysignf(float, float)' (from C99) since Issue 6. diff --git a/include/core/SkPostConfig.h b/include/core/SkPostConfig.h index ec17b65353..2d6ab44b65 100644 --- a/include/core/SkPostConfig.h +++ b/include/core/SkPostConfig.h @@ -126,10 +126,10 @@ * Defaults to 1 in DEBUG and 0 in RELEASE. */ #ifndef SK_ENABLE_INST_COUNT -# ifdef SK_DEBUG // Only enabled for static builds, because instance counting relies on static // variables in functions defined in header files. -# define SK_ENABLE_INST_COUNT !defined(SKIA_DLL) +# if defined(SK_DEBUG) && !defined(SKIA_DLL) +# define SK_ENABLE_INST_COUNT 1 # else # define SK_ENABLE_INST_COUNT 0 # endif |