Clone of mesa.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

c99_compat.h 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /**************************************************************************
  2. *
  3. * Copyright 2007-2013 VMware, Inc.
  4. * All Rights Reserved.
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a
  7. * copy of this software and associated documentation files (the
  8. * "Software"), to deal in the Software without restriction, including
  9. * without limitation the rights to use, copy, modify, merge, publish,
  10. * distribute, sub license, and/or sell copies of the Software, and to
  11. * permit persons to whom the Software is furnished to do so, subject to
  12. * the following conditions:
  13. *
  14. * The above copyright notice and this permission notice (including the
  15. * next paragraph) shall be included in all copies or substantial portions
  16. * of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  19. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  20. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
  21. * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
  22. * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  23. * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  24. * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  25. *
  26. **************************************************************************/
  27. #ifndef _C99_COMPAT_H_
  28. #define _C99_COMPAT_H_
  29. /*
  30. * MSVC hacks.
  31. */
  32. #if defined(_MSC_VER)
  33. /*
  34. * Visual Studio 2012 will complain if we define the `inline` keyword, but
  35. * actually it only supports the keyword on C++.
  36. *
  37. * To avoid this the _ALLOW_KEYWORD_MACROS must be set.
  38. */
  39. # if (_MSC_VER >= 1700) && !defined(_ALLOW_KEYWORD_MACROS)
  40. # define _ALLOW_KEYWORD_MACROS
  41. # endif
  42. /*
  43. * XXX: MSVC has a `__restrict` keyword, but it also has a
  44. * `__declspec(restrict)` modifier, so it is impossible to define a
  45. * `restrict` macro without interfering with the latter. Furthermore the
  46. * MSVC standard library uses __declspec(restrict) under the _CRTRESTRICT
  47. * macro. For now resolve this issue by redefining _CRTRESTRICT, but going
  48. * forward we should probably should stop using restrict, especially
  49. * considering that our code does not obbey strict aliasing rules any way.
  50. */
  51. # include <crtdefs.h>
  52. # undef _CRTRESTRICT
  53. # define _CRTRESTRICT
  54. #endif
  55. /*
  56. * C99 inline keyword
  57. */
  58. #ifndef inline
  59. # ifdef __cplusplus
  60. /* C++ supports inline keyword */
  61. # elif defined(__GNUC__)
  62. # define inline __inline__
  63. # elif defined(_MSC_VER)
  64. # define inline __inline
  65. # elif defined(__ICL)
  66. # define inline __inline
  67. # elif defined(__INTEL_COMPILER)
  68. /* Intel compiler supports inline keyword */
  69. # elif defined(__WATCOMC__) && (__WATCOMC__ >= 1100)
  70. # define inline __inline
  71. # elif defined(__SUNPRO_C) && defined(__C99FEATURES__)
  72. /* C99 supports inline keyword */
  73. # elif (__STDC_VERSION__ >= 199901L)
  74. /* C99 supports inline keyword */
  75. # else
  76. # define inline
  77. # endif
  78. #endif
  79. /*
  80. * C99 restrict keyword
  81. *
  82. * See also:
  83. * - http://cellperformance.beyond3d.com/articles/2006/05/demystifying-the-restrict-keyword.html
  84. */
  85. #ifndef restrict
  86. # if (__STDC_VERSION__ >= 199901L)
  87. /* C99 */
  88. # elif defined(__SUNPRO_C) && defined(__C99FEATURES__)
  89. /* C99 */
  90. # elif defined(__GNUC__)
  91. # define restrict __restrict__
  92. # elif defined(_MSC_VER)
  93. # define restrict __restrict
  94. # else
  95. # define restrict /* */
  96. # endif
  97. #endif
  98. /*
  99. * C99 __func__ macro
  100. */
  101. #ifndef __func__
  102. # if (__STDC_VERSION__ >= 199901L)
  103. /* C99 */
  104. # elif defined(__SUNPRO_C) && defined(__C99FEATURES__)
  105. /* C99 */
  106. # elif defined(__GNUC__)
  107. # if __GNUC__ >= 2
  108. # define __func__ __FUNCTION__
  109. # else
  110. # define __func__ "<unknown>"
  111. # endif
  112. # elif defined(_MSC_VER)
  113. # if _MSC_VER >= 1300
  114. # define __func__ __FUNCTION__
  115. # else
  116. # define __func__ "<unknown>"
  117. # endif
  118. # else
  119. # define __func__ "<unknown>"
  120. # endif
  121. #endif
  122. /* Simple test case for debugging */
  123. #if 0
  124. static inline const char *
  125. test_c99_compat_h(const void * restrict a,
  126. const void * restrict b)
  127. {
  128. return __func__;
  129. }
  130. #endif
  131. #endif /* _C99_COMPAT_H_ */