port_def.inc 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793
  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 3018001
  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 3018000
  149. #ifdef PROTOBUF_MIN_PROTOC_VERSION
  150. #error PROTOBUF_MIN_PROTOC_VERSION was previously defined
  151. #endif
  152. #define PROTOBUF_MIN_PROTOC_VERSION 3018000
  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. #define PROTOBUF_SECTION_VARIABLE(x)
  271. #if defined(PROTOBUF_DEPRECATED)
  272. #error PROTOBUF_DEPRECATED was previously defined
  273. #endif
  274. #if defined(PROTOBUF_DEPRECATED_MSG)
  275. #error PROTOBUF_DEPRECATED_MSG was previously defined
  276. #endif
  277. #if __has_attribute(deprecated) || PROTOBUF_GNUC_MIN(3, 0)
  278. # define PROTOBUF_DEPRECATED __attribute__((deprecated))
  279. # define PROTOBUF_DEPRECATED_MSG(msg) __attribute__((deprecated(msg)))
  280. #elif defined(_MSC_VER)
  281. # define PROTOBUF_DEPRECATED __declspec(deprecated)
  282. # define PROTOBUF_DEPRECATED_MSG(msg) __declspec(deprecated(msg))
  283. #else
  284. # define PROTOBUF_DEPRECATED
  285. # define PROTOBUF_DEPRECATED_MSG(msg)
  286. #endif
  287. #if defined(PROTOBUF_DEPRECATED_ENUM)
  288. #error PROTOBUF_DEPRECATED_ENUM was previously defined
  289. #endif
  290. #if defined(__clang__) || PROTOBUF_GNUC_MIN(6, 0)
  291. // https://gcc.gnu.org/gcc-6/changes.html
  292. # define PROTOBUF_DEPRECATED_ENUM __attribute__((deprecated))
  293. #else
  294. # define PROTOBUF_DEPRECATED_ENUM
  295. #endif
  296. #ifdef PROTOBUF_FUNC_ALIGN
  297. #error PROTOBUF_FUNC_ALIGN was previously defined
  298. #endif
  299. #if __has_attribute(aligned) || PROTOBUF_GNUC_MIN(4, 3)
  300. #define PROTOBUF_FUNC_ALIGN(bytes) __attribute__((aligned(bytes)))
  301. #else
  302. #define PROTOBUF_FUNC_ALIGN(bytes)
  303. #endif
  304. #ifdef PROTOBUF_RETURNS_NONNULL
  305. #error PROTOBUF_RETURNS_NONNULL was previously defined
  306. #endif
  307. #if __has_attribute(returns_nonnull) || PROTOBUF_GNUC_MIN(4, 9)
  308. #define PROTOBUF_RETURNS_NONNULL __attribute__((returns_nonnull))
  309. #else
  310. #define PROTOBUF_RETURNS_NONNULL
  311. #endif
  312. #ifdef PROTOBUF_ATTRIBUTE_REINITIALIZES
  313. #error PROTOBUF_ATTRIBUTE_REINITIALIZES was previously defined
  314. #endif
  315. #if __has_cpp_attribute(clang::reinitializes)
  316. #define PROTOBUF_ATTRIBUTE_REINITIALIZES [[clang::reinitializes]]
  317. #else
  318. #define PROTOBUF_ATTRIBUTE_REINITIALIZES
  319. #endif
  320. // The minimum library version which works with the current version of the
  321. // headers.
  322. #define GOOGLE_PROTOBUF_MIN_LIBRARY_VERSION 3018000
  323. #ifdef PROTOBUF_RTTI
  324. #error PROTOBUF_RTTI was previously defined
  325. #endif
  326. #if defined(GOOGLE_PROTOBUF_NO_RTTI) && GOOGLE_PROTOBUF_NO_RTTI
  327. #define PROTOBUF_RTTI 0
  328. #elif __has_feature(cxx_rtti)
  329. #define PROTOBUF_RTTI 1
  330. #elif defined(__cxx_rtti)
  331. // https://en.cppreference.com/w/User:D41D8CD98F/feature_testing_macros#C.2B.2B98
  332. #define PROTOBUF_RTTI 1
  333. #else
  334. #define PROTOBUF_RTTI 0
  335. #endif
  336. // Returns the offset of the given field within the given aggregate type.
  337. // This is equivalent to the ANSI C offsetof() macro. However, according
  338. // to the C++ standard, offsetof() only works on POD types, and GCC
  339. // enforces this requirement with a warning. In practice, this rule is
  340. // unnecessarily strict; there is probably no compiler or platform on
  341. // which the offsets of the direct fields of a class are non-constant.
  342. // Fields inherited from superclasses *can* have non-constant offsets,
  343. // but that's not what this macro will be used for.
  344. #ifdef PROTOBUF_FIELD_OFFSET
  345. #error PROTOBUF_FIELD_OFFSET was previously defined
  346. #endif
  347. #if defined(__clang__)
  348. // For Clang we use __builtin_offsetof() and suppress the warning,
  349. // to avoid Control Flow Integrity and UBSan vptr sanitizers from
  350. // crashing while trying to validate the invalid reinterpret_casts.
  351. #define PROTOBUF_FIELD_OFFSET(TYPE, FIELD) \
  352. _Pragma("clang diagnostic push") \
  353. _Pragma("clang diagnostic ignored \"-Winvalid-offsetof\"") \
  354. __builtin_offsetof(TYPE, FIELD) \
  355. _Pragma("clang diagnostic pop")
  356. #elif PROTOBUF_GNUC_MIN(4, 8)
  357. #define PROTOBUF_FIELD_OFFSET(TYPE, FIELD) __builtin_offsetof(TYPE, FIELD)
  358. #else // defined(__clang__)
  359. // Note that we calculate relative to the pointer value 16 here since if we
  360. // just use zero, GCC complains about dereferencing a NULL pointer. We
  361. // choose 16 rather than some other number just in case the compiler would
  362. // be confused by an unaligned pointer.
  363. #define PROTOBUF_FIELD_OFFSET(TYPE, FIELD) \
  364. static_cast< ::google::protobuf::uint32>(reinterpret_cast<const char*>( \
  365. &reinterpret_cast<const TYPE*>(16)->FIELD) - \
  366. reinterpret_cast<const char*>(16))
  367. #endif
  368. #ifdef PROTOBUF_EXPORT
  369. #error PROTOBUF_EXPORT was previously defined
  370. #endif
  371. #if defined(PROTOBUF_USE_DLLS) && defined(_MSC_VER)
  372. # if defined(LIBPROTOBUF_EXPORTS)
  373. # define PROTOBUF_EXPORT __declspec(dllexport)
  374. # define PROTOBUF_EXPORT_TEMPLATE_DECLARE
  375. # define PROTOBUF_EXPORT_TEMPLATE_DEFINE __declspec(dllexport)
  376. # else
  377. # define PROTOBUF_EXPORT __declspec(dllimport)
  378. # define PROTOBUF_EXPORT_TEMPLATE_DECLARE
  379. # define PROTOBUF_EXPORT_TEMPLATE_DEFINE __declspec(dllimport)
  380. # endif // defined(LIBPROTOBUF_EXPORTS)
  381. #elif defined(PROTOBUF_USE_DLLS) && defined(LIBPROTOBUF_EXPORTS)
  382. # define PROTOBUF_EXPORT __attribute__((visibility("default")))
  383. # define PROTOBUF_EXPORT_TEMPLATE_DECLARE __attribute__((visibility("default")))
  384. # define PROTOBUF_EXPORT_TEMPLATE_DEFINE
  385. #else
  386. # define PROTOBUF_EXPORT
  387. # define PROTOBUF_EXPORT_TEMPLATE_DECLARE
  388. # define PROTOBUF_EXPORT_TEMPLATE_DEFINE
  389. #endif
  390. #ifdef PROTOC_EXPORT
  391. #error PROTOC_EXPORT was previously defined
  392. #endif
  393. #if defined(PROTOBUF_USE_DLLS) && defined(_MSC_VER)
  394. # if defined(LIBPROTOC_EXPORTS)
  395. # define PROTOC_EXPORT __declspec(dllexport)
  396. # else
  397. # define PROTOC_EXPORT __declspec(dllimport)
  398. # endif // defined(LIBPROTOC_EXPORTS)
  399. #elif defined(PROTOBUF_USE_DLLS) && defined(LIBPROTOBUF_EXPORTS)
  400. # define PROTOC_EXPORT __attribute__((visibility("default")))
  401. #else
  402. # define PROTOC_EXPORT
  403. #endif
  404. #if defined(PROTOBUF_PREDICT_TRUE) || defined(PROTOBUF_PREDICT_FALSE)
  405. #error PROTOBUF_PREDICT_(TRUE|FALSE) was previously defined
  406. #endif
  407. #if PROTOBUF_GNUC_MIN(3, 0)
  408. # define PROTOBUF_PREDICT_TRUE(x) (__builtin_expect(false || (x), true))
  409. # define PROTOBUF_PREDICT_FALSE(x) (__builtin_expect(false || (x), false))
  410. #else
  411. # define PROTOBUF_PREDICT_TRUE(x) (x)
  412. # define PROTOBUF_PREDICT_FALSE(x) (x)
  413. #endif
  414. #ifdef PROTOBUF_MUST_USE_RESULT
  415. #error PROTOBUF_MUST_USE_RESULT was previously defined
  416. #endif
  417. # define PROTOBUF_MUST_USE_RESULT
  418. #ifdef PROTOBUF_FORCE_COPY_IN_RELEASE
  419. #error PROTOBUF_FORCE_COPY_IN_RELEASE was previously defined
  420. #endif
  421. #ifdef PROTOBUF_FORCE_COPY_IN_SWAP
  422. #error PROTOBUF_FORCE_COPY_IN_SWAP was previously defined
  423. #endif
  424. #ifdef PROTOBUF_FORCE_COPY_IN_MOVE
  425. #error PROTOBUF_FORCE_COPY_IN_MOVE was previously defined
  426. #endif
  427. #ifdef PROTOBUF_FALLTHROUGH_INTENDED
  428. #error PROTOBUF_FALLTHROUGH_INTENDED was previously defined
  429. #endif
  430. #if __has_cpp_attribute(fallthrough)
  431. #define PROTOBUF_FALLTHROUGH_INTENDED [[fallthrough]]
  432. #elif __has_feature(cxx_attributes) && __has_warning("-Wimplicit-fallthrough")
  433. #define PROTOBUF_FALLTHROUGH_INTENDED [[clang::fallthrough]]
  434. #elif PROTOBUF_GNUC_MIN(7, 0)
  435. #define PROTOBUF_FALLTHROUGH_INTENDED [[gnu::fallthrough]]
  436. #else
  437. #define PROTOBUF_FALLTHROUGH_INTENDED
  438. #endif
  439. // PROTOBUF_ASSUME(pred) tells the compiler that it can assume pred is true. To
  440. // be safe, we also validate the assumption with a GOOGLE_DCHECK in unoptimized
  441. // builds. The macro does not do anything useful if the compiler does not
  442. // support __builtin_assume.
  443. #ifdef PROTOBUF_ASSUME
  444. #error PROTOBUF_ASSUME was previously defined
  445. #endif
  446. #if __has_builtin(__builtin_assume)
  447. #define PROTOBUF_ASSUME(pred) \
  448. GOOGLE_DCHECK(pred); \
  449. __builtin_assume(pred)
  450. #else
  451. #define PROTOBUF_ASSUME(pred) GOOGLE_DCHECK(pred)
  452. #endif
  453. // Specify memory alignment for structs, classes, etc.
  454. // Use like:
  455. // class PROTOBUF_ALIGNAS(16) MyClass { ... }
  456. // PROTOBUF_ALIGNAS(16) int array[4];
  457. //
  458. // In most places you can use the C++11 keyword "alignas", which is preferred.
  459. //
  460. // But compilers have trouble mixing __attribute__((...)) syntax with
  461. // alignas(...) syntax.
  462. //
  463. // Doesn't work in clang or gcc:
  464. // struct alignas(16) __attribute__((packed)) S { char c; };
  465. // Works in clang but not gcc:
  466. // struct __attribute__((packed)) alignas(16) S2 { char c; };
  467. // Works in clang and gcc:
  468. // struct alignas(16) S3 { char c; } __attribute__((packed));
  469. //
  470. // There are also some attributes that must be specified *before* a class
  471. // definition: visibility (used for exporting functions/classes) is one of
  472. // these attributes. This means that it is not possible to use alignas() with a
  473. // class that is marked as exported.
  474. #ifdef PROTOBUF_ALIGNAS
  475. #error PROTOBUF_ALIGNAS was previously defined
  476. #endif
  477. #if defined(_MSC_VER)
  478. #define PROTOBUF_ALIGNAS(byte_alignment) __declspec(align(byte_alignment))
  479. #elif PROTOBUF_GNUC_MIN(3, 0)
  480. #define PROTOBUF_ALIGNAS(byte_alignment) \
  481. __attribute__((aligned(byte_alignment)))
  482. #else
  483. #define PROTOBUF_ALIGNAS(byte_alignment) alignas(byte_alignment)
  484. #endif
  485. #ifdef PROTOBUF_FINAL
  486. #error PROTOBUF_FINAL was previously defined
  487. #endif
  488. #define PROTOBUF_FINAL final
  489. #ifdef PROTOBUF_THREAD_LOCAL
  490. #error PROTOBUF_THREAD_LOCAL was previously defined
  491. #endif
  492. #if defined(_MSC_VER)
  493. #define PROTOBUF_THREAD_LOCAL __declspec(thread)
  494. #else
  495. #define PROTOBUF_THREAD_LOCAL __thread
  496. #endif
  497. // For enabling message owned arena, one major blocker is semantic change from
  498. // moving to copying when there is ownership transfer (e.g., move ctor, swap,
  499. // set allocated, release). This change not only causes performance regression
  500. // but also breaks users code (e.g., dangling reference). For top-level
  501. // messages, since it owns the arena, we can mitigate the issue by transferring
  502. // ownership of arena. However, we cannot do that for nested messages. In order
  503. // to tell how many usages of nested messages affected by message owned arena,
  504. // we need to simulate the arena ownership.
  505. // This experiment is purely for the purpose of gathering data. All code guarded
  506. // by this flag is supposed to be removed after this experiment.
  507. #define PROTOBUF_MESSAGE_OWNED_ARENA_EXPERIMENT
  508. #ifdef PROTOBUF_CONSTINIT
  509. #error PROTOBUF_CONSTINIT was previously defined
  510. #endif
  511. #if defined(__cpp_constinit) && !PROTOBUF_GNUC_MIN(3, 0) && !defined(_MSC_VER)
  512. // Our use of constinit does not yet work with GCC:
  513. // https://github.com/protocolbuffers/protobuf/issues/8310
  514. // Does not work yet with Visual Studio 2019 Update 16.10
  515. #define PROTOBUF_CONSTINIT constinit
  516. #elif __has_cpp_attribute(clang::require_constant_initialization)
  517. #define PROTOBUF_CONSTINIT [[clang::require_constant_initialization]]
  518. #else
  519. #define PROTOBUF_CONSTINIT
  520. #endif
  521. // Some globals with an empty non-trivial destructor are annotated with
  522. // no_destroy for performance reasons. It reduces the cost of these globals in
  523. // non-opt mode and under sanitizers.
  524. #ifdef PROTOBUF_ATTRIBUTE_NO_DESTROY
  525. #error PROTOBUF_ATTRIBUTE_NO_DESTROY was previously defined
  526. #endif
  527. #if __has_cpp_attribute(clang::no_destroy)
  528. #define PROTOBUF_ATTRIBUTE_NO_DESTROY [[clang::no_destroy]]
  529. #else
  530. #define PROTOBUF_ATTRIBUTE_NO_DESTROY
  531. #endif
  532. // Protobuf extensions and reflection require registration of the protos linked
  533. // in the binary. Not until everything is registered does the runtime have a
  534. // complete view on all protos. When code is using reflection or extensions
  535. // in between registration calls this can lead to surprising behavior. By
  536. // having the registration run first we mitigate this scenario.
  537. // Highest priority is 101. We use 102 to allow code that really wants to
  538. // higher priority to still beat us.
  539. #ifdef PROTOBUF_ATTRIBUTE_INIT_PRIORITY
  540. #error PROTOBUF_ATTRIBUTE_INIT_PRIORITY was previously defined
  541. #endif
  542. #if PROTOBUF_GNUC_MIN(3, 0) && (!defined(__APPLE__) || defined(__clang__))
  543. #define PROTOBUF_ATTRIBUTE_INIT_PRIORITY __attribute__((init_priority((102))))
  544. #else
  545. #define PROTOBUF_ATTRIBUTE_INIT_PRIORITY
  546. #endif
  547. #ifdef PROTOBUF_PRAGMA_INIT_SEG
  548. #error PROTOBUF_PRAGMA_INIT_SEG was previously defined
  549. #endif
  550. #if _MSC_VER
  551. #define PROTOBUF_PRAGMA_INIT_SEG __pragma(init_seg(lib))
  552. #else
  553. #define PROTOBUF_PRAGMA_INIT_SEG
  554. #endif
  555. #ifdef PROTOBUF_ATTRIBUTE_WEAK
  556. #error PROTOBUF_ATTRIBUTE_WEAK was previously defined
  557. #endif
  558. #if __has_attribute(weak) && \
  559. !defined(__APPLE__) && \
  560. (!defined(_WIN32) || __clang_major__ < 9) && \
  561. !defined(__MINGW32__)
  562. #define PROTOBUF_ATTRIBUTE_WEAK __attribute__((weak))
  563. #define PROTOBUF_HAVE_ATTRIBUTE_WEAK 1
  564. #else
  565. #define PROTOBUF_ATTRIBUTE_WEAK
  566. #define PROTOBUF_HAVE_ATTRIBUTE_WEAK 0
  567. #endif
  568. // Macros to detect sanitizers.
  569. #ifdef PROTOBUF_ASAN
  570. #error PROTOBUF_ASAN was previously defined
  571. #endif
  572. #ifdef PROTOBUF_MSAN
  573. #error PROTOBUF_MSAN was previously defined
  574. #endif
  575. #ifdef PROTOBUF_TSAN
  576. #error PROTOBUF_TSAN was previously defined
  577. #endif
  578. #if defined(__clang__)
  579. # if __has_feature(address_sanitizer)
  580. # define PROTOBUF_ASAN 1
  581. # endif
  582. # if __has_feature(thread_sanitizer)
  583. # define PROTOBUF_TSAN 1
  584. # endif
  585. # if __has_feature(memory_sanitizer)
  586. # define PROTOBUF_MSAN 1
  587. # endif
  588. #elif PROTOBUF_GNUC_MIN(3, 0)
  589. # define PROTOBUF_ASAN __SANITIZE_ADDRESS__
  590. # define PROTOBUF_TSAN __SANITIZE_THREAD__
  591. #endif
  592. // Tail call table-driven parsing can be enabled by defining
  593. // PROTOBUF_EXPERIMENTAL_USE_TAIL_CALL_TABLE_PARSER at compilation time. Note
  594. // that this macro is for small-scale testing only, and is not supported.
  595. #ifdef PROTOBUF_TAIL_CALL_TABLE_PARSER_ENABLED
  596. #error PROTOBUF_TAIL_CALL_TABLE_PARSER_ENABLED was previously declared
  597. #endif
  598. #if defined(PROTOBUF_EXPERIMENTAL_USE_TAIL_CALL_TABLE_PARSER)
  599. #define PROTOBUF_TAIL_CALL_TABLE_PARSER_ENABLED 1
  600. // Selectively use static member functions instead of templates:
  601. #ifndef PROTOBUF_TC_STATIC_PARSE_SINGULAR1
  602. # define PROTOBUF_TC_STATIC_PARSE_SINGULAR1 1
  603. #endif
  604. #ifndef PROTOBUF_TC_STATIC_PARSE_SINGULAR2
  605. # define PROTOBUF_TC_STATIC_PARSE_SINGULAR2 0
  606. #endif
  607. #ifndef PROTOBUF_TC_STATIC_PARSE_REPEATED1
  608. # define PROTOBUF_TC_STATIC_PARSE_REPEATED1 0
  609. #endif
  610. #ifndef PROTOBUF_TC_STATIC_PARSE_REPEATED2
  611. # define PROTOBUF_TC_STATIC_PARSE_REPEATED2 0
  612. #endif
  613. #endif
  614. #define PROTOBUF_TC_PARAM_DECL \
  615. ::google::protobuf::MessageLite *msg, const char *ptr, \
  616. ::google::protobuf::internal::ParseContext *ctx, \
  617. const ::google::protobuf::internal::TailCallParseTableBase *table, \
  618. uint64_t hasbits, ::google::protobuf::internal::TcFieldData data
  619. #ifdef PROTOBUF_UNUSED
  620. #error PROTOBUF_UNUSED was previously defined
  621. #endif
  622. #if __has_cpp_attribute(maybe_unused) || \
  623. (PROTOBUF_MSC_VER_MIN(1911) && PROTOBUF_CPLUSPLUS_MIN(201703L))
  624. #define PROTOBUF_UNUSED [[maybe_unused]]
  625. #elif __has_attribute(unused) || PROTOBUF_GNUC_MIN(3, 0)
  626. #define PROTOBUF_UNUSED __attribute__((__unused__))
  627. #else
  628. #define PROTOBUF_UNUSED
  629. #endif
  630. // Windows declares several inconvenient macro names. We #undef them and then
  631. // restore them in port_undef.inc.
  632. #ifdef _MSC_VER
  633. #pragma push_macro("CREATE_NEW")
  634. #undef CREATE_NEW
  635. #pragma push_macro("DELETE")
  636. #undef DELETE
  637. #pragma push_macro("DOUBLE_CLICK")
  638. #undef DOUBLE_CLICK
  639. #pragma push_macro("ERROR")
  640. #undef ERROR
  641. #pragma push_macro("ERROR_BUSY")
  642. #undef ERROR_BUSY
  643. #pragma push_macro("ERROR_INSTALL_FAILED")
  644. #undef ERROR_INSTALL_FAILED
  645. #pragma push_macro("ERROR_NOT_FOUND")
  646. #undef ERROR_NOT_FOUND
  647. #pragma push_macro("GetMessage")
  648. #undef GetMessage
  649. #pragma push_macro("IGNORE")
  650. #undef IGNORE
  651. #pragma push_macro("IN")
  652. #undef IN
  653. #pragma push_macro("INPUT_KEYBOARD")
  654. #undef INPUT_KEYBOARD
  655. #pragma push_macro("NO_ERROR")
  656. #undef NO_ERROR
  657. #pragma push_macro("OUT")
  658. #undef OUT
  659. #pragma push_macro("OPTIONAL")
  660. #undef OPTIONAL
  661. #pragma push_macro("min")
  662. #undef min
  663. #pragma push_macro("max")
  664. #undef max
  665. #pragma push_macro("NEAR")
  666. #undef NEAR
  667. #pragma push_macro("NO_DATA")
  668. #undef NO_DATA
  669. #pragma push_macro("REASON_UNKNOWN")
  670. #undef REASON_UNKNOWN
  671. #pragma push_macro("SERVICE_DISABLED")
  672. #undef SERVICE_DISABLED
  673. #pragma push_macro("SEVERITY_ERROR")
  674. #undef SEVERITY_ERROR
  675. #pragma push_macro("STRICT")
  676. #undef STRICT
  677. #pragma push_macro("timezone")
  678. #undef timezone
  679. #endif // _MSC_VER
  680. #if defined(__clang__) || PROTOBUF_GNUC_MIN(3, 0) || defined(_MSC_VER)
  681. // Don't let Objective-C Macros interfere with proto identifiers with the same
  682. // name.
  683. #pragma push_macro("DEBUG")
  684. #undef DEBUG
  685. #endif // defined(__clang__) || PROTOBUF_GNUC_MIN(3, 0) || defined(_MSC_VER)
  686. #if defined(__clang__)
  687. #pragma clang diagnostic push
  688. // TODO(gerbens) ideally we cleanup the code. But a cursory try shows many
  689. // violations. So let's ignore for now.
  690. #pragma clang diagnostic ignored "-Wshorten-64-to-32"
  691. #elif PROTOBUF_GNUC_MIN(3, 0)
  692. // GCC does not allow disabling diagnostics within an expression:
  693. // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60875, so we disable this one
  694. // globally even though it's only used for PROTOBUF_FIELD_OFFSET.
  695. #pragma GCC diagnostic push
  696. #pragma GCC diagnostic ignored "-Winvalid-offsetof"
  697. #endif
  698. // Silence some MSVC warnings in all our code.
  699. #if _MSC_VER
  700. #pragma warning(push)
  701. // For non-trivial unions
  702. #pragma warning(disable : 4582)
  703. #pragma warning(disable : 4583)
  704. // For init_seg(lib)
  705. #pragma warning(disable : 4073)
  706. // To silence the fact that we will pop this push from another file
  707. #pragma warning(disable : 5031)
  708. #endif
  709. // We don't want code outside port_def doing complex testing, so
  710. // remove our portable condition test macros to nudge folks away from
  711. // using it themselves.
  712. #ifdef PROTOBUF_has_cpp_attribute_DEFINED_
  713. # undef __has_cpp_attribute
  714. # undef PROTOBUF_has_cpp_attribute_DEFINED_
  715. #endif
  716. #ifdef PROTOBUF_has_feature_DEFINED_
  717. # undef __has_feature
  718. # undef PROTOBUF_has_feature_DEFINED_
  719. #endif
  720. #ifdef PROTOBUF_has_warning_DEFINED_
  721. # undef __has_warning
  722. # undef PROTOBUF_has_warning_DEFINED_
  723. #endif
  724. #ifdef PROTOBUF_has_attribute_DEFINED_
  725. # undef __has_attribute
  726. # undef PROTOBUF_has_attribute_DEFINED_
  727. #endif
  728. #ifdef PROTOBUF_has_builtin_DEFINED_
  729. # undef __has_builtin
  730. # undef PROTOBUF_has_builtin_DEFINED_
  731. #endif