| 1 |
// Protocol Buffers - Google's data interchange format |
| 2 |
// Copyright 2008 Google Inc. All rights reserved. |
| 3 |
// https://developers.google.com/protocol-buffers/ |
| 4 |
// |
| 5 |
// Redistribution and use in source and binary forms, with or without |
| 6 |
// modification, are permitted provided that the following conditions are |
| 7 |
// met: |
| 8 |
// |
| 9 |
// * Redistributions of source code must retain the above copyright |
| 10 |
// notice, this list of conditions and the following disclaimer. |
| 11 |
// * Redistributions in binary form must reproduce the above |
| 12 |
// copyright notice, this list of conditions and the following disclaimer |
| 13 |
// in the documentation and/or other materials provided with the |
| 14 |
// distribution. |
| 15 |
// * Neither the name of Google Inc. nor the names of its |
| 16 |
// contributors may be used to endorse or promote products derived from |
| 17 |
// this software without specific prior written permission. |
| 18 |
// |
| 19 |
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 20 |
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 21 |
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 22 |
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 23 |
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 24 |
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 25 |
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 26 |
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 27 |
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 28 |
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 29 |
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 |
|
| 31 |
// This file defines common macros that are used in protobuf. |
| 32 |
// |
| 33 |
// To hide these definitions from the outside world (and to prevent collisions |
| 34 |
// if more than one version of protobuf is #included in the same project) you |
| 35 |
// must follow this pattern when #including port_def.inc in a header file: |
| 36 |
// |
| 37 |
// #include "other_header.h" |
| 38 |
// #include "message.h" |
| 39 |
// // etc. |
| 40 |
// |
| 41 |
// #include "port_def.inc" // MUST be last header included |
| 42 |
// |
| 43 |
// // Definitions for this header. |
| 44 |
// |
| 45 |
// #include "port_undef.inc" |
| 46 |
// |
| 47 |
// This is a textual header with no include guard, because we want to |
| 48 |
// detect/prohibit anytime it is #included twice without a corresponding |
| 49 |
// #undef. |
| 50 |
|
| 51 |
// These macros are private and should always be |
| 52 |
// ::util::RetrieveErrorSpace(*this) headers. If any of these errors fire, you |
| 53 |
// should either properly #include port_undef.h at the end of your header that |
| 54 |
// #includes port.h, or don't #include port.h twice in a .cc file. |
| 55 |
#ifdef PROTOBUF_NAMESPACE |
| 56 |
#error PROTOBUF_NAMESPACE was previously defined |
| 57 |
#endif |
| 58 |
#ifdef PROTOBUF_NAMESPACE_ID |
| 59 |
#error PROTOBUF_NAMESPACE_ID was previously defined |
| 60 |
#endif |
| 61 |
#ifdef PROTOBUF_ALWAYS_INLINE |
| 62 |
#error PROTOBUF_ALWAYS_INLINE was previously defined |
| 63 |
#endif |
| 64 |
#ifdef PROTOBUF_COLD |
| 65 |
#error PROTOBUF_COLD was previously defined |
| 66 |
#endif |
| 67 |
#ifdef PROTOBUF_NOINLINE |
| 68 |
#error PROTOBUF_NOINLINE was previously defined |
| 69 |
#endif |
| 70 |
#ifdef PROTOBUF_SECTION_VARIABLE |
| 71 |
#error PROTOBUF_SECTION_VARIABLE was previously defined |
| 72 |
#endif |
| 73 |
#ifdef PROTOBUF_DEPRECATED |
| 74 |
#error PROTOBUF_DEPRECATED was previously defined |
| 75 |
#endif |
| 76 |
#ifdef PROTOBUF_DEPRECATED_MSG |
| 77 |
#error PROTOBUF_DEPRECATED_MSG was previously defined |
| 78 |
#endif |
| 79 |
#ifdef PROTOBUF_FUNC_ALIGN |
| 80 |
#error PROTOBUF_FUNC_ALIGN was previously defined |
| 81 |
#endif |
| 82 |
#ifdef PROTOBUF_RETURNS_NONNULL |
| 83 |
#error PROTOBUF_RETURNS_NONNULL was previously defined |
| 84 |
#endif |
| 85 |
#ifdef PROTOBUF_ATTRIBUTE_REINITIALIZES |
| 86 |
#error PROTOBUF_ATTRIBUTE_REINITIALIZES was previously defined |
| 87 |
#endif |
| 88 |
#ifdef PROTOBUF_RTTI |
| 89 |
#error PROTOBUF_RTTI was previously defined |
| 90 |
#endif |
| 91 |
#ifdef PROTOBUF_VERSION |
| 92 |
#error PROTOBUF_VERSION was previously defined |
| 93 |
#endif |
| 94 |
#ifdef PROTOBUF_VERSION_SUFFIX |
| 95 |
#error PROTOBUF_VERSION_SUFFIX was previously defined |
| 96 |
#endif |
| 97 |
#ifdef PROTOBUF_MIN_HEADER_VERSION_FOR_PROTOC |
| 98 |
#error PROTOBUF_MIN_HEADER_VERSION_FOR_PROTOC was previously defined |
| 99 |
#endif |
| 100 |
#ifdef PROTOBUF_MIN_PROTOC_VERSION |
| 101 |
#error PROTOBUF_MIN_PROTOC_VERSION was previously defined |
| 102 |
#endif |
| 103 |
#ifdef PROTOBUF_PREDICT_TRUE |
| 104 |
#error PROTOBUF_PREDICT_TRUE was previously defined |
| 105 |
#endif |
| 106 |
#ifdef PROTOBUF_PREDICT_FALSE |
| 107 |
#error PROTOBUF_PREDICT_FALSE was previously defined |
| 108 |
#endif |
| 109 |
#ifdef PROTOBUF_FIELD_OFFSET |
| 110 |
#error PROTOBUF_FIELD_OFFSET was previously defined |
| 111 |
#endif |
| 112 |
#ifdef PROTOBUF_LL_FORMAT |
| 113 |
#error PROTOBUF_LL_FORMAT was previously defined |
| 114 |
#endif |
| 115 |
#ifdef PROTOBUF_GUARDED_BY |
| 116 |
#error PROTOBUF_GUARDED_BY was previously defined |
| 117 |
#endif |
| 118 |
#ifdef PROTOBUF_LONGLONG |
| 119 |
#error PROTOBUF_LONGLONG was previously defined |
| 120 |
#endif |
| 121 |
#ifdef PROTOBUF_ULONGLONG |
| 122 |
#error PROTOBUF_ULONGLONG was previously defined |
| 123 |
#endif |
| 124 |
#ifdef PROTOBUF_FALLTHROUGH_INTENDED |
| 125 |
#error PROTOBUF_FALLTHROUGH_INTENDED was previously defined |
| 126 |
#endif |
| 127 |
#ifdef PROTOBUF_EXPORT |
| 128 |
#error PROTOBUF_EXPORT was previously defined |
| 129 |
#endif |
| 130 |
#ifdef PROTOC_EXPORT |
| 131 |
#error PROTOC_EXPORT was previously defined |
| 132 |
#endif |
| 133 |
#ifdef PROTOBUF_MUST_USE_RESULT |
| 134 |
#error PROTOBUF_MUST_USE_RESULT was previously defined |
| 135 |
#endif |
| 136 |
#ifdef PROTOBUF_UNUSED |
| 137 |
#error PROTOBUF_UNUSED was previously defined |
| 138 |
#endif |
| 139 |
#ifdef PROTOBUF_FINAL |
| 140 |
#error PROTOBUF_FINAL was previously defined |
| 141 |
#endif |
| 142 |
#ifdef PROTOBUF_DISABLE_MSVC_UNION_WARNING |
| 143 |
#error PROTOBUF_DISABLE_MSVC_UNION_WARNING was previously defined |
| 144 |
#endif |
| 145 |
#ifdef PROTOBUF_ENABLE_MSVC_UNION_WARNING |
| 146 |
#error PROTOBUF_ENABLE_MSVC_UNION_WARNING was previously defined |
| 147 |
#endif |
| 148 |
#ifdef PROTOBUF_CONSTINIT |
| 149 |
#error PROTOBUF_CONSTINIT was previously defined |
| 150 |
#endif |
| 151 |
#ifdef PROTOBUF_MAYBE_CONSTEXPR |
| 152 |
#error PROTOBUF_MAYBE_CONSTEXPR was previously defined |
| 153 |
#endif |
| 154 |
#ifdef PROTOBUF_ATTRIBUTE_NO_DESTROY |
| 155 |
#error PROTOBUF_ATTRIBUTE_NO_DESTROY was previously defined |
| 156 |
#endif |
| 157 |
|
| 158 |
|
| 159 |
#define PROTOBUF_NAMESPACE "google::protobuf" |
| 160 |
#define PROTOBUF_NAMESPACE_ID google::protobuf |
| 161 |
#define PROTOBUF_NAMESPACE_OPEN \ |
| 162 |
namespace google { \ |
| 163 |
namespace protobuf { |
| 164 |
#define PROTOBUF_NAMESPACE_CLOSE \ |
| 165 |
} /* namespace protobuf */ \ |
| 166 |
} /* namespace google */ |
| 167 |
|
| 168 |
#if defined(__GNUC__) || defined(__clang__) |
| 169 |
#define PROTOBUF_DEPRECATED __attribute__((deprecated)) |
| 170 |
#define PROTOBUF_DEPRECATED_ENUM __attribute__((deprecated)) |
| 171 |
#define PROTOBUF_DEPRECATED_MSG(msg) __attribute__((deprecated(msg))) |
| 172 |
#elif defined(_MSC_VER) |
| 173 |
#define PROTOBUF_DEPRECATED __declspec(deprecated) |
| 174 |
#define PROTOBUF_DEPRECATED_ENUM |
| 175 |
#define PROTOBUF_DEPRECATED_MSG(msg) __declspec(deprecated(msg)) |
| 176 |
#endif |
| 177 |
|
| 178 |
#define PROTOBUF_SECTION_VARIABLE(x) |
| 179 |
#define PROTOBUF_MUST_USE_RESULT |
| 180 |
|
| 181 |
// ---------------------------------------------------------------------------- |
| 182 |
// Annotations: Some parts of the code have been annotated in ways that might |
| 183 |
// be useful to some compilers or tools, but are not supported universally. |
| 184 |
// You can #define these annotations yourself if the default implementation |
| 185 |
// is not right for you. |
| 186 |
|
| 187 |
#ifdef GOOGLE_ATTRIBUTE_ALWAYS_INLINE |
| 188 |
#define PROTOBUF_ALWAYS_INLINE GOOGLE_ATTRIBUTE_ALWAYS_INLINE |
| 189 |
#else |
| 190 |
#if defined(__GNUC__) && \ |
| 191 |
(__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)) |
| 192 |
// For functions we want to force inline. |
| 193 |
// Introduced in gcc 3.1. |
| 194 |
#define PROTOBUF_ALWAYS_INLINE __attribute__((always_inline)) |
| 195 |
#else |
| 196 |
// Other compilers will have to figure it out for themselves. |
| 197 |
#define PROTOBUF_ALWAYS_INLINE |
| 198 |
#endif |
| 199 |
#endif |
| 200 |
|
| 201 |
#ifdef GOOGLE_ATTRIBUTE_NOINLINE |
| 202 |
#define PROTOBUF_NOINLINE GOOGLE_ATTRIBUTE_NOINLINE |
| 203 |
#else |
| 204 |
#if defined(__GNUC__) && \ |
| 205 |
(__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)) |
| 206 |
// For functions we want to force not inline. |
| 207 |
// Introduced in gcc 3.1. |
| 208 |
#define PROTOBUF_NOINLINE __attribute__((noinline)) |
| 209 |
#elif defined(_MSC_VER) && (_MSC_VER >= 1400) |
| 210 |
// Seems to have been around since at least Visual Studio 2005 |
| 211 |
#define PROTOBUF_NOINLINE __declspec(noinline) |
| 212 |
#else |
| 213 |
// Other compilers will have to figure it out for themselves. |
| 214 |
#define PROTOBUF_NOINLINE |
| 215 |
#endif |
| 216 |
#endif |
| 217 |
|
| 218 |
#ifdef GOOGLE_ATTRIBUTE_FUNC_ALIGN |
| 219 |
#define PROTOBUF_FUNC_ALIGN GOOGLE_ATTRIBUTE_FUNC_ALIGN |
| 220 |
#else |
| 221 |
#if defined(__clang__) || \ |
| 222 |
defined(__GNUC__) && \ |
| 223 |
(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)) |
| 224 |
// Function alignment attribute introduced in gcc 4.3 |
| 225 |
#define PROTOBUF_FUNC_ALIGN(bytes) __attribute__((aligned(bytes))) |
| 226 |
#else |
| 227 |
#define PROTOBUF_FUNC_ALIGN(bytes) |
| 228 |
#endif |
| 229 |
#endif |
| 230 |
|
| 231 |
#ifdef GOOGLE_PREDICT_TRUE |
| 232 |
#define PROTOBUF_PREDICT_TRUE GOOGLE_PREDICT_TRUE |
| 233 |
#else |
| 234 |
#ifdef __GNUC__ |
| 235 |
// Provided at least since GCC 3.0. |
| 236 |
#define PROTOBUF_PREDICT_TRUE(x) (__builtin_expect(!!(x), 1)) |
| 237 |
#else |
| 238 |
#define PROTOBUF_PREDICT_TRUE(x) (x) |
| 239 |
#endif |
| 240 |
#endif |
| 241 |
|
| 242 |
#ifdef GOOGLE_PREDICT_FALSE |
| 243 |
#define PROTOBUF_PREDICT_FALSE GOOGLE_PREDICT_FALSE |
| 244 |
#else |
| 245 |
#ifdef __GNUC__ |
| 246 |
// Provided at least since GCC 3.0. |
| 247 |
#define PROTOBUF_PREDICT_FALSE(x) (__builtin_expect(x, 0)) |
| 248 |
#else |
| 249 |
#define PROTOBUF_PREDICT_FALSE(x) (x) |
| 250 |
#endif |
| 251 |
#endif |
| 252 |
|
| 253 |
#ifdef GOOGLE_PROTOBUF_ATTRIBUTE_RETURNS_NONNULL |
| 254 |
#define PROTOBUF_RETURNS_NONNULL GOOGLE_PROTOBUF_ATTRIBUTE_RETURNS_NONNULL |
| 255 |
#else |
| 256 |
#if defined(__has_attribute) |
| 257 |
#if __has_attribute(returns_nonnull) |
| 258 |
#define PROTOBUF_RETURNS_NONNULL __attribute__((returns_nonnull)) |
| 259 |
#endif |
| 260 |
#endif |
| 261 |
#endif |
| 262 |
#ifndef PROTOBUF_RETURNS_NONNULL |
| 263 |
#define PROTOBUF_RETURNS_NONNULL |
| 264 |
#endif |
| 265 |
|
| 266 |
#if defined(__has_cpp_attribute) |
| 267 |
#if __has_cpp_attribute(clang::reinitializes) |
| 268 |
#define PROTOBUF_ATTRIBUTE_REINITIALIZES [[clang::reinitializes]] |
| 269 |
#endif |
| 270 |
#endif |
| 271 |
#ifndef PROTOBUF_ATTRIBUTE_REINITIALIZES |
| 272 |
#define PROTOBUF_ATTRIBUTE_REINITIALIZES |
| 273 |
#endif |
| 274 |
|
| 275 |
#define PROTOBUF_GUARDED_BY(x) |
| 276 |
#define PROTOBUF_COLD |
| 277 |
|
| 278 |
// Copied from ABSL. |
| 279 |
#if defined(__clang__) && defined(__has_warning) |
| 280 |
#if __has_feature(cxx_attributes) && __has_warning("-Wimplicit-fallthrough") |
| 281 |
#define PROTOBUF_FALLTHROUGH_INTENDED [[clang::fallthrough]] |
| 282 |
#endif |
| 283 |
#elif defined(__GNUC__) && __GNUC__ >= 7 |
| 284 |
#define PROTOBUF_FALLTHROUGH_INTENDED [[gnu::fallthrough]] |
| 285 |
#endif |
| 286 |
|
| 287 |
#ifndef PROTOBUF_FALLTHROUGH_INTENDED |
| 288 |
#define PROTOBUF_FALLTHROUGH_INTENDED |
| 289 |
#endif |
| 290 |
|
| 291 |
#if defined(__has_cpp_attribute) |
| 292 |
#define HAS_ATTRIBUTE(attr) __has_cpp_attribute(attr) |
| 293 |
#else |
| 294 |
#define HAS_ATTRIBUTE(attr) 0 |
| 295 |
#endif |
| 296 |
|
| 297 |
#if HAS_ATTRIBUTE(unused) || (defined(__GNUC__) && !defined(__clang__)) |
| 298 |
#define PROTOBUF_UNUSED __attribute__((__unused__)) |
| 299 |
#else |
| 300 |
#define PROTOBUF_UNUSED |
| 301 |
#endif |
| 302 |
|
| 303 |
#undef HAS_ATTRIBUTE |
| 304 |
|
| 305 |
#ifdef _MSC_VER |
| 306 |
#define PROTOBUF_LONGLONG(x) x##I64 |
| 307 |
#define PROTOBUF_ULONGLONG(x) x##UI64 |
| 308 |
#define PROTOBUF_LL_FORMAT "I64" // As in printf("%I64d", ...) |
| 309 |
#else |
| 310 |
// By long long, we actually mean int64. |
| 311 |
#define PROTOBUF_LONGLONG(x) x##LL |
| 312 |
#define PROTOBUF_ULONGLONG(x) x##ULL |
| 313 |
// Used to format real long long integers. |
| 314 |
#define PROTOBUF_LL_FORMAT \ |
| 315 |
"ll" // As in "%lld". Note that "q" is poor form also. |
| 316 |
#endif |
| 317 |
|
| 318 |
|
| 319 |
// Shared google3/opensource definitions. ////////////////////////////////////// |
| 320 |
|
| 321 |
#define PROTOBUF_VERSION 3014000 |
| 322 |
#define PROTOBUF_MIN_HEADER_VERSION_FOR_PROTOC 3014000 |
| 323 |
#define PROTOBUF_MIN_PROTOC_VERSION 3014000 |
| 324 |
#define PROTOBUF_VERSION_SUFFIX "" |
| 325 |
|
| 326 |
// The minimum library version which works with the current version of the |
| 327 |
// headers. |
| 328 |
#define GOOGLE_PROTOBUF_MIN_LIBRARY_VERSION 3014000 |
| 329 |
|
| 330 |
#if defined(GOOGLE_PROTOBUF_NO_RTTI) && GOOGLE_PROTOBUF_NO_RTTI |
| 331 |
#define PROTOBUF_RTTI 0 |
| 332 |
#elif defined(__has_feature) |
| 333 |
// https://clang.llvm.org/docs/LanguageExtensions.html#has-feature-and-has-extension |
| 334 |
#define PROTOBUF_RTTI __has_feature(cxx_rtti) |
| 335 |
#elif !defined(__cxx_rtti) |
| 336 |
// https://en.cppreference.com/w/User:D41D8CD98F/feature_testing_macros#C.2B.2B98 |
| 337 |
#define PROTOBUF_RTTI 0 |
| 338 |
#elif defined(__GNUC__) && !defined(__GXX_RTTI) |
| 339 |
#https: // gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html |
| 340 |
#define PROTOBUF_RTTI 0 |
| 341 |
#else |
| 342 |
#define PROTOBUF_RTTI 1 |
| 343 |
#endif |
| 344 |
|
| 345 |
// Returns the offset of the given field within the given aggregate type. |
| 346 |
// This is equivalent to the ANSI C offsetof() macro. However, according |
| 347 |
// to the C++ standard, offsetof() only works on POD types, and GCC |
| 348 |
// enforces this requirement with a warning. In practice, this rule is |
| 349 |
// unnecessarily strict; there is probably no compiler or platform on |
| 350 |
// which the offsets of the direct fields of a class are non-constant. |
| 351 |
// Fields inherited from superclasses *can* have non-constant offsets, |
| 352 |
// but that's not what this macro will be used for. |
| 353 |
#if defined(__clang__) |
| 354 |
// For Clang we use __builtin_offsetof() and suppress the warning, |
| 355 |
// to avoid Control Flow Integrity and UBSan vptr sanitizers from |
| 356 |
// crashing while trying to validate the invalid reinterpet_casts. |
| 357 |
#define PROTOBUF_FIELD_OFFSET(TYPE, FIELD) \ |
| 358 |
_Pragma("clang diagnostic push") \ |
| 359 |
_Pragma("clang diagnostic ignored \"-Winvalid-offsetof\"") \ |
| 360 |
__builtin_offsetof(TYPE, FIELD) \ |
| 361 |
_Pragma("clang diagnostic pop") |
| 362 |
#elif defined(__GNUC__) && \ |
| 363 |
(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)) |
| 364 |
#define PROTOBUF_FIELD_OFFSET(TYPE, FIELD) __builtin_offsetof(TYPE, FIELD) |
| 365 |
#else // defined(__clang__) |
| 366 |
// Note that we calculate relative to the pointer value 16 here since if we |
| 367 |
// just use zero, GCC complains about dereferencing a NULL pointer. We |
| 368 |
// choose 16 rather than some other number just in case the compiler would |
| 369 |
// be confused by an unaligned pointer. |
| 370 |
#define PROTOBUF_FIELD_OFFSET(TYPE, FIELD) \ |
| 371 |
static_cast< ::google::protobuf::uint32>(reinterpret_cast<const char*>( \ |
| 372 |
&reinterpret_cast<const TYPE*>(16)->FIELD) - \ |
| 373 |
reinterpret_cast<const char*>(16)) |
| 374 |
#endif |
| 375 |
|
| 376 |
#if defined(PROTOBUF_USE_DLLS) |
| 377 |
#if defined(_MSC_VER) |
| 378 |
#ifdef LIBPROTOBUF_EXPORTS |
| 379 |
#define PROTOBUF_EXPORT __declspec(dllexport) |
| 380 |
#define PROTOBUF_EXPORT_TEMPLATE_DECLARE |
| 381 |
#define PROTOBUF_EXPORT_TEMPLATE_DEFINE __declspec(dllexport) |
| 382 |
#else |
| 383 |
#define PROTOBUF_EXPORT __declspec(dllimport) |
| 384 |
#define PROTOBUF_EXPORT_TEMPLATE_DECLARE |
| 385 |
#define PROTOBUF_EXPORT_TEMPLATE_DEFINE __declspec(dllimport) |
| 386 |
#endif |
| 387 |
#ifdef LIBPROTOC_EXPORTS |
| 388 |
#define PROTOC_EXPORT __declspec(dllexport) |
| 389 |
#else |
| 390 |
#define PROTOC_EXPORT __declspec(dllimport) |
| 391 |
#endif |
| 392 |
#else // defined(_MSC_VER) |
| 393 |
#ifdef LIBPROTOBUF_EXPORTS |
| 394 |
#define PROTOBUF_EXPORT __attribute__((visibility("default"))) |
| 395 |
#define PROTOBUF_EXPORT_TEMPLATE_DECLARE __attribute__((visibility("default"))) |
| 396 |
#define PROTOBUF_EXPORT_TEMPLATE_DEFINE |
| 397 |
#else |
| 398 |
#define PROTOBUF_EXPORT |
| 399 |
#define PROTOBUF_EXPORT_TEMPLATE_DECLARE |
| 400 |
#define PROTOBUF_EXPORT_TEMPLATE_DEFINE |
| 401 |
#endif |
| 402 |
#ifdef LIBPROTOC_EXPORTS |
| 403 |
#define PROTOC_EXPORT __attribute__((visibility("default"))) |
| 404 |
#else |
| 405 |
#define PROTOC_EXPORT |
| 406 |
#endif |
| 407 |
#endif |
| 408 |
#else // defined(PROTOBUF_USE_DLLS) |
| 409 |
#define PROTOBUF_EXPORT |
| 410 |
#define PROTOC_EXPORT |
| 411 |
#define PROTOBUF_EXPORT_TEMPLATE_DECLARE |
| 412 |
#define PROTOBUF_EXPORT_TEMPLATE_DEFINE |
| 413 |
#endif |
| 414 |
|
| 415 |
// Windows declares several inconvenient macro names. We #undef them and then |
| 416 |
// restore them in port_undef.inc. |
| 417 |
#ifdef _MSC_VER |
| 418 |
#pragma push_macro("CREATE_NEW") |
| 419 |
#undef CREATE_NEW |
| 420 |
#pragma push_macro("DOUBLE_CLICK") |
| 421 |
#undef DOUBLE_CLICK |
| 422 |
#pragma push_macro("ERROR") |
| 423 |
#undef ERROR |
| 424 |
#pragma push_macro("ERROR_BUSY") |
| 425 |
#undef ERROR_BUSY |
| 426 |
#pragma push_macro("ERROR_NOT_FOUND") |
| 427 |
#undef ERROR_NOT_FOUND |
| 428 |
#pragma push_macro("GetMessage") |
| 429 |
#undef GetMessage |
| 430 |
#pragma push_macro("IGNORE") |
| 431 |
#undef IGNORE |
| 432 |
#pragma push_macro("IN") |
| 433 |
#undef IN |
| 434 |
#pragma push_macro("INPUT_KEYBOARD") |
| 435 |
#undef INPUT_KEYBOARD |
| 436 |
#pragma push_macro("NO_ERROR") |
| 437 |
#undef NO_ERROR |
| 438 |
#pragma push_macro("OUT") |
| 439 |
#undef OUT |
| 440 |
#pragma push_macro("OPTIONAL") |
| 441 |
#undef OPTIONAL |
| 442 |
#pragma push_macro("min") |
| 443 |
#undef min |
| 444 |
#pragma push_macro("max") |
| 445 |
#undef max |
| 446 |
#pragma push_macro("NEAR") |
| 447 |
#undef NEAR |
| 448 |
#pragma push_macro("NO_DATA") |
| 449 |
#undef NO_DATA |
| 450 |
#pragma push_macro("REASON_UNKNOWN") |
| 451 |
#undef REASON_UNKNOWN |
| 452 |
#pragma push_macro("SERVICE_DISABLED") |
| 453 |
#undef SERVICE_DISABLED |
| 454 |
#pragma push_macro("SEVERITY_ERROR") |
| 455 |
#undef SEVERITY_ERROR |
| 456 |
#pragma push_macro("STRICT") |
| 457 |
#undef STRICT |
| 458 |
#pragma push_macro("timezone") |
| 459 |
#undef timezone |
| 460 |
#endif // _MSC_VER |
| 461 |
|
| 462 |
#if defined(__clang__) || defined(__GNUC__) || defined(_MSC_VER) |
| 463 |
// Don't let Objective-C Macros interfere with proto identifiers with the same |
| 464 |
// name. |
| 465 |
#pragma push_macro("DEBUG") |
| 466 |
#undef DEBUG |
| 467 |
#pragma push_macro("TRUE") |
| 468 |
#undef TRUE |
| 469 |
#pragma push_macro("FALSE") |
| 470 |
#undef FALSE |
| 471 |
#endif // defined(__clang__) || defined(__GNUC__) || defined(_MSC_VER) |
| 472 |
|
| 473 |
#if defined(__clang__) |
| 474 |
#pragma clang diagnostic push |
| 475 |
// TODO(gerbens) ideally we cleanup the code. But a cursory try shows many |
| 476 |
// violations. So let's ignore for now. |
| 477 |
#pragma clang diagnostic ignored "-Wshorten-64-to-32" |
| 478 |
#elif defined(__GNUC__) |
| 479 |
// GCC does not allow disabling diagnostics within an expression: |
| 480 |
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60875, so we disable this one |
| 481 |
// globally even though it's only used for PROTOBUF_FIELD_OFFSET. |
| 482 |
#pragma GCC diagnostic push |
| 483 |
#pragma GCC diagnostic ignored "-Winvalid-offsetof" |
| 484 |
#endif |
| 485 |
|
| 486 |
// PROTOBUF_ASSUME(pred) tells the compiler that it can assume pred is true. To |
| 487 |
// be safe, we also validate the assumption with a GOOGLE_DCHECK in unoptimized |
| 488 |
// builds. The macro does not do anything useful if the compiler does not |
| 489 |
// support __builtin_assume. |
| 490 |
#ifdef __has_builtin |
| 491 |
#if __has_builtin(__builtin_assume) |
| 492 |
#define PROTOBUF_ASSUME(pred) \ |
| 493 |
GOOGLE_DCHECK(pred); \ |
| 494 |
__builtin_assume(pred) |
| 495 |
#else |
| 496 |
#define PROTOBUF_ASSUME(pred) GOOGLE_DCHECK(pred) |
| 497 |
#endif |
| 498 |
#else |
| 499 |
#define PROTOBUF_ASSUME(pred) GOOGLE_DCHECK(pred) |
| 500 |
#endif |
| 501 |
|
| 502 |
// Specify memory alignment for structs, classes, etc. |
| 503 |
// Use like: |
| 504 |
// class PROTOBUF_ALIGNAS(16) MyClass { ... } |
| 505 |
// PROTOBUF_ALIGNAS(16) int array[4]; |
| 506 |
// |
| 507 |
// In most places you can use the C++11 keyword "alignas", which is preferred. |
| 508 |
// |
| 509 |
// But compilers have trouble mixing __attribute__((...)) syntax with |
| 510 |
// alignas(...) syntax. |
| 511 |
// |
| 512 |
// Doesn't work in clang or gcc: |
| 513 |
// struct alignas(16) __attribute__((packed)) S { char c; }; |
| 514 |
// Works in clang but not gcc: |
| 515 |
// struct __attribute__((packed)) alignas(16) S2 { char c; }; |
| 516 |
// Works in clang and gcc: |
| 517 |
// struct alignas(16) S3 { char c; } __attribute__((packed)); |
| 518 |
// |
| 519 |
// There are also some attributes that must be specified *before* a class |
| 520 |
// definition: visibility (used for exporting functions/classes) is one of |
| 521 |
// these attributes. This means that it is not possible to use alignas() with a |
| 522 |
// class that is marked as exported. |
| 523 |
#if defined(_MSC_VER) |
| 524 |
#define PROTOBUF_ALIGNAS(byte_alignment) __declspec(align(byte_alignment)) |
| 525 |
#elif defined(__GNUC__) |
| 526 |
#define PROTOBUF_ALIGNAS(byte_alignment) \ |
| 527 |
__attribute__((aligned(byte_alignment))) |
| 528 |
#else |
| 529 |
#define PROTOBUF_ALIGNAS(byte_alignment) alignas(byte_alignment) |
| 530 |
#endif |
| 531 |
|
| 532 |
#define PROTOBUF_FINAL final |
| 533 |
|
| 534 |
#if defined(_MSC_VER) |
| 535 |
#define PROTOBUF_THREAD_LOCAL __declspec(thread) |
| 536 |
#else |
| 537 |
#define PROTOBUF_THREAD_LOCAL __thread |
| 538 |
#endif |
| 539 |
|
| 540 |
// For enabling message owned arena, one major blocker is semantic change from |
| 541 |
// moving to copying when there is ownership transfer (e.g., move ctor, swap, |
| 542 |
// set allocated, release). This change not only causes performance regression |
| 543 |
// but also breaks users code (e.g., dangling reference). For top-level |
| 544 |
// messages, since it owns the arena, we can mitigate the issue by transferring |
| 545 |
// ownership of arena. However, we cannot do that for nested messages. In order |
| 546 |
// to tell how many usages of nested messages affected by message owned arena, |
| 547 |
// we need to simulate the arena ownership. |
| 548 |
// This experiment is purely for the purpose of gathering data. All code guarded |
| 549 |
// by this flag is supposed to be removed after this experiment. |
| 550 |
// #define PROTOBUF_MESSAGE_OWNED_ARENA_EXPERIMENT |
| 551 |
|
| 552 |
#if defined(__cpp_constinit) |
| 553 |
#define PROTOBUF_CONSTINIT constinit |
| 554 |
#elif defined(__has_cpp_attribute) |
| 555 |
#if __has_cpp_attribute(clang::require_constant_initialization) |
| 556 |
#define PROTOBUF_CONSTINIT [[clang::require_constant_initialization]] |
| 557 |
#endif |
| 558 |
#endif |
| 559 |
#ifndef PROTOBUF_CONSTINIT |
| 560 |
#define PROTOBUF_CONSTINIT |
| 561 |
#endif |
| 562 |
|
| 563 |
// Some constructors can't be constexpr under MSVC, but given that MSVC will not |
| 564 |
// do constant initialization of globals anyway we can omit `constexpr` from |
| 565 |
// them. These constructors are marked with PROTOBUF_MAYBE_CONSTEXPR |
| 566 |
#if defined(_MSC_VER) |
| 567 |
#define PROTOBUF_MAYBE_CONSTEXPR |
| 568 |
#else |
| 569 |
#define PROTOBUF_MAYBE_CONSTEXPR constexpr |
| 570 |
#endif |
| 571 |
|
| 572 |
#if _MSC_VER |
| 573 |
#define PROTOBUF_DISABLE_MSVC_UNION_WARNING \ |
| 574 |
__pragma(warning(push)) \ |
| 575 |
__pragma(warning(disable : 4582)) \ |
| 576 |
__pragma(warning(disable : 4583)) |
| 577 |
|
| 578 |
#define PROTOBUF_ENABLE_MSVC_UNION_WARNING \ |
| 579 |
__pragma(warning(pop)) |
| 580 |
#else |
| 581 |
#define PROTOBUF_DISABLE_MSVC_UNION_WARNING |
| 582 |
#define PROTOBUF_ENABLE_MSVC_UNION_WARNING |
| 583 |
#endif |
| 584 |
|
| 585 |
#if defined(__cpp_constinit) |
| 586 |
#define PROTOBUF_CONSTINIT constinit |
| 587 |
#elif defined(__has_cpp_attribute) |
| 588 |
#if __has_cpp_attribute(clang::require_constant_initialization) |
| 589 |
#define PROTOBUF_CONSTINIT [[clang::require_constant_initialization]] |
| 590 |
#endif |
| 591 |
#endif |
| 592 |
#ifndef PROTOBUF_CONSTINIT |
| 593 |
#define PROTOBUF_CONSTINIT |
| 594 |
#endif |
| 595 |
|
| 596 |
// Some globals with an empty non-trivial destructor are annotated with |
| 597 |
// no_destroy for performance reasons. It reduces the cost of these globals in |
| 598 |
// non-opt mode and under sanitizers. |
| 599 |
#if defined(__has_cpp_attribute) |
| 600 |
#if __has_cpp_attribute(clang::no_destroy) |
| 601 |
#define PROTOBUF_ATTRIBUTE_NO_DESTROY [[clang::no_destroy]] |
| 602 |
#endif |
| 603 |
#endif |
| 604 |
#if !defined(PROTOBUF_ATTRIBUTE_NO_DESTROY) |
| 605 |
#define PROTOBUF_ATTRIBUTE_NO_DESTROY |
| 606 |
#endif |