blob: 94148e83043cb9b69407f0cae4bc8d7f2a6ec75c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
diff -Nru flatbuffers-1.7.1.orig/include/flatbuffers/base.h flatbuffers-1.7.1/include/flatbuffers/base.h
--- flatbuffers-1.7.1.orig/include/flatbuffers/base.h 2017-06-20 19:42:07.000000001 +0300
+++ flatbuffers-1.7.1/include/flatbuffers/base.h 2017-11-02 21:13:40.659530321 +0300
@@ -150,6 +150,41 @@
// We support aligning the contents of buffers up to this size.
#define FLATBUFFERS_MAX_ALIGNMENT 16
+template<typename T> T EndianSwap(T t) {
+ #if defined(_MSC_VER)
+ #define FLATBUFFERS_BYTESWAP16(x) \
+ static_cast<uint16_t>(_byteswap_ushort(static_cast<uint16_t>(x)))
+ #define FLATBUFFERS_BYTESWAP32(x) \
+ static_cast<uint32_t>(_byteswap_ulong(static_cast<uint32_t>(x)))
+ #define FLATBUFFERS_BYTESWAP64(x) \
+ static_cast<uint64_t>(_byteswap_uint64(static_cast<uint64_t>(x)))
+ #else
+ #if defined(__GNUC__) && __GNUC__ * 100 + __GNUC_MINOR__ < 408
+ // __builtin_bswap16 was missing prior to GCC 4.8.
+ #define FLATBUFFERS_BYTESWAP16(x) \
+ static_cast<uint16_t>(__builtin_bswap32(static_cast<uint32_t>(x) << 16))
+ #else
+ #define FLATBUFFERS_BYTESWAP16(x) \
+ static_cast<uint16_t>(__builtin_bswap16(static_cast<uint16_t>(x)))
+ #endif
+ #define FLATBUFFERS_BYTESWAP32(x) \
+ static_cast<uint32_t>(__builtin_bswap32(static_cast<uint32_t>(x)))
+ #define FLATBUFFERS_BYTESWAP64(x) \
+ static_cast<uint64_t>(__builtin_bswap64(static_cast<uint64_t>(x)))
+ #endif
+ if (sizeof(T) == 1) { // Compile-time if-then's.
+ return t;
+ } else if (sizeof(T) == 2) {
+ return FLATBUFFERS_BYTESWAP16(t);
+ } else if (sizeof(T) == 4) {
+ return FLATBUFFERS_BYTESWAP32(t);
+ } else if (sizeof(T) == 8) {
+ return FLATBUFFERS_BYTESWAP64(t);
+ } else {
+ assert(0);
+ }
+}
+
template<typename T> T EndianScalar(T t) {
#if FLATBUFFERS_LITTLEENDIAN
return t;
diff -Nru flatbuffers-1.7.1.orig/include/flatbuffers/flatbuffers.h flatbuffers-1.7.1/include/flatbuffers/flatbuffers.h
--- flatbuffers-1.7.1.orig/include/flatbuffers/flatbuffers.h 2017-06-20 19:42:07.000000001 +0300
+++ flatbuffers-1.7.1/include/flatbuffers/flatbuffers.h 2017-11-02 21:13:32.271527753 +0300
@@ -37,38 +37,6 @@
(void)endiantest;
}
-template<typename T> T EndianSwap(T t) {
- #if defined(_MSC_VER)
- #define FLATBUFFERS_BYTESWAP16 _byteswap_ushort
- #define FLATBUFFERS_BYTESWAP32 _byteswap_ulong
- #define FLATBUFFERS_BYTESWAP64 _byteswap_uint64
- #else
- #if defined(__GNUC__) && __GNUC__ * 100 + __GNUC_MINOR__ < 408
- // __builtin_bswap16 was missing prior to GCC 4.8.
- #define FLATBUFFERS_BYTESWAP16(x) \
- static_cast<uint16_t>(__builtin_bswap32(static_cast<uint32_t>(x) << 16))
- #else
- #define FLATBUFFERS_BYTESWAP16 __builtin_bswap16
- #endif
- #define FLATBUFFERS_BYTESWAP32 __builtin_bswap32
- #define FLATBUFFERS_BYTESWAP64 __builtin_bswap64
- #endif
- if (sizeof(T) == 1) { // Compile-time if-then's.
- return t;
- } else if (sizeof(T) == 2) {
- auto r = FLATBUFFERS_BYTESWAP16(*reinterpret_cast<uint16_t *>(&t));
- return *reinterpret_cast<T *>(&r);
- } else if (sizeof(T) == 4) {
- auto r = FLATBUFFERS_BYTESWAP32(*reinterpret_cast<uint32_t *>(&t));
- return *reinterpret_cast<T *>(&r);
- } else if (sizeof(T) == 8) {
- auto r = FLATBUFFERS_BYTESWAP64(*reinterpret_cast<uint64_t *>(&t));
- return *reinterpret_cast<T *>(&r);
- } else {
- assert(0);
- }
-}
-
template<typename T> FLATBUFFERS_CONSTEXPR size_t AlignOf() {
#ifdef _MSC_VER
return __alignof(T);
|