diff options
Diffstat (limited to 'mesalib/include')
-rw-r--r-- | mesalib/include/c11/threads_posix.h | 7 | ||||
-rw-r--r-- | mesalib/include/c99_alloca.h | 2 | ||||
-rw-r--r-- | mesalib/include/c99_compat.h | 2 | ||||
-rw-r--r-- | mesalib/include/c99_math.h | 45 | ||||
-rw-r--r-- | mesalib/include/no_extern_c.h | 48 |
5 files changed, 97 insertions, 7 deletions
diff --git a/mesalib/include/c11/threads_posix.h b/mesalib/include/c11/threads_posix.h index f9c165df4..2182c2835 100644 --- a/mesalib/include/c11/threads_posix.h +++ b/mesalib/include/c11/threads_posix.h @@ -177,13 +177,8 @@ mtx_init(mtx_t *mtx, int type) && type != (mtx_try|mtx_recursive)) return thrd_error; pthread_mutexattr_init(&attr); - if ((type & mtx_recursive) != 0) { -#if defined(__linux__) || defined(__linux) - pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE_NP); -#else + if ((type & mtx_recursive) != 0) pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); -#endif - } pthread_mutex_init(mtx, &attr); pthread_mutexattr_destroy(&attr); return thrd_success; diff --git a/mesalib/include/c99_alloca.h b/mesalib/include/c99_alloca.h index ed66fda01..5a3b8c19a 100644 --- a/mesalib/include/c99_alloca.h +++ b/mesalib/include/c99_alloca.h @@ -35,7 +35,7 @@ # define alloca _alloca -#elif defined(__sun) +#elif defined(__sun) || defined(__CYGWIN__) # include <alloca.h> diff --git a/mesalib/include/c99_compat.h b/mesalib/include/c99_compat.h index f56f6f326..4fc91bc13 100644 --- a/mesalib/include/c99_compat.h +++ b/mesalib/include/c99_compat.h @@ -25,6 +25,8 @@ * **************************************************************************/ +#include "no_extern_c.h" + #ifndef _C99_COMPAT_H_ #define _C99_COMPAT_H_ diff --git a/mesalib/include/c99_math.h b/mesalib/include/c99_math.h index 0a49950cf..5b01d53a8 100644 --- a/mesalib/include/c99_math.h +++ b/mesalib/include/c99_math.h @@ -71,6 +71,7 @@ roundf(float x) #endif #ifndef INFINITY +#include <float.h> // DBL_MAX #define INFINITY (DBL_MAX + DBL_MAX) #endif @@ -161,4 +162,48 @@ llrintf(float f) #endif +#if defined(fpclassify) +/* ISO C99 says that fpclassify is a macro. Assume that any implementation + * of fpclassify, whether it's in a C99 compiler or not, will be a macro. + */ +#elif defined(__cplusplus) +/* For C++, fpclassify() should be defined in <cmath> */ +#elif defined(_MSC_VER) +/* Not required on VS2013 and above. Oddly, the fpclassify() function + * doesn't exist in such a form on MSVC. This is an implementation using + * slightly different lower-level Windows functions. + */ +#include <float.h> + +static inline enum {FP_NAN, FP_INFINITE, FP_ZERO, FP_SUBNORMAL, FP_NORMAL} +fpclassify(double x) +{ + switch(_fpclass(x)) { + case _FPCLASS_SNAN: /* signaling NaN */ + case _FPCLASS_QNAN: /* quiet NaN */ + return FP_NAN; + case _FPCLASS_NINF: /* negative infinity */ + case _FPCLASS_PINF: /* positive infinity */ + return FP_INFINITE; + case _FPCLASS_NN: /* negative normal */ + case _FPCLASS_PN: /* positive normal */ + return FP_NORMAL; + case _FPCLASS_ND: /* negative denormalized */ + case _FPCLASS_PD: /* positive denormalized */ + return FP_SUBNORMAL; + case _FPCLASS_NZ: /* negative zero */ + case _FPCLASS_PZ: /* positive zero */ + return FP_ZERO; + default: + /* Should never get here; but if we do, this will guarantee + * that the pattern is not treated like a number. + */ + return FP_NAN; + } +} +#else +#error "Need to include or define an fpclassify function" +#endif + + #endif /* #define _C99_MATH_H_ */ diff --git a/mesalib/include/no_extern_c.h b/mesalib/include/no_extern_c.h new file mode 100644 index 000000000..f79602c03 --- /dev/null +++ b/mesalib/include/no_extern_c.h @@ -0,0 +1,48 @@ +/************************************************************************** + * + * Copyright 2014 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + +/* + * Including system's headers inside `extern "C" { ... }` is not safe, as system + * headers may have C++ code in them, and C++ code inside extern "C" + * leads to syntatically incorrect code. + * + * This is because putting code inside extern "C" won't make __cplusplus define + * go away, that is, the system header being included thinks is free to use C++ + * as it sees fits. + * + * Including non-system headers inside extern "C" is not safe either, because + * non-system headers end up including system headers, hence fall in the above + * case too. + * + * Conclusion, includes inside extern "C" is simply not portable. + * + * + * This header helps surface these issues. + */ + +#ifdef __cplusplus +template<class T> class _IncludeInsideExternCNotPortable; +#endif |