Skip to content

Instantly share code, notes, and snippets.

Created October 30, 2015 22:37
Show Gist options
  • Save anonymous/84e14543cbc3691f83c5 to your computer and use it in GitHub Desktop.
Save anonymous/84e14543cbc3691f83c5 to your computer and use it in GitHub Desktop.
zimg clang
Subject: [PATCH] fix compilation for apple clang
---
src/zimg/api/zimg.cpp | 13 +++++++++++--
src/zimg/common/matrix.h | 2 +-
src/zimg/graph/filtergraph.cpp | 1 +
src/zimg/graph/image_buffer.h | 2 +-
src/zimg/resize/filter.cpp | 4 ++--
5 files changed, 16 insertions(+), 6 deletions(-)
diff --git a/src/zimg/api/zimg.cpp b/src/zimg/api/zimg.cpp
index bbba392..6f27326 100644
--- a/src/zimg/api/zimg.cpp
+++ b/src/zimg/api/zimg.cpp
@@ -17,6 +17,15 @@
#include "resize/filter.h"
#include "zimg.h"
+// Static/global variable exists in a per-thread context (thread local storage).
+#if defined (__GNUC__)
+ #define ATTRIBUTE_TLS __thread
+#elif defined (_MSC_VER)
+ #define ATTRIBUTE_TLS __declspec(thread)
+#else // !__GNUC__ && !_MSC_VER
+ #error "Define a thread local storage qualifier for your compiler/platform!"
+#endif
+
namespace {;
const unsigned API_VERSION_2_0 = ZIMG_MAKE_API_VERSION(2, 0);
@@ -25,8 +34,8 @@ const unsigned API_VERSION_2_0 = ZIMG_MAKE_API_VERSION(2, 0);
#define POINTER_ALIGNMENT_ASSERT(x) _zassert_d(!(x) || reinterpret_cast<uintptr_t>(x) % zimg::ALIGNMENT == 0, "pointer not aligned")
#define STRIDE_ALIGNMENT_ASSERT(x) _zassert_d(!(x) || (x) % zimg::ALIGNMENT == 0, "buffer stride not aligned")
-thread_local zimg_error_code_e g_last_error = ZIMG_ERROR_SUCCESS;
-thread_local char g_last_error_msg[1024];
+ATTRIBUTE_TLS zimg_error_code_e g_last_error = ZIMG_ERROR_SUCCESS;
+ATTRIBUTE_TLS char g_last_error_msg[1024];
const unsigned VERSION_INFO[] = { 2, 0, 1 };
diff --git a/src/zimg/common/matrix.h b/src/zimg/common/matrix.h
index 335bab0..9a4eef0 100644
--- a/src/zimg/common/matrix.h
+++ b/src/zimg/common/matrix.h
@@ -47,7 +47,7 @@ private:
operator T() const;
- friend class RowMatrix::row_proxy;
+ friend class RowMatrix;
};
class row_proxy : private non_copyable {
diff --git a/src/zimg/graph/filtergraph.cpp b/src/zimg/graph/filtergraph.cpp
index c922365..052e186 100644
--- a/src/zimg/graph/filtergraph.cpp
+++ b/src/zimg/graph/filtergraph.cpp
@@ -1,4 +1,5 @@
#include <algorithm>
+#include <cmath>
#include <cstdint>
#include <vector>
#include "common/align.h"
diff --git a/src/zimg/graph/image_buffer.h b/src/zimg/graph/image_buffer.h
index 8ddefe9..75d0453 100644
--- a/src/zimg/graph/image_buffer.h
+++ b/src/zimg/graph/image_buffer.h
@@ -197,7 +197,7 @@ public:
template <class U>
const ColorImageBuffer<U> &static_buffer_cast() const
{
- static_assert(std::is_standard_layout<decltype(m_buffer->static_buffer_cast<U>())>::value,
+ static_assert(std::is_standard_layout<decltype(m_buffer->template static_buffer_cast<U>())>::value,
"type not convertible by static_cast");
// Break strict aliasing to avoid unnecessary object copies.
diff --git a/src/zimg/resize/filter.cpp b/src/zimg/resize/filter.cpp
index e5ec98f..7e81343 100644
--- a/src/zimg/resize/filter.cpp
+++ b/src/zimg/resize/filter.cpp
@@ -92,7 +92,7 @@ FilterContext matrix_to_filter(const RowMatrix<double> &m)
f32_err = (double)coeff_f32 - coeff_expected_f32;
i16_err = (double)coeff_i16 - coeff_expected_i16;
- if (std::abs(coeff_i16) > i16_greatest) {
+ if (std::fabs(coeff_i16) > i16_greatest) {
i16_greatest = coeff_i16;
i16_greatest_idx = j;
}
@@ -109,7 +109,7 @@ FilterContext matrix_to_filter(const RowMatrix<double> &m)
* but for integer data, the error can be added to the greatest coefficient.
*/
_zassert_d(1.0 - f32_sum <= FLT_EPSILON, "error too great");
- _zassert_d(std::abs((1 << 14) - i16_sum) <= 1, "error too great");
+ _zassert_d(std::fabs((1 << 14) - i16_sum) <= 1, "error too great");
e.data_i16[i * e.stride_i16 + i16_greatest_idx] += (1 << 14) - i16_sum;
--
2.5.3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment