Skip to content

Commit

Permalink
update msgpack
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] committed Jul 20, 2019
1 parent 7705828 commit e338689
Show file tree
Hide file tree
Showing 39 changed files with 778 additions and 432 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// MessagePack for C++ static resolution routine
//
// Copyright (C) 2019 KONDO Takatoshi
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//

#ifndef MSGPACK_TYPE_CPP11_TIMESPEC_HPP
#define MSGPACK_TYPE_CPP11_TIMESPEC_HPP

#include "msgpack/v1/adaptor/cpp11/timespec.hpp"

#endif // MSGPACK_TYPE_CPP11_TIMESPEC_HPP
15 changes: 15 additions & 0 deletions module/ngx_http_hi_module/lib/msgpack/msgpack/adaptor/wstring.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// MessagePack for C++ static resolution routine
//
// Copyright (C) 2018 KONDO Takatoshi
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef MSGPACK_TYPE_WSTRING_HPP
#define MSGPACK_TYPE_WSTRING_HPP

#include "msgpack/v1/adaptor/wstring.hpp"

#endif // MSGPACK_TYPE_WSTRING_HPP
2 changes: 2 additions & 0 deletions module/ngx_http_hi_module/lib/msgpack/msgpack/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,10 @@ typedef struct msgpack_object_kv {
msgpack_object val;
} msgpack_object_kv;

#if !defined(_KERNEL_MODE)
MSGPACK_DLLEXPORT
void msgpack_object_print(FILE* out, msgpack_object o);
#endif

MSGPACK_DLLEXPORT
int msgpack_object_print_buffer(char *buffer, size_t buffer_size, msgpack_object o);
Expand Down
26 changes: 17 additions & 9 deletions module/ngx_http_hi_module/lib/msgpack/msgpack/pack_template.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
#error msgpack_pack_append_buffer callback is not defined
#endif

#if defined(_MSC_VER)
# pragma warning(push)
# pragma warning(disable : 4204) /* nonstandard extension used: non-constant aggregate initializer */
#endif

/*
* Integer
Expand Down Expand Up @@ -834,51 +838,51 @@ msgpack_pack_inline_func(_ext)(msgpack_pack_user x, size_t l, int8_t type)
case 1: {
unsigned char buf[2];
buf[0] = 0xd4;
buf[1] = type;
buf[1] = (unsigned char)type;
msgpack_pack_append_buffer(x, buf, 2);
} break;
case 2: {
unsigned char buf[2];
buf[0] = 0xd5;
buf[1] = type;
buf[1] = (unsigned char)type;
msgpack_pack_append_buffer(x, buf, 2);
} break;
case 4: {
unsigned char buf[2];
buf[0] = 0xd6;
buf[1] = type;
buf[1] = (unsigned char)type;
msgpack_pack_append_buffer(x, buf, 2);
} break;
case 8: {
unsigned char buf[2];
buf[0] = 0xd7;
buf[1] = type;
buf[1] = (unsigned char)type;
msgpack_pack_append_buffer(x, buf, 2);
} break;
case 16: {
unsigned char buf[2];
buf[0] = 0xd8;
buf[1] = type;
buf[1] = (unsigned char)type;
msgpack_pack_append_buffer(x, buf, 2);
} break;
default:
if(l < 256) {
unsigned char buf[3];
buf[0] = 0xc7;
buf[1] = (unsigned char)l;
buf[2] = type;
buf[2] = (unsigned char)type;
msgpack_pack_append_buffer(x, buf, 3);
} else if(l < 65536) {
unsigned char buf[4];
buf[0] = 0xc8;
_msgpack_store16(&buf[1], l);
buf[3] = type;
buf[3] = (unsigned char)type;
msgpack_pack_append_buffer(x, buf, 4);
} else {
unsigned char buf[6];
buf[0] = 0xc9;
_msgpack_store32(&buf[1], l);
buf[5] = type;
buf[5] = (unsigned char)type;
msgpack_pack_append_buffer(x, buf, 6);
}
break;
Expand All @@ -893,7 +897,7 @@ msgpack_pack_inline_func(_ext_body)(msgpack_pack_user x, const void* b, size_t l
msgpack_pack_inline_func(_timestamp)(msgpack_pack_user x, const msgpack_timestamp* d)
{
if ((((int64_t)d->tv_sec) >> 34) == 0) {
uint64_t data64 = ((uint64_t) d->tv_nsec << 34) | d->tv_sec;
uint64_t data64 = ((uint64_t) d->tv_nsec << 34) | (uint64_t)d->tv_sec;
if ((data64 & 0xffffffff00000000L) == 0) {
// timestamp 32
char buf[4];
Expand Down Expand Up @@ -935,3 +939,7 @@ msgpack_pack_inline_func(_timestamp)(msgpack_pack_user x, const msgpack_timestam
#undef msgpack_pack_real_int16
#undef msgpack_pack_real_int32
#undef msgpack_pack_real_int64

#if defined(_MSC_VER)
# pragma warning(pop)
#endif
43 changes: 27 additions & 16 deletions module/ngx_http_hi_module/lib/msgpack/msgpack/sysdep.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,22 @@
#endif

#ifdef _WIN32
# define _msgpack_atomic_counter_header <windows.h>
# if !defined(WIN32_LEAN_AND_MEAN)
# define WIN32_LEAN_AND_MEAN
# endif /* WIN32_LEAN_AND_MEAN */
# if defined(_KERNEL_MODE)
# define _msgpack_atomic_counter_header <ntddk.h>
# else
# define _msgpack_atomic_counter_header <windows.h>
# if !defined(WIN32_LEAN_AND_MEAN)
# define WIN32_LEAN_AND_MEAN
# endif /* WIN32_LEAN_AND_MEAN */
# endif
typedef long _msgpack_atomic_counter_t;
# define _msgpack_sync_decr_and_fetch(ptr) InterlockedDecrement(ptr)
# define _msgpack_sync_incr_and_fetch(ptr) InterlockedIncrement(ptr)
#if defined(_AMD64_) || defined(_M_X64) || defined(_M_ARM64)
# define _msgpack_sync_decr_and_fetch(ptr) _InterlockedDecrement(ptr)
# define _msgpack_sync_incr_and_fetch(ptr) _InterlockedIncrement(ptr)
#else
# define _msgpack_sync_decr_and_fetch(ptr) InterlockedDecrement(ptr)
# define _msgpack_sync_incr_and_fetch(ptr) InterlockedIncrement(ptr)
#endif
#elif defined(__GNUC__) && ((__GNUC__*10 + __GNUC_MINOR__) < 41)

