port_def.inc 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824
  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. // This file defines common macros that are used in protobuf.
  31. //
  32. // To hide these definitions from the outside world (and to prevent collisions
  33. // if more than one version of protobuf is #included in the same project) you
  34. // must follow this pattern when #including port_def.inc in a header file:
  35. //
  36. // #include "other_header.h"
  37. // #include "message.h"
  38. // // etc.
  39. //
  40. // #include "port_def.inc" // MUST be last header included
  41. //
  42. // // Definitions for this header.
  43. //
  44. // #include "port_undef.inc"
  45. //
  46. // This is a textual header with no include guard, because we want to
  47. // detect/prohibit anytime it is #included twice without a corresponding
  48. // #undef.
  49. // The definitions in this file are intended to be portable across Clang,
  50. // GCC, and MSVC. Function-like macros are usable without an #ifdef guard.
  51. // Syntax macros (for example, attributes) are always defined, although
  52. // they may be empty.
  53. //
  54. // Some definitions rely on the NDEBUG macro and/or (in MSVC) _DEBUG:
  55. // - https://en.cppreference.com/w/c/error/assert
  56. // - https://docs.microsoft.com/en-us/cpp/preprocessor/predefined-macros#microsoft-specific-predefined-macros
  57. //
  58. // References for predefined macros:
  59. // - Standard: https://en.cppreference.com/w/cpp/preprocessor/replace
  60. // - Clang: https://clang.llvm.org/docs/LanguageExtensions.html
  61. // (see also GCC predefined macros)
  62. // - GCC: https://gcc.gnu.org/onlinedocs/cpp/Predefined-Macros.html
  63. // - MSVC: https://docs.microsoft.com/en-us/cpp/preprocessor/predefined-macros
  64. // - Interactive (Clang/GCC only): https://www.compiler-explorer.com/z/hc6jKd3sj
  65. //
  66. // References for attributes (and extension attributes):
  67. // - Standard: https://en.cppreference.com/w/cpp/language/attributes
  68. // - Clang: https://clang.llvm.org/docs/AttributeReference.html
  69. // - GCC: https://gcc.gnu.org/onlinedocs/gcc/Attribute-Syntax.html
  70. // (see Clang attribute docs as well)
  71. //
  72. // References for standard C++ language conformance (and minimum versions):
  73. // - Clang: https://clang.llvm.org/cxx_status.html
  74. // - GCC: https://gcc.gnu.org/projects/cxx-status.html
  75. // - MSVC: https://docs.microsoft.com/en-us/cpp/overview/visual-cpp-language-conformance
  76. //
  77. // Historical release notes (which can help to determine minimum versions):
  78. // - Clang: https://releases.llvm.org/
  79. // - GCC: https://gcc.gnu.org/releases.html
  80. // - MSVC: https://docs.microsoft.com/en-us/visualstudio/releases/2019/release-notes-history
  81. // https://docs.microsoft.com/en-us/visualstudio/releasenotes/vs2017-relnotes-history
  82. // Portable fallbacks for C++20 feature test macros:
  83. // https://en.cppreference.com/w/cpp/feature_test
  84. #ifndef __has_cpp_attribute
  85. #define __has_cpp_attribute(x) 0
  86. #define PROTOBUF_has_cpp_attribute_DEFINED_
  87. #endif
  88. // Portable fallback for Clang's __has_feature macro:
  89. // https://clang.llvm.org/docs/LanguageExtensions.html#has-feature-and-has-extension
  90. #ifndef __has_feature
  91. #define __has_feature(x) 0
  92. #define PROTOBUF_has_feature_DEFINED_
  93. #endif
  94. // Portable fallback for Clang's __has_warning macro:
  95. #ifndef __has_warning
  96. #define __has_warning(x) 0
  97. #define PROTOBUF_has_warning_DEFINED_
  98. #endif
  99. // Portable fallbacks for the __has_attribute macro (GCC and Clang):
  100. // https://clang.llvm.org/docs/LanguageExtensions.html#has-attribute
  101. // https://gcc.gnu.org/onlinedocs/cpp/_005f_005fhas_005fattribute.html
  102. #ifndef __has_attribute
  103. #define __has_attribute(x) 0
  104. #define PROTOBUF_has_attribute_DEFINED_
  105. #endif
  106. // Portable fallback for __has_builtin (GCC and Clang):
  107. // https://clang.llvm.org/docs/LanguageExtensions.html#has-builtin
  108. // https://gcc.gnu.org/onlinedocs/cpp/_005f_005fhas_005fbuiltin.html
  109. #ifndef __has_builtin
  110. #define __has_builtin(x) 0
  111. #define PROTOBUF_has_builtin_DEFINED_
  112. #endif
  113. // Portable check for GCC minimum version:
  114. // https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html
  115. #if defined(__GNUC__) && defined(__GNUC_MINOR__) \
  116. && defined(__GNUC_PATCHLEVEL__)
  117. # define PROTOBUF_GNUC_MIN(x, y) \
  118. (__GNUC__ > (x) || __GNUC__ == (x) && __GNUC_MINOR__ >= (y))
  119. #else
  120. # define PROTOBUF_GNUC_MIN(x, y) 0
  121. #endif
  122. // Portable check for MSVC minimum version:
  123. // https://docs.microsoft.com/en-us/cpp/preprocessor/predefined-macros
  124. #if defined(_MSC_VER)
  125. #define PROTOBUF_MSC_VER_MIN(x) (_MSC_VER >= x)
  126. #else
  127. #define PROTOBUF_MSC_VER_MIN(x) 0
  128. #endif
  129. // Portable check for minimum C++ language version:
  130. // https://en.cppreference.com/w/cpp/preprocessor/replace
  131. // https://docs.microsoft.com/en-us/cpp/preprocessor/predefined-macros
  132. #if !defined(_MSVC_LANG)
  133. #define PROTOBUF_CPLUSPLUS_MIN(x) (__cplusplus >= x)
  134. #else
  135. #define PROTOBUF_CPLUSPLUS_MIN(x) (_MSVC_LANG >= x)
  136. #endif
  137. // Future versions of protobuf will include breaking changes to some APIs.
  138. // This macro can be set to enable these API changes ahead of time, so that
  139. // user code can be updated before upgrading versions of protobuf.
  140. // #define PROTOBUF_FUTURE_BREAKING_CHANGES 1
  141. #ifdef PROTOBUF_VERSION
  142. #error PROTOBUF_VERSION was previously defined
  143. #endif
  144. #define PROTOBUF_VERSION 3019004
  145. #ifdef PROTOBUF_MIN_HEADER_VERSION_FOR_PROTOC
  146. #error PROTOBUF_MIN_HEADER_VERSION_FOR_PROTOC was previously defined
  147. #endif
  148. #define PROTOBUF_MIN_HEADER_VERSION_FOR_PROTOC 3019000
  149. #ifdef PROTOBUF_MIN_PROTOC_VERSION
  150. #error PROTOBUF_MIN_PROTOC_VERSION was previously defined
  151. #endif
  152. #define PROTOBUF_MIN_PROTOC_VERSION 3019000
  153. #ifdef PROTOBUF_VERSION_SUFFIX
  154. #error PROTOBUF_VERSION_SUFFIX was previously defined
  155. #endif
  156. #define PROTOBUF_VERSION_SUFFIX ""
  157. #if defined(PROTOBUF_NAMESPACE) || defined(PROTOBUF_NAMESPACE_ID)
  158. #error PROTOBUF_NAMESPACE or PROTOBUF_NAMESPACE_ID was previously defined
  159. #endif
  160. #define PROTOBUF_NAMESPACE "google::protobuf"
  161. #define PROTOBUF_NAMESPACE_ID google::protobuf
  162. #define PROTOBUF_NAMESPACE_OPEN \
  163. namespace google { \
  164. namespace protobuf {
  165. #define PROTOBUF_NAMESPACE_CLOSE \
  166. } /* namespace protobuf */ \
  167. } /* namespace google */
  168. #ifdef PROTOBUF_ALWAYS_INLINE
  169. #error PROTOBUF_ALWAYS_INLINE was previously defined
  170. #endif
  171. // For functions we want to force inline.
  172. #if defined(PROTOBUF_NO_INLINE)
  173. # define PROTOBUF_ALWAYS_INLINE
  174. #elif PROTOBUF_GNUC_MIN(3, 1)
  175. # define PROTOBUF_ALWAYS_INLINE __attribute__((always_inline))
  176. #elif defined(_MSC_VER)
  177. # define PROTOBUF_ALWAYS_INLINE __forceinline
  178. #else
  179. # define PROTOBUF_ALWAYS_INLINE
  180. #endif
  181. #ifdef PROTOBUF_NDEBUG_INLINE
  182. #error PROTOBUF_NDEBUG_INLINE was previously defined
  183. #endif
  184. // Avoid excessive inlining in non-optimized builds. Without other optimizations
  185. // the inlining is not going to provide benefits anyway and the huge resulting
  186. // functions, especially in the proto-generated serialization functions, produce
  187. // stack frames so large that many tests run into stack overflows (b/32192897).
  188. #if defined(NDEBUG) || (defined(_MSC_VER) && !defined(_DEBUG))
  189. # define PROTOBUF_NDEBUG_INLINE PROTOBUF_ALWAYS_INLINE
  190. #else
  191. # define PROTOBUF_NDEBUG_INLINE
  192. #endif
  193. // Note that PROTOBUF_NOINLINE is an attribute applied to functions, to prevent
  194. // them from being inlined by the compiler. This is different from
  195. // PROTOBUF_NO_INLINE, which is a user-supplied macro that disables forced
  196. // inlining by PROTOBUF_(ALWAYS|NDEBUG)_INLINE.
  197. #ifdef PROTOBUF_NOINLINE
  198. #error PROTOBUF_NOINLINE was previously defined
  199. #endif
  200. #if PROTOBUF_GNUC_MIN(3, 1)
  201. # define PROTOBUF_NOINLINE __attribute__((noinline))
  202. #elif defined(_MSC_VER)
  203. // Seems to have been around since at least Visual Studio 2005
  204. # define PROTOBUF_NOINLINE __declspec(noinline)
  205. #endif
  206. #ifdef PROTOBUF_MUSTTAIL
  207. #error PROTOBUF_MUSTTAIL was previously defined
  208. #endif
  209. #ifdef PROTOBUF_TAILCALL
  210. #error PROTOBUF_TAILCALL was previously defined
  211. #endif
  212. #if __has_cpp_attribute(clang::musttail) && \
  213. !defined(__arm__) && !defined(_ARCH_PPC) && !defined(__wasm__)
  214. # ifndef PROTO2_OPENSOURCE
  215. // Compilation fails on ARM32: b/195943306
  216. // Compilation fails on powerpc64le: b/187985113
  217. # endif
  218. #define PROTOBUF_MUSTTAIL [[clang::musttail]]
  219. #define PROTOBUF_TAILCALL true
  220. #else
  221. #define PROTOBUF_MUSTTAIL
  222. #define PROTOBUF_TAILCALL false
  223. #endif
  224. #ifdef PROTOBUF_EXCLUSIVE_LOCKS_REQUIRED
  225. #error PROTOBUF_EXCLUSIVE_LOCKS_REQUIRED was previously defined
  226. #endif
  227. #if __has_attribute(exclusive_locks_required)
  228. #define PROTOBUF_EXCLUSIVE_LOCKS_REQUIRED(...) \
  229. __attribute__((exclusive_locks_required(__VA_ARGS__)))
  230. #else
  231. #define PROTOBUF_EXCLUSIVE_LOCKS_REQUIRED(...)
  232. #endif
  233. #ifdef PROTOBUF_NO_THREAD_SAFETY_ANALYSIS
  234. #error PROTOBUF_NO_THREAD_SAFETY_ANALYSIS was previously defined
  235. #endif
  236. #if __has_attribute(no_thread_safety_analysis)
  237. #define PROTOBUF_NO_THREAD_SAFETY_ANALYSIS \
  238. __attribute__((no_thread_safety_analysis))
  239. #else
  240. #define PROTOBUF_NO_THREAD_SAFETY_ANALYSIS
  241. #endif
  242. #ifdef PROTOBUF_GUARDED_BY
  243. #error PROTOBUF_GUARDED_BY was previously defined
  244. #endif
  245. #if __has_attribute(guarded_by)
  246. #define PROTOBUF_GUARDED_BY(x) __attribute__((guarded_by(x)))
  247. #else
  248. #define PROTOBUF_GUARDED_BY(x)
  249. #endif
  250. #ifdef PROTOBUF_LOCKS_EXCLUDED
  251. #error PROTOBUF_LOCKS_EXCLUDED was previously defined
  252. #endif
  253. #if __has_attribute(locks_excluded)
  254. #define PROTOBUF_LOCKS_EXCLUDED(...) \
  255. __attribute__((locks_excluded(__VA_ARGS__)))
  256. #else
  257. #define PROTOBUF_LOCKS_EXCLUDED(...)
  258. #endif
  259. #ifdef PROTOBUF_COLD
  260. #error PROTOBUF_COLD was previously defined
  261. #endif
  262. #if __has_attribute(cold) || PROTOBUF_GNUC_MIN(4, 3)
  263. # define PROTOBUF_COLD __attribute__((cold))
  264. #else
  265. # define PROTOBUF_COLD
  266. #endif
  267. #ifdef PROTOBUF_SECTION_VARIABLE
  268. #error PROTOBUF_SECTION_VARIABLE was previously defined
  269. #endif
  270. #if (__has_attribute(section) || defined(__GNUC__)) && defined(__ELF__)
  271. // Place a variable in the given ELF section.
  272. # define PROTOBUF_SECTION_VARIABLE(x) __attribute__((section(#x)))
  273. #else
  274. # define PROTOBUF_SECTION_VARIABLE(x)
  275. #endif
  276. #if defined(PROTOBUF_DEPRECATED)
  277. #error PROTOBUF_DEPRECATED was previously defined
  278. #endif
  279. #if defined(PROTOBUF_DEPRECATED_MSG)
  280. #error PROTOBUF_DEPRECATED_MSG was previously defined
  281. #endif
  282. #if __has_attribute(deprecated) || PROTOBUF_GNUC_MIN(3, 0)
  283. # define PROTOBUF_DEPRECATED __attribute__((deprecated))
  284. # define PROTOBUF_DEPRECATED_MSG(msg) __attribute__((deprecated(msg)))
  285. #elif defined(_MSC_VER)
  286. # define PROTOBUF_DEPRECATED __declspec(deprecated)
  287. # define PROTOBUF_DEPRECATED_MSG(msg) __declspec(deprecated(msg))
  288. #else
  289. # define PROTOBUF_DEPRECATED
  290. # define PROTOBUF_DEPRECATED_MSG(msg)
  291. #endif
  292. #if defined(PROTOBUF_DEPRECATED_ENUM)
  293. #error PROTOBUF_DEPRECATED_ENUM was previously defined
  294. #endif
  295. #if defined(__clang__) || PROTOBUF_GNUC_MIN(6, 0)
  296. // https://gcc.gnu.org/gcc-6/changes.html
  297. # define PROTOBUF_DEPRECATED_ENUM __attribute__((deprecated))
  298. #else
  299. # define PROTOBUF_DEPRECATED_ENUM
  300. #endif
  301. #ifdef PROTOBUF_FUNC_ALIGN
  302. #error PROTOBUF_FUNC_ALIGN was previously defined
  303. #endif
  304. #if __has_attribute(aligned) || PROTOBUF_GNUC_MIN(4, 3)
  305. #define PROTOBUF_FUNC_ALIGN(bytes) __attribute__((aligned(bytes)))
  306. #else
  307. #define PROTOBUF_FUNC_ALIGN(bytes)
  308. #endif
  309. #ifdef PROTOBUF_RETURNS_NONNULL
  310. #error PROTOBUF_RETURNS_NONNULL was previously defined
  311. #endif
  312. #if __has_attribute(returns_nonnull) || PROTOBUF_GNUC_MIN(4, 9)
  313. #define PROTOBUF_RETURNS_NONNULL __attribute__((returns_nonnull))
  314. #else
  315. #define PROTOBUF_RETURNS_NONNULL
  316. #endif
  317. #ifdef PROTOBUF_ATTRIBUTE_REINITIALIZES
  318. #error PROTOBUF_ATTRIBUTE_REINITIALIZES was previously defined
  319. #endif
  320. #if __has_cpp_attribute(clang::reinitializes)
  321. #define PROTOBUF_ATTRIBUTE_REINITIALIZES [[clang::reinitializes]]
  322. #else
  323. #define PROTOBUF_ATTRIBUTE_REINITIALIZES
  324. #endif
  325. // The minimum library version which works with the current version of the
  326. // headers.
  327. #define GOOGLE_PROTOBUF_MIN_LIBRARY_VERSION 3019000
  328. #ifdef PROTOBUF_RTTI
  329. #error PROTOBUF_RTTI was previously defined
  330. #endif
  331. #if defined(GOOGLE_PROTOBUF_NO_RTTI) && GOOGLE_PROTOBUF_NO_RTTI
  332. #define PROTOBUF_RTTI 0
  333. #elif __has_feature(cxx_rtti)
  334. #define PROTOBUF_RTTI 1
  335. #elif defined(__cxx_rtti)
  336. // https://en.cppreference.com/w/User:D41D8CD98F/feature_testing_macros#C.2B.2B98
  337. #define PROTOBUF_RTTI 1
  338. #else
  339. #define PROTOBUF_RTTI 0
  340. #endif
  341. // Returns the offset of the given field within the given aggregate type.
  342. // This is equivalent to the ANSI C offsetof() macro. However, according
  343. // to the C++ standard, offsetof() only works on POD types, and GCC
  344. // enforces this requirement with a warning. In practice, this rule is
  345. // unnecessarily strict; there is probably no compiler or platform on
  346. // which the offsets of the direct fields of a class are non-constant.
  347. // Fields inherited from superclasses *can* have non-constant offsets,
  348. // but that's not what this macro will be used for.
  349. #ifdef PROTOBUF_FIELD_OFFSET
  350. #error PROTOBUF_FIELD_OFFSET was previously defined
  351. #endif
  352. #if defined(__clang__)
  353. // For Clang we use __builtin_offsetof() and suppress the warning,
  354. // to avoid Control Flow Integrity and UBSan vptr sanitizers from
  355. // crashing while trying to validate the invalid reinterpret_casts.
  356. #define PROTOBUF_FIELD_OFFSET(TYPE, FIELD) \
  357. _Pragma("clang diagnostic push") \
  358. _Pragma("clang diagnostic ignored \"-Winvalid-offsetof\"") \
  359. __builtin_offsetof(TYPE, FIELD) \
  360. _Pragma("clang diagnostic pop")
  361. #elif PROTOBUF_GNUC_MIN(4, 8)
  362. #define PROTOBUF_FIELD_OFFSET(TYPE, FIELD) __builtin_offsetof(TYPE, FIELD)
  363. #else // defined(__clang__)
  364. // Note that we calculate relative to the pointer value 16 here since if we
  365. // just use zero, GCC complains about dereferencing a NULL pointer. We
  366. // choose 16 rather than some other number just in case the compiler would
  367. // be confused by an unaligned pointer.
  368. #define PROTOBUF_FIELD_OFFSET(TYPE, FIELD) \
  369. static_cast< ::uint32_t>(reinterpret_cast<const char*>( \
  370. &reinterpret_cast<const TYPE*>(16)->FIELD) - \
  371. reinterpret_cast<const char*>(16))
  372. #endif
  373. #ifdef PROTOBUF_EXPORT
  374. #error PROTOBUF_EXPORT was previously defined
  375. #endif
  376. #if defined(PROTOBUF_USE_DLLS) && defined(_MSC_VER)
  377. # if defined(LIBPROTOBUF_EXPORTS)
  378. # define PROTOBUF_EXPORT __declspec(dllexport)
  379. # define PROTOBUF_EXPORT_TEMPLATE_DECLARE
  380. # define PROTOBUF_EXPORT_TEMPLATE_DEFINE __declspec(dllexport)
  381. # else
  382. # define PROTOBUF_EXPORT __declspec(dllimport)
  383. # define PROTOBUF_EXPORT_TEMPLATE_DECLARE
  384. # define PROTOBUF_EXPORT_TEMPLATE_DEFINE __declspec(dllimport)
  385. # endif // defined(LIBPROTOBUF_EXPORTS)
  386. #elif defined(PROTOBUF_USE_DLLS) && defined(LIBPROTOBUF_EXPORTS)
  387. # define PROTOBUF_EXPORT __attribute__((visibility("default")))
  388. # define PROTOBUF_EXPORT_TEMPLATE_DECLARE __attribute__((visibility("default")))
  389. # define PROTOBUF_EXPORT_TEMPLATE_DEFINE
  390. #else
  391. # define PROTOBUF_EXPORT
  392. # define PROTOBUF_EXPORT_TEMPLATE_DECLARE
  393. # define PROTOBUF_EXPORT_TEMPLATE_DEFINE
  394. #endif
  395. #ifdef PROTOC_EXPORT
  396. #error PROTOC_EXPORT was previously defined
  397. #endif
  398. #if defined(PROTOBUF_USE_DLLS) && defined(_MSC_VER)
  399. # if defined(LIBPROTOC_EXPORTS)
  400. # define PROTOC_EXPORT __declspec(dllexport)
  401. # else
  402. # define PROTOC_EXPORT __declspec(dllimport)
  403. # endif // defined(LIBPROTOC_EXPORTS)
  404. #elif defined(PROTOBUF_USE_DLLS) && defined(LIBPROTOBUF_EXPORTS)
  405. # define PROTOC_EXPORT __attribute__((visibility("default")))
  406. #else
  407. # define PROTOC_EXPORT
  408. #endif
  409. #if defined(PROTOBUF_PREDICT_TRUE) || defined(PROTOBUF_PREDICT_FALSE)
  410. #error PROTOBUF_PREDICT_(TRUE|FALSE) was previously defined
  411. #endif
  412. #if PROTOBUF_GNUC_MIN(3, 0)
  413. # define PROTOBUF_PREDICT_TRUE(x) (__builtin_expect(false || (x), true))
  414. # define PROTOBUF_PREDICT_FALSE(x) (__builtin_expect(false || (x), false))
  415. #else
  416. # define PROTOBUF_PREDICT_TRUE(x) (x)
  417. # define PROTOBUF_PREDICT_FALSE(x) (x)
  418. #endif
  419. #ifdef PROTOBUF_NODISCARD
  420. #error PROTOBUF_NODISCARD was previously defined
  421. #endif
  422. #if __has_cpp_attribute(nodiscard)
  423. #define PROTOBUF_NODISCARD [[nodiscard]]
  424. #elif __has_attribute(warn_unused_result) || PROTOBUF_GNUC_MIN(4, 8)
  425. #define PROTOBUF_NODISCARD __attribute__((warn_unused_result))
  426. #else
  427. #define PROTOBUF_NODISCARD
  428. #endif
  429. #ifdef PROTOBUF_FORCE_COPY_IN_RELEASE
  430. #error PROTOBUF_FORCE_COPY_IN_RELEASE was previously defined
  431. #endif
  432. #ifdef PROTOBUF_FORCE_COPY_IN_SWAP
  433. #error PROTOBUF_FORCE_COPY_IN_SWAP was previously defined
  434. #endif
  435. #ifdef PROTOBUF_FORCE_COPY_IN_MOVE
  436. #error PROTOBUF_FORCE_COPY_IN_MOVE was previously defined
  437. #endif
  438. // Force copy the default string to a string field so that non-optimized builds
  439. // have harder-to-rely-on address stability.
  440. #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
  441. #error PROTOBUF_FORCE_COPY_DEFAULT_STRING was previously defined
  442. #endif
  443. #ifdef PROTOBUF_FALLTHROUGH_INTENDED
  444. #error PROTOBUF_FALLTHROUGH_INTENDED was previously defined
  445. #endif
  446. #if __has_cpp_attribute(fallthrough)
  447. #define PROTOBUF_FALLTHROUGH_INTENDED [[fallthrough]]
  448. #elif __has_feature(cxx_attributes) && __has_warning("-Wimplicit-fallthrough")
  449. #define PROTOBUF_FALLTHROUGH_INTENDED [[clang::fallthrough]]
  450. #elif PROTOBUF_GNUC_MIN(7, 0)
  451. #define PROTOBUF_FALLTHROUGH_INTENDED [[gnu::fallthrough]]
  452. #else
  453. #define PROTOBUF_FALLTHROUGH_INTENDED
  454. #endif
  455. // PROTOBUF_ASSUME(pred) tells the compiler that it can assume pred is true. To
  456. // be safe, we also validate the assumption with a GOOGLE_DCHECK in unoptimized
  457. // builds. The macro does not do anything useful if the compiler does not
  458. // support __builtin_assume.
  459. #ifdef PROTOBUF_ASSUME
  460. #error PROTOBUF_ASSUME was previously defined
  461. #endif
  462. #if __has_builtin(__builtin_assume)
  463. #define PROTOBUF_ASSUME(pred) \
  464. GOOGLE_DCHECK(pred); \
  465. __builtin_assume(pred)
  466. #else
  467. #define PROTOBUF_ASSUME(pred) GOOGLE_DCHECK(pred)
  468. #endif
  469. // Specify memory alignment for structs, classes, etc.
  470. // Use like:
  471. // class PROTOBUF_ALIGNAS(16) MyClass { ... }
  472. // PROTOBUF_ALIGNAS(16) int array[4];
  473. //
  474. // In most places you can use the C++11 keyword "alignas", which is preferred.
  475. //
  476. // But compilers have trouble mixing __attribute__((...)) syntax with
  477. // alignas(...) syntax.
  478. //
  479. // Doesn't work in clang or gcc:
  480. // struct alignas(16) __attribute__((packed)) S { char c; };
  481. // Works in clang but not gcc:
  482. // struct __attribute__((packed)) alignas(16) S2 { char c; };
  483. // Works in clang and gcc:
  484. // struct alignas(16) S3 { char c; } __attribute__((packed));
  485. //
  486. // There are also some attributes that must be specified *before* a class
  487. // definition: visibility (used for exporting functions/classes) is one of
  488. // these attributes. This means that it is not possible to use alignas() with a
  489. // class that is marked as exported.
  490. #ifdef PROTOBUF_ALIGNAS
  491. #error PROTOBUF_ALIGNAS was previously defined
  492. #endif
  493. #if defined(_MSC_VER)
  494. #define PROTOBUF_ALIGNAS(byte_alignment) __declspec(align(byte_alignment))
  495. #elif PROTOBUF_GNUC_MIN(3, 0)
  496. #define PROTOBUF_ALIGNAS(byte_alignment) \
  497. __attribute__((aligned(byte_alignment)))
  498. #else
  499. #define PROTOBUF_ALIGNAS(byte_alignment) alignas(byte_alignment)
  500. #endif
  501. #ifdef PROTOBUF_FINAL
  502. #error PROTOBUF_FINAL was previously defined
  503. #endif
  504. #define PROTOBUF_FINAL final
  505. #ifdef PROTOBUF_THREAD_LOCAL
  506. #error PROTOBUF_THREAD_LOCAL was previously defined
  507. #endif
  508. #if defined(_MSC_VER)
  509. #define PROTOBUF_THREAD_LOCAL __declspec(thread)
  510. #else
  511. #define PROTOBUF_THREAD_LOCAL __thread
  512. #endif
  513. // For enabling message owned arena, one major blocker is semantic change from
  514. // moving to copying when there is ownership transfer (e.g., move ctor, swap,
  515. // set allocated, release). This change not only causes performance regression
  516. // but also breaks users code (e.g., dangling reference). For top-level
  517. // messages, since it owns the arena, we can mitigate the issue by transferring
  518. // ownership of arena. However, we cannot do that for nested messages. In order
  519. // to tell how many usages of nested messages affected by message owned arena,
  520. // we need to simulate the arena ownership.
  521. // This experiment is purely for the purpose of gathering data. All code guarded
  522. // by this flag is supposed to be removed after this experiment.
  523. #define PROTOBUF_MESSAGE_OWNED_ARENA_EXPERIMENT
  524. #ifdef PROTOBUF_CONSTINIT
  525. #error PROTOBUF_CONSTINIT was previously defined
  526. #endif
  527. #if defined(__cpp_constinit) && !PROTOBUF_GNUC_MIN(3, 0) && !defined(_MSC_VER)
  528. // Our use of constinit does not yet work with GCC:
  529. // https://github.com/protocolbuffers/protobuf/issues/8310
  530. // Does not work yet with Visual Studio 2019 Update 16.10
  531. #define PROTOBUF_CONSTINIT constinit
  532. #elif !defined(_MSC_VER) && \
  533. __has_cpp_attribute(clang::require_constant_initialization)
  534. #define PROTOBUF_CONSTINIT [[clang::require_constant_initialization]]
  535. #else
  536. #define PROTOBUF_CONSTINIT
  537. #endif
  538. // Some globals with an empty non-trivial destructor are annotated with
  539. // no_destroy for performance reasons. It reduces the cost of these globals in
  540. // non-opt mode and under sanitizers.
  541. #ifdef PROTOBUF_ATTRIBUTE_NO_DESTROY
  542. #error PROTOBUF_ATTRIBUTE_NO_DESTROY was previously defined
  543. #endif
  544. #if __has_cpp_attribute(clang::no_destroy)
  545. #define PROTOBUF_ATTRIBUTE_NO_DESTROY [[clang::no_destroy]]
  546. #else
  547. #define PROTOBUF_ATTRIBUTE_NO_DESTROY
  548. #endif
  549. // Protobuf extensions and reflection require registration of the protos linked
  550. // in the binary. Not until everything is registered does the runtime have a
  551. // complete view on all protos. When code is using reflection or extensions
  552. // in between registration calls this can lead to surprising behavior. By
  553. // having the registration run first we mitigate this scenario.
  554. // Highest priority is 101. We use 102 to allow code that really wants to
  555. // higher priority to still beat us.
  556. #ifdef PROTOBUF_ATTRIBUTE_INIT_PRIORITY
  557. #error PROTOBUF_ATTRIBUTE_INIT_PRIORITY was previously defined
  558. #endif
  559. #if PROTOBUF_GNUC_MIN(3, 0) && (!defined(__APPLE__) || defined(__clang__)) && !((defined(sun) || defined(__sun)) && (defined(__SVR4) || defined(__svr4__)))
  560. #define PROTOBUF_ATTRIBUTE_INIT_PRIORITY __attribute__((init_priority((102))))
  561. #else
  562. #define PROTOBUF_ATTRIBUTE_INIT_PRIORITY
  563. #endif
  564. #ifdef PROTOBUF_PRAGMA_INIT_SEG
  565. #error PROTOBUF_PRAGMA_INIT_SEG was previously defined
  566. #endif
  567. #if _MSC_VER
  568. #define PROTOBUF_PRAGMA_INIT_SEG __pragma(init_seg(lib))
  569. #else
  570. #define PROTOBUF_PRAGMA_INIT_SEG
  571. #endif
  572. #ifdef PROTOBUF_ATTRIBUTE_WEAK
  573. #error PROTOBUF_ATTRIBUTE_WEAK was previously defined
  574. #endif
  575. #if __has_attribute(weak) && \
  576. !defined(__APPLE__) && \
  577. (!defined(_WIN32) || __clang_major__ < 9) && \
  578. !defined(__MINGW32__)
  579. #define PROTOBUF_ATTRIBUTE_WEAK __attribute__((weak))
  580. #define PROTOBUF_HAVE_ATTRIBUTE_WEAK 1
  581. #else
  582. #define PROTOBUF_ATTRIBUTE_WEAK
  583. #define PROTOBUF_HAVE_ATTRIBUTE_WEAK 0
  584. #endif
  585. // Macros to detect sanitizers.
  586. #ifdef PROTOBUF_ASAN
  587. #error PROTOBUF_ASAN was previously defined
  588. #endif
  589. #ifdef PROTOBUF_MSAN
  590. #error PROTOBUF_MSAN was previously defined
  591. #endif
  592. #ifdef PROTOBUF_TSAN
  593. #error PROTOBUF_TSAN was previously defined
  594. #endif
  595. #if defined(__clang__)
  596. # if __has_feature(address_sanitizer)
  597. # define PROTOBUF_ASAN 1
  598. # endif
  599. # if __has_feature(thread_sanitizer)
  600. # define PROTOBUF_TSAN 1
  601. # endif
  602. # if __has_feature(memory_sanitizer)
  603. # define PROTOBUF_MSAN 1
  604. # endif
  605. #elif PROTOBUF_GNUC_MIN(3, 0)
  606. // Double-guard is needed for -Wundef:
  607. # ifdef __SANITIZE_ADDRESS__
  608. # if __SANITIZE_ADDRESS__
  609. # define PROTOBUF_ASAN 1
  610. # endif
  611. # endif
  612. # ifdef __SANITIZE_THREAD__
  613. # if __SANITIZE_THREAD__
  614. # define PROTOBUF_TSAN 1
  615. # endif
  616. # endif
  617. #endif
  618. // Tail call table-driven parsing can be enabled by defining
  619. // PROTOBUF_EXPERIMENTAL_USE_TAIL_CALL_TABLE_PARSER at compilation time. Note
  620. // that this macro is for small-scale testing only, and is not supported.
  621. #ifdef PROTOBUF_TAIL_CALL_TABLE_PARSER_ENABLED
  622. #error PROTOBUF_TAIL_CALL_TABLE_PARSER_ENABLED was previously declared
  623. #endif
  624. #if defined(PROTOBUF_EXPERIMENTAL_USE_TAIL_CALL_TABLE_PARSER)
  625. #define PROTOBUF_TAIL_CALL_TABLE_PARSER_ENABLED 1
  626. // Selectively use static member functions instead of templates:
  627. #ifndef PROTOBUF_TC_STATIC_PARSE_SINGULAR1
  628. # define PROTOBUF_TC_STATIC_PARSE_SINGULAR1 1
  629. #endif
  630. #ifndef PROTOBUF_TC_STATIC_PARSE_SINGULAR2
  631. # define PROTOBUF_TC_STATIC_PARSE_SINGULAR2 0
  632. #endif
  633. #ifndef PROTOBUF_TC_STATIC_PARSE_REPEATED1
  634. # define PROTOBUF_TC_STATIC_PARSE_REPEATED1 0
  635. #endif
  636. #ifndef PROTOBUF_TC_STATIC_PARSE_REPEATED2
  637. # define PROTOBUF_TC_STATIC_PARSE_REPEATED2 0
  638. #endif
  639. #endif
  640. #define PROTOBUF_TC_PARAM_DECL \
  641. ::google::protobuf::MessageLite *msg, const char *ptr, \
  642. ::google::protobuf::internal::ParseContext *ctx, \
  643. const ::google::protobuf::internal::TcParseTableBase *table, \
  644. uint64_t hasbits, ::google::protobuf::internal::TcFieldData data
  645. #ifdef PROTOBUF_UNUSED
  646. #error PROTOBUF_UNUSED was previously defined
  647. #endif
  648. #if __has_cpp_attribute(maybe_unused) || \
  649. (PROTOBUF_MSC_VER_MIN(1911) && PROTOBUF_CPLUSPLUS_MIN(201703L))
  650. #define PROTOBUF_UNUSED [[maybe_unused]]
  651. #elif __has_attribute(unused) || PROTOBUF_GNUC_MIN(3, 0)
  652. #define PROTOBUF_UNUSED __attribute__((__unused__))
  653. #else
  654. #define PROTOBUF_UNUSED
  655. #endif
  656. // Windows declares several inconvenient macro names. We #undef them and then
  657. // restore them in port_undef.inc.
  658. #ifdef _MSC_VER
  659. #pragma push_macro("CREATE_NEW")
  660. #undef CREATE_NEW
  661. #pragma push_macro("DELETE")
  662. #undef DELETE
  663. #pragma push_macro("DOUBLE_CLICK")
  664. #undef DOUBLE_CLICK
  665. #pragma push_macro("ERROR")
  666. #undef ERROR
  667. #pragma push_macro("ERROR_BUSY")
  668. #undef ERROR_BUSY
  669. #pragma push_macro("ERROR_INSTALL_FAILED")
  670. #undef ERROR_INSTALL_FAILED
  671. #pragma push_macro("ERROR_NOT_FOUND")
  672. #undef ERROR_NOT_FOUND
  673. #pragma push_macro("GetMessage")
  674. #undef GetMessage
  675. #pragma push_macro("IGNORE")
  676. #undef IGNORE
  677. #pragma push_macro("IN")
  678. #undef IN
  679. #pragma push_macro("INPUT_KEYBOARD")
  680. #undef INPUT_KEYBOARD
  681. #pragma push_macro("NO_ERROR")
  682. #undef NO_ERROR
  683. #pragma push_macro("OUT")
  684. #undef OUT
  685. #pragma push_macro("OPTIONAL")
  686. #undef OPTIONAL
  687. #pragma push_macro("min")
  688. #undef min
  689. #pragma push_macro("max")
  690. #undef max
  691. #pragma push_macro("NEAR")
  692. #undef NEAR
  693. #pragma push_macro("NO_DATA")
  694. #undef NO_DATA
  695. #pragma push_macro("REASON_UNKNOWN")
  696. #undef REASON_UNKNOWN
  697. #pragma push_macro("SERVICE_DISABLED")
  698. #undef SERVICE_DISABLED
  699. #pragma push_macro("SEVERITY_ERROR")
  700. #undef SEVERITY_ERROR
  701. #pragma push_macro("STRICT")
  702. #undef STRICT
  703. #pragma push_macro("timezone")
  704. #undef timezone
  705. #endif // _MSC_VER
  706. #if defined(__clang__) || PROTOBUF_GNUC_MIN(3, 0) || defined(_MSC_VER)
  707. // Don't let Objective-C Macros interfere with proto identifiers with the same
  708. // name.
  709. #pragma push_macro("DEBUG")
  710. #undef DEBUG
  711. #endif // defined(__clang__) || PROTOBUF_GNUC_MIN(3, 0) || defined(_MSC_VER)
  712. #if defined(__clang__)
  713. #pragma clang diagnostic push
  714. // TODO(gerbens) ideally we cleanup the code. But a cursory try shows many
  715. // violations. So let's ignore for now.
  716. #pragma clang diagnostic ignored "-Wshorten-64-to-32"
  717. #elif PROTOBUF_GNUC_MIN(3, 0)
  718. // GCC does not allow disabling diagnostics within an expression:
  719. // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60875, so we disable this one
  720. // globally even though it's only used for PROTOBUF_FIELD_OFFSET.
  721. #pragma GCC diagnostic push
  722. #pragma GCC diagnostic ignored "-Winvalid-offsetof"
  723. #endif
  724. // Silence some MSVC warnings in all our code.
  725. #if _MSC_VER
  726. #pragma warning(push)
  727. // For non-trivial unions
  728. #pragma warning(disable : 4582)
  729. #pragma warning(disable : 4583)
  730. // For init_seg(lib)
  731. #pragma warning(disable : 4073)
  732. // To silence the fact that we will pop this push from another file
  733. #pragma warning(disable : 5031)
  734. // Conditional expression is constant
  735. #pragma warning(disable: 4127)
  736. // decimal digit terminates octal escape sequence
  737. #pragma warning(disable: 4125)
  738. #endif
  739. // We don't want code outside port_def doing complex testing, so
  740. // remove our portable condition test macros to nudge folks away from
  741. // using it themselves.
  742. #ifdef PROTOBUF_has_cpp_attribute_DEFINED_
  743. # undef __has_cpp_attribute
  744. # undef PROTOBUF_has_cpp_attribute_DEFINED_
  745. #endif
  746. #ifdef PROTOBUF_has_feature_DEFINED_
  747. # undef __has_feature
  748. # undef PROTOBUF_has_feature_DEFINED_
  749. #endif
  750. #ifdef PROTOBUF_has_warning_DEFINED_
  751. # undef __has_warning
  752. # undef PROTOBUF_has_warning_DEFINED_
  753. #endif
  754. #ifdef PROTOBUF_has_attribute_DEFINED_
  755. # undef __has_attribute
  756. # undef PROTOBUF_has_attribute_DEFINED_
  757. #endif
  758. #ifdef PROTOBUF_has_builtin_DEFINED_
  759. # undef __has_builtin
  760. # undef PROTOBUF_has_builtin_DEFINED_
  761. #endif