Skip to content

Commit

Permalink
Merge pull request pgriess#13 from crow-misia/update-msgpack0.5.8
Browse files Browse the repository at this point in the history
update msgpack 0.5.8
  • Loading branch information
godsflaw committed Feb 18, 2014
2 parents 8398fa2 + 9d88546 commit e0df7bc
Show file tree
Hide file tree
Showing 19 changed files with 287 additions and 60 deletions.
22 changes: 20 additions & 2 deletions deps/msgpack/gcc_atomic.cpp
@@ -1,16 +1,34 @@
//
// MessagePack for C++ atomic operations
//
// Copyright (C) 2008-2013 FURUHASHI Sadayuki
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

#if defined(__GNUC__) && ((__GNUC__*10 + __GNUC_MINOR__) < 41)

#include "gcc_atomic.h"
#include <bits/atomicity.h>

int _msgpack_sync_decr_and_fetch(volatile _msgpack_atomic_counter_t* ptr)
{
return __gnu_cxx::__exchange_and_add(ptr, -1);
return __gnu_cxx::__exchange_and_add(ptr, -1) - 1;
}

int _msgpack_sync_incr_and_fetch(volatile _msgpack_atomic_counter_t* ptr)
{
return __gnu_cxx::__exchange_and_add(ptr, 1);
return __gnu_cxx::__exchange_and_add(ptr, 1) + 1;
}


Expand Down
33 changes: 33 additions & 0 deletions deps/msgpack/gcc_atomic.h
@@ -0,0 +1,33 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef MSGPACK_GCC_ATOMIC_H__
#define MSGPACK_GCC_ATOMIC_H__

#if defined(__cplusplus)
extern "C" {
#endif

typedef int _msgpack_atomic_counter_t;

int _msgpack_sync_decr_and_fetch(volatile _msgpack_atomic_counter_t* ptr);
int _msgpack_sync_incr_and_fetch(volatile _msgpack_atomic_counter_t* ptr);


#if defined(__cplusplus)
}
#endif


#endif // MSGPACK_GCC_ATOMIC_H__
1 change: 1 addition & 0 deletions deps/msgpack/msgpack.gyp
Expand Up @@ -5,6 +5,7 @@
'include_dirs': [ '.' ],
'type': 'static_library',
'sources': [
'gcc_atomic.cpp',
'object.cpp',
'objectc.c',
'unpack.c',
Expand Down
15 changes: 12 additions & 3 deletions deps/msgpack/msgpack/object.hpp
@@ -1,7 +1,7 @@
//
// MessagePack for C++ static resolution routine
//
// Copyright (C) 2008-2009 FURUHASHI Sadayuki
// Copyright (C) 2008-2010 FURUHASHI Sadayuki
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -212,11 +212,20 @@ inline T& operator>> (object o, T& v)
return v;
}

namespace detail {
template <typename Stream, typename T>
struct packer_serializer {
static packer<Stream>& pack(packer<Stream>& o, const T& v) {
v.msgpack_pack(o);
return o;
}
};
}

template <typename Stream, typename T>
inline packer<Stream>& operator<< (packer<Stream>& o, const T& v)
{
v.msgpack_pack(o);
return o;
return detail::packer_serializer<Stream, T>::pack(o, v);
}

