2 * MessagePack system dependencies
4 * Copyright (C) 2008-2010 FURUHASHI Sadayuki
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)
10 #ifndef MSGPACK_SYSDEP_H
11 #define MSGPACK_SYSDEP_H
16 #include "vendor/msgpack/lttng-config.h"
18 #if defined(_MSC_VER) && _MSC_VER <= 1800
19 # define snprintf(buf, len, format,...) _snprintf_s(buf, len, _TRUNCATE, format, __VA_ARGS__)
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;
32 typedef signed __int64
intptr_t;
33 typedef unsigned __int64
uintptr_t;
35 typedef signed __int32
intptr_t;
36 typedef unsigned __int32
uintptr_t;
38 #elif defined(_MSC_VER) // && _MSC_VER >= 1600
45 #if !defined(MSGPACK_DLLEXPORT)
47 # define MSGPACK_DLLEXPORT __declspec(dllexport)
49 # define MSGPACK_DLLEXPORT
54 # if defined(_KERNEL_MODE)
55 # define _msgpack_atomic_counter_header <ntddk.h>
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 */
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)
67 # define _msgpack_sync_decr_and_fetch(ptr) InterlockedDecrement(ptr)
68 # define _msgpack_sync_incr_and_fetch(ptr) InterlockedIncrement(ptr)
70 #elif defined(__GNUC__) && ((__GNUC__*10 + __GNUC_MINOR__) < 41)
72 # if defined(__cplusplus)
73 # define _msgpack_atomic_counter_header "vendor/msgpack/gcc_atomic.hpp"
75 # define _msgpack_atomic_counter_header "vendor/msgpack/gcc_atomic.h"
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)
87 /* numeric_limits<T>::min,max */
96 #elif defined(unix) || defined(__unix) || defined(__APPLE__) || defined(__OpenBSD__)
98 #include <arpa/inet.h> /* __BYTE_ORDER */
100 # include <byteswap.h>
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)
109 #if MSGPACK_ENDIAN_LITTLE_BYTE
111 # if defined(unix) || defined(__unix) || defined(__APPLE__) || defined(__OpenBSD__)
112 # define _msgpack_be16(x) ntohs((uint16_t)x)
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))
119 # define _msgpack_be16(x) ( \
120 ((((uint16_t)x) << 8) ) | \
121 ((((uint16_t)x) >> 8) ) )
125 # if defined(unix) || defined(__unix) || defined(__APPLE__) || defined(__OpenBSD__)
126 # define _msgpack_be32(x) ntohl((uint32_t)x)
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))
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) ) )
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)
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) ) )
159 #elif MSGPACK_ENDIAN_BIG_BYTE
161 # define _msgpack_be16(x) (x)
162 # define _msgpack_be32(x) (x)
163 # define _msgpack_be64(x) (x)
166 # error msgpack-c supports only big endian and little endian
167 #endif /* MSGPACK_ENDIAN_LITTLE_BYTE */
169 #define _msgpack_load16(cast, from, to) do { \
170 memcpy((cast*)(to), (from), sizeof(cast)); \
171 *(to) = (cast)_msgpack_be16(*(to)); \
174 #define _msgpack_load32(cast, from, to) do { \
175 memcpy((cast*)(to), (from), sizeof(cast)); \
176 *(to) = (cast)_msgpack_be32(*(to)); \
178 #define _msgpack_load64(cast, from, to) do { \
179 memcpy((cast*)(to), (from), sizeof(cast)); \
180 *(to) = (cast)_msgpack_be64(*(to)); \
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)
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); })
200 #if !defined(__cplusplus) && defined(_MSC_VER)
201 # if !defined(_KERNEL_MODE)
206 # define TRUE (!FALSE)
209 # if _MSC_VER >= 1800
210 # include <stdbool.h>
216 # define inline __inline
220 # include <TargetConditionals.h>
223 #endif /* msgpack/sysdep.h */