grpc 1.26.0 → 1.27.0.pre1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of grpc might be problematic. Click here for more details.

Files changed (209) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +1654 -1519
  3. data/etc/roots.pem +44 -0
  4. data/include/grpc/grpc_security.h +37 -15
  5. data/include/grpc/grpc_security_constants.h +27 -0
  6. data/include/grpc/impl/codegen/grpc_types.h +14 -0
  7. data/include/grpc/impl/codegen/port_platform.h +1 -1
  8. data/src/core/ext/filters/client_channel/client_channel.cc +0 -20
  9. data/src/core/ext/filters/client_channel/http_proxy.cc +4 -4
  10. data/src/core/ext/filters/client_channel/lb_policy.cc +4 -3
  11. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +191 -201
  12. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_balancer_addresses.cc +89 -0
  13. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_balancer_addresses.h +40 -0
  14. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc +3 -2
  15. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc +88 -121
  16. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h +28 -57
  17. data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +0 -7
  18. data/src/core/ext/filters/client_channel/lb_policy/xds/cds.cc +8 -9
  19. data/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +53 -34
  20. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +18 -5
  21. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +24 -19
  22. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +2 -1
  23. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_fallback.cc +4 -2
  24. data/src/core/ext/filters/client_channel/server_address.cc +6 -9
  25. data/src/core/ext/filters/client_channel/server_address.h +3 -10
  26. data/src/core/ext/filters/client_channel/xds/xds_api.cc +394 -150
  27. data/src/core/ext/filters/client_channel/xds/xds_api.h +75 -35
  28. data/src/core/ext/filters/client_channel/xds/xds_bootstrap.cc +59 -22
  29. data/src/core/ext/filters/client_channel/xds/xds_bootstrap.h +13 -9
  30. data/src/core/ext/filters/client_channel/xds/xds_channel_secure.cc +8 -6
  31. data/src/core/ext/filters/client_channel/xds/xds_client.cc +456 -175
  32. data/src/core/ext/filters/client_channel/xds/xds_client.h +33 -21
  33. data/src/core/ext/filters/client_channel/xds/xds_client_stats.cc +5 -8
  34. data/src/core/ext/filters/client_channel/xds/xds_client_stats.h +18 -24
  35. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +2 -2
  36. data/src/core/ext/upb-generated/src/proto/grpc/lb/v1/load_balancer.upb.c +13 -5
  37. data/src/core/ext/upb-generated/src/proto/grpc/lb/v1/load_balancer.upb.h +34 -0
  38. data/src/core/lib/channel/channelz.h +11 -1
  39. data/src/core/lib/gpr/time_precise.cc +1 -1
  40. data/src/core/lib/gprpp/optional.h +26 -0
  41. data/src/core/lib/gprpp/string_view.h +14 -10
  42. data/src/core/lib/iomgr/executor.cc +1 -1
  43. data/src/core/lib/iomgr/fork_posix.cc +4 -0
  44. data/src/core/lib/iomgr/poller/eventmanager_libuv.cc +87 -0
  45. data/src/core/lib/iomgr/poller/eventmanager_libuv.h +88 -0
  46. data/src/core/lib/iomgr/socket_utils_common_posix.cc +14 -0
  47. data/src/core/lib/iomgr/socket_utils_posix.h +12 -0
  48. data/src/core/lib/iomgr/tcp_custom.h +3 -0
  49. data/src/core/lib/iomgr/tcp_posix.cc +607 -56
  50. data/src/core/lib/iomgr/tcp_server_custom.cc +15 -2
  51. data/src/core/lib/iomgr/tcp_server_utils_posix_common.cc +8 -0
  52. data/src/core/lib/json/json.h +11 -1
  53. data/src/core/lib/json/json_reader.cc +206 -28
  54. data/src/core/lib/json/json_writer.cc +111 -24
  55. data/src/core/lib/security/credentials/composite/composite_credentials.cc +7 -0
  56. data/src/core/lib/security/credentials/composite/composite_credentials.h +5 -1
  57. data/src/core/lib/security/credentials/credentials.h +10 -1
  58. data/src/core/lib/security/credentials/fake/fake_credentials.h +2 -1
  59. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +1 -1
  60. data/src/core/lib/security/credentials/plugin/plugin_credentials.cc +6 -4
  61. data/src/core/lib/security/credentials/plugin/plugin_credentials.h +2 -1
  62. data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.cc +20 -0
  63. data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.h +8 -0
  64. data/src/core/lib/security/credentials/tls/{spiffe_credentials.cc → tls_credentials.cc} +23 -24
  65. data/src/core/lib/security/credentials/tls/{spiffe_credentials.h → tls_credentials.h} +9 -9
  66. data/src/core/lib/security/security_connector/alts/alts_security_connector.cc +13 -0
  67. data/src/core/lib/security/security_connector/fake/fake_security_connector.cc +22 -2
  68. data/src/core/lib/security/security_connector/load_system_roots_fallback.cc +2 -2
  69. data/src/core/lib/security/security_connector/load_system_roots_linux.cc +2 -2
  70. data/src/core/lib/security/security_connector/local/local_security_connector.cc +30 -3
  71. data/src/core/lib/security/security_connector/ssl_utils.cc +45 -3
  72. data/src/core/lib/security/security_connector/ssl_utils.h +12 -0
  73. data/src/core/lib/security/security_connector/tls/{spiffe_security_connector.cc → tls_security_connector.cc} +82 -69
  74. data/src/core/lib/security/security_connector/tls/{spiffe_security_connector.h → tls_security_connector.h} +17 -18
  75. data/src/core/lib/security/transport/client_auth_filter.cc +33 -0
  76. data/src/core/lib/surface/completion_queue.cc +22 -1
  77. data/src/core/lib/surface/version.cc +1 -1
  78. data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc +11 -1
  79. data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.h +1 -1
  80. data/src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc +3 -3
  81. data/src/core/tsi/fake_transport_security.cc +7 -3
  82. data/src/core/tsi/fake_transport_security.h +2 -0
  83. data/src/core/tsi/ssl_transport_security.cc +144 -8
  84. data/src/core/tsi/ssl_transport_security.h +15 -1
  85. data/src/core/tsi/transport_security.cc +13 -0
  86. data/src/core/tsi/transport_security_grpc.cc +2 -2
  87. data/src/core/tsi/transport_security_grpc.h +2 -2
  88. data/src/core/tsi/transport_security_interface.h +12 -0
  89. data/src/ruby/bin/math_pb.rb +5 -5
  90. data/src/ruby/ext/grpc/rb_call_credentials.c +4 -1
  91. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +2 -0
  92. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +4 -1
  93. data/src/ruby/lib/grpc/version.rb +1 -1
  94. data/src/ruby/pb/grpc/health/v1/health_pb.rb +3 -3
  95. data/src/ruby/pb/src/proto/grpc/testing/empty_pb.rb +1 -1
  96. data/src/ruby/pb/src/proto/grpc/testing/messages_pb.rb +23 -13
  97. data/third_party/abseil-cpp/absl/algorithm/algorithm.h +159 -0
  98. data/third_party/abseil-cpp/absl/base/attributes.h +609 -0
  99. data/third_party/abseil-cpp/absl/base/call_once.h +226 -0
  100. data/third_party/abseil-cpp/absl/base/casts.h +184 -0
  101. data/third_party/abseil-cpp/absl/base/config.h +622 -0
  102. data/third_party/abseil-cpp/absl/base/const_init.h +76 -0
  103. data/third_party/abseil-cpp/absl/base/dynamic_annotations.cc +129 -0
  104. data/third_party/abseil-cpp/absl/base/dynamic_annotations.h +389 -0
  105. data/third_party/abseil-cpp/absl/base/internal/atomic_hook.h +179 -0
  106. data/third_party/abseil-cpp/absl/base/internal/bits.h +218 -0
  107. data/third_party/abseil-cpp/absl/base/internal/cycleclock.cc +107 -0
  108. data/third_party/abseil-cpp/absl/base/internal/cycleclock.h +94 -0
  109. data/third_party/abseil-cpp/absl/base/internal/endian.h +266 -0
  110. data/third_party/abseil-cpp/absl/base/internal/hide_ptr.h +51 -0
  111. data/third_party/abseil-cpp/absl/base/internal/identity.h +37 -0
  112. data/third_party/abseil-cpp/absl/base/internal/inline_variable.h +107 -0
  113. data/third_party/abseil-cpp/absl/base/internal/invoke.h +187 -0
  114. data/third_party/abseil-cpp/absl/base/internal/low_level_scheduling.h +107 -0
  115. data/third_party/abseil-cpp/absl/base/internal/per_thread_tls.h +52 -0
  116. data/third_party/abseil-cpp/absl/base/internal/raw_logging.cc +237 -0
  117. data/third_party/abseil-cpp/absl/base/internal/raw_logging.h +179 -0
  118. data/third_party/abseil-cpp/absl/base/internal/scheduling_mode.h +58 -0
  119. data/third_party/abseil-cpp/absl/base/internal/spinlock.cc +233 -0
  120. data/third_party/abseil-cpp/absl/base/internal/spinlock.h +243 -0
  121. data/third_party/abseil-cpp/absl/base/internal/spinlock_akaros.inc +35 -0
  122. data/third_party/abseil-cpp/absl/base/internal/spinlock_linux.inc +67 -0
  123. data/third_party/abseil-cpp/absl/base/internal/spinlock_posix.inc +46 -0
  124. data/third_party/abseil-cpp/absl/base/internal/spinlock_wait.cc +81 -0
  125. data/third_party/abseil-cpp/absl/base/internal/spinlock_wait.h +93 -0
  126. data/third_party/abseil-cpp/absl/base/internal/spinlock_win32.inc +37 -0
  127. data/third_party/abseil-cpp/absl/base/internal/sysinfo.cc +414 -0
  128. data/third_party/abseil-cpp/absl/base/internal/sysinfo.h +66 -0
  129. data/third_party/abseil-cpp/absl/base/internal/thread_annotations.h +271 -0
  130. data/third_party/abseil-cpp/absl/base/internal/thread_identity.cc +140 -0
  131. data/third_party/abseil-cpp/absl/base/internal/thread_identity.h +250 -0
  132. data/third_party/abseil-cpp/absl/base/internal/throw_delegate.cc +108 -0
  133. data/third_party/abseil-cpp/absl/base/internal/throw_delegate.h +75 -0
  134. data/third_party/abseil-cpp/absl/base/internal/tsan_mutex_interface.h +66 -0
  135. data/third_party/abseil-cpp/absl/base/internal/unaligned_access.h +158 -0
  136. data/third_party/abseil-cpp/absl/base/internal/unscaledcycleclock.cc +103 -0
  137. data/third_party/abseil-cpp/absl/base/internal/unscaledcycleclock.h +124 -0
  138. data/third_party/abseil-cpp/absl/base/log_severity.cc +27 -0
  139. data/third_party/abseil-cpp/absl/base/log_severity.h +121 -0
  140. data/third_party/abseil-cpp/absl/base/macros.h +220 -0
  141. data/third_party/abseil-cpp/absl/base/optimization.h +181 -0
  142. data/third_party/abseil-cpp/absl/base/options.h +214 -0
  143. data/third_party/abseil-cpp/absl/base/policy_checks.h +111 -0
  144. data/third_party/abseil-cpp/absl/base/port.h +26 -0
  145. data/third_party/abseil-cpp/absl/base/thread_annotations.h +280 -0
  146. data/third_party/abseil-cpp/absl/container/inlined_vector.h +848 -0
  147. data/third_party/abseil-cpp/absl/container/internal/compressed_tuple.h +265 -0
  148. data/third_party/abseil-cpp/absl/container/internal/inlined_vector.h +892 -0
  149. data/third_party/abseil-cpp/absl/memory/memory.h +695 -0
  150. data/third_party/abseil-cpp/absl/meta/type_traits.h +759 -0
  151. data/third_party/abseil-cpp/absl/numeric/int128.cc +404 -0
  152. data/third_party/abseil-cpp/absl/numeric/int128.h +1091 -0
  153. data/third_party/abseil-cpp/absl/numeric/int128_have_intrinsic.inc +302 -0
  154. data/third_party/abseil-cpp/absl/numeric/int128_no_intrinsic.inc +308 -0
  155. data/third_party/abseil-cpp/absl/strings/ascii.cc +200 -0
  156. data/third_party/abseil-cpp/absl/strings/ascii.h +241 -0
  157. data/third_party/abseil-cpp/absl/strings/charconv.cc +985 -0
  158. data/third_party/abseil-cpp/absl/strings/charconv.h +119 -0
  159. data/third_party/abseil-cpp/absl/strings/escaping.cc +949 -0
  160. data/third_party/abseil-cpp/absl/strings/escaping.h +164 -0
  161. data/third_party/abseil-cpp/absl/strings/internal/char_map.h +156 -0
  162. data/third_party/abseil-cpp/absl/strings/internal/charconv_bigint.cc +359 -0
  163. data/third_party/abseil-cpp/absl/strings/internal/charconv_bigint.h +421 -0
  164. data/third_party/abseil-cpp/absl/strings/internal/charconv_parse.cc +504 -0
  165. data/third_party/abseil-cpp/absl/strings/internal/charconv_parse.h +99 -0
  166. data/third_party/abseil-cpp/absl/strings/internal/escaping.cc +180 -0
  167. data/third_party/abseil-cpp/absl/strings/internal/escaping.h +58 -0
  168. data/third_party/abseil-cpp/absl/strings/internal/memutil.cc +112 -0
  169. data/third_party/abseil-cpp/absl/strings/internal/memutil.h +148 -0
  170. data/third_party/abseil-cpp/absl/strings/internal/ostringstream.cc +36 -0
  171. data/third_party/abseil-cpp/absl/strings/internal/ostringstream.h +89 -0
  172. data/third_party/abseil-cpp/absl/strings/internal/resize_uninitialized.h +73 -0
  173. data/third_party/abseil-cpp/absl/strings/internal/stl_type_traits.h +248 -0
  174. data/third_party/abseil-cpp/absl/strings/internal/str_join_internal.h +314 -0
  175. data/third_party/abseil-cpp/absl/strings/internal/str_split_internal.h +455 -0
  176. data/third_party/abseil-cpp/absl/strings/internal/utf8.cc +53 -0
  177. data/third_party/abseil-cpp/absl/strings/internal/utf8.h +50 -0
  178. data/third_party/abseil-cpp/absl/strings/match.cc +40 -0
  179. data/third_party/abseil-cpp/absl/strings/match.h +90 -0
  180. data/third_party/abseil-cpp/absl/strings/numbers.cc +916 -0
  181. data/third_party/abseil-cpp/absl/strings/numbers.h +263 -0
  182. data/third_party/abseil-cpp/absl/strings/str_cat.cc +246 -0
  183. data/third_party/abseil-cpp/absl/strings/str_cat.h +408 -0
  184. data/third_party/abseil-cpp/absl/strings/str_join.h +293 -0
  185. data/third_party/abseil-cpp/absl/strings/str_replace.cc +82 -0
  186. data/third_party/abseil-cpp/absl/strings/str_replace.h +219 -0
  187. data/third_party/abseil-cpp/absl/strings/str_split.cc +139 -0
  188. data/third_party/abseil-cpp/absl/strings/str_split.h +513 -0
  189. data/third_party/abseil-cpp/absl/strings/string_view.cc +235 -0
  190. data/third_party/abseil-cpp/absl/strings/string_view.h +615 -0
  191. data/third_party/abseil-cpp/absl/strings/strip.h +91 -0
  192. data/third_party/abseil-cpp/absl/strings/substitute.cc +171 -0
  193. data/third_party/abseil-cpp/absl/strings/substitute.h +693 -0
  194. data/third_party/abseil-cpp/absl/types/bad_optional_access.cc +48 -0
  195. data/third_party/abseil-cpp/absl/types/bad_optional_access.h +78 -0
  196. data/third_party/abseil-cpp/absl/types/internal/optional.h +396 -0
  197. data/third_party/abseil-cpp/absl/types/internal/span.h +128 -0
  198. data/third_party/abseil-cpp/absl/types/optional.h +776 -0
  199. data/third_party/abseil-cpp/absl/types/span.h +713 -0
  200. data/third_party/abseil-cpp/absl/utility/utility.h +350 -0
  201. data/third_party/upb/upb/decode.c +4 -0
  202. data/third_party/upb/upb/port.c +0 -1
  203. data/third_party/upb/upb/port_def.inc +1 -3
  204. data/third_party/upb/upb/table.c +2 -1
  205. metadata +147 -43
  206. data/src/core/lib/json/json_common.h +0 -34
  207. data/src/core/lib/json/json_reader.h +0 -146
  208. data/src/core/lib/json/json_string.cc +0 -367
  209. data/src/core/lib/json/json_writer.h +0 -84
