sessiond: Add msgpack-c 3.3.0 to the tree
[lttng-tools.git] / src / vendor / msgpack / sysdep.h
1 /*
2 * MessagePack system dependencies
3 *
4 * Copyright (C) 2008-2010 FURUHASHI Sadayuki
5 *
6 * Distributed under the Boost Software License, Version 1.0.
7 * (See accompanying file LICENSE_1_0.txt or copy at
8 * http://www.boost.org/LICENSE_1_0.txt)
9 */
10 #ifndef MSGPACK_SYSDEP_H
11 #define MSGPACK_SYSDEP_H
12
13 #include <stdlib.h>
14 #include <stddef.h>
15
16 #include "vendor/msgpack/lttng-config.h"
17
18 #if defined(_MSC_VER) && _MSC_VER <= 1800
19 # define snprintf(buf, len, format,...) _snprintf_s(buf, len, _TRUNCATE, format, __VA_ARGS__)
20 #endif
21
22 #if defined(_MSC_VER) && _MSC_VER < 1600
23 typedef signed __int8 int8_t;
24 typedef unsigned __int8 uint8_t;
25 typedef signed __int16 int16_t;
26 typedef unsigned __int16 uint16_t;
27 typedef signed __int32 int32_t;
28 typedef unsigned __int32 uint32_t;
29 typedef signed __int64 int64_t;
30 typedef unsigned __int64 uint64_t;
31 #elif defined(_MSC_VER) // && _MSC_VER >= 1600
32 # include <stdint.h>
33 #else
34 # include <stdint.h>
35 # include <stdbool.h>
36 #endif
37
38 #if !defined(MSGPACK_DLLEXPORT)
39 #if defined(_MSC_VER)
40 # define MSGPACK_DLLEXPORT __declspec(dllexport)
41 #else /* _MSC_VER */
42 # define MSGPACK_DLLEXPORT
43 #endif /* _MSC_VER */
44 #endif
45
46 #ifdef _WIN32
47 # if defined(_KERNEL_MODE)
48 # define _msgpack_atomic_counter_header <ntddk.h>
49 # else
50 # define _msgpack_atomic_counter_header <windows.h>
51 # if !defined(WIN32_LEAN_AND_MEAN)
52 # define WIN32_LEAN_AND_MEAN
53 # endif /* WIN32_LEAN_AND_MEAN */
54 # endif
55 typedef long _msgpack_atomic_counter_t;
56 #if defined(_AMD64_) || defined(_M_X64) || defined(_M_ARM64)
57 # define _msgpack_sync_decr_and_fetch(ptr) _InterlockedDecrement(ptr)
58 # define _msgpack_sync_incr_and_fetch(ptr) _InterlockedIncrement(ptr)
59 #else
60 # define _msgpack_sync_decr_and_fetch(ptr) InterlockedDecrement(ptr)
61 # define _msgpack_sync_incr_and_fetch(ptr) InterlockedIncrement(ptr)
62 #endif
63 #elif defined(__GNUC__) && ((__GNUC__*10 + __GNUC_MINOR__) < 41)
64
65 # if defined(__cplusplus)
66 # define _msgpack_atomic_counter_header "vendor/msgpack/gcc_atomic.hpp"
67 # else
68 # define _msgpack_atomic_counter_header "vendor/msgpack/gcc_atomic.h"
69 # endif
70
71 #else
72 typedef unsigned int _msgpack_atomic_counter_t;
73 # define _msgpack_sync_decr_and_fetch(ptr) __sync_sub_and_fetch(ptr, 1)
74 # define _msgpack_sync_incr_and_fetch(ptr) __sync_add_and_fetch(ptr, 1)
75 #endif
76
77 #ifdef _WIN32
78
79 # ifdef __cplusplus
80 /* numeric_limits<T>::min,max */
81 # ifdef max
82 # undef max
83 # endif
84 # ifdef min
85 # undef min
86 # endif
87 # endif
88
89 #elif defined(unix) || defined(__unix) || defined(__APPLE__) || defined(__OpenBSD__)
90
91 #include <arpa/inet.h> /* __BYTE_ORDER */
92 # if defined(linux)
93 # include <byteswap.h>
94 # endif
95
96 #endif
97
98 #if !defined(MSGPACK_ENDIAN_LITTLE_BYTE) && !defined(MSGPACK_ENDIAN_BIG_BYTE)
99 #include <msgpack/predef/other/endian.h>
100 #endif // !defined(MSGPACK_ENDIAN_LITTLE_BYTE) && !defined(MSGPACK_ENDIAN_BIG_BYTE)
101
102 #if MSGPACK_ENDIAN_LITTLE_BYTE
103
104 # if defined(unix) || defined(__unix) || defined(__APPLE__) || defined(__OpenBSD__)
105 # define _msgpack_be16(x) ntohs((uint16_t)x)
106 # else
107 # if defined(ntohs)
108 # define _msgpack_be16(x) ntohs(x)
109 # elif defined(_byteswap_ushort) || (defined(_MSC_VER) && _MSC_VER >= 1400)
110 # define _msgpack_be16(x) ((uint16_t)_byteswap_ushort((unsigned short)x))
111 # else
112 # define _msgpack_be16(x) ( \
113 ((((uint16_t)x) << 8) ) | \
114 ((((uint16_t)x) >> 8) ) )
115 # endif
116 # endif
117
118 # if defined(unix) || defined(__unix) || defined(__APPLE__) || defined(__OpenBSD__)
119 # define _msgpack_be32(x) ntohl((uint32_t)x)
120 # else
121 # if defined(ntohl)
122 # define _msgpack_be32(x) ntohl(x)
123 # elif defined(_byteswap_ulong) || (defined(_MSC_VER) && _MSC_VER >= 1400)
124 # define _msgpack_be32(x) ((uint32_t)_byteswap_ulong((unsigned long)x))
125 # else
126 # define _msgpack_be32(x) \
127 ( ((((uint32_t)x) << 24) ) | \
128 ((((uint32_t)x) << 8) & 0x00ff0000U ) | \
129 ((((uint32_t)x) >> 8) & 0x0000ff00U ) | \
130 ((((uint32_t)x) >> 24) ) )
131 # endif
132 # endif
133
134 # if defined(_byteswap_uint64) || (defined(_MSC_VER) && _MSC_VER >= 1400)
135 # define _msgpack_be64(x) (_byteswap_uint64(x))
136 # elif defined(bswap_64)
137 # define _msgpack_be64(x) bswap_64(x)
138 # elif defined(__DARWIN_OSSwapInt64)
139 # define _msgpack_be64(x) __DARWIN_OSSwapInt64(x)
140 # else
141 # define _msgpack_be64(x) \
142 ( ((((uint64_t)x) << 56) ) | \
143 ((((uint64_t)x) << 40) & 0x00ff000000000000ULL ) | \
144 ((((uint64_t)x) << 24) & 0x0000ff0000000000ULL ) | \
145 ((((uint64_t)x) << 8) & 0x000000ff00000000ULL ) | \
146 ((((uint64_t)x) >> 8) & 0x00000000ff000000ULL ) | \
147 ((((uint64_t)x) >> 24) & 0x0000000000ff0000ULL ) | \
148 ((((uint64_t)x) >> 40) & 0x000000000000ff00ULL ) | \
149 ((((uint64_t)x) >> 56) ) )
150 # endif
151
152 #elif MSGPACK_ENDIAN_BIG_BYTE
153
154 # define _msgpack_be16(x) (x)
155 # define _msgpack_be32(x) (x)
156 # define _msgpack_be64(x) (x)
157
158 #else
159 # error msgpack-c supports only big endian and little endian
160 #endif /* MSGPACK_ENDIAN_LITTLE_BYTE */
161
162 #define _msgpack_load16(cast, from, to) do { \
163 memcpy((cast*)(to), (from), sizeof(cast)); \
164 *(to) = (cast)_msgpack_be16(*(to)); \
165 } while (0);
166
167 #define _msgpack_load32(cast, from, to) do { \
168 memcpy((cast*)(to), (from), sizeof(cast)); \
169 *(to) = (cast)_msgpack_be32(*(to)); \
170 } while (0);
171 #define _msgpack_load64(cast, from, to) do { \
172 memcpy((cast*)(to), (from), sizeof(cast)); \
173 *(to) = (cast)_msgpack_be64(*(to)); \
174 } while (0);
175
176 #define _msgpack_store16(to, num) \
177 do { uint16_t val = _msgpack_be16(num); memcpy(to, &val, 2); } while(0)
178 #define _msgpack_store32(to, num) \
179 do { uint32_t val = _msgpack_be32(num); memcpy(to, &val, 4); } while(0)
180 #define _msgpack_store64(to, num) \
181 do { uint64_t val = _msgpack_be64(num); memcpy(to, &val, 8); } while(0)
182
183 /*
184 #define _msgpack_load16(cast, from) \
185 ({ cast val; memcpy(&val, (char*)from, 2); _msgpack_be16(val); })
186 #define _msgpack_load32(cast, from) \
187 ({ cast val; memcpy(&val, (char*)from, 4); _msgpack_be32(val); })
188 #define _msgpack_load64(cast, from) \
189 ({ cast val; memcpy(&val, (char*)from, 8); _msgpack_be64(val); })
190 */
191
192
193 #if !defined(__cplusplus) && defined(_MSC_VER)
194 # if !defined(_KERNEL_MODE)
195 # if !defined(FALSE)
196 # define FALSE (0)
197 # endif
198 # if !defined(TRUE)
199 # define TRUE (!FALSE)
200 # endif
201 # endif
202 # if _MSC_VER >= 1800
203 # include <stdbool.h>
204 # else
205 # define bool int
206 # define true TRUE
207 # define false FALSE
208 # endif
209 # define inline __inline
210 #endif
211
212 #ifdef __APPLE__
213 # include <TargetConditionals.h>
214 #endif
215
216 #endif /* msgpack/sysdep.h */
This page took 0.046932 seconds and 4 git commands to generate.