macros.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*
  2. * Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License 2.0 (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. #include <openssl/opensslconf.h>
  10. #ifndef OPENSSL_MACROS_H
  11. # define OPENSSL_MACROS_H
  12. /*
  13. * Sometimes OPENSSSL_NO_xxx ends up with an empty file and some compilers
  14. * don't like that. This will hopefully silence them.
  15. */
  16. # define NON_EMPTY_TRANSLATION_UNIT static void *dummy = &dummy;
  17. /*
  18. * Applications should use -DOPENSSL_API_COMPAT=<version> to suppress the
  19. * declarations of functions deprecated in or before <version>. If this is
  20. * undefined, the value of the macro OPENSSL_API_MIN above is the default.
  21. *
  22. * For any version number up until version 1.1.x, <version> is expected to be
  23. * the calculated version number 0xMNNFFPPSL. For version numbers 3.0.0 and
  24. * on, <version> is expected to be only the major version number (i.e. 3 for
  25. * version 3.0.0).
  26. */
  27. # ifndef DECLARE_DEPRECATED
  28. # define DECLARE_DEPRECATED(f) f;
  29. # ifdef __GNUC__
  30. # if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 0)
  31. # undef DECLARE_DEPRECATED
  32. # define DECLARE_DEPRECATED(f) f __attribute__ ((deprecated));
  33. # endif
  34. # elif defined(__SUNPRO_C)
  35. # if (__SUNPRO_C >= 0x5130)
  36. # undef DECLARE_DEPRECATED
  37. # define DECLARE_DEPRECATED(f) f __attribute__ ((deprecated));
  38. # endif
  39. # endif
  40. # endif
  41. /*
  42. * We convert the OPENSSL_API_COMPAT value to an API level. The API level
  43. * is the major version number for 3.0.0 and on. For earlier versions, it
  44. * uses this scheme, which is close enough for our purposes:
  45. *
  46. * 0.x.y 0 (0.9.8 was the last release in this series)
  47. * 1.0.x 1 (1.0.2 was the last release in this series)
  48. * 1.1.x 2 (1.1.1 was the last release in this series)
  49. */
  50. /* In case someone defined both */
  51. # if defined(OPENSSL_API_COMPAT) && defined(OPENSSL_API_LEVEL)
  52. # error "Disallowed to define both OPENSSL_API_COMPAT and OPENSSL_API_LEVEL"
  53. # endif
  54. # ifndef OPENSSL_API_COMPAT
  55. # define OPENSSL_API_LEVEL OPENSSL_MIN_API
  56. # else
  57. # if (OPENSSL_API_COMPAT < 0x1000L) /* Major version numbers up to 16777215 */
  58. # define OPENSSL_API_LEVEL OPENSSL_API_COMPAT
  59. # elif (OPENSSL_API_COMPAT & 0xF0000000L) == 0x00000000L
  60. # define OPENSSL_API_LEVEL 0
  61. # elif (OPENSSL_API_COMPAT & 0xFFF00000L) == 0x10000000L
  62. # define OPENSSL_API_LEVEL 1
  63. # elif (OPENSSL_API_COMPAT & 0xFFF00000L) == 0x10100000L
  64. # define OPENSSL_API_LEVEL 2
  65. # else
  66. /* Major number 3 to 15 */
  67. # define OPENSSL_API_LEVEL ((OPENSSL_API_COMPAT >> 28) & 0xF)
  68. # endif
  69. # endif
  70. /*
  71. * Define API level check macros up to what makes sense. Since we
  72. * do future deprecations, we define one API level beyond the current
  73. * major version number.
  74. */
  75. # if OPENSSL_API_LEVEL < 4
  76. # define DEPRECATEDIN_4(f) DECLARE_DEPRECATED(f)
  77. # define OPENSSL_API_4 0
  78. # else
  79. # define DEPRECATEDIN_4(f)
  80. # define OPENSSL_API_4 1
  81. # endif
  82. # if OPENSSL_API_LEVEL < 3
  83. # define DEPRECATEDIN_3(f) DECLARE_DEPRECATED(f)
  84. # define OPENSSL_API_3 0
  85. # else
  86. # define DEPRECATEDIN_3(f)
  87. # define OPENSSL_API_3 1
  88. # endif
  89. # if OPENSSL_API_LEVEL < 2
  90. # define DEPRECATEDIN_1_1_0(f) DECLARE_DEPRECATED(f)
  91. # define OPENSSL_API_1_1_0 0
  92. # else
  93. # define DEPRECATEDIN_1_1_0(f)
  94. # define OPENSSL_API_1_1_0 1
  95. # endif
  96. # if OPENSSL_API_LEVEL < 1
  97. # define DEPRECATEDIN_1_0_0(f) DECLARE_DEPRECATED(f)
  98. # define OPENSSL_API_1_0_0 0
  99. # else
  100. # define DEPRECATEDIN_1_0_0(f)
  101. # define OPENSSL_API_1_0_0 1
  102. # endif
  103. # if OPENSSL_API_LEVEL < 0
  104. # define DEPRECATEDIN_0_9_8(f) DECLARE_DEPRECATED(f)
  105. # define OPENSSL_API_0_9_8 0
  106. # else
  107. # define DEPRECATEDIN_0_9_8(f)
  108. # define OPENSSL_API_0_9_8 1
  109. # endif
  110. # ifndef OPENSSL_FILE
  111. # ifdef OPENSSL_NO_FILENAMES
  112. # define OPENSSL_FILE ""
  113. # define OPENSSL_LINE 0
  114. # else
  115. # define OPENSSL_FILE __FILE__
  116. # define OPENSSL_LINE __LINE__
  117. # endif
  118. # endif
  119. /*
  120. * __func__ was standardized in C99, so for any compiler that claims
  121. * to implement that language level or newer, we assume we can safely
  122. * use that symbol.
  123. *
  124. * GNU C also provides __FUNCTION__ since version 2, which predates
  125. * C99. We can, however, only use this if __STDC_VERSION__ exists,
  126. * as it's otherwise not allowed according to ISO C standards (C90).
  127. * (compiling with GNU C's -pedantic tells us so)
  128. *
  129. * If none of the above applies, we check if the compiler is MSVC,
  130. * and use __FUNCTION__ if that's the case.
  131. */
  132. # ifndef OPENSSL_FUNC
  133. # if defined(__STDC_VERSION__)
  134. # if __STDC_VERSION__ >= 199901L
  135. # define OPENSSL_FUNC __func__
  136. # elif defined(__GNUC__) && __GNUC__ >= 2
  137. # define OPENSSL_FUNC __FUNCTION__
  138. # endif
  139. # elif defined(_MSC_VER)
  140. # define OPENSSL_FUNC __FUNCTION__
  141. # endif
  142. /*
  143. * If all these possibilities are exhausted, we give up and use a
  144. * static string.
  145. */
  146. # ifndef OPENSSL_FUNC
  147. # define OPENSSL_FUNC "(unknown function)"
  148. # endif
  149. # endif
  150. #endif /* OPENSSL_MACROS_H */