@@ -0,0 +1,302 @@
1
+ //
2
+ // Copyright 2017 The Abseil Authors.
3
+ //
4
+ // Licensed under the Apache License, Version 2.0 (the "License");
5
+ // you may not use this file except in compliance with the License.
6
+ // You may obtain a copy of the License at
7
+ //
8
+ // https://www.apache.org/licenses/LICENSE-2.0
9
+ //
10
+ // Unless required by applicable law or agreed to in writing, software
11
+ // distributed under the License is distributed on an "AS IS" BASIS,
12
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ // See the License for the specific language governing permissions and
14
+ // limitations under the License.
15
+
16
+ // This file contains :int128 implementation details that depend on internal
17
+ // representation when ABSL_HAVE_INTRINSIC_INT128 is defined. This file is
18
+ // included by int128.h and relies on ABSL_INTERNAL_WCHAR_T being defined.
19
+
20
+ namespace int128_internal {
21
+
22
+ // Casts from unsigned to signed while preserving the underlying binary
23
+ // representation.
24
+ constexpr __int128 BitCastToSigned(unsigned __int128 v) {
25
+ // Casting an unsigned integer to a signed integer of the same
26
+ // width is implementation defined behavior if the source value would not fit
27
+ // in the destination type. We step around it with a roundtrip bitwise not
28
+ // operation to make sure this function remains constexpr. Clang and GCC
29
+ // optimize this to a no-op on x86-64.
30
+ return v & (static_cast<unsigned __int128>(1) << 127)
31
+ ? ~static_cast<__int128>(~v)
32
+ : static_cast<__int128>(v);
33
+ }
34
+
35
+ } // namespace int128_internal
36
+
37
+ inline int128& int128::operator=(__int128 v) {
38
+ v_ = v;
39
+ return *this;
40
+ }
41
+
42
+ constexpr uint64_t Int128Low64(int128 v) {
43
+ return static_cast<uint64_t>(v.v_ & ~uint64_t{0});
44
+ }
45
+
46
+ constexpr int64_t Int128High64(int128 v) {
47
+ // Initially cast to unsigned to prevent a right shift on a negative value.
48
+ return int128_internal::BitCastToSigned(
49
+ static_cast<uint64_t>(static_cast<unsigned __int128>(v.v_) >> 64));
50
+ }
51
+
52
+ constexpr int128::int128(int64_t high, uint64_t low)
53
+ // Initially cast to unsigned to prevent a left shift that overflows.
54
+ : v_(int128_internal::BitCastToSigned(static_cast<unsigned __int128>(high)
55
+ << 64) |
56
+ low) {}
57
+
58
+
59
+ constexpr int128::int128(int v) : v_{v} {}
60
+
61
+ constexpr int128::int128(long v) : v_{v} {} // NOLINT(runtime/int)
62
+
63
+ constexpr int128::int128(long long v) : v_{v} {} // NOLINT(runtime/int)
64
+
65
+ constexpr int128::int128(__int128 v) : v_{v} {}
66
+
67
+ constexpr int128::int128(unsigned int v) : v_{v} {}
68
+
69
+ constexpr int128::int128(unsigned long v) : v_{v} {} // NOLINT(runtime/int)
70
+
71
+ // NOLINTNEXTLINE(runtime/int)
72
+ constexpr int128::int128(unsigned long long v) : v_{v} {}
73
+
74
+ constexpr int128::int128(unsigned __int128 v) : v_{static_cast<__int128>(v)} {}
75
+
76
+ inline int128::int128(float v) {
77
+ v_ = static_cast<__int128>(v);
78
+ }
79
+
80
+ inline int128::int128(double v) {
81
+ v_ = static_cast<__int128>(v);
82
+ }
83
+
84
+ inline int128::int128(long double v) {
85
+ v_ = static_cast<__int128>(v);
86
+ }
87
+
88
+ constexpr int128::int128(uint128 v) : v_{static_cast<__int128>(v)} {}
89
+
90
+ constexpr int128::operator bool() const { return static_cast<bool>(v_); }
91
+
92
+ constexpr int128::operator char() const { return static_cast<char>(v_); }
93
+
94
+ constexpr int128::operator signed char() const {
95
+ return static_cast<signed char>(v_);
96
+ }
97
+
98
+ constexpr int128::operator unsigned char() const {
99
+ return static_cast<unsigned char>(v_);
100
+ }
101
+
102
+ constexpr int128::operator char16_t() const {
103
+ return static_cast<char16_t>(v_);
104
+ }
105
+
106
+ constexpr int128::operator char32_t() const {
107
+ return static_cast<char32_t>(v_);
108
+ }
109
+
110
+ constexpr int128::operator ABSL_INTERNAL_WCHAR_T() const {
111
+ return static_cast<ABSL_INTERNAL_WCHAR_T>(v_);
112
+ }
113
+
114
+ constexpr int128::operator short() const { // NOLINT(runtime/int)
115
+ return static_cast<short>(v_); // NOLINT(runtime/int)
116
+ }
117
+
118
+ constexpr int128::operator unsigned short() const { // NOLINT(runtime/int)
119
+ return static_cast<unsigned short>(v_); // NOLINT(runtime/int)
120
+ }
121
+
122
+ constexpr int128::operator int() const {
123
+ return static_cast<int>(v_);
124
+ }
125
+
126
+ constexpr int128::operator unsigned int() const {
127
+ return static_cast<unsigned int>(v_);
128
+ }
129
+
130
+ constexpr int128::operator long() const { // NOLINT(runtime/int)
131
+ return static_cast<long>(v_); // NOLINT(runtime/int)
132
+ }
133
+
134
+ constexpr int128::operator unsigned long() const { // NOLINT(runtime/int)
135
+ return static_cast<unsigned long>(v_); // NOLINT(runtime/int)
136
+ }
137
+
138
+ constexpr int128::operator long long() const { // NOLINT(runtime/int)
139
+ return static_cast<long long>(v_); // NOLINT(runtime/int)
140
+ }
141
+
142
+ constexpr int128::operator unsigned long long() const { // NOLINT(runtime/int)
143
+ return static_cast<unsigned long long>(v_); // NOLINT(runtime/int)
144
+ }
145
+
146
+ constexpr int128::operator __int128() const { return v_; }
147
+
148
+ constexpr int128::operator unsigned __int128() const {
149
+ return static_cast<unsigned __int128>(v_);
150
+ }
151
+
152
+ // Clang on PowerPC sometimes produces incorrect __int128 to floating point
153
+ // conversions. In that case, we do the conversion with a similar implementation
154
+ // to the conversion operators in int128_no_intrinsic.inc.
155
+ #if defined(__clang__) && !defined(__ppc64__)
156
+ inline int128::operator float() const { return static_cast<float>(v_); }
157
+
158
+ inline int128::operator double () const { return static_cast<double>(v_); }
159
+
160
+ inline int128::operator long double() const {
161
+ return static_cast<long double>(v_);
162
+ }
163
+
164
+ #else // Clang on PowerPC
165
+ // Forward declaration for conversion operators to floating point types.
166
+ int128 operator-(int128 v);
167
+ bool operator!=(int128 lhs, int128 rhs);
168
+
169
+ inline int128::operator float() const {
170
+ // We must convert the absolute value and then negate as needed, because
171
+ // floating point types are typically sign-magnitude. Otherwise, the
172
+ // difference between the high and low 64 bits when interpreted as two's
173
+ // complement overwhelms the precision of the mantissa.
174
+ //
175
+ // Also check to make sure we don't negate Int128Min()
176
+ return v_ < 0 && *this != Int128Min()
177
+ ? -static_cast<float>(-*this)
178
+ : static_cast<float>(Int128Low64(*this)) +
179
+ std::ldexp(static_cast<float>(Int128High64(*this)), 64);
180
+ }
181
+
182
+ inline int128::operator double() const {
183
+ // See comment in int128::operator float() above.
184
+ return v_ < 0 && *this != Int128Min()
185
+ ? -static_cast<double>(-*this)
186
+ : static_cast<double>(Int128Low64(*this)) +
187
+ std::ldexp(static_cast<double>(Int128High64(*this)), 64);
188
+ }
189
+
190
+ inline int128::operator long double() const {
191
+ // See comment in int128::operator float() above.
192
+ return v_ < 0 && *this != Int128Min()
193
+ ? -static_cast<long double>(-*this)
194
+ : static_cast<long double>(Int128Low64(*this)) +
195
+ std::ldexp(static_cast<long double>(Int128High64(*this)),
196
+ 64);
197
+ }
198
+ #endif // Clang on PowerPC
199
+
200
+ // Comparison operators.
201
+
202
+ inline bool operator==(int128 lhs, int128 rhs) {
203
+ return static_cast<__int128>(lhs) == static_cast<__int128>(rhs);
204
+ }
205
+
206
+ inline bool operator!=(int128 lhs, int128 rhs) {
207
+ return static_cast<__int128>(lhs) != static_cast<__int128>(rhs);
208
+ }
209
+
210
+ inline bool operator<(int128 lhs, int128 rhs) {
211
+ return static_cast<__int128>(lhs) < static_cast<__int128>(rhs);
212
+ }
213
+
214
+ inline bool operator>(int128 lhs, int128 rhs) {
215
+ return static_cast<__int128>(lhs) > static_cast<__int128>(rhs);
216
+ }
217
+
218
+ inline bool operator<=(int128 lhs, int128 rhs) {
219
+ return static_cast<__int128>(lhs) <= static_cast<__int128>(rhs);
220
+ }
221
+
222
+ inline bool operator>=(int128 lhs, int128 rhs) {
223
+ return static_cast<__int128>(lhs) >= static_cast<__int128>(rhs);
224
+ }
225
+
226
+ // Unary operators.
227
+
228
+ inline int128 operator-(int128 v) {
229
+ return -static_cast<__int128>(v);
230
+ }
231
+
232
+ inline bool operator!(int128 v) {
233
+ return !static_cast<__int128>(v);
234
+ }
235
+
236
+ inline int128 operator~(int128 val) {
237
+ return ~static_cast<__int128>(val);
238
+ }
239
+
240
+ // Arithmetic operators.
241
+
242
+ inline int128 operator+(int128 lhs, int128 rhs) {
243
+ return static_cast<__int128>(lhs) + static_cast<__int128>(rhs);
244
+ }
245
+
246
+ inline int128 operator-(int128 lhs, int128 rhs) {
247
+ return static_cast<__int128>(lhs) - static_cast<__int128>(rhs);
248
+ }
249
+
250
+ inline int128 operator*(int128 lhs, int128 rhs) {
251
+ return static_cast<__int128>(lhs) * static_cast<__int128>(rhs);
252
+ }
253
+
254
+ inline int128 operator/(int128 lhs, int128 rhs) {
255
+ return static_cast<__int128>(lhs) / static_cast<__int128>(rhs);
256
+ }
257
+
258
+ inline int128 operator%(int128 lhs, int128 rhs) {
259
+ return static_cast<__int128>(lhs) % static_cast<__int128>(rhs);
260
+ }
261
+
262
+ inline int128 int128::operator++(int) {
263
+ int128 tmp(*this);
264
+ ++v_;
265
+ return tmp;
266
+ }
267
+
268
+ inline int128 int128::operator--(int) {
269
+ int128 tmp(*this);
270
+ --v_;
271
+ return tmp;
272
+ }
273
+
274
+ inline int128& int128::operator++() {
275
+ ++v_;
276
+ return *this;
277
+ }
278
+
279
+ inline int128& int128::operator--() {
280
+ --v_;
281
+ return *this;
282
+ }
283
+
284
+ inline int128 operator|(int128 lhs, int128 rhs) {
285
+ return static_cast<__int128>(lhs) | static_cast<__int128>(rhs);
286
+ }
287
+
288
+ inline int128 operator&(int128 lhs, int128 rhs) {
289
+ return static_cast<__int128>(lhs) & static_cast<__int128>(rhs);
290
+ }
291
+
292
+ inline int128 operator^(int128 lhs, int128 rhs) {
293
+ return static_cast<__int128>(lhs) ^ static_cast<__int128>(rhs);
294
+ }
295
+
296
+ inline int128 operator<<(int128 lhs, int amount) {
297
+ return static_cast<__int128>(lhs) << amount;
298
+ }
299
+
300
+ inline int128 operator>>(int128 lhs, int amount) {
301
+ return static_cast<__int128>(lhs) >> amount;
302
+ }
@@ -0,0 +1,308 @@
1
+ //
2
+ // Copyright 2017 The Abseil Authors.
3
+ //
4
+ // Licensed under the Apache License, Version 2.0 (the "License");
5
+ // you may not use this file except in compliance with the License.
6
+ // You may obtain a copy of the License at
7
+ //
8
+ // https://www.apache.org/licenses/LICENSE-2.0
9
+ //
10
+ // Unless required by applicable law or agreed to in writing, software
11
+ // distributed under the License is distributed on an "AS IS" BASIS,
12
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ // See the License for the specific language governing permissions and
14
+ // limitations under the License.
15
+
16
+ // This file contains :int128 implementation details that depend on internal
17
+ // representation when ABSL_HAVE_INTRINSIC_INT128 is *not* defined. This file
18
+ // is included by int128.h and relies on ABSL_INTERNAL_WCHAR_T being defined.
19
+
20
+ constexpr uint64_t Int128Low64(int128 v) { return v.lo_; }
21
+
22
+ constexpr int64_t Int128High64(int128 v) { return v.hi_; }
23
+
24
+ #if defined(ABSL_IS_LITTLE_ENDIAN)
25
+
26
+ constexpr int128::int128(int64_t high, uint64_t low) :
27
+ lo_(low), hi_(high) {}
28
+
29
+ constexpr int128::int128(int v)
30
+ : lo_{static_cast<uint64_t>(v)}, hi_{v < 0 ? ~int64_t{0} : 0} {}
31
+ constexpr int128::int128(long v) // NOLINT(runtime/int)
32
+ : lo_{static_cast<uint64_t>(v)}, hi_{v < 0 ? ~int64_t{0} : 0} {}
33
+ constexpr int128::int128(long long v) // NOLINT(runtime/int)
34
+ : lo_{static_cast<uint64_t>(v)}, hi_{v < 0 ? ~int64_t{0} : 0} {}
35
+
36
+ constexpr int128::int128(unsigned int v) : lo_{v}, hi_{0} {}
37
+ // NOLINTNEXTLINE(runtime/int)
38
+ constexpr int128::int128(unsigned long v) : lo_{v}, hi_{0} {}
39
+ // NOLINTNEXTLINE(runtime/int)
40
+ constexpr int128::int128(unsigned long long v) : lo_{v}, hi_{0} {}
41
+
42
+ constexpr int128::int128(uint128 v)
43
+ : lo_{Uint128Low64(v)}, hi_{static_cast<int64_t>(Uint128High64(v))} {}
44
+
45
+ #elif defined(ABSL_IS_BIG_ENDIAN)
46
+
47
+ constexpr int128::int128(int64_t high, uint64_t low) :
48
+ hi_{high}, lo_{low} {}
49
+
50
+ constexpr int128::int128(int v)
51
+ : hi_{v < 0 ? ~int64_t{0} : 0}, lo_{static_cast<uint64_t>(v)} {}
52
+ constexpr int128::int128(long v) // NOLINT(runtime/int)
53
+ : hi_{v < 0 ? ~int64_t{0} : 0}, lo_{static_cast<uint64_t>(v)} {}
54
+ constexpr int128::int128(long long v) // NOLINT(runtime/int)
55
+ : hi_{v < 0 ? ~int64_t{0} : 0}, lo_{static_cast<uint64_t>(v)} {}
56
+
57
+ constexpr int128::int128(unsigned int v) : hi_{0}, lo_{v} {}
58
+ // NOLINTNEXTLINE(runtime/int)
59
+ constexpr int128::int128(unsigned long v) : hi_{0}, lo_{v} {}
60
+ // NOLINTNEXTLINE(runtime/int)
61
+ constexpr int128::int128(unsigned long long v) : hi_{0}, lo_{v} {}
62
+
63
+ constexpr int128::int128(uint128 v)
64
+ : hi_{static_cast<int64_t>(Uint128High64(v))}, lo_{Uint128Low64(v)} {}
65
+
66
+ #else // byte order
67
+ #error "Unsupported byte order: must be little-endian or big-endian."
68
+ #endif // byte order
69
+
70
+ constexpr int128::operator bool() const { return lo_ || hi_; }
71
+
72
+ constexpr int128::operator char() const {
73
+ // NOLINTNEXTLINE(runtime/int)
74
+ return static_cast<char>(static_cast<long long>(*this));
75
+ }
76
+
77
+ constexpr int128::operator signed char() const {
78
+ // NOLINTNEXTLINE(runtime/int)
79
+ return static_cast<signed char>(static_cast<long long>(*this));
80
+ }
81
+
82
+ constexpr int128::operator unsigned char() const {
83
+ return static_cast<unsigned char>(lo_);
84
+ }
85
+
86
+ constexpr int128::operator char16_t() const {
87
+ return static_cast<char16_t>(lo_);
88
+ }
89
+
90
+ constexpr int128::operator char32_t() const {
91
+ return static_cast<char32_t>(lo_);
92
+ }
93
+
94
+ constexpr int128::operator ABSL_INTERNAL_WCHAR_T() const {
95
+ // NOLINTNEXTLINE(runtime/int)
96
+ return static_cast<ABSL_INTERNAL_WCHAR_T>(static_cast<long long>(*this));
97
+ }
98
+
99
+ constexpr int128::operator short() const { // NOLINT(runtime/int)
100
+ // NOLINTNEXTLINE(runtime/int)
101
+ return static_cast<short>(static_cast<long long>(*this));
102
+ }
103
+
104
+ constexpr int128::operator unsigned short() const { // NOLINT(runtime/int)
105
+ return static_cast<unsigned short>(lo_); // NOLINT(runtime/int)
106
+ }
107
+
108
+ constexpr int128::operator int() const {
109
+ // NOLINTNEXTLINE(runtime/int)
110
+ return static_cast<int>(static_cast<long long>(*this));
111
+ }
112
+
113
+ constexpr int128::operator unsigned int() const {
114
+ return static_cast<unsigned int>(lo_);
115
+ }
116
+
117
+ constexpr int128::operator long() const { // NOLINT(runtime/int)
118
+ // NOLINTNEXTLINE(runtime/int)
119
+ return static_cast<long>(static_cast<long long>(*this));
120
+ }
121
+
122
+ constexpr int128::operator unsigned long() const { // NOLINT(runtime/int)
123
+ return static_cast<unsigned long>(lo_); // NOLINT(runtime/int)
124
+ }
125
+
126
+ constexpr int128::operator long long() const { // NOLINT(runtime/int)
127
+ // We don't bother checking the value of hi_. If *this < 0, lo_'s high bit
128
+ // must be set in order for the value to fit into a long long. Conversely, if
129
+ // lo_'s high bit is set, *this must be < 0 for the value to fit.
130
+ return int128_internal::BitCastToSigned(lo_);
131
+ }
132
+
133
+ constexpr int128::operator unsigned long long() const { // NOLINT(runtime/int)
134
+ return static_cast<unsigned long long>(lo_); // NOLINT(runtime/int)
135
+ }
136
+
137
+ // Forward declaration for conversion operators to floating point types.
138
+ int128 operator-(int128 v);
139
+ bool operator!=(int128 lhs, int128 rhs);
140
+
141
+ inline int128::operator float() const {
142
+ // We must convert the absolute value and then negate as needed, because
143
+ // floating point types are typically sign-magnitude. Otherwise, the
144
+ // difference between the high and low 64 bits when interpreted as two's
145
+ // complement overwhelms the precision of the mantissa.
146
+ //
147
+ // Also check to make sure we don't negate Int128Min()
148
+ return hi_ < 0 && *this != Int128Min()
149
+ ? -static_cast<float>(-*this)
150
+ : static_cast<float>(lo_) +
151
+ std::ldexp(static_cast<float>(hi_), 64);
152
+ }
153
+
154
+ inline int128::operator double() const {
155
+ // See comment in int128::operator float() above.
156
+ return hi_ < 0 && *this != Int128Min()
157
+ ? -static_cast<double>(-*this)
158
+ : static_cast<double>(lo_) +
159
+ std::ldexp(static_cast<double>(hi_), 64);
160
+ }
161
+
162
+ inline int128::operator long double() const {
163
+ // See comment in int128::operator float() above.
164
+ return hi_ < 0 && *this != Int128Min()
165
+ ? -static_cast<long double>(-*this)
166
+ : static_cast<long double>(lo_) +
167
+ std::ldexp(static_cast<long double>(hi_), 64);
168
+ }
169
+
170
+ // Comparison operators.
171
+
172
+ inline bool operator==(int128 lhs, int128 rhs) {
173
+ return (Int128Low64(lhs) == Int128Low64(rhs) &&
174
+ Int128High64(lhs) == Int128High64(rhs));
175
+ }
176
+
177
+ inline bool operator!=(int128 lhs, int128 rhs) {
178
+ return !(lhs == rhs);
179
+ }
180
+
181
+ inline bool operator<(int128 lhs, int128 rhs) {
182
+ return (Int128High64(lhs) == Int128High64(rhs))
183
+ ? (Int128Low64(lhs) < Int128Low64(rhs))
184
+ : (Int128High64(lhs) < Int128High64(rhs));
185
+ }
186
+
187
+ inline bool operator>(int128 lhs, int128 rhs) {
188
+ return (Int128High64(lhs) == Int128High64(rhs))
189
+ ? (Int128Low64(lhs) > Int128Low64(rhs))
190
+ : (Int128High64(lhs) > Int128High64(rhs));
191
+ }
192
+
193
+ inline bool operator<=(int128 lhs, int128 rhs) {
194
+ return !(lhs > rhs);
195
+ }
196
+
197
+ inline bool operator>=(int128 lhs, int128 rhs) {
198
+ return !(lhs < rhs);
199
+ }
200
+
201
+ // Unary operators.
202
+
203
+ inline int128 operator-(int128 v) {
204
+ int64_t hi = ~Int128High64(v);
205
+ uint64_t lo = ~Int128Low64(v) + 1;
206
+ if (lo == 0) ++hi; // carry
207
+ return MakeInt128(hi, lo);
208
+ }
209
+
210
+ inline bool operator!(int128 v) {
211
+ return !Int128Low64(v) && !Int128High64(v);
212
+ }
213
+
214
+ inline int128 operator~(int128 val) {
215
+ return MakeInt128(~Int128High64(val), ~Int128Low64(val));
216
+ }
217
+
218
+ // Arithmetic operators.
219
+
220
+ inline int128 operator+(int128 lhs, int128 rhs) {
221
+ int128 result = MakeInt128(Int128High64(lhs) + Int128High64(rhs),
222
+ Int128Low64(lhs) + Int128Low64(rhs));
223
+ if (Int128Low64(result) < Int128Low64(lhs)) { // check for carry
224
+ return MakeInt128(Int128High64(result) + 1, Int128Low64(result));
225
+ }
226
+ return result;
227
+ }
228
+
229
+ inline int128 operator-(int128 lhs, int128 rhs) {
230
+ int128 result = MakeInt128(Int128High64(lhs) - Int128High64(rhs),
231
+ Int128Low64(lhs) - Int128Low64(rhs));
232
+ if (Int128Low64(lhs) < Int128Low64(rhs)) { // check for carry
233
+ return MakeInt128(Int128High64(result) - 1, Int128Low64(result));
234
+ }
235
+ return result;
236
+ }
237
+
238
+ inline int128 operator*(int128 lhs, int128 rhs) {
239
+ uint128 result = uint128(lhs) * rhs;
240
+ return MakeInt128(int128_internal::BitCastToSigned(Uint128High64(result)),
241
+ Uint128Low64(result));
242
+ }
243
+
244
+ inline int128 int128::operator++(int) {
245
+ int128 tmp(*this);
246
+ *this += 1;
247
+ return tmp;
248
+ }
249
+
250
+ inline int128 int128::operator--(int) {
251
+ int128 tmp(*this);
252
+ *this -= 1;
253
+ return tmp;
254
+ }
255
+
256
+ inline int128& int128::operator++() {
257
+ *this += 1;
258
+ return *this;
259
+ }
260
+
261
+ inline int128& int128::operator--() {
262
+ *this -= 1;
263
+ return *this;
264
+ }
265
+
266
+ inline int128 operator|(int128 lhs, int128 rhs) {
267
+ return MakeInt128(Int128High64(lhs) | Int128High64(rhs),
268
+ Int128Low64(lhs) | Int128Low64(rhs));
269
+ }
270
+
271
+ inline int128 operator&(int128 lhs, int128 rhs) {
272
+ return MakeInt128(Int128High64(lhs) & Int128High64(rhs),
273
+ Int128Low64(lhs) & Int128Low64(rhs));
274
+ }
275
+
276
+ inline int128 operator^(int128 lhs, int128 rhs) {
277
+ return MakeInt128(Int128High64(lhs) ^ Int128High64(rhs),
278
+ Int128Low64(lhs) ^ Int128Low64(rhs));
279
+ }
280
+
281
+ inline int128 operator<<(int128 lhs, int amount) {
282
+ // uint64_t shifts of >= 64 are undefined, so we need some special-casing.
283
+ if (amount < 64) {
284
+ if (amount != 0) {
285
+ return MakeInt128(
286
+ (Int128High64(lhs) << amount) |
287
+ static_cast<int64_t>(Int128Low64(lhs) >> (64 - amount)),
288
+ Int128Low64(lhs) << amount);
289
+ }
290
+ return lhs;
291
+ }
292
+ return MakeInt128(static_cast<int64_t>(Int128Low64(lhs) << (amount - 64)), 0);
293
+ }
294
+
295
+ inline int128 operator>>(int128 lhs, int amount) {
296
+ // uint64_t shifts of >= 64 are undefined, so we need some special-casing.
297
+ if (amount < 64) {
298
+ if (amount != 0) {
299
+ return MakeInt128(
300
+ Int128High64(lhs) >> amount,
301
+ (Int128Low64(lhs) >> amount) |
302
+ (static_cast<uint64_t>(Int128High64(lhs)) << (64 - amount)));
303
+ }
304
+ return lhs;
305
+ }
306
+ return MakeInt128(0,
307
+ static_cast<uint64_t>(Int128High64(lhs) >> (amount - 64)));
308
+ }