defaults.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. #pragma once
  2. #include "platform.h"
  3. #if defined _unix_
  4. #define LOCSLASH_C '/'
  5. #define LOCSLASH_S "/"
  6. #else
  7. #define LOCSLASH_C '\\'
  8. #define LOCSLASH_S "\\"
  9. #endif // _unix_
  10. #if defined(__INTEL_COMPILER) && defined(__cplusplus)
  11. #include <new>
  12. #endif
  13. // low and high parts of integers
  14. #if !defined(_win_)
  15. #include <sys/param.h>
  16. #endif
  17. #if defined(BSD) || defined(_android_)
  18. #if defined(BSD)
  19. #include <machine/endian.h>
  20. #endif
  21. #if defined(_android_)
  22. #include <endian.h>
  23. #endif
  24. #if (BYTE_ORDER == LITTLE_ENDIAN)
  25. #define _little_endian_
  26. #elif (BYTE_ORDER == BIG_ENDIAN)
  27. #define _big_endian_
  28. #else
  29. #error unknown endian not supported
  30. #endif
  31. #elif (defined(_sun_) && !defined(__i386__)) || defined(_hpux_) || defined(WHATEVER_THAT_HAS_BIG_ENDIAN)
  32. #define _big_endian_
  33. #else
  34. #define _little_endian_
  35. #endif
  36. // alignment
  37. #if (defined(_sun_) && !defined(__i386__)) || defined(_hpux_) || defined(__alpha__) || defined(__ia64__) || defined(WHATEVER_THAT_NEEDS_ALIGNING_QUADS)
  38. #define _must_align8_
  39. #endif
  40. #if (defined(_sun_) && !defined(__i386__)) || defined(_hpux_) || defined(__alpha__) || defined(__ia64__) || defined(WHATEVER_THAT_NEEDS_ALIGNING_LONGS)
  41. #define _must_align4_
  42. #endif
  43. #if (defined(_sun_) && !defined(__i386__)) || defined(_hpux_) || defined(__alpha__) || defined(__ia64__) || defined(WHATEVER_THAT_NEEDS_ALIGNING_SHORTS)
  44. #define _must_align2_
  45. #endif
  46. #if defined(__GNUC__)
  47. #define alias_hack __attribute__((__may_alias__))
  48. #endif
  49. #ifndef alias_hack
  50. #define alias_hack
  51. #endif
  52. #include "types.h"
  53. #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
  54. #define PRAGMA(x) _Pragma(#x)
  55. #define RCSID(idstr) PRAGMA(comment(exestr, idstr))
  56. #else
  57. #define RCSID(idstr) static const char rcsid[] = idstr
  58. #endif
  59. #include "compiler.h"
  60. #ifdef _win_
  61. #include <malloc.h>
  62. #elif defined(_sun_)
  63. #include <alloca.h>
  64. #endif
  65. #ifdef NDEBUG
  66. #define Y_IF_DEBUG(X)
  67. #ifdef __cplusplus
  68. constexpr bool Y_IS_DEBUG_BUILD = false;
  69. #endif
  70. #else
  71. #define Y_IF_DEBUG(X) X
  72. #ifdef __cplusplus
  73. constexpr bool Y_IS_DEBUG_BUILD = true;
  74. #endif
  75. #endif
  76. /**
  77. * @def Y_ARRAY_SIZE
  78. *
  79. * This macro is needed to get number of elements in a statically allocated fixed size array. The
  80. * expression is a compile-time constant and therefore can be used in compile time computations.
  81. *
  82. * @code
  83. * enum ENumbers {
  84. * EN_ONE,
  85. * EN_TWO,
  86. * EN_SIZE
  87. * }
  88. *
  89. * const char* NAMES[] = {
  90. * "one",
  91. * "two"
  92. * }
  93. *
  94. * static_assert(Y_ARRAY_SIZE(NAMES) == EN_SIZE, "you should define `NAME` for each enumeration");
  95. * @endcode
  96. *
  97. * This macro also catches type errors. If you see a compiler error like "warning: division by zero
  98. * is undefined" when using `Y_ARRAY_SIZE` then you are probably giving it a pointer.
  99. *
  100. * Since all of our code is expected to work on a 64 bit platform where pointers are 8 bytes we may
  101. * falsefully accept pointers to types of sizes that are divisors of 8 (1, 2, 4 and 8).
  102. */
  103. #if defined(__cplusplus)
  104. #include <util/generic/array_size.h>
  105. #else
  106. #undef Y_ARRAY_SIZE
  107. #define Y_ARRAY_SIZE(arr) \
  108. ((sizeof(arr) / sizeof((arr)[0])) / static_cast<size_t>(!(sizeof(arr) % sizeof((arr)[0]))))
  109. #endif
  110. #undef Y_ARRAY_BEGIN
  111. #define Y_ARRAY_BEGIN(arr) (arr)
  112. #undef Y_ARRAY_END
  113. #define Y_ARRAY_END(arr) ((arr) + Y_ARRAY_SIZE(arr))
  114. /**
  115. * Concatenates two symbols, even if one of them is itself a macro.
  116. */
  117. #define Y_CAT(X, Y) Y_CAT_I(X, Y)
  118. #define Y_CAT_I(X, Y) Y_CAT_II(X, Y)
  119. #define Y_CAT_II(X, Y) X##Y
  120. #define Y_STRINGIZE(X) UTIL_PRIVATE_STRINGIZE_AUX(X)
  121. #define UTIL_PRIVATE_STRINGIZE_AUX(X) #X
  122. #if defined(__COUNTER__)
  123. #define Y_GENERATE_UNIQUE_ID(N) Y_CAT(N, __COUNTER__)
  124. #endif
  125. #if !defined(Y_GENERATE_UNIQUE_ID)
  126. #define Y_GENERATE_UNIQUE_ID(N) Y_CAT(N, __LINE__)
  127. #endif
  128. #define NPOS ((size_t)-1)