// // Copyright (C) 2011-15 DyND Developers // BSD 2-Clause License, see LICENSE.txt // #pragma once #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include /** The number of elements to process at once when doing chunking/buffering */ #define DYND_BUFFER_CHUNK_SIZE 128 #ifdef __clang__ #if __has_feature(cxx_constexpr) #define DYND_CONSTEXPR constexpr #else #define DYND_CONSTEXPR #endif // Workaround for a clang issue #define DYND_ISSPACE std::isspace #define DYND_TOLOWER std::tolower #define DYND_USED(NAME) NAME __attribute__((used)) #define DYND_EMIT_LLVM(NAME) __attribute__((annotate(#NAME), annotate("emit_llvm"))) NAME #define DYND_ALLOW_UNSIGNED_UNARY_MINUS #define DYND_END_ALLOW_UNSIGNED_UNARY_MINUS #elif defined(__GNUC__) // Hack trying to work around gcc isfinite problems #if !defined(_GNU_SOURCE) #define _GNU_SOURCE #endif #define DYND_IGNORE_UNUSED(NAME) NAME __attribute__((unused)) #define DYND_USED(NAME) NAME #define DYND_EMIT_LLVM(NAME) NAME // Ignore erroneous maybe-uninitizlized // warnings on a given line or code block. #define DYND_IGNORE_MAYBE_UNINITIALIZED _Pragma("GCC diagnostic ignored \"-Wmaybe-uninitialized\"") #define DYND_END_IGNORE_MAYBE_UNINITIALIZED _Pragma("GCC diagnostic pop") #define DYND_CONSTEXPR constexpr #define DYND_ISSPACE isspace #define DYND_TOLOWER tolower #define DYND_ALLOW_UNSIGNED_UNARY_MINUS #define DYND_END_ALLOW_UNSIGNED_UNARY_MINUS #elif defined(_MSC_VER) #define DYND_ISSPACE isspace #define DYND_TOLOWER tolower #define DYND_USED(NAME) NAME #define DYND_EMIT_LLVM(NAME) NAME #define DYND_ALLOW_UNSIGNED_UNARY_MINUS __pragma(warning(push)) __pragma(warning(disable : 4146)) #define DYND_END_ALLOW_UNSIGNED_UNARY_MINUS __pragma(warning(pop)) #include // If set, uses the FP status registers. // On some compilers, there is no proper // way to tell the compiler that these are // important, and it reorders instructions // so as to make them useless. On MSVC, there // is #pragma fenv_access(on), which works. // // Update 2014-11-29: Found on 32-bit Windows, MSVC 2013 does not respect // pragma fenv_access(on), and reorders incorrectly, so // disabling this on 32-bit. #ifdef _WIN64 #define DYND_USE_FPSTATUS #endif // No DYND_CONSTEXPR yet, define it as nothing #define DYND_CONSTEXPR // Some C library calls will abort if given bad format strings, etc // This RAII class temporarily disables that class disable_invalid_parameter_handler { _invalid_parameter_handler m_saved; disable_invalid_parameter_handler(const disable_invalid_parameter_handler &); disable_invalid_parameter_handler &operator=(const disable_invalid_parameter_handler &); static void nop_parameter_handler(const wchar_t *, const wchar_t *, const wchar_t *, unsigned int, uintptr_t) {} public: disable_invalid_parameter_handler() { m_saved = _set_invalid_parameter_handler(&nop_parameter_handler); } ~disable_invalid_parameter_handler() { _set_invalid_parameter_handler(m_saved); } }; #endif // end of compiler vendor checks // If being run from the CLING C++ interpreter #ifdef DYND_CLING // Don't use the memcpy function (it has inline assembly). inline void DYND_MEMCPY(char *dst, const char *src, intptr_t count) { char *cdst = (char *)dst; const char *csrc = (const char *)src; while (count--) { *cdst++ = *csrc++; } } #else #include #define DYND_MEMCPY(dst, src, count) std::memcpy(dst, src, count) #endif #include // These are small templates 'missing' from the standard library namespace dynd { template struct is_common_type_of : std::conditional::type>::value, std::true_type, std::false_type>::type { }; template class T, template class U, typename... As> struct conditional_make; template