template <typename T>
Expand Down
8 changes: 6 additions & 2 deletions deps/msgpack/msgpack/pack.h
Expand Up @@ -52,10 +52,14 @@ static void msgpack_packer_init(msgpack_packer* pk, void* data, msgpack_packer_w
static msgpack_packer* msgpack_packer_new(void* data, msgpack_packer_write callback);
static void msgpack_packer_free(msgpack_packer* pk);

static int msgpack_pack_char(msgpack_packer* pk, char d);

static int msgpack_pack_signed_char(msgpack_packer* pk, signed char d);
static int msgpack_pack_short(msgpack_packer* pk, short d);
static int msgpack_pack_int(msgpack_packer* pk, int d);
static int msgpack_pack_long(msgpack_packer* pk, long d);
static int msgpack_pack_long_long(msgpack_packer* pk, long long d);
static int msgpack_pack_unsigned_char(msgpack_packer* pk, unsigned char d);
static int msgpack_pack_unsigned_short(msgpack_packer* pk, unsigned short d);
static int msgpack_pack_unsigned_int(msgpack_packer* pk, unsigned int d);
static int msgpack_pack_unsigned_long(msgpack_packer* pk, unsigned long d);
Expand Down Expand Up @@ -86,9 +90,9 @@ static int msgpack_pack_nil(msgpack_packer* pk);
static int msgpack_pack_true(msgpack_packer* pk);
static int msgpack_pack_false(msgpack_packer* pk);

static int msgpack_pack_array(msgpack_packer* pk, unsigned int n);
static int msgpack_pack_array(msgpack_packer* pk, size_t n);

static int msgpack_pack_map(msgpack_packer* pk, unsigned int n);
static int msgpack_pack_map(msgpack_packer* pk, size_t n);

static int msgpack_pack_raw(msgpack_packer* pk, size_t l);
static int msgpack_pack_raw_body(msgpack_packer* pk, const void* b, size_t l);
Expand Down
33 changes: 26 additions & 7 deletions deps/msgpack/msgpack/pack.hpp
Expand Up @@ -54,10 +54,13 @@ class packer {
packer<Stream>& pack_fix_int32(int32_t d);
packer<Stream>& pack_fix_int64(int64_t d);

packer<Stream>& pack_char(char d);
packer<Stream>& pack_signed_char(signed char d);
packer<Stream>& pack_short(short d);
packer<Stream>& pack_int(int d);
packer<Stream>& pack_long(long d);
packer<Stream>& pack_long_long(long long d);
packer<Stream>& pack_unsigned_char(unsigned char d);
packer<Stream>& pack_unsigned_short(unsigned short d);
packer<Stream>& pack_unsigned_int(unsigned int d);
packer<Stream>& pack_unsigned_long(unsigned long d);
Expand All @@ -70,9 +73,9 @@ class packer {
packer<Stream>& pack_true();
packer<Stream>& pack_false();

packer<Stream>& pack_array(unsigned int n);
packer<Stream>& pack_array(size_t n);

packer<Stream>& pack_map(unsigned int n);
packer<Stream>& pack_map(size_t n);

packer<Stream>& pack_raw(size_t l);
packer<Stream>& pack_raw_body(const char* b, size_t l);
Expand All @@ -96,10 +99,14 @@ class packer {
static void _pack_fix_int32(Stream& x, int32_t d);
static void _pack_fix_int64(Stream& x, int64_t d);

static void _pack_char(Stream& x, char d);

static void _pack_signed_char(Stream& x, signed char d);
static void _pack_short(Stream& x, short d);
static void _pack_int(Stream& x, int d);
static void _pack_long(Stream& x, long d);
static void _pack_long_long(Stream& x, long long d);
static void _pack_unsigned_char(Stream& x, unsigned char d);
static void _pack_unsigned_short(Stream& x, unsigned short d);
static void _pack_unsigned_int(Stream& x, unsigned int d);
static void _pack_unsigned_long(Stream& x, unsigned long d);
Expand All @@ -112,14 +119,14 @@ class packer {
static void _pack_true(Stream& x);
static void _pack_false(Stream& x);

static void _pack_array(Stream& x, unsigned int n);
static void _pack_array(Stream& x, size_t n);

static void _pack_map(Stream& x, unsigned int n);
static void _pack_map(Stream& x, size_t n);

static void _pack_raw(Stream& x, size_t l);
static void _pack_raw_body(Stream& x, const void* b, size_t l);

static void append_buffer(Stream& x, const unsigned char* buf, unsigned int len)
static void append_buffer(Stream& x, const unsigned char* buf, size_t len)
{ x.write((const char*)buf, len); }

private:
Expand Down Expand Up @@ -238,6 +245,14 @@ inline packer<Stream>& packer<Stream>::pack_fix_int64(int64_t d)
{ _pack_fix_int64(m_stream, d); return *this;}


template <typename Stream>
inline packer<Stream>& packer<Stream>::pack_char(char d)
{ _pack_char(m_stream, d); return *this; }

template <typename Stream>
inline packer<Stream>& packer<Stream>::pack_signed_char(signed char d)
{ _pack_signed_char(m_stream, d); return *this; }

template <typename Stream>
inline packer<Stream>& packer<Stream>::pack_short(short d)
{ _pack_short(m_stream, d); return *this; }
Expand All @@ -254,6 +269,10 @@ template <typename Stream>
inline packer<Stream>& packer<Stream>::pack_long_long(long long d)
{ _pack_long_long(m_stream, d); return *this; }

template <typename Stream>
inline packer<Stream>& packer<Stream>::pack_unsigned_char(unsigned char d)
{ _pack_unsigned_char(m_stream, d); return *this; }

template <typename Stream>
inline packer<Stream>& packer<Stream>::pack_unsigned_short(unsigned short d)
{ _pack_unsigned_short(m_stream, d); return *this; }
Expand Down Expand Up @@ -294,12 +313,12 @@ inline packer<Stream>& packer<Stream>::pack_false()


template <typename Stream>
inline packer<Stream>& packer<Stream>::pack_array(unsigned int n)
inline packer<Stream>& packer<Stream>::pack_array(size_t n)
{ _pack_array(m_stream, n); return *this; }


template <typename Stream>
inline packer<Stream>& packer<Stream>::pack_map(unsigned int n)
inline packer<Stream>& packer<Stream>::pack_map(size_t n)
{ _pack_map(m_stream, n); return *this; }


Expand Down
35 changes: 31 additions & 4 deletions deps/msgpack/msgpack/pack_template.h
Expand Up @@ -372,6 +372,28 @@ msgpack_pack_inline_func(_int64)(msgpack_pack_user x, int64_t d)
msgpack_pack_real_int64(x, d);
}

msgpack_pack_inline_func(_char)(msgpack_pack_user x, char d)
{
#if defined(CHAR_MIN)
#if CHAR_MIN < 0
msgpack_pack_real_int8(x, d);
#else
msgpack_pack_real_uint8(x, d);
#endif
#else
#error CHAR_MIN is not defined
#endif
}

msgpack_pack_inline_func(_signed_char)(msgpack_pack_user x, signed char d)
{
msgpack_pack_real_int8(x, d);
}

msgpack_pack_inline_func(_unsigned_char)(msgpack_pack_user x, unsigned char d)
{
msgpack_pack_real_uint8(x, d);
}

#ifdef msgpack_pack_inline_func_cint

Expand Down Expand Up @@ -646,7 +668,12 @@ msgpack_pack_inline_func(_double)(msgpack_pack_user x, double d)
union { double f; uint64_t i; } mem;
mem.f = d;
unsigned char buf[9];
buf[0] = 0xcb; _msgpack_store64(&buf[1], mem.i);
buf[0] = 0xcb;
#if defined(__arm__) && !(__ARM_EABI__) // arm-oabi
// https://github.com/msgpack/msgpack-perl/pull/1
mem.i = (mem.i & 0xFFFFFFFFUL) << 32UL | (mem.i >> 32UL);
#endif
_msgpack_store64(&buf[1], mem.i);
msgpack_pack_append_buffer(x, buf, 9);
}

Expand Down Expand Up @@ -683,7 +710,7 @@ msgpack_pack_inline_func(_false)(msgpack_pack_user x)
* Array
*/

msgpack_pack_inline_func(_array)(msgpack_pack_user x, unsigned int n)
msgpack_pack_inline_func(_array)(msgpack_pack_user x, size_t n)
{
if(n < 16) {
unsigned char d = 0x90 | n;
Expand All @@ -704,7 +731,7 @@ msgpack_pack_inline_func(_array)(msgpack_pack_user x, unsigned int n)
* Map
*/

msgpack_pack_inline_func(_map)(msgpack_pack_user x, unsigned int n)
msgpack_pack_inline_func(_map)(msgpack_pack_user x, size_t n)
{
if(n < 16) {
unsigned char d = 0x80 | n;
Expand Down Expand Up @@ -743,7 +770,7 @@ msgpack_pack_inline_func(_raw)(msgpack_pack_user x, size_t l)

msgpack_pack_inline_func(_raw_body)(msgpack_pack_user x, const void* b, size_t l)
{
msgpack_pack_append_buffer(x, (const unsigned char*)b, (unsigned int)(l));
msgpack_pack_append_buffer(x, (const unsigned char*)b, l);
}

#undef msgpack_pack_inline_func
Expand Down
3 changes: 2 additions & 1 deletion deps/msgpack/msgpack/type.hpp
Expand Up @@ -13,4 +13,5 @@
#include "type/vector.hpp"
#include "type/tuple.hpp"
#include "type/define.hpp"

#include "type/tr1/unordered_map.hpp"
#include "type/tr1/unordered_set.hpp"
28 changes: 27 additions & 1 deletion deps/msgpack/msgpack/type/define.hpp
Expand Up @@ -34,6 +34,32 @@
msgpack::type::make_define(__VA_ARGS__).msgpack_object(o, z); \
}

// MSGPACK_ADD_ENUM must be used in the global namespace.
#define MSGPACK_ADD_ENUM(enum) \
namespace msgpack { \
template <> \
inline enum& operator>> (object o, enum& v) \
{ \
int tmp; \
o >> tmp; \
v = static_cast<enum>(tmp); \
return v; \
} \
template <> \
void operator<< (object::with_zone& o, const enum& v) \
{ \
o << static_cast<int>(v); \
} \
namespace detail { \
template <typename Stream> \
struct packer_serializer<Stream, enum> { \
static packer<Stream>& pack(packer<Stream>& o, const enum& v) { \
return o << static_cast<int>(v); \
} \
}; \
} \
}

namespace msgpack {
namespace type {

Expand All @@ -50,7 +76,7 @@ struct define<> {
template <typename Packer>
void msgpack_pack(Packer& pk) const
{
pk.pack_array(1);
pk.pack_array(0);
}
void msgpack_unpack(msgpack::object o)
{
Expand Down

0 comments on commit e0df7bc

Please sign in to comment.