port.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542
  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. #ifndef GOOGLE_PROTOBUF_STUBS_PORT_H_
  31. #define GOOGLE_PROTOBUF_STUBS_PORT_H_
  32. #include <assert.h>
  33. #include <stdlib.h>
  34. #include <cstddef>
  35. #include <string>
  36. #include <string.h>
  37. #if defined(__osf__)
  38. // Tru64 lacks stdint.h, but has inttypes.h which defines a superset of
  39. // what stdint.h would define.
  40. #include <inttypes.h>
  41. #elif !defined(_MSC_VER)
  42. #include <stdint.h>
  43. #endif
  44. #include <google/protobuf/stubs/platform_macros.h>
  45. #undef PROTOBUF_LITTLE_ENDIAN
  46. #ifdef _WIN32
  47. // Assuming windows is always little-endian.
  48. // TODO(xiaofeng): The PROTOBUF_LITTLE_ENDIAN is not only used for
  49. // optimization but also for correctness. We should define an
  50. // different macro to test the big-endian code path in coded_stream.
  51. #if !defined(PROTOBUF_DISABLE_LITTLE_ENDIAN_OPT_FOR_TEST)
  52. #define PROTOBUF_LITTLE_ENDIAN 1
  53. #endif
  54. #if _MSC_VER >= 1300 && !defined(__INTEL_COMPILER)
  55. // If MSVC has "/RTCc" set, it will complain about truncating casts at
  56. // runtime. This file contains some intentional truncating casts.
  57. #pragma runtime_checks("c", off)
  58. #endif
  59. #else
  60. #include <sys/param.h> // __BYTE_ORDER
  61. #if defined(__OpenBSD__)
  62. #include <endian.h>
  63. #endif
  64. #if ((defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)) || \
  65. (defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN) || \
  66. (defined(BYTE_ORDER) && BYTE_ORDER == LITTLE_ENDIAN)) && \
  67. !defined(PROTOBUF_DISABLE_LITTLE_ENDIAN_OPT_FOR_TEST)
  68. #define PROTOBUF_LITTLE_ENDIAN 1
  69. #endif
  70. #endif
  71. #if defined(_MSC_VER) && defined(PROTOBUF_USE_DLLS)
  72. #ifdef LIBPROTOBUF_EXPORTS
  73. #define LIBPROTOBUF_EXPORT __declspec(dllexport)
  74. #else
  75. #define LIBPROTOBUF_EXPORT __declspec(dllimport)
  76. #endif
  77. #ifdef LIBPROTOC_EXPORTS
  78. #define LIBPROTOC_EXPORT __declspec(dllexport)
  79. #else
  80. #define LIBPROTOC_EXPORT __declspec(dllimport)
  81. #endif
  82. #else
  83. #define LIBPROTOBUF_EXPORT
  84. #define LIBPROTOC_EXPORT
  85. #endif
  86. // These #includes are for the byte swap functions declared later on.
  87. #ifdef _MSC_VER
  88. #include <stdlib.h> // NOLINT(build/include)
  89. #include <intrin.h>
  90. #elif defined(__APPLE__)
  91. #include <libkern/OSByteOrder.h>
  92. #elif defined(__GLIBC__) || defined(__BIONIC__) || defined(__CYGWIN__)
  93. #include <byteswap.h> // IWYU pragma: export
  94. #endif
  95. #define PROTOBUF_RUNTIME_DEPRECATED(message)
  96. // ===================================================================
  97. // from google3/base/port.h
  98. #if (defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L || \
  99. (defined(_MSC_VER) && _MSC_VER >= 1900))
  100. // Define this to 1 if the code is compiled in C++11 mode; leave it
  101. // undefined otherwise. Do NOT define it to 0 -- that causes
  102. // '#ifdef LANG_CXX11' to behave differently from '#if LANG_CXX11'.
  103. #define LANG_CXX11 1
  104. #endif
  105. #if LANG_CXX11 && !defined(__NVCC__)
  106. #define PROTOBUF_CXX11 1
  107. #else
  108. #define PROTOBUF_CXX11 0
  109. #endif
  110. #if PROTOBUF_CXX11
  111. #define PROTOBUF_FINAL final
  112. #else
  113. #define PROTOBUF_FINAL
  114. #endif
  115. namespace google {
  116. namespace protobuf {
  117. typedef unsigned int uint;
  118. #ifdef _MSC_VER
  119. typedef signed __int8 int8;
  120. typedef __int16 int16;
  121. typedef __int32 int32;
  122. typedef __int64 int64;
  123. typedef unsigned __int8 uint8;
  124. typedef unsigned __int16 uint16;
  125. typedef unsigned __int32 uint32;
  126. typedef unsigned __int64 uint64;
  127. #else
  128. typedef int8_t int8;
  129. typedef int16_t int16;
  130. typedef int32_t int32;
  131. typedef int64_t int64;
  132. typedef uint8_t uint8;
  133. typedef uint16_t uint16;
  134. typedef uint32_t uint32;
  135. typedef uint64_t uint64;
  136. #endif
  137. // long long macros to be used because gcc and vc++ use different suffixes,
  138. // and different size specifiers in format strings
  139. #undef GOOGLE_LONGLONG
  140. #undef GOOGLE_ULONGLONG
  141. #undef GOOGLE_LL_FORMAT
  142. #ifdef _MSC_VER
  143. #define GOOGLE_LONGLONG(x) x##I64
  144. #define GOOGLE_ULONGLONG(x) x##UI64
  145. #define GOOGLE_LL_FORMAT "I64" // As in printf("%I64d", ...)
  146. #else
  147. // By long long, we actually mean int64.
  148. #define GOOGLE_LONGLONG(x) x##LL
  149. #define GOOGLE_ULONGLONG(x) x##ULL
  150. // Used to format real long long integers.
  151. #define GOOGLE_LL_FORMAT "ll" // As in "%lld". Note that "q" is poor form also.
  152. #endif
  153. static const int32 kint32max = 0x7FFFFFFF;
  154. static const int32 kint32min = -kint32max - 1;
  155. static const int64 kint64max = GOOGLE_LONGLONG(0x7FFFFFFFFFFFFFFF);
  156. static const int64 kint64min = -kint64max - 1;
  157. static const uint32 kuint32max = 0xFFFFFFFFu;
  158. static const uint64 kuint64max = GOOGLE_ULONGLONG(0xFFFFFFFFFFFFFFFF);
  159. // -------------------------------------------------------------------
  160. // Annotations: Some parts of the code have been annotated in ways that might
  161. // be useful to some compilers or tools, but are not supported universally.
  162. // You can #define these annotations yourself if the default implementation
  163. // is not right for you.
  164. #ifndef GOOGLE_ATTRIBUTE_ALWAYS_INLINE
  165. #if defined(__GNUC__) && (__GNUC__ > 3 ||(__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
  166. // For functions we want to force inline.
  167. // Introduced in gcc 3.1.
  168. #define GOOGLE_ATTRIBUTE_ALWAYS_INLINE __attribute__ ((always_inline))
  169. #else
  170. // Other compilers will have to figure it out for themselves.
  171. #define GOOGLE_ATTRIBUTE_ALWAYS_INLINE
  172. #endif
  173. #endif
  174. #define GOOGLE_PROTOBUF_ATTRIBUTE_ALWAYS_INLINE GOOGLE_ATTRIBUTE_ALWAYS_INLINE
  175. #ifndef GOOGLE_ATTRIBUTE_NOINLINE
  176. #if defined(__GNUC__) && (__GNUC__ > 3 ||(__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
  177. // For functions we want to force not inline.
  178. // Introduced in gcc 3.1.
  179. #define GOOGLE_ATTRIBUTE_NOINLINE __attribute__ ((noinline))
  180. #elif defined(_MSC_VER) && (_MSC_VER >= 1400)
  181. // Seems to have been around since at least Visual Studio 2005
  182. #define GOOGLE_ATTRIBUTE_NOINLINE __declspec(noinline)
  183. #else
  184. // Other compilers will have to figure it out for themselves.
  185. #define GOOGLE_ATTRIBUTE_NOINLINE
  186. #endif
  187. #endif
  188. #define GOOGLE_PROTOBUF_ATTRIBUTE_NOINLINE GOOGLE_ATTRIBUTE_NOINLINE
  189. #ifndef GOOGLE_ATTRIBUTE_FUNC_ALIGN
  190. #if defined(__clang__) || \
  191. defined(__GNUC__) && (__GNUC__ > 4 ||(__GNUC__ == 4 && __GNUC_MINOR__ >= 3))
  192. // Function alignment attribute introduced in gcc 4.3
  193. #define GOOGLE_ATTRIBUTE_FUNC_ALIGN(bytes) __attribute__ ((aligned(bytes)))
  194. #else
  195. #define GOOGLE_ATTRIBUTE_FUNC_ALIGN(bytes)
  196. #endif
  197. #endif
  198. #define GOOGLE_PROTOBUF_ATTRIBUTE_FUNC_ALIGN(bytes) \
  199. GOOGLE_ATTRIBUTE_FUNC_ALIGN(bytes)
  200. #ifndef GOOGLE_PREDICT_TRUE
  201. #ifdef __GNUC__
  202. // Provided at least since GCC 3.0.
  203. #define GOOGLE_PREDICT_TRUE(x) (__builtin_expect(!!(x), 1))
  204. #else
  205. #define GOOGLE_PREDICT_TRUE(x) (x)
  206. #endif
  207. #endif
  208. #ifndef GOOGLE_PREDICT_FALSE
  209. #ifdef __GNUC__
  210. // Provided at least since GCC 3.0.
  211. #define GOOGLE_PREDICT_FALSE(x) (__builtin_expect(x, 0))
  212. #else
  213. #define GOOGLE_PREDICT_FALSE(x) (x)
  214. #endif
  215. #endif
  216. #ifndef GOOGLE_PROTOBUF_ATTRIBUTE_RETURNS_NONNULL
  217. #ifdef __GNUC__
  218. #define GOOGLE_PROTOBUF_ATTRIBUTE_RETURNS_NONNULL \
  219. __attribute__((returns_nonnull))
  220. #endif
  221. #endif
  222. // Delimits a block of code which may write to memory which is simultaneously
  223. // written by other threads, but which has been determined to be thread-safe
  224. // (e.g. because it is an idempotent write).
  225. #ifndef GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN
  226. #define GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN()
  227. #endif
  228. #ifndef GOOGLE_SAFE_CONCURRENT_WRITES_END
  229. #define GOOGLE_SAFE_CONCURRENT_WRITES_END()
  230. #endif
  231. #define GOOGLE_GUARDED_BY(x)
  232. #define GOOGLE_ATTRIBUTE_COLD
  233. #ifdef GOOGLE_PROTOBUF_DONT_USE_UNALIGNED
  234. # define GOOGLE_PROTOBUF_USE_UNALIGNED 0
  235. #else
  236. # if defined(_M_X64) || defined(__x86_64__) || defined(_M_IX86) || defined(__i386__)
  237. # define GOOGLE_PROTOBUF_USE_UNALIGNED 1
  238. # else
  239. # define GOOGLE_PROTOBUF_USE_UNALIGNED 0
  240. # endif
  241. #endif
  242. #define GOOGLE_PROTOBUF_ATTRIBUTE_COLD GOOGLE_ATTRIBUTE_COLD
  243. #if defined(ADDRESS_SANITIZER) || defined(THREAD_SANITIZER) ||\
  244. defined(MEMORY_SANITIZER)
  245. #ifdef __cplusplus
  246. extern "C" {
  247. #endif // __cplusplus
  248. uint16_t __sanitizer_unaligned_load16(const void *p);
  249. uint32_t __sanitizer_unaligned_load32(const void *p);
  250. uint64_t __sanitizer_unaligned_load64(const void *p);
  251. void __sanitizer_unaligned_store16(void *p, uint16_t v);
  252. void __sanitizer_unaligned_store32(void *p, uint32_t v);
  253. void __sanitizer_unaligned_store64(void *p, uint64_t v);
  254. #ifdef __cplusplus
  255. } // extern "C"
  256. #endif // __cplusplus
  257. inline uint16 GOOGLE_UNALIGNED_LOAD16(const void *p) {
  258. return __sanitizer_unaligned_load16(p);
  259. }
  260. inline uint32 GOOGLE_UNALIGNED_LOAD32(const void *p) {
  261. return __sanitizer_unaligned_load32(p);
  262. }
  263. inline uint64 GOOGLE_UNALIGNED_LOAD64(const void *p) {
  264. return __sanitizer_unaligned_load64(p);
  265. }
  266. inline void GOOGLE_UNALIGNED_STORE16(void *p, uint16 v) {
  267. __sanitizer_unaligned_store16(p, v);
  268. }
  269. inline void GOOGLE_UNALIGNED_STORE32(void *p, uint32 v) {
  270. __sanitizer_unaligned_store32(p, v);
  271. }
  272. inline void GOOGLE_UNALIGNED_STORE64(void *p, uint64 v) {
  273. __sanitizer_unaligned_store64(p, v);
  274. }
  275. #elif GOOGLE_PROTOBUF_USE_UNALIGNED
  276. #define GOOGLE_UNALIGNED_LOAD16(_p) (*reinterpret_cast<const uint16 *>(_p))
  277. #define GOOGLE_UNALIGNED_LOAD32(_p) (*reinterpret_cast<const uint32 *>(_p))
  278. #define GOOGLE_UNALIGNED_LOAD64(_p) (*reinterpret_cast<const uint64 *>(_p))
  279. #define GOOGLE_UNALIGNED_STORE16(_p, _val) (*reinterpret_cast<uint16 *>(_p) = (_val))
  280. #define GOOGLE_UNALIGNED_STORE32(_p, _val) (*reinterpret_cast<uint32 *>(_p) = (_val))
  281. #define GOOGLE_UNALIGNED_STORE64(_p, _val) (*reinterpret_cast<uint64 *>(_p) = (_val))
  282. #else
  283. inline uint16 GOOGLE_UNALIGNED_LOAD16(const void *p) {
  284. uint16 t;
  285. memcpy(&t, p, sizeof t);
  286. return t;
  287. }
  288. inline uint32 GOOGLE_UNALIGNED_LOAD32(const void *p) {
  289. uint32 t;
  290. memcpy(&t, p, sizeof t);
  291. return t;
  292. }
  293. inline uint64 GOOGLE_UNALIGNED_LOAD64(const void *p) {
  294. uint64 t;
  295. memcpy(&t, p, sizeof t);
  296. return t;
  297. }
  298. inline void GOOGLE_UNALIGNED_STORE16(void *p, uint16 v) {
  299. memcpy(p, &v, sizeof v);
  300. }
  301. inline void GOOGLE_UNALIGNED_STORE32(void *p, uint32 v) {
  302. memcpy(p, &v, sizeof v);
  303. }
  304. inline void GOOGLE_UNALIGNED_STORE64(void *p, uint64 v) {
  305. memcpy(p, &v, sizeof v);
  306. }
  307. #endif
  308. #if defined(GOOGLE_PROTOBUF_OS_NACL) \
  309. || (defined(__ANDROID__) && defined(__clang__) \
  310. && (__clang_major__ == 3 && __clang_minor__ == 8) \
  311. && (__clang_patchlevel__ < 275480))
  312. # define GOOGLE_PROTOBUF_USE_PORTABLE_LOG2
  313. #endif
  314. #if defined(_MSC_VER)
  315. #define GOOGLE_THREAD_LOCAL __declspec(thread)
  316. #else
  317. #define GOOGLE_THREAD_LOCAL __thread
  318. #endif
  319. // The following guarantees declaration of the byte swap functions.
  320. #ifdef _MSC_VER
  321. #define bswap_16(x) _byteswap_ushort(x)
  322. #define bswap_32(x) _byteswap_ulong(x)
  323. #define bswap_64(x) _byteswap_uint64(x)
  324. #elif defined(__APPLE__)
  325. // Mac OS X / Darwin features
  326. #define bswap_16(x) OSSwapInt16(x)
  327. #define bswap_32(x) OSSwapInt32(x)
  328. #define bswap_64(x) OSSwapInt64(x)
  329. #elif !defined(__GLIBC__) && !defined(__BIONIC__) && !defined(__CYGWIN__)
  330. static inline uint16 bswap_16(uint16 x) {
  331. return static_cast<uint16>(((x & 0xFF) << 8) | ((x & 0xFF00) >> 8));
  332. }
  333. #define bswap_16(x) bswap_16(x)
  334. static inline uint32 bswap_32(uint32 x) {
  335. return (((x & 0xFF) << 24) |
  336. ((x & 0xFF00) << 8) |
  337. ((x & 0xFF0000) >> 8) |
  338. ((x & 0xFF000000) >> 24));
  339. }
  340. #define bswap_32(x) bswap_32(x)
  341. static inline uint64 bswap_64(uint64 x) {
  342. return (((x & GOOGLE_ULONGLONG(0xFF)) << 56) |
  343. ((x & GOOGLE_ULONGLONG(0xFF00)) << 40) |
  344. ((x & GOOGLE_ULONGLONG(0xFF0000)) << 24) |
  345. ((x & GOOGLE_ULONGLONG(0xFF000000)) << 8) |
  346. ((x & GOOGLE_ULONGLONG(0xFF00000000)) >> 8) |
  347. ((x & GOOGLE_ULONGLONG(0xFF0000000000)) >> 24) |
  348. ((x & GOOGLE_ULONGLONG(0xFF000000000000)) >> 40) |
  349. ((x & GOOGLE_ULONGLONG(0xFF00000000000000)) >> 56));
  350. }
  351. #define bswap_64(x) bswap_64(x)
  352. #endif
  353. // ===================================================================
  354. // from google3/util/bits/bits.h
  355. class Bits {
  356. public:
  357. static uint32 Log2FloorNonZero(uint32 n) {
  358. #if defined(__GNUC__)
  359. return 31 ^ static_cast<uint32>(__builtin_clz(n));
  360. #elif defined(_MSC_VER)
  361. unsigned long where;
  362. _BitScanReverse(&where, n);
  363. return where;
  364. #else
  365. return Log2FloorNonZero_Portable(n);
  366. #endif
  367. }
  368. static uint32 Log2FloorNonZero64(uint64 n) {
  369. // Older versions of clang run into an instruction-selection failure when
  370. // it encounters __builtin_clzll:
  371. // https://bugs.chromium.org/p/nativeclient/issues/detail?id=4395
  372. // This includes arm-nacl-clang and clang in older Android NDK versions.
  373. // To work around this, when we build with those we use the portable
  374. // implementation instead.
  375. #if defined(__GNUC__) && !defined(GOOGLE_PROTOBUF_USE_PORTABLE_LOG2)
  376. return 63 ^ static_cast<uint32>(__builtin_clzll(n));
  377. #elif defined(_MSC_VER) && defined(_M_X64)
  378. unsigned long where;
  379. _BitScanReverse64(&where, n);
  380. return where;
  381. #else
  382. return Log2FloorNonZero64_Portable(n);
  383. #endif
  384. }
  385. private:
  386. static int Log2FloorNonZero_Portable(uint32 n) {
  387. if (n == 0)
  388. return -1;
  389. int log = 0;
  390. uint32 value = n;
  391. for (int i = 4; i >= 0; --i) {
  392. int shift = (1 << i);
  393. uint32 x = value >> shift;
  394. if (x != 0) {
  395. value = x;
  396. log += shift;
  397. }
  398. }
  399. assert(value == 1);
  400. return log;
  401. }
  402. static int Log2FloorNonZero64_Portable(uint64 n) {
  403. const uint32 topbits = static_cast<uint32>(n >> 32);
  404. if (topbits == 0) {
  405. // Top bits are zero, so scan in bottom bits
  406. return static_cast<int>(Log2FloorNonZero(static_cast<uint32>(n)));
  407. } else {
  408. return 32 + static_cast<int>(Log2FloorNonZero(topbits));
  409. }
  410. }
  411. };
  412. // ===================================================================
  413. // from google3/util/endian/endian.h
  414. LIBPROTOBUF_EXPORT uint32 ghtonl(uint32 x);
  415. class BigEndian {
  416. public:
  417. #ifdef PROTOBUF_LITTLE_ENDIAN
  418. static uint16 FromHost16(uint16 x) { return bswap_16(x); }
  419. static uint16 ToHost16(uint16 x) { return bswap_16(x); }
  420. static uint32 FromHost32(uint32 x) { return bswap_32(x); }
  421. static uint32 ToHost32(uint32 x) { return bswap_32(x); }
  422. static uint64 FromHost64(uint64 x) { return bswap_64(x); }
  423. static uint64 ToHost64(uint64 x) { return bswap_64(x); }
  424. static bool IsLittleEndian() { return true; }
  425. #else
  426. static uint16 FromHost16(uint16 x) { return x; }
  427. static uint16 ToHost16(uint16 x) { return x; }
  428. static uint32 FromHost32(uint32 x) { return x; }
  429. static uint32 ToHost32(uint32 x) { return x; }
  430. static uint64 FromHost64(uint64 x) { return x; }
  431. static uint64 ToHost64(uint64 x) { return x; }
  432. static bool IsLittleEndian() { return false; }
  433. #endif /* ENDIAN */
  434. // Functions to do unaligned loads and stores in big-endian order.
  435. static uint16 Load16(const void *p) {
  436. return ToHost16(GOOGLE_UNALIGNED_LOAD16(p));
  437. }
  438. static void Store16(void *p, uint16 v) {
  439. GOOGLE_UNALIGNED_STORE16(p, FromHost16(v));
  440. }
  441. static uint32 Load32(const void *p) {
  442. return ToHost32(GOOGLE_UNALIGNED_LOAD32(p));
  443. }
  444. static void Store32(void *p, uint32 v) {
  445. GOOGLE_UNALIGNED_STORE32(p, FromHost32(v));
  446. }
  447. static uint64 Load64(const void *p) {
  448. return ToHost64(GOOGLE_UNALIGNED_LOAD64(p));
  449. }
  450. static void Store64(void *p, uint64 v) {
  451. GOOGLE_UNALIGNED_STORE64(p, FromHost64(v));
  452. }
  453. };
  454. #ifndef GOOGLE_ATTRIBUTE_SECTION_VARIABLE
  455. #define GOOGLE_ATTRIBUTE_SECTION_VARIABLE(name)
  456. #endif
  457. #define GOOGLE_PROTOBUF_ATTRIBUTE_SECTION_VARIABLE(name)
  458. } // namespace protobuf
  459. } // namespace google
  460. #endif // GOOGLE_PROTOBUF_STUBS_PORT_H_