9cbb7a1db4d9e9f11bbbea852adbb122e8037c9f
[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 # if defined(_WIN64)
32 typedef signed __int64 intptr_t;
33 typedef unsigned __int64 uintptr_t;
34 # else
35 typedef signed __int32 intptr_t;
36 typedef unsigned __int32 uintptr_t;
37 # endif
38 #elif defined(_MSC_VER) // && _MSC_VER >= 1600
39 # include <stdint.h>
40 #else
41 # include <stdint.h>
42 # include <stdbool.h>
43 #endif
44
45 #if !defined(MSGPACK_DLLEXPORT)
46 #if defined(_MSC_VER)
47 # define MSGPACK_DLLEXPORT __declspec(dllexport)
48 #else /* _MSC_VER */
49 # define MSGPACK_DLLEXPORT
50 #endif /* _MSC_VER */
51 #endif
52
53 #ifdef _WIN32
54 # if defined(_KERNEL_MODE)
55 # define _msgpack_atomic_counter_header <ntddk.h>
56 # else
57 # define _msgpack_atomic_counter_header <windows.h>
58 # if !defined(WIN32_LEAN_AND_MEAN)
59 # define WIN32_LEAN_AND_MEAN
60 # endif /* WIN32_LEAN_AND_MEAN */
61 # endif
62 typedef long _msgpack_atomic_counter_t;
63 #if defined(_AMD64_) || defined(_M_X64) || defined(_M_ARM64)
64 # define _msgpack_sync_decr_and_fetch(ptr) _InterlockedDecrement(ptr)
65 # define _msgpack_sync_incr_and_fetch(ptr) _InterlockedIncrement(ptr)
66 #else
67 # define _msgpack_sync_decr_and_fetch(ptr) InterlockedDecrement(ptr)
68 # define _msgpack_sync_incr_and_fetch(ptr) InterlockedIncrement(ptr)
69 #endif
70 #elif defined(__GNUC__) && ((__GNUC__*10 + __GNUC_MINOR__) < 41)
71
72 # if defined(__cplusplus)
73 # define _msgpack_atomic_counter_header "vendor/msgpack/gcc_atomic.hpp"
74 # else
75 # define _msgpack_atomic_counter_header "vendor/msgpack/gcc_atomic.h"
76 # endif
77
78 #else
79 typedef unsigned int _msgpack_atomic_counter_t;
80 # define _msgpack_sync_decr_and_fetch(ptr) __sync_sub_and_fetch(ptr, 1)
81 # define _msgpack_sync_incr_and_fetch(ptr) __sync_add_and_fetch(ptr, 1)
82 #endif
83
84 #ifdef _WIN32
85
86 # ifdef __cplusplus
87 /* numeric_limits<T>::min,max */
88 # ifdef max
89 # undef max
90 # endif
91 # ifdef min
92 # undef min
93 # endif
94 # endif
95
96 #elif defined(unix) || defined(__unix) || defined(__APPLE__) || defined(__OpenBSD__)
97
98 #include <arpa/inet.h> /* __BYTE_ORDER */
99 # if defined(linux)
100 # include <byteswap.h>
101 # endif
102
103 #endif
104
105 #if !defined(MSGPACK_ENDIAN_LITTLE_BYTE) && !defined(MSGPACK_ENDIAN_BIG_BYTE)
106 #include <msgpack/predef/other/endian.h>
107 #endif // !defined(MSGPACK_ENDIAN_LITTLE_BYTE) && !defined(MSGPACK_ENDIAN_BIG_BYTE)
108
109 #if MSGPACK_ENDIAN_LITTLE_BYTE
110
111 # if defined(unix) || defined(__unix) || defined(__APPLE__) || defined(__OpenBSD__)
112 # define _msgpack_be16(x) ntohs((uint16_t)x)
113 # else
114 # if defined(ntohs)
115 # define _msgpack_be16(x) ntohs(x)
116 # elif defined(_byteswap_ushort) || (defined(_MSC_VER) && _MSC_VER >= 1400)
117 # define _msgpack_be16(x) ((uint16_t)_byteswap_ushort((unsigned short)x))
118 # else
119 # define _msgpack_be16(x) ( \
120 ((((uint16_t)x) << 8) ) | \
121 ((((uint16_t)x) >> 8) ) )
122 # endif
123 # endif
124
125 # if defined(unix) || defined(__unix) || defined(__APPLE__) || defined(__OpenBSD__)
126 # define _msgpack_be32(x) ntohl((uint32_t)x)
127 # else
128 # if defined(ntohl)
129 # define _msgpack_be32(x) ntohl(x)
130 # elif defined(_byteswap_ulong) || (defined(_MSC_VER) && _MSC_VER >= 1400)
131 # define _msgpack_be32(x) ((uint32_t)_byteswap_ulong((unsigned long)x))
132 # else
133 # define _msgpack_be32(x) \
134 ( ((((uint32_t)x) << 24) ) | \
135 ((((uint32_t)x) << 8) & 0x00ff0000U ) | \
136 ((((uint32_t)x) >> 8) & 0x0000ff00U ) | \
137 ((((uint32_t)x) >> 24) ) )
138 # endif
139 # endif
140
141 # if defined(_byteswap_uint64) || (defined(_MSC_VER) && _MSC_VER >= 1400)
142 # define _msgpack_be64(x) (_byteswap_uint64(x))
143 # elif defined(bswap_64)
144 # define _msgpack_be64(x) bswap_64(x)
145 # elif defined(__DARWIN_OSSwapInt64)
146 # define _msgpack_be64(x) __DARWIN_OSSwapInt64(x)
147 # else
148 # define _msgpack_be64(x) \
149 ( ((((uint64_t)x) << 56) ) | \
150 ((((uint64_t)x) << 40) & 0x00ff000000000000ULL ) | \
151 ((((uint64_t)x) << 24) & 0x0000ff0000000000ULL ) | \
152 ((((uint64_t)x) << 8) & 0x000000ff00000000ULL ) | \
153 ((((uint64_t)x) >> 8) & 0x00000000ff000000ULL ) | \
154 ((((uint64_t)x) >> 24) & 0x0000000000ff0000ULL ) | \
155 ((((uint64_t)x) >> 40) & 0x000000000000ff00ULL ) | \
156 ((((uint64_t)x) >> 56) ) )
157 # endif
158
159 #elif MSGPACK_ENDIAN_BIG_BYTE
160
161 # define _msgpack_be16(x) (x)
162 # define _msgpack_be32(x) (x)
163 # define _msgpack_be64(x) (x)
164
165 #else
166 # error msgpack-c supports only big endian and little endian
167 #endif /* MSGPACK_ENDIAN_LITTLE_BYTE */
168
169 #define _msgpack_load16(cast, from, to) do { \
170 memcpy((cast*)(to), (from), sizeof(cast)); \
171 *(to) = (cast)_msgpack_be16(*(to)); \
172 } while (0);
173
174 #define _msgpack_load32(cast, from, to) do { \
175 memcpy((cast*)(to), (from), sizeof(cast)); \
176 *(to) = (cast)_msgpack_be32(*(to)); \
177 } while (0);
178 #define _msgpack_load64(cast, from, to) do { \
179 memcpy((cast*)(to), (from), sizeof(cast)); \
180 *(to) = (cast)_msgpack_be64(*(to)); \
181 } while (0);
182
183 #define _msgpack_store16(to, num) \
184 do { uint16_t val = _msgpack_be16(num); memcpy(to, &val, 2); } while(0)
185 #define _msgpack_store32(to, num) \
186 do { uint32_t val = _msgpack_be32(num); memcpy(to, &val, 4); } while(0)
187 #define _msgpack_store64(to, num) \
188 do { uint64_t val = _msgpack_be64(num); memcpy(to, &val, 8); } while(0)
189
190 /*
191 #define _msgpack_load16(cast, from) \
192 ({ cast val; memcpy(&val, (char*)from, 2); _msgpack_be16(val); })
193 #define _msgpack_load32(cast, from) \
194 ({ cast val; memcpy(&val, (char*)from, 4); _msgpack_be32(val); })
195 #define _msgpack_load64(cast, from) \
196 ({ cast val; memcpy(&val, (char*)from, 8); _msgpack_be64(val); })
197 */
198
199
200 #if !defined(__cplusplus) && defined(_MSC_VER)
201 # if !defined(_KERNEL_MODE)
202 # if !defined(FALSE)
203 # define FALSE (0)
204 # endif
205 # if !defined(TRUE)
206 # define TRUE (!FALSE)
207 # endif
208 # endif
209 # if _MSC_VER >= 1800
210 # include <stdbool.h>
211 # else
212 # define bool int
213 # define true TRUE
214 # define false FALSE
215 # endif
216 # define inline __inline
217 #endif
218
219 #ifdef __APPLE__
220 # include <TargetConditionals.h>
221 #endif
222
223 #endif /* msgpack/sysdep.h */
This page took 0.035036 seconds and 4 git commands to generate.