From c1645f5e8b30961419485e8b3f28092900a99148 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Sat, 7 Mar 2020 14:31:52 +0100 Subject: [PATCH] Add a pair of headers to guard against intrusive Windows macros. --- include/lol/bigint | 2 ++ include/lol/color | 2 ++ include/lol/getopt | 2 ++ include/lol/half | 2 ++ include/lol/math | 2 ++ include/lol/noise | 2 ++ include/lol/private/math/functions.h | 12 ------------ include/lol/private/math/matrix.h | 13 ------------- include/lol/private/math/matrix.ipp | 21 +-------------------- include/lol/private/math/vector.h | 12 ------------ include/lol/private/pop_macros.h | 20 ++++++++++++++++++++ include/lol/private/push_macros.h | 25 +++++++++++++++++++++++++ include/lol/private/types/half.h | 12 ------------ include/lol/private/types/real.h | 12 ------------ include/lol/real | 2 ++ include/lol/thread | 2 ++ include/lol/transform | 2 ++ include/lol/unit_test | 2 ++ include/lol/utils | 2 ++ include/lol/vector | 2 ++ 20 files changed, 70 insertions(+), 81 deletions(-) create mode 100644 include/lol/private/pop_macros.h create mode 100644 include/lol/private/push_macros.h diff --git a/include/lol/bigint b/include/lol/bigint index 9520cd9d..7b5db120 100644 --- a/include/lol/bigint +++ b/include/lol/bigint @@ -12,5 +12,7 @@ #pragma once +#include "private/push_macros.h" #include "private/types/bigint.h" +#include "private/pop_macros.h" diff --git a/include/lol/color b/include/lol/color index d018baec..edce6c69 100644 --- a/include/lol/color +++ b/include/lol/color @@ -12,5 +12,7 @@ #pragma once +#include "private/push_macros.h" #include "private/image/color.h" +#include "private/pop_macros.h" diff --git a/include/lol/getopt b/include/lol/getopt index 9f0b70b5..bd04b468 100644 --- a/include/lol/getopt +++ b/include/lol/getopt @@ -12,5 +12,7 @@ #pragma once +#include "private/push_macros.h" #include "private/sys/getopt.h" +#include "private/pop_macros.h" diff --git a/include/lol/half b/include/lol/half index 303eeebc..9ef7b45c 100644 --- a/include/lol/half +++ b/include/lol/half @@ -12,5 +12,7 @@ #pragma once +#include "private/push_macros.h" #include "private/types/half.h" +#include "private/pop_macros.h" diff --git a/include/lol/math b/include/lol/math index 17d0ace9..979b61a0 100644 --- a/include/lol/math +++ b/include/lol/math @@ -12,8 +12,10 @@ #pragma once +#include "private/push_macros.h" #include "private/math/constants.h" #include "private/math/functions.h" #include "private/math/rand.h" #include "private/math/polynomial.h" +#include "private/pop_macros.h" diff --git a/include/lol/noise b/include/lol/noise index 087f4c82..38dfb71a 100644 --- a/include/lol/noise +++ b/include/lol/noise @@ -17,7 +17,9 @@ // ——————————————— // +#include "private/push_macros.h" #include "private/math/gradient.h" #include "private/math/perlin.h" #include "private/math/simplex.h" +#include "private/pop_macros.h" diff --git a/include/lol/private/math/functions.h b/include/lol/private/math/functions.h index 72fe4f32..e8bf3fa9 100644 --- a/include/lol/private/math/functions.h +++ b/include/lol/private/math/functions.h @@ -24,13 +24,6 @@ #include -#if _MSC_VER -# pragma push_macro("min") -# pragma push_macro("max") -# undef min -# undef max -#endif - namespace lol { @@ -167,8 +160,3 @@ template [[nodiscard]] static inline T2 sign(T x) { return (T)((T)0 < x); } } // namespace lol - -#if _MSC_VER -# pragma pop_macro("min") -# pragma pop_macro("max") -#endif diff --git a/include/lol/private/math/matrix.h b/include/lol/private/math/matrix.h index 77d31bcc..d64aa2b0 100644 --- a/include/lol/private/math/matrix.h +++ b/include/lol/private/math/matrix.h @@ -22,13 +22,6 @@ #include // std::ostream #include // std::fabs -#if _WIN32 -# pragma push_macro("near") -# pragma push_macro("far") -# undef near -# undef far -#endif - namespace lol { @@ -610,9 +603,3 @@ template mat_t const mat_t::identity = mat_t((T)1); } /* namespace lol */ - -#if _WIN32 -# pragma pop_macro("near") -# pragma pop_macro("far") -#endif - diff --git a/include/lol/private/math/matrix.ipp b/include/lol/private/math/matrix.ipp index 1d996684..01f31d6e 100644 --- a/include/lol/private/math/matrix.ipp +++ b/include/lol/private/math/matrix.ipp @@ -16,17 +16,6 @@ #include // std::tan #include // std::max -#if _MSC_VER -# pragma push_macro("min") -# pragma push_macro("max") -# pragma push_macro("near") -# pragma push_macro("far") -# undef min -# undef max -# undef near -# undef far -#endif - namespace lol { @@ -291,12 +280,4 @@ inline mat4 mat4::shifted_perspective(float fov_y, float screen_size, mat4::translate(.0f, .0f, -dist_scr); } -} /* namespace lol */ - -#if _WIN32 -# pragma pop_macro("min") -# pragma pop_macro("max") -# pragma pop_macro("near") -# pragma pop_macro("far") -#endif - +} // namespace lol diff --git a/include/lol/private/math/vector.h b/include/lol/private/math/vector.h index 89396503..cfb29fd1 100644 --- a/include/lol/private/math/vector.h +++ b/include/lol/private/math/vector.h @@ -28,13 +28,6 @@ #include "ops.h" -#if _MSC_VER -# pragma push_macro("min") -# pragma push_macro("max") -# undef min -# undef max -#endif - namespace lol { @@ -1438,8 +1431,3 @@ typedef ivec12 int12; } // namespace lol #include "vector.ipp" - -#if _MSC_VER -# pragma pop_macro("min") -# pragma pop_macro("max") -#endif diff --git a/include/lol/private/pop_macros.h b/include/lol/private/pop_macros.h new file mode 100644 index 00000000..90eb0a09 --- /dev/null +++ b/include/lol/private/pop_macros.h @@ -0,0 +1,20 @@ +// +// Lol Engine +// +// Copyright © 2010—2020 Sam Hocevar +// +// Lol Engine is free software. It comes without any warranty, to +// the extent permitted by applicable law. You can redistribute it +// and/or modify it under the terms of the Do What the Fuck You Want +// to Public License, Version 2, as published by the WTFPL Task Force. +// See http://www.wtfpl.net/ for more details. +// + +// Restore macros that push_macros.h disabled. + +#if _MSC_VER +# pragma pop_macro("min") +# pragma pop_macro("max") +# pragma pop_macro("near") +# pragma pop_macro("far") +#endif diff --git a/include/lol/private/push_macros.h b/include/lol/private/push_macros.h new file mode 100644 index 00000000..aee5107c --- /dev/null +++ b/include/lol/private/push_macros.h @@ -0,0 +1,25 @@ +// +// Lol Engine +// +// Copyright © 2010—2020 Sam Hocevar +// +// Lol Engine is free software. It comes without any warranty, to +// the extent permitted by applicable law. You can redistribute it +// and/or modify it under the terms of the Do What the Fuck You Want +// to Public License, Version 2, as published by the WTFPL Task Force. +// See http://www.wtfpl.net/ for more details. +// + +// Undefine some intrusive macros from the Windows headers but allow +// to restore them afterwards if that’s what the user really wants. + +#if _MSC_VER +# pragma push_macro("min") +# pragma push_macro("max") +# pragma push_macro("near") +# pragma push_macro("far") +# undef min +# undef max +# undef near +# undef far +#endif diff --git a/include/lol/private/types/half.h b/include/lol/private/types/half.h index 29c58d58..c349f380 100644 --- a/include/lol/private/types/half.h +++ b/include/lol/private/types/half.h @@ -28,13 +28,6 @@ namespace lol { -#if _WIN32 -# pragma push_macro("near") -# pragma push_macro("far") -# undef near -# undef far -#endif - namespace half_ops { struct base {}; } class [[nodiscard]] half @@ -335,8 +328,3 @@ DECLARE_HALF_BOOL_OPS(<=) } // namespace half_ops } // namespace lol - -#if _WIN32 -# pragma pop_macro("near") -# pragma pop_macro("far") -#endif diff --git a/include/lol/private/types/real.h b/include/lol/private/types/real.h index 6be1d72a..7eb6ea59 100644 --- a/include/lol/private/types/real.h +++ b/include/lol/private/types/real.h @@ -24,13 +24,6 @@ #include // std::string #include // int64_t etc. -#if _MSC_VER -# pragma push_macro("min") -# pragma push_macro("max") -# undef min -# undef max -#endif - namespace lol { @@ -266,8 +259,3 @@ typedef real_t real; } // namespace lol #include "real.ipp" - -#if _MSC_VER -# pragma pop_macro("min") -# pragma pop_macro("max") -#endif diff --git a/include/lol/real b/include/lol/real index 093493ce..ed6f0ff4 100644 --- a/include/lol/real +++ b/include/lol/real @@ -12,5 +12,7 @@ #pragma once +#include "private/push_macros.h" #include "private/types/real.h" +#include "private/pop_macros.h" diff --git a/include/lol/thread b/include/lol/thread index 37167910..af9b8dea 100644 --- a/include/lol/thread +++ b/include/lol/thread @@ -12,5 +12,7 @@ #pragma once +#include "private/push_macros.h" #include "private/sys/threading.h" +#include "private/pop_macros.h" diff --git a/include/lol/transform b/include/lol/transform index 78b0088b..46fbde9d 100644 --- a/include/lol/transform +++ b/include/lol/transform @@ -12,5 +12,7 @@ #pragma once +#include "private/push_macros.h" #include "private/math/transform.h" +#include "private/pop_macros.h" diff --git a/include/lol/unit_test b/include/lol/unit_test index 9dc08bed..f6c5c7d5 100644 --- a/include/lol/unit_test +++ b/include/lol/unit_test @@ -12,5 +12,7 @@ #pragma once +#include "private/push_macros.h" #include "private/lolunit.h" +#include "private/pop_macros.h" diff --git a/include/lol/utils b/include/lol/utils index a0cc21f0..bbd18b6a 100644 --- a/include/lol/utils +++ b/include/lol/utils @@ -12,9 +12,11 @@ #pragma once +#include "private/push_macros.h" #include "private/features.h" #include "private/base/env.h" #include "private/base/string.h" #include "private/base/containers.h" #include "private/base/misc.h" +#include "private/pop_macros.h" diff --git a/include/lol/vector b/include/lol/vector index cc22357a..f471eb1a 100644 --- a/include/lol/vector +++ b/include/lol/vector @@ -12,5 +12,7 @@ #pragma once +#include "private/push_macros.h" #include "private/math/vector.h" +#include "private/pop_macros.h"