# if defined(__cplusplus)
Expand Down Expand Up @@ -91,7 +100,7 @@
#if MSGPACK_ENDIAN_LITTLE_BYTE

# if defined(unix) || defined(__unix) || defined(__APPLE__) || defined(__OpenBSD__)
# define _msgpack_be16(x) ntohs(x)
# define _msgpack_be16(x) ntohs((uint16_t)x)
# else
# if defined(ntohs)
# define _msgpack_be16(x) ntohs(x)
Expand All @@ -105,7 +114,7 @@
# endif

# if defined(unix) || defined(__unix) || defined(__APPLE__) || defined(__OpenBSD__)
# define _msgpack_be32(x) ntohl(x)
# define _msgpack_be32(x) ntohl((uint32_t)x)
# else
# if defined(ntohl)
# define _msgpack_be32(x) ntohl(x)
Expand Down Expand Up @@ -150,16 +159,16 @@

#define _msgpack_load16(cast, from, to) do { \
memcpy((cast*)(to), (from), sizeof(cast)); \
*(to) = _msgpack_be16(*(to)); \
*(to) = (cast)_msgpack_be16(*(to)); \
} while (0);

#define _msgpack_load32(cast, from, to) do { \
memcpy((cast*)(to), (from), sizeof(cast)); \
*(to) = _msgpack_be32(*(to)); \
*(to) = (cast)_msgpack_be32(*(to)); \
} while (0);
#define _msgpack_load64(cast, from, to) do { \
memcpy((cast*)(to), (from), sizeof(cast)); \
*(to) = _msgpack_be64(*(to)); \
*(to) = (cast)_msgpack_be64(*(to)); \
} while (0);

#define _msgpack_store16(to, num) \
Expand All @@ -180,11 +189,13 @@


