diff options
author | 2021-01-10 20:13:21 +0000 | |
---|---|---|
committer | 2021-01-10 20:13:21 +0000 | |
commit | 862558c29ea49be0016c97045a060fa91710838e (patch) | |
tree | 847762a36e95b2454ae666f1dfca5da54642ddc3 /gnu/llvm/libcxx/include/stdlib.h | |
parent | add quirks for Kensington Slimblade trackball via new vendor buttons (diff) | |
download | wireguard-openbsd-862558c29ea49be0016c97045a060fa91710838e.tar.xz wireguard-openbsd-862558c29ea49be0016c97045a060fa91710838e.zip |
Backport fix to avoid including math.h from stdlib.h.
Fixes building the textproc/groff port (and maybe others).
ok naddy@
Diffstat (limited to '')
-rw-r--r-- | gnu/llvm/libcxx/include/stdlib.h | 64 |
1 files changed, 58 insertions, 6 deletions
diff --git a/gnu/llvm/libcxx/include/stdlib.h b/gnu/llvm/libcxx/include/stdlib.h index 1d682758703..812ea1024ed 100644 --- a/gnu/llvm/libcxx/include/stdlib.h +++ b/gnu/llvm/libcxx/include/stdlib.h @@ -7,16 +7,12 @@ // //===----------------------------------------------------------------------===// -#if defined(__need_malloc_and_calloc) || defined(_LIBCPP_STDLIB_INCLUDE_NEXT) +#if defined(__need_malloc_and_calloc) #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header #endif -#if defined(_LIBCPP_STDLIB_INCLUDE_NEXT) -#undef _LIBCPP_STDLIB_INCLUDE_NEXT -#endif - #include_next <stdlib.h> #elif !defined(_LIBCPP_STDLIB_H) @@ -97,7 +93,63 @@ void *aligned_alloc(size_t alignment, size_t size); // C11 #include_next <stdlib.h> #ifdef __cplusplus -#include <math.h> +extern "C++" { +// abs + +#undef abs +#undef labs +#ifndef _LIBCPP_HAS_NO_LONG_LONG +#undef llabs +#endif + +// MSVCRT already has the correct prototype in <stdlib.h> if __cplusplus is defined +#if !defined(_LIBCPP_MSVCRT) && !defined(__sun__) && !defined(_AIX) +inline _LIBCPP_INLINE_VISIBILITY long abs(long __x) _NOEXCEPT { + return __builtin_labs(__x); +} +#ifndef _LIBCPP_HAS_NO_LONG_LONG +inline _LIBCPP_INLINE_VISIBILITY long long abs(long long __x) _NOEXCEPT { + return __builtin_llabs(__x); +} +#endif // _LIBCPP_HAS_NO_LONG_LONG +#endif // !defined(_LIBCPP_MSVCRT) && !defined(__sun__) && !defined(_AIX) + +#if !(defined(_AIX) || defined(__sun__)) +inline _LIBCPP_INLINE_VISIBILITY float abs(float __lcpp_x) _NOEXCEPT { + return __builtin_fabsf(__lcpp_x); // Use builtins to prevent needing math.h +} + +inline _LIBCPP_INLINE_VISIBILITY double abs(double __lcpp_x) _NOEXCEPT { + return __builtin_fabs(__lcpp_x); +} + +inline _LIBCPP_INLINE_VISIBILITY long double +abs(long double __lcpp_x) _NOEXCEPT { + return __builtin_fabsl(__lcpp_x); +} +#endif // !(defined(_AIX) || defined(__sun__)) + +// div + +#undef div +#undef ldiv +#ifndef _LIBCPP_HAS_NO_LONG_LONG +#undef lldiv +#endif + +// MSVCRT already has the correct prototype in <stdlib.h> if __cplusplus is defined +#if !defined(_LIBCPP_MSVCRT) && !defined(__sun__) && !defined(_AIX) +inline _LIBCPP_INLINE_VISIBILITY ldiv_t div(long __x, long __y) _NOEXCEPT { + return ::ldiv(__x, __y); +} +#ifndef _LIBCPP_HAS_NO_LONG_LONG +inline _LIBCPP_INLINE_VISIBILITY lldiv_t div(long long __x, + long long __y) _NOEXCEPT { + return ::lldiv(__x, __y); +} +#endif // _LIBCPP_HAS_NO_LONG_LONG +#endif // _LIBCPP_MSVCRT / __sun__ / _AIX +} // extern "C++" #endif // __cplusplus #endif // _LIBCPP_STDLIB_H |