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