mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-03-31 07:58:20 +02:00
ruby binding: fix Fixnum serialization bug on x86_64
git-svn-id: file:///Users/frsyuki/project/msgpack-git/svn/x@88 5a5092ae-2292-43ba-b2d5-dcab9c1a2731
This commit is contained in:
parent
15837bc332
commit
8f3444c081
@ -1,5 +1,5 @@
|
|||||||
AC_INIT(msgpack/unpack_template.h)
|
AC_INIT(msgpack/unpack_template.h)
|
||||||
AM_INIT_AUTOMAKE(msgpack, 0.2.0)
|
AM_INIT_AUTOMAKE(msgpack, 0.2.1)
|
||||||
AC_CONFIG_HEADER(config.h)
|
AC_CONFIG_HEADER(config.h)
|
||||||
|
|
||||||
AC_PROG_LIBTOOL
|
AC_PROG_LIBTOOL
|
||||||
|
@ -68,15 +68,14 @@
|
|||||||
* Integer
|
* Integer
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// wrapper
|
static inline void msgpack_pack_compress_int32(msgpack_pack_user x, uint32_t d)
|
||||||
msgpack_pack_inline_func(int)(msgpack_pack_user x, int d)
|
|
||||||
{
|
{
|
||||||
if(d < -32) {
|
if(d < -(1<<5)) {
|
||||||
if(d < -32768) {
|
if(d < -(1<<15)) {
|
||||||
// signed 32
|
// signed 32
|
||||||
const unsigned char buf[5] = {0xd2, STORE_BE32(d)};
|
const unsigned char buf[5] = {0xd2, STORE_BE32(d)};
|
||||||
msgpack_pack_append_buffer(x, buf, 5);
|
msgpack_pack_append_buffer(x, buf, 5);
|
||||||
} else if(d < -128) {
|
} else if(d < -(1<<7)) {
|
||||||
// signed 16
|
// signed 16
|
||||||
const unsigned char buf[3] = {0xd1, STORE_BE16(d)};
|
const unsigned char buf[3] = {0xd1, STORE_BE16(d)};
|
||||||
msgpack_pack_append_buffer(x, buf, 3);
|
msgpack_pack_append_buffer(x, buf, 3);
|
||||||
@ -85,15 +84,15 @@ msgpack_pack_inline_func(int)(msgpack_pack_user x, int d)
|
|||||||
const unsigned char buf[2] = {0xd0, (uint8_t)d};
|
const unsigned char buf[2] = {0xd0, (uint8_t)d};
|
||||||
msgpack_pack_append_buffer(x, buf, 2);
|
msgpack_pack_append_buffer(x, buf, 2);
|
||||||
}
|
}
|
||||||
} else if(d < 128) {
|
} else if(d < (1<<7)) {
|
||||||
// fixnum
|
// fixnum
|
||||||
msgpack_pack_append_buffer(x, (uint8_t*)&d, 1);
|
msgpack_pack_append_buffer(x, (uint8_t*)&d, 1);
|
||||||
} else {
|
} else {
|
||||||
if(d < 256) {
|
if(d < (1<<8)) {
|
||||||
// unsigned 8
|
// unsigned 8
|
||||||
const unsigned char buf[2] = {0xcc, (uint8_t)d};
|
const unsigned char buf[2] = {0xcc, (uint8_t)d};
|
||||||
msgpack_pack_append_buffer(x, buf, 2);
|
msgpack_pack_append_buffer(x, buf, 2);
|
||||||
} else if(d < 65536) {
|
} else if(d < (1<<16)) {
|
||||||
// unsigned 16
|
// unsigned 16
|
||||||
const unsigned char buf[3] = {0xcd, STORE_BE16(d)};
|
const unsigned char buf[3] = {0xcd, STORE_BE16(d)};
|
||||||
msgpack_pack_append_buffer(x, buf, 3);
|
msgpack_pack_append_buffer(x, buf, 3);
|
||||||
@ -105,11 +104,10 @@ msgpack_pack_inline_func(int)(msgpack_pack_user x, int d)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// wrapper
|
static inline void msgpack_pack_compress_uint32(msgpack_pack_user x, uint32_t d)
|
||||||
msgpack_pack_inline_func(unsigned_int)(msgpack_pack_user x, unsigned int d)
|
|
||||||
{
|
{
|
||||||
if(d < 256) {
|
if(d < (1<<8)) {
|
||||||
if(d < 128) {
|
if(d < (1<<7)) {
|
||||||
// fixnum
|
// fixnum
|
||||||
msgpack_pack_append_buffer(x, (unsigned char*)&d, 1);
|
msgpack_pack_append_buffer(x, (unsigned char*)&d, 1);
|
||||||
} else {
|
} else {
|
||||||
@ -118,7 +116,7 @@ msgpack_pack_inline_func(unsigned_int)(msgpack_pack_user x, unsigned int d)
|
|||||||
msgpack_pack_append_buffer(x, buf, 2);
|
msgpack_pack_append_buffer(x, buf, 2);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if(d < 65536) {
|
if(d < (1<<16)) {
|
||||||
// unsigned 16
|
// unsigned 16
|
||||||
const unsigned char buf[3] = {0xcd, STORE_BE16(d)};
|
const unsigned char buf[3] = {0xcd, STORE_BE16(d)};
|
||||||
msgpack_pack_append_buffer(x, buf, 3);
|
msgpack_pack_append_buffer(x, buf, 3);
|
||||||
@ -130,6 +128,123 @@ msgpack_pack_inline_func(unsigned_int)(msgpack_pack_user x, unsigned int d)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void msgpack_pack_compress_int64(msgpack_pack_user x, int64_t d)
|
||||||
|
{
|
||||||
|
if(d < -(1LL<<5)) {
|
||||||
|
if(d < -(1LL<<15)) {
|
||||||
|
if(d < -(1LL<<31)) {
|
||||||
|
// signed 64
|
||||||
|
const unsigned char buf[9] = {0xd3, STORE_BE64(d)};
|
||||||
|
msgpack_pack_append_buffer(x, buf, 9);
|
||||||
|
} else {
|
||||||
|
// signed 32
|
||||||
|
const unsigned char buf[5] = {0xd2, STORE_BE32(d)};
|
||||||
|
msgpack_pack_append_buffer(x, buf, 5);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if(d < -(1<<7)) {
|
||||||
|
// signed 16
|
||||||
|
const unsigned char buf[3] = {0xd1, STORE_BE16(d)};
|
||||||
|
msgpack_pack_append_buffer(x, buf, 3);
|
||||||
|
} else {
|
||||||
|
// signed 8
|
||||||
|
const unsigned char buf[2] = {0xd0, (uint8_t)d};
|
||||||
|
msgpack_pack_append_buffer(x, buf, 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if(d < (1<<7)) {
|
||||||
|
// fixnum
|
||||||
|
msgpack_pack_append_buffer(x, (uint8_t*)&d, 1);
|
||||||
|
} else {
|
||||||
|
if(d < (1LL<<16)) {
|
||||||
|
if(d < (1<<8)) {
|
||||||
|
// unsigned 8
|
||||||
|
const unsigned char buf[2] = {0xcc, (uint8_t)d};
|
||||||
|
msgpack_pack_append_buffer(x, buf, 2);
|
||||||
|
} else {
|
||||||
|
// unsigned 16
|
||||||
|
const unsigned char buf[3] = {0xcd, STORE_BE16(d)};
|
||||||
|
msgpack_pack_append_buffer(x, buf, 3);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if(d < (1LL<<32)) {
|
||||||
|
// unsigned 32
|
||||||
|
const unsigned char buf[5] = {0xce, STORE_BE32(d)};
|
||||||
|
msgpack_pack_append_buffer(x, buf, 5);
|
||||||
|
} else {
|
||||||
|
// unsigned 64
|
||||||
|
const unsigned char buf[9] = {0xcf, STORE_BE64(d)};
|
||||||
|
msgpack_pack_append_buffer(x, buf, 9);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void msgpack_pack_compress_uint64(msgpack_pack_user x, uint64_t d)
|
||||||
|
{
|
||||||
|
if(d < (1ULL<<8)) {
|
||||||
|
if(d < (1<<7)) {
|
||||||
|
// fixnum
|
||||||
|
msgpack_pack_append_buffer(x, (unsigned char*)&d, 1);
|
||||||
|
} else {
|
||||||
|
// unsigned 8
|
||||||
|
const unsigned char buf[2] = {0xcc, (uint8_t)d};
|
||||||
|
msgpack_pack_append_buffer(x, buf, 2);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if(d < (1ULL<<16)) {
|
||||||
|
// signed 16
|
||||||
|
const unsigned char buf[3] = {0xcd, STORE_BE16(d)};
|
||||||
|
msgpack_pack_append_buffer(x, buf, 3);
|
||||||
|
} else if(d < (1ULL<<32)) {
|
||||||
|
// signed 32
|
||||||
|
const unsigned char buf[5] = {0xce, STORE_BE32(d)};
|
||||||
|
msgpack_pack_append_buffer(x, buf, 5);
|
||||||
|
} else {
|
||||||
|
// signed 64
|
||||||
|
const unsigned char buf[9] = {0xcf, STORE_BE64(d)};
|
||||||
|
msgpack_pack_append_buffer(x, buf, 9);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
msgpack_pack_inline_func(int)(msgpack_pack_user x, int d)
|
||||||
|
{
|
||||||
|
#if SIZEOF_INT == 8
|
||||||
|
msgpack_pack_compress_int64(x, d);
|
||||||
|
#else
|
||||||
|
msgpack_pack_compress_int32(x, d);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
msgpack_pack_inline_func(unsigned_int)(msgpack_pack_user x, unsigned int d)
|
||||||
|
{
|
||||||
|
#if SIZEOF_INT == 8
|
||||||
|
msgpack_pack_compress_uint64(x, d);
|
||||||
|
#else
|
||||||
|
msgpack_pack_compress_uint32(x, d);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
msgpack_pack_inline_func(long)(msgpack_pack_user x, long d)
|
||||||
|
{
|
||||||
|
#if SIZEOF_LONG == 8
|
||||||
|
msgpack_pack_compress_int64(x, d);
|
||||||
|
#else
|
||||||
|
msgpack_pack_compress_int32(x, d);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
msgpack_pack_inline_func(unsigned_long)(msgpack_pack_user x, unsigned long d)
|
||||||
|
{
|
||||||
|
#if SIZEOF_LONG == 8
|
||||||
|
msgpack_pack_compress_uint64(x, d);
|
||||||
|
#else
|
||||||
|
msgpack_pack_compress_uint32(x, d);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
msgpack_pack_inline_func(uint8)(msgpack_pack_user x, uint8_t d)
|
msgpack_pack_inline_func(uint8)(msgpack_pack_user x, uint8_t d)
|
||||||
{
|
{
|
||||||
if(d < 128) {
|
if(d < 128) {
|
||||||
|
@ -2,7 +2,7 @@ module MessagePack
|
|||||||
module VERSION #:nodoc:
|
module VERSION #:nodoc:
|
||||||
MAJOR = 0
|
MAJOR = 0
|
||||||
MINOR = 2
|
MINOR = 2
|
||||||
TINY = 0
|
TINY = 1
|
||||||
|
|
||||||
STRING = [MAJOR, MINOR, TINY].join('.')
|
STRING = [MAJOR, MINOR, TINY].join('.')
|
||||||
end
|
end
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#define msgpack_pack_inline_func(name) \
|
#define msgpack_pack_inline_func(name) \
|
||||||
static void msgpack_pack_##name
|
static inline void msgpack_pack_##name
|
||||||
|
|
||||||
#define msgpack_pack_user VALUE
|
#define msgpack_pack_user VALUE
|
||||||
|
|
||||||
@ -30,6 +30,8 @@
|
|||||||
/*
|
/*
|
||||||
static void msgpack_pack_int(VALUE x, int d);
|
static void msgpack_pack_int(VALUE x, int d);
|
||||||
static void msgpack_pack_unsigned_int(VALUE x, unsigned int d);
|
static void msgpack_pack_unsigned_int(VALUE x, unsigned int d);
|
||||||
|
static void msgpack_pack_long(VALUE x, long d);
|
||||||
|
static void msgpack_pack_unsigned_long(VALUE x, unsigned long d);
|
||||||
static void msgpack_pack_uint8(VALUE x, uint8_t d);
|
static void msgpack_pack_uint8(VALUE x, uint8_t d);
|
||||||
static void msgpack_pack_uint16(VALUE x, uint16_t d);
|
static void msgpack_pack_uint16(VALUE x, uint16_t d);
|
||||||
static void msgpack_pack_uint32(VALUE x, uint32_t d);
|
static void msgpack_pack_uint32(VALUE x, uint32_t d);
|
||||||
@ -93,7 +95,7 @@ static VALUE MessagePack_FalseClass_to_msgpack(int argc, VALUE *argv, VALUE self
|
|||||||
static VALUE MessagePack_Fixnum_to_msgpack(int argc, VALUE *argv, VALUE self)
|
static VALUE MessagePack_Fixnum_to_msgpack(int argc, VALUE *argv, VALUE self)
|
||||||
{
|
{
|
||||||
ARG_BUFFER(out, argc, argv);
|
ARG_BUFFER(out, argc, argv);
|
||||||
msgpack_pack_int(out, FIX2INT(self));
|
msgpack_pack_long(out, FIX2LONG(self));
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user