#if !defined(__cplusplus) && defined(_MSC_VER)
# if !defined(FALSE)
# define FALSE (0)
# endif
# if !defined(TRUE)
# define TRUE (!FALSE)
# if !defined(_KERNEL_MODE)
# if !defined(FALSE)
# define FALSE (0)
# endif
# if !defined(TRUE)
# define TRUE (!FALSE)
# endif
# endif
# if _MSC_VER >= 1800
# include <stdbool.h>
Expand Down
2 changes: 2 additions & 0 deletions module/ngx_http_hi_module/lib/msgpack/msgpack/type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "adaptor/vector_bool.hpp"
#include "adaptor/vector_char.hpp"
#include "adaptor/vector_unsigned_char.hpp"
#include "adaptor/wstring.hpp"
#include "adaptor/msgpack_tuple.hpp"
#include "adaptor/define.hpp"

Expand All @@ -38,6 +39,7 @@
#include "adaptor/cpp11/forward_list.hpp"
#include "adaptor/cpp11/reference_wrapper.hpp"
#include "adaptor/cpp11/shared_ptr.hpp"
#include "adaptor/cpp11/timespec.hpp"
#include "adaptor/cpp11/tuple.hpp"
#include "adaptor/cpp11/unique_ptr.hpp"
#include "adaptor/cpp11/unordered_map.hpp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@
#endif
#endif

#if defined(_KERNEL_MODE)
#undef assert
#define assert NT_ASSERT
#endif

msgpack_unpack_struct_decl(_stack) {
msgpack_unpack_object obj;
size_t count;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#ifndef MSGPACK_V1_TYPE_ARRAY_REF_HPP
#define MSGPACK_V1_TYPE_ARRAY_REF_HPP

#include "msgpack/v1/adaptor/array_ref.hpp"
#include "msgpack/adaptor/check_container_size.hpp"
#include "msgpack/cpp_config.hpp"
#include <cstring>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ inline void check_container_size_for_ext<4>(std::size_t size) {

template <typename T>
inline uint32_t checked_get_container_size(T size) {
detail::check_container_size<sizeof(T)>(size);
detail::check_container_size<sizeof(T)>(static_cast<std::size_t>(size));
return static_cast<uint32_t>(size);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ struct pack<std::chrono::system_clock::time_point> {
* std::chrono::system_clock::duration::period::ratio::num
/ std::chrono::system_clock::duration::period::ratio::den;
if ((sec >> 34) == 0) {
uint64_t data64 = (nanosec << 34) | sec;
uint64_t data64 = (static_cast<uint64_t>(nanosec) << 34) | static_cast<uint64_t>(sec);
if ((data64 & 0xffffffff00000000L) == 0) {
// timestamp 32
o.pack_ext(4, -1);
Expand Down Expand Up @@ -170,13 +170,13 @@ struct object_with_zone<std::chrono::system_clock::time_point> {
* std::chrono::system_clock::duration::period::ratio::num
/ std::chrono::system_clock::duration::period::ratio::den;
if ((sec >> 34) == 0) {
uint64_t data64 = (nanosec << 34) | sec;
uint64_t data64 = (static_cast<uint64_t>(nanosec) << 34) | static_cast<uint64_t>(sec);
if ((data64 & 0xffffffff00000000L) == 0) {
// timestamp 32
o.type = msgpack::type::EXT;
o.via.ext.size = 4;
char* p = static_cast<char*>(o.zone.allocate_no_align(o.via.ext.size + 1));
p[0] = -1;
p[0] = static_cast<char>(-1);
uint32_t data32 = static_cast<uint32_t>(data64);
_msgpack_store32(&p[1], data32);
o.via.ext.ptr = p;
Expand All @@ -186,7 +186,7 @@ struct object_with_zone<std::chrono::system_clock::time_point> {
o.type = msgpack::type::EXT;
o.via.ext.size = 8;
char* p = static_cast<char*>(o.zone.allocate_no_align(o.via.ext.size + 1));
p[0] = -1;
p[0] = static_cast<char>(-1);
_msgpack_store64(&p[1], data64);
o.via.ext.ptr = p;
}
Expand All @@ -196,7 +196,7 @@ struct object_with_zone<std::chrono::system_clock::time_point> {
o.type = msgpack::type::EXT;
o.via.ext.size = 12;
char* p = static_cast<char*>(o.zone.allocate_no_align(o.via.ext.size + 1));
p[0] = -1;
p[0] = static_cast<char>(-1);
_msgpack_store32(&p[1], static_cast<uint32_t>(nanosec));
_msgpack_store64(&p[1 + 4], sec);
o.via.ext.ptr = p;
Expand Down
Loading

0 comments on commit e338689

Please sign in to comment.