10 #ifndef MSGPACK_SYSDEP_HPP
11 #define MSGPACK_SYSDEP_HPP
16 #if defined(_MSC_VER) && _MSC_VER <= 1800
17 # define snprintf(buf, len, format,...) _snprintf_s(buf, len, _TRUNCATE, format, __VA_ARGS__)
20 #if defined(_MSC_VER) && _MSC_VER < 1600
21 typedef signed __int8 int8_t;
22 typedef unsigned __int8 uint8_t;
23 typedef signed __int16 int16_t;
24 typedef unsigned __int16 uint16_t;
25 typedef signed __int32 int32_t;
26 typedef unsigned __int32 uint32_t;
27 typedef signed __int64 int64_t;
28 typedef unsigned __int64 uint64_t;
30 typedef signed __int64 intptr_t;
31 typedef unsigned __int64 uintptr_t;
33 typedef signed __int32 intptr_t;
34 typedef unsigned __int32 uintptr_t;
36 #elif defined(_MSC_VER)
43 #if !defined(MSGPACK_DLLEXPORT)
45 # define MSGPACK_DLLEXPORT __declspec(dllexport)
47 # define MSGPACK_DLLEXPORT
52 # if defined(_KERNEL_MODE)
53 # define _msgpack_atomic_counter_header <ntddk.h>
55 # define _msgpack_atomic_counter_header <windows.h>
56 # if !defined(WIN32_LEAN_AND_MEAN)
57 # define WIN32_LEAN_AND_MEAN
61 #if defined(_AMD64_) || defined(_M_X64) || defined(_M_ARM64)
62 # define _msgpack_sync_decr_and_fetch(ptr) _InterlockedDecrement(ptr)
63 # define _msgpack_sync_incr_and_fetch(ptr) _InterlockedIncrement(ptr)
65 # define _msgpack_sync_decr_and_fetch(ptr) InterlockedDecrement(ptr)
66 # define _msgpack_sync_incr_and_fetch(ptr) InterlockedIncrement(ptr)
68 #elif defined(__GNUC__) && ((__GNUC__*10 + __GNUC_MINOR__) < 41)
70 # define _msgpack_atomic_counter_header "msgpack/gcc_atomic.hpp"
74 # define _msgpack_sync_decr_and_fetch(ptr) __sync_sub_and_fetch(ptr, 1)
75 # define _msgpack_sync_incr_and_fetch(ptr) __sync_add_and_fetch(ptr, 1)
88 #elif defined(unix) || defined(__unix) || defined(__APPLE__) || defined(__OpenBSD__)
90 #include <arpa/inet.h>
92 # include <byteswap.h>
97 #if !defined(MSGPACK_ENDIAN_LITTLE_BYTE) && !defined(MSGPACK_ENDIAN_BIG_BYTE)
98 #include <boost/predef/other/endian.h>
99 #define MSGPACK_ENDIAN_LITTLE_BYTE BOOST_ENDIAN_LITTLE_BYTE
100 #define MSGPACK_ENDIAN_BIG_BYTE BOOST_ENDIAN_BIG_BYTE
103 #if MSGPACK_ENDIAN_LITTLE_BYTE
105 # if defined(unix) || defined(__unix) || defined(__APPLE__) || defined(__OpenBSD__)
106 # define _msgpack_be16(x) ntohs((uint16_t)x)
109 # define _msgpack_be16(x) ntohs(x)
110 # elif defined(_byteswap_ushort) || (defined(_MSC_VER) && _MSC_VER >= 1400)
111 # define _msgpack_be16(x) ((uint16_t)_byteswap_ushort((unsigned short)x))
113 # define _msgpack_be16(x) ( \
114 ((((uint16_t)x) << 8) ) | \
115 ((((uint16_t)x) >> 8) ) )
119 # if defined(unix) || defined(__unix) || defined(__APPLE__) || defined(__OpenBSD__)
120 # define _msgpack_be32(x) ntohl((uint32_t)x)
123 # define _msgpack_be32(x) ntohl(x)
124 # elif defined(_byteswap_ulong) || (defined(_MSC_VER) && _MSC_VER >= 1400)
125 # define _msgpack_be32(x) ((uint32_t)_byteswap_ulong((unsigned long)x))
127 # define _msgpack_be32(x) \
128 ( ((((uint32_t)x) << 24) ) | \
129 ((((uint32_t)x) << 8) & 0x00ff0000U ) | \
130 ((((uint32_t)x) >> 8) & 0x0000ff00U ) | \
131 ((((uint32_t)x) >> 24) ) )
135 # if defined(_byteswap_uint64) || (defined(_MSC_VER) && _MSC_VER >= 1400)
136 # define _msgpack_be64(x) (_byteswap_uint64(x))
137 # elif defined(bswap_64)
138 # define _msgpack_be64(x) bswap_64(x)
139 # elif defined(__DARWIN_OSSwapInt64)
140 # define _msgpack_be64(x) __DARWIN_OSSwapInt64(x)
142 # define _msgpack_be64(x) \
143 ( ((((uint64_t)x) << 56) ) | \
144 ((((uint64_t)x) << 40) & 0x00ff000000000000ULL ) | \
145 ((((uint64_t)x) << 24) & 0x0000ff0000000000ULL ) | \
146 ((((uint64_t)x) << 8) & 0x000000ff00000000ULL ) | \
147 ((((uint64_t)x) >> 8) & 0x00000000ff000000ULL ) | \
148 ((((uint64_t)x) >> 24) & 0x0000000000ff0000ULL ) | \
149 ((((uint64_t)x) >> 40) & 0x000000000000ff00ULL ) | \
150 ((((uint64_t)x) >> 56) ) )
153 #elif MSGPACK_ENDIAN_BIG_BYTE
155 # define _msgpack_be16(x) (x)
156 # define _msgpack_be32(x) (x)
157 # define _msgpack_be64(x) (x)
160 # error msgpack-c supports only big endian and little endian
163 #define _msgpack_load16(cast, from, to) do { \
164 memcpy((cast*)(to), (from), sizeof(cast)); \
165 *(to) = (cast)_msgpack_be16(*(to)); \
168 #define _msgpack_load32(cast, from, to) do { \
169 memcpy((cast*)(to), (from), sizeof(cast)); \
170 *(to) = (cast)_msgpack_be32(*(to)); \
172 #define _msgpack_load64(cast, from, to) do { \
173 memcpy((cast*)(to), (from), sizeof(cast)); \
174 *(to) = (cast)_msgpack_be64(*(to)); \
177 #define _msgpack_store16(to, num) \
178 do { uint16_t val = _msgpack_be16(num); memcpy(to, &val, 2); } while(0)
179 #define _msgpack_store32(to, num) \
180 do { uint32_t val = _msgpack_be32(num); memcpy(to, &val, 4); } while(0)
181 #define _msgpack_store64(to, num) \
182 do { uint64_t val = _msgpack_be64(num); memcpy(to, &val, 8); } while(0)
195 # include <TargetConditionals.h>
unsigned int _msgpack_atomic_counter_t
Definition: sysdep.hpp:73