|
| 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 http://swift.org/LICENSE.txt for license information |
| 9 | + * See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors |
| 10 | + * |
| 11 | + */ |
| 12 | + |
| 13 | +#ifndef __OS_GENERIC_WIN_BASE__ |
| 14 | +#define __OS_GENERIC_WIN_BASE__ |
| 15 | + |
| 16 | +// Unices provide `roundup` via sys/param.h |
| 17 | +#define roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y)) |
| 18 | +// Unices provide `MAX` via sys/param.h |
| 19 | +#define MAX(a,b) (((a)>(b))?(a):(b)) |
| 20 | +// Unices provide `MIN` via sys/param.h |
| 21 | +#define MIN(a,b) (((a)<(b))?(a):(b)) |
| 22 | +// Unices provide `howmany` via sys/param.h |
| 23 | +#define howmany(x, y) (((x) + ((y) - 1)) / (y)) |
| 24 | + |
| 25 | +typedef int mode_t; |
| 26 | +typedef void pthread_attr_t; |
| 27 | + |
| 28 | +#if defined(__cplusplus) |
| 29 | +#define __BEGIN_DECLS extern "C" { |
| 30 | +#define __END_DECLS } |
| 31 | +#else |
| 32 | +#define __BEGIN_DECLS |
| 33 | +#define __END_DECLS |
| 34 | +#endif |
| 35 | + |
| 36 | +#ifndef API_AVAILABLE |
| 37 | +#define API_AVAILABLE(...) |
| 38 | +#endif |
| 39 | +#ifndef API_DEPRECATED |
| 40 | +#define API_DEPRECATED(...) |
| 41 | +#endif |
| 42 | +#ifndef API_UNAVAILABLE |
| 43 | +#define API_UNAVAILABLE(...) |
| 44 | +#endif |
| 45 | +#ifndef API_DEPRECATED_WITH_REPLACEMENT |
| 46 | +#define API_DEPRECATED_WITH_REPLACEMENT(...) |
| 47 | +#endif |
| 48 | + |
| 49 | +#if !defined(__has_attribute) |
| 50 | +#define __has_attribute(attibute) 0 |
| 51 | +#endif |
| 52 | + |
| 53 | +#if !defined(__has_builtin) |
| 54 | +#define __has_builtin(builtin) 0 |
| 55 | +#endif |
| 56 | + |
| 57 | +#if !defined(__has_feature) |
| 58 | +#define __has_feature(feature) 0 |
| 59 | +#endif |
| 60 | + |
| 61 | +#if __has_builtin(__builtin_expect) |
| 62 | +#define OS_EXPECT(expression, value) __builtin_expect((expression), (value)) |
| 63 | +#else |
| 64 | +#define OS_EXPECT(expression, value) (expression) |
| 65 | +#endif |
| 66 | + |
| 67 | +#if __has_attribute(__unused__) |
| 68 | +#define OS_UNUSED __attribute__((__unused__)) |
| 69 | +#else |
| 70 | +#define OS_UNUSED |
| 71 | +#endif |
| 72 | + |
| 73 | +#ifndef os_likely |
| 74 | +#define os_likely(expression) OS_EXPECT(!!(expression), 1) |
| 75 | +#endif |
| 76 | +#ifndef os_unlikely |
| 77 | +#define os_unlikely(expression) OS_EXPECT(!!(expression), 0) |
| 78 | +#endif |
| 79 | + |
| 80 | +#if __has_feature(assume_nonnull) |
| 81 | +#define OS_ASSUME_NONNULL_BEGIN _Pragma("clang assume_nonnull begin") |
| 82 | +#define OS_ASSUME_NONNULL_END _Pragma("clang assume_nonnull end") |
| 83 | +#else |
| 84 | +#define OS_ASSUME_NONNULL_BEGIN |
| 85 | +#define OS_ASSUME_NONNULL_END |
| 86 | +#endif |
| 87 | + |
| 88 | +#if __has_builtin(__builtin_assume) |
| 89 | +#define OS_COMPILER_CAN_ASSUME(expr) __builtin_assume(expr) |
| 90 | +#else |
| 91 | +#define OS_COMPILER_CAN_ASSUME(expr) ((void)(expr)) |
| 92 | +#endif |
| 93 | + |
| 94 | +#if __has_feature(attribute_availability_swift) |
| 95 | +// equivalent to __SWIFT_UNAVAILABLE from Availability.h |
| 96 | +#define OS_SWIFT_UNAVAILABLE(msg) \ |
| 97 | + __attribute__((__availability__(swift, unavailable, message = msg))) |
| 98 | +#else |
| 99 | +#define OS_SWIFT_UNAVAILABLE(msg) |
| 100 | +#endif |
| 101 | + |
| 102 | +#define __OS_STRINGIFY(s) #s |
| 103 | +#define OS_STRINGIFY(s) __OS_STRINGIFY(s) |
| 104 | + |
| 105 | +#if __has_feature(objc_fixed_enum) || __has_extension(cxx_strong_enums) |
| 106 | +#define OS_ENUM(name, type, ...) typedef enum : type { __VA_ARGS__ } name##_t |
| 107 | +#else |
| 108 | +#define OS_ENUM(name, type, ...) \ |
| 109 | + enum { __VA_ARGS__ }; \ |
| 110 | + typedef type name##_t |
| 111 | +#endif |
| 112 | + |
| 113 | +#ifdef OS_EXPORT |
| 114 | +#undef OS_EXPORT |
| 115 | +#endif |
| 116 | +#define OS_EXPORT __declspec(dllexport) |
| 117 | + |
| 118 | +#ifdef OS_WARN_RESULT_NEEDS_RELEASE |
| 119 | +#undef OS_WARN_RESULT_NEEDS_RELEASE |
| 120 | +#endif |
| 121 | + |
| 122 | +#ifdef OS_WARN_RESULT |
| 123 | +#undef OS_WARN_RESULT |
| 124 | +#endif |
| 125 | +#define OS_WARN_RESULT |
| 126 | + |
| 127 | +#ifdef OS_NOTHROW |
| 128 | +#undef OS_NOTHROW |
| 129 | +#endif |
| 130 | +#define OS_NOTHROW |
| 131 | + |
| 132 | +#endif |
0 commit comments