diff --git a/src/msgpack/object.hpp b/src/msgpack/object.hpp index a622c100..a5d5bb80 100644 --- a/src/msgpack/object.hpp +++ b/src/msgpack/object.hpp @@ -530,7 +530,7 @@ std::ostream& operator<< (std::ostream& s, const object& o) default: // FIXME - s << "#"; + s << "#(o.type) << ">"; } return s; } diff --git a/src/msgpack/pack.hpp b/src/msgpack/pack.hpp index 7010d4e3..2e247719 100644 --- a/src/msgpack/pack.hpp +++ b/src/msgpack/pack.hpp @@ -616,11 +616,11 @@ inline packer& packer::pack_array(size_t n) append_buffer(&d, 1); } else if(n < 65536) { char buf[3]; - buf[0] = static_cast(0xdc); _msgpack_store16(&buf[1], (uint16_t)n); + buf[0] = static_cast(0xdc); _msgpack_store16(&buf[1], static_cast(n)); append_buffer(buf, 3); } else { char buf[5]; - buf[0] = static_cast(0xdd); _msgpack_store32(&buf[1], (uint32_t)n); + buf[0] = static_cast(0xdd); _msgpack_store32(&buf[1], static_cast(n)); append_buffer(buf, 5); } return *this; @@ -635,11 +635,11 @@ inline packer& packer::pack_map(size_t n) append_buffer(&buf, 1); } else if(n < 65536) { char buf[3]; - buf[0] = static_cast(0xde); _msgpack_store16(&buf[1], (uint16_t)n); + buf[0] = static_cast(0xde); _msgpack_store16(&buf[1], static_cast(n)); append_buffer(buf, 3); } else { char buf[5]; - buf[0] = static_cast(0xdf); _msgpack_store32(&buf[1], (uint32_t)n); + buf[0] = static_cast(0xdf); _msgpack_store32(&buf[1], static_cast(n)); append_buffer(buf, 5); } return *this; @@ -649,20 +649,20 @@ template inline packer& packer::pack_str(size_t l) { if(l < 32) { - unsigned char d = 0xa0 | (uint8_t)l; + unsigned char d = 0xa0 | static_cast(l); char buf = take8_8(d); append_buffer(&buf, 1); } else if(l < 256) { char buf[2]; - buf[0] = static_cast(0xd9); buf[1] = (uint8_t)l; + buf[0] = static_cast(0xd9); buf[1] = static_cast(l); append_buffer(buf, 2); } else if(l < 65536) { char buf[3]; - buf[0] = static_cast(0xda); _msgpack_store16(&buf[1], (uint16_t)l); + buf[0] = static_cast(0xda); _msgpack_store16(&buf[1], static_cast(l)); append_buffer(buf, 3); } else { char buf[5]; - buf[0] = static_cast(0xdb); _msgpack_store32(&buf[1], (uint32_t)l); + buf[0] = static_cast(0xdb); _msgpack_store32(&buf[1], static_cast(l)); append_buffer(buf, 5); } return *this; @@ -680,15 +680,15 @@ inline packer& packer::pack_bin(size_t l) { if(l < 256) { char buf[2]; - buf[0] = static_cast(0xc4); buf[1] = (uint8_t)l; + buf[0] = static_cast(0xc4); buf[1] = static_cast(l); append_buffer(buf, 2); } else if(l < 65536) { char buf[3]; - buf[0] = static_cast(0xc5); _msgpack_store16(&buf[1], (uint16_t)l); + buf[0] = static_cast(0xc5); _msgpack_store16(&buf[1], static_cast(l)); append_buffer(buf, 3); } else { char buf[5]; - buf[0] = static_cast(0xc6); _msgpack_store32(&buf[1], (uint32_t)l); + buf[0] = static_cast(0xc6); _msgpack_store32(&buf[1], static_cast(l)); append_buffer(buf, 5); } return *this; @@ -731,7 +731,7 @@ inline void packer::pack_imp_uint16(T d) } else { /* unsigned 16 */ char buf[3]; - buf[0] = static_cast(0xcd); _msgpack_store16(&buf[1], (uint16_t)d); + buf[0] = static_cast(0xcd); _msgpack_store16(&buf[1], static_cast(d)); append_buffer(buf, 3); } } @@ -754,12 +754,12 @@ inline void packer::pack_imp_uint32(T d) if(d < (1<<16)) { /* unsigned 16 */ char buf[3]; - buf[0] = static_cast(0xcd); _msgpack_store16(&buf[1], (uint16_t)d); + buf[0] = static_cast(0xcd); _msgpack_store16(&buf[1], static_cast(d)); append_buffer(buf, 3); } else { /* unsigned 32 */ char buf[5]; - buf[0] = static_cast(0xce); _msgpack_store32(&buf[1], (uint32_t)d); + buf[0] = static_cast(0xce); _msgpack_store32(&buf[1], static_cast(d)); append_buffer(buf, 5); } } @@ -783,12 +783,12 @@ inline void packer::pack_imp_uint64(T d) if(d < (1ULL<<16)) { /* unsigned 16 */ char buf[3]; - buf[0] = static_cast(0xcd); _msgpack_store16(&buf[1], (uint16_t)d); + buf[0] = static_cast(0xcd); _msgpack_store16(&buf[1], static_cast(d)); append_buffer(buf, 3); } else if(d < (1ULL<<32)) { /* unsigned 32 */ char buf[5]; - buf[0] = static_cast(0xce); _msgpack_store32(&buf[1], (uint32_t)d); + buf[0] = static_cast(0xce); _msgpack_store32(&buf[1], static_cast(d)); append_buffer(buf, 5); } else { /* unsigned 64 */ @@ -822,7 +822,7 @@ inline void packer::pack_imp_int16(T d) if(d < -(1<<7)) { /* signed 16 */ char buf[3]; - buf[0] = static_cast(0xd1); _msgpack_store16(&buf[1], (int16_t)d); + buf[0] = static_cast(0xd1); _msgpack_store16(&buf[1], static_cast(d)); append_buffer(buf, 3); } else { /* signed 8 */ @@ -841,7 +841,7 @@ inline void packer::pack_imp_int16(T d) } else { /* unsigned 16 */ char buf[3]; - buf[0] = static_cast(0xcd); _msgpack_store16(&buf[1], (uint16_t)d); + buf[0] = static_cast(0xcd); _msgpack_store16(&buf[1], static_cast(d)); append_buffer(buf, 3); } } @@ -855,12 +855,12 @@ inline void packer::pack_imp_int32(T d) if(d < -(1<<15)) { /* signed 32 */ char buf[5]; - buf[0] = static_cast(0xd2); _msgpack_store32(&buf[1], (int32_t)d); + buf[0] = static_cast(0xd2); _msgpack_store32(&buf[1], static_cast(d)); append_buffer(buf, 5); } else if(d < -(1<<7)) { /* signed 16 */ char buf[3]; - buf[0] = static_cast(0xd1); _msgpack_store16(&buf[1], (int16_t)d); + buf[0] = static_cast(0xd1); _msgpack_store16(&buf[1], static_cast(d)); append_buffer(buf, 3); } else { /* signed 8 */ @@ -879,12 +879,12 @@ inline void packer::pack_imp_int32(T d) } else if(d < (1<<16)) { /* unsigned 16 */ char buf[3]; - buf[0] = static_cast(0xcd); _msgpack_store16(&buf[1], (uint16_t)d); + buf[0] = static_cast(0xcd); _msgpack_store16(&buf[1], static_cast(d)); append_buffer(buf, 3); } else { /* unsigned 32 */ char buf[5]; - buf[0] = static_cast(0xce); _msgpack_store32(&buf[1], (uint32_t)d); + buf[0] = static_cast(0xce); _msgpack_store32(&buf[1], static_cast(d)); append_buffer(buf, 5); } } @@ -904,14 +904,14 @@ inline void packer::pack_imp_int64(T d) } else { /* signed 32 */ char buf[5]; - buf[0] = static_cast(0xd2); _msgpack_store32(&buf[1], (int32_t)d); + buf[0] = static_cast(0xd2); _msgpack_store32(&buf[1], static_cast(d)); append_buffer(buf, 5); } } else { if(d < -(1<<7)) { /* signed 16 */ char buf[3]; - buf[0] = static_cast(0xd1); _msgpack_store16(&buf[1], (int16_t)d); + buf[0] = static_cast(0xd1); _msgpack_store16(&buf[1], static_cast(d)); append_buffer(buf, 3); } else { /* signed 8 */ @@ -932,14 +932,14 @@ inline void packer::pack_imp_int64(T d) } else { /* unsigned 16 */ char buf[3]; - buf[0] = static_cast(0xcd); _msgpack_store16(&buf[1], (uint16_t)d); + buf[0] = static_cast(0xcd); _msgpack_store16(&buf[1], static_cast(d)); append_buffer(buf, 3); } } else { if(d < (1LL<<32)) { /* unsigned 32 */ char buf[5]; - buf[0] = static_cast(0xce); _msgpack_store32(&buf[1], (uint32_t)d); + buf[0] = static_cast(0xce); _msgpack_store32(&buf[1], static_cast(d)); append_buffer(buf, 5); } else { /* unsigned 64 */ diff --git a/src/msgpack/type/float.hpp b/src/msgpack/type/float.hpp index fbbe8aed..48bc1be8 100644 --- a/src/msgpack/type/float.hpp +++ b/src/msgpack/type/float.hpp @@ -30,13 +30,13 @@ namespace msgpack { inline float& operator>> (object const& o, float& v) { if(o.type == type::DOUBLE) { - v = (float)o.via.dec; + v = static_cast(o.via.dec); } else if (o.type == type::POSITIVE_INTEGER) { - v = (float)o.via.u64; + v = static_cast(o.via.u64); } else if (o.type == type::NEGATIVE_INTEGER) { - v = (float)o.via.i64; + v = static_cast(o.via.i64); } else { throw type_error(); @@ -58,10 +58,10 @@ inline double& operator>> (object const& o, double& v) v = o.via.dec; } else if (o.type == type::POSITIVE_INTEGER) { - v = (double)o.via.u64; + v = static_cast(o.via.u64); } else if (o.type == type::NEGATIVE_INTEGER) { - v = (double)o.via.i64; + v = static_cast(o.via.i64); } else { throw type_error(); @@ -80,7 +80,7 @@ inline packer& operator<< (packer& o, const double& v) inline void operator<< (object& o, float v) { o.type = type::DOUBLE; - o.via.dec = (double)v; + o.via.dec = static_cast(v); } inline void operator<< (object& o, double v) diff --git a/src/msgpack/type/int.hpp b/src/msgpack/type/int.hpp index e70e2043..f1b588b6 100644 --- a/src/msgpack/type/int.hpp +++ b/src/msgpack/type/int.hpp @@ -33,13 +33,13 @@ namespace detail { struct convert_integer_sign { static inline T convert(object const& o) { if(o.type == type::POSITIVE_INTEGER) { - if(o.via.u64 > (uint64_t)std::numeric_limits::max()) + if(o.via.u64 > static_cast(std::numeric_limits::max())) { throw type_error(); } - return (T)o.via.u64; + return static_cast(o.via.u64); } else if(o.type == type::NEGATIVE_INTEGER) { - if(o.via.i64 < (int64_t)std::numeric_limits::min()) + if(o.via.i64 < static_cast(std::numeric_limits::min())) { throw type_error(); } - return (T)o.via.i64; + return static_cast(o.via.i64); } throw type_error(); } @@ -49,9 +49,9 @@ namespace detail { struct convert_integer_sign { static inline T convert(object const& o) { if(o.type == type::POSITIVE_INTEGER) { - if(o.via.u64 > (uint64_t)std::numeric_limits::max()) + if(o.via.u64 > static_cast(std::numeric_limits::max())) { throw type_error(); } - return (T)o.via.u64; + return static_cast(o.via.u64); } throw type_error(); } diff --git a/src/msgpack/type/string.hpp b/src/msgpack/type/string.hpp index 62161f44..5f99fe58 100644 --- a/src/msgpack/type/string.hpp +++ b/src/msgpack/type/string.hpp @@ -51,9 +51,9 @@ inline packer& operator<< (packer& o, const std::string& v) inline void operator<< (object::with_zone& o, const std::string& v) { o.type = type::STR; - char* ptr = (char*)o.zone->allocate_align(v.size()); + char* ptr = static_cast(o.zone->allocate_align(v.size())); o.via.str.ptr = ptr; - o.via.str.size = (uint32_t)v.size(); + o.via.str.size = static_cast(v.size()); memcpy(ptr, v.data(), v.size()); } @@ -61,7 +61,7 @@ inline void operator<< (object& o, const std::string& v) { o.type = type::STR; o.via.str.ptr = v.data(); - o.via.str.size = (uint32_t)v.size(); + o.via.str.size = static_cast(v.size()); } diff --git a/src/msgpack/unpack.hpp b/src/msgpack/unpack.hpp index 97e9db73..a82d2238 100644 --- a/src/msgpack/unpack.hpp +++ b/src/msgpack/unpack.hpp @@ -109,7 +109,7 @@ struct unpack_array { bool operator()(unpack_user&u, unsigned int n, object& o) const { o.type = type::ARRAY; o.via.array.size = 0; - o.via.array.ptr = (object*)u.zone().allocate_align(n*sizeof(object)); + o.via.array.ptr = static_cast(u.zone().allocate_align(n*sizeof(object))); if(o.via.array.ptr == nullptr) { return false; } return true; } @@ -128,7 +128,7 @@ struct unpack_map { bool operator()(unpack_user& u, unsigned int n, object& o) const { o.type = type::MAP; o.via.map.size = 0; - o.via.map.ptr = (object_kv*)u.zone().allocate_align(n*sizeof(object_kv)); + o.via.map.ptr = static_cast(u.zone().allocate_align(n*sizeof(object_kv))); if(o.via.map.ptr == nullptr) { return false; } return true; } @@ -184,26 +184,24 @@ private: inline void init_count(void* buffer) { - *(volatile _msgpack_atomic_counter_t*)buffer = 1; + *reinterpret_cast(buffer) = 1; } inline void decl_count(void* buffer) { - // atomic if(--*(_msgpack_atomic_counter_t*)buffer == 0) { free(buffer); } - if(_msgpack_sync_decr_and_fetch((volatile _msgpack_atomic_counter_t*)buffer) == 0) { + if(_msgpack_sync_decr_and_fetch(reinterpret_cast(buffer)) == 0) { free(buffer); } } inline void incr_count(void* buffer) { - // atomic ++*(_msgpack_atomic_counter_t*)buffer; - _msgpack_sync_incr_and_fetch((volatile _msgpack_atomic_counter_t*)buffer); + _msgpack_sync_incr_and_fetch(reinterpret_cast(buffer)); } inline _msgpack_atomic_counter_t get_count(void* buffer) { - return *(volatile _msgpack_atomic_counter_t*)buffer; + return *reinterpret_cast(buffer); } struct fix_tag { @@ -872,7 +870,7 @@ inline unpacker::unpacker(size_t initial_buffer_size) initial_buffer_size = COUNTER_SIZE; } - char* buffer = reinterpret_cast(::malloc(initial_buffer_size)); + char* buffer = static_cast(::malloc(initial_buffer_size)); if(!buffer) { throw std::bad_alloc(); } @@ -929,7 +927,7 @@ inline void unpacker::expand_buffer(size_t size) next_size *= 2; } - char* tmp = reinterpret_cast(::realloc(buffer_, next_size)); + char* tmp = static_cast(::realloc(buffer_, next_size)); if(!tmp) { throw std::bad_alloc(); } @@ -944,7 +942,7 @@ inline void unpacker::expand_buffer(size_t size) next_size *= 2; } - char* tmp = reinterpret_cast(::malloc(next_size)); + char* tmp = static_cast(::malloc(next_size)); if(!tmp) { throw std::bad_alloc(); } diff --git a/src/msgpack/vrefbuffer.hpp b/src/msgpack/vrefbuffer.hpp index a2f4db58..97afcf38 100644 --- a/src/msgpack/vrefbuffer.hpp +++ b/src/msgpack/vrefbuffer.hpp @@ -128,7 +128,7 @@ public: tail_ = nvec + nused; } - tail_->iov_base = (char*)buf; + tail_->iov_base = const_cast(buf); tail_->iov_len = len; ++tail_; } diff --git a/src/msgpack/zbuffer.hpp b/src/msgpack/zbuffer.hpp index 117bc498..da84edae 100644 --- a/src/msgpack/zbuffer.hpp +++ b/src/msgpack/zbuffer.hpp @@ -102,7 +102,7 @@ public: size_t size() const { - return (char*)stream_.next_out - data_; + return reinterpret_cast(stream_.next_out) - data_; } void reset()