generic_win_base.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * This source file is part of the Swift.org open source project
  3. *
  4. * Copyright (c) 2015 Apple Inc. and the Swift project authors
  5. *
  6. * Licensed under Apache License v2.0 with Runtime Library Exception
  7. *
  8. * See https://swift.org/LICENSE.txt for license information
  9. * See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
  10. *
  11. */
  12. #ifndef __OS_GENERIC_WIN_BASE__
  13. #define __OS_GENERIC_WIN_BASE__
  14. #include <os/generic_base.h>
  15. // Unices provide `roundup` via sys/param.h
  16. #define roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y))
  17. // Unices provide `MAX` via sys/param.h
  18. #define MAX(a,b) (((a)>(b))?(a):(b))
  19. // Unices provide `MIN` via sys/param.h
  20. #define MIN(a,b) (((a)<(b))?(a):(b))
  21. // Unices provide `howmany` via sys/param.h
  22. #define howmany(x, y) (((x) + ((y) - 1)) / (y))
  23. #ifndef HAVE_MODE_T
  24. typedef int mode_t;
  25. #endif
  26. typedef void pthread_attr_t;
  27. #ifndef API_AVAILABLE
  28. #define API_AVAILABLE(...)
  29. #endif
  30. #ifndef API_DEPRECATED
  31. #define API_DEPRECATED(...)
  32. #endif
  33. #ifndef API_UNAVAILABLE
  34. #define API_UNAVAILABLE(...)
  35. #endif
  36. #ifndef API_DEPRECATED_WITH_REPLACEMENT
  37. #define API_DEPRECATED_WITH_REPLACEMENT(...)
  38. #endif
  39. #if !defined(__has_attribute)
  40. #define __has_attribute(attibute) 0
  41. #endif
  42. #if !defined(__has_builtin)
  43. #define __has_builtin(builtin) 0
  44. #endif
  45. #if !defined(__has_feature)
  46. #define __has_feature(feature) 0
  47. #endif
  48. #if __has_builtin(__builtin_expect)
  49. #define OS_EXPECT(expression, value) __builtin_expect((expression), (value))
  50. #else
  51. #define OS_EXPECT(expression, value) (expression)
  52. #endif
  53. #if __has_attribute(__unused__)
  54. #define OS_UNUSED __attribute__((__unused__))
  55. #else
  56. #define OS_UNUSED
  57. #endif
  58. #ifndef os_likely
  59. #define os_likely(expression) OS_EXPECT(!!(expression), 1)
  60. #endif
  61. #ifndef os_unlikely
  62. #define os_unlikely(expression) OS_EXPECT(!!(expression), 0)
  63. #endif
  64. #if __has_feature(assume_nonnull)
  65. #define OS_ASSUME_NONNULL_BEGIN _Pragma("clang assume_nonnull begin")
  66. #define OS_ASSUME_NONNULL_END _Pragma("clang assume_nonnull end")
  67. #else
  68. #define OS_ASSUME_NONNULL_BEGIN
  69. #define OS_ASSUME_NONNULL_END
  70. #endif
  71. #if __has_builtin(__builtin_assume)
  72. #define OS_COMPILER_CAN_ASSUME(expr) __builtin_assume(expr)
  73. #else
  74. #define OS_COMPILER_CAN_ASSUME(expr) ((void)(expr))
  75. #endif
  76. #if __has_feature(attribute_availability_swift)
  77. // equivalent to __SWIFT_UNAVAILABLE from Availability.h
  78. #define OS_SWIFT_UNAVAILABLE(msg) \
  79. __attribute__((__availability__(swift, unavailable, message = msg)))
  80. #else
  81. #define OS_SWIFT_UNAVAILABLE(msg)
  82. #endif
  83. #define __OS_STRINGIFY(s) #s
  84. #define OS_STRINGIFY(s) __OS_STRINGIFY(s)
  85. #if __has_feature(objc_fixed_enum) || __has_extension(cxx_strong_enums)
  86. #define OS_ENUM(name, type, ...) typedef enum : type { __VA_ARGS__ } name##_t
  87. #else
  88. #define OS_ENUM(name, type, ...) \
  89. enum { __VA_ARGS__ }; \
  90. typedef type name##_t
  91. #endif
  92. #ifdef OS_EXPORT
  93. #undef OS_EXPORT
  94. #endif
  95. #define OS_EXPORT __declspec(dllexport)
  96. #ifdef OS_WARN_RESULT_NEEDS_RELEASE
  97. #undef OS_WARN_RESULT_NEEDS_RELEASE
  98. #endif
  99. #ifdef OS_WARN_RESULT
  100. #undef OS_WARN_RESULT
  101. #endif
  102. #define OS_WARN_RESULT
  103. #ifdef OS_NOTHROW
  104. #undef OS_NOTHROW
  105. #endif
  106. #define OS_NOTHROW
  107. #endif