template: casts integer types explicitly

This commit is contained in:
frsyuki 2010-08-31 06:27:15 +09:00
parent 9684c8664f
commit a1bd14e516

View File

@ -69,7 +69,7 @@ do { \
} else { \ } else { \
/* unsigned 16 */ \ /* unsigned 16 */ \
unsigned char buf[3]; \ unsigned char buf[3]; \
buf[0] = 0xcd; _msgpack_store16(&buf[1], d); \ buf[0] = 0xcd; _msgpack_store16(&buf[1], (uint16_t)d); \
msgpack_pack_append_buffer(x, buf, 3); \ msgpack_pack_append_buffer(x, buf, 3); \
} \ } \
} while(0) } while(0)
@ -89,12 +89,12 @@ do { \
if(d < (1<<16)) { \ if(d < (1<<16)) { \
/* unsigned 16 */ \ /* unsigned 16 */ \
unsigned char buf[3]; \ unsigned char buf[3]; \
buf[0] = 0xcd; _msgpack_store16(&buf[1], d); \ buf[0] = 0xcd; _msgpack_store16(&buf[1], (uint16_t)d); \
msgpack_pack_append_buffer(x, buf, 3); \ msgpack_pack_append_buffer(x, buf, 3); \
} else { \ } else { \
/* unsigned 32 */ \ /* unsigned 32 */ \
unsigned char buf[5]; \ unsigned char buf[5]; \
buf[0] = 0xce; _msgpack_store32(&buf[1], d); \ buf[0] = 0xce; _msgpack_store32(&buf[1], (uint32_t)d); \
msgpack_pack_append_buffer(x, buf, 5); \ msgpack_pack_append_buffer(x, buf, 5); \
} \ } \
} \ } \
@ -103,7 +103,7 @@ do { \
#define msgpack_pack_real_uint64(x, d) \ #define msgpack_pack_real_uint64(x, d) \
do { \ do { \
if(d < (1ULL<<8)) { \ if(d < (1ULL<<8)) { \
if(d < (1<<7)) { \ if(d < (1ULL<<7)) { \
/* fixnum */ \ /* fixnum */ \
msgpack_pack_append_buffer(x, &TAKE8_64(d), 1); \ msgpack_pack_append_buffer(x, &TAKE8_64(d), 1); \
} else { \ } else { \
@ -115,12 +115,12 @@ do { \
if(d < (1ULL<<16)) { \ if(d < (1ULL<<16)) { \
/* unsigned 16 */ \ /* unsigned 16 */ \
unsigned char buf[3]; \ unsigned char buf[3]; \
buf[0] = 0xcd; _msgpack_store16(&buf[1], d); \ buf[0] = 0xcd; _msgpack_store16(&buf[1], (uint16_t)d); \
msgpack_pack_append_buffer(x, buf, 3); \ msgpack_pack_append_buffer(x, buf, 3); \
} else if(d < (1ULL<<32)) { \ } else if(d < (1ULL<<32)) { \
/* unsigned 32 */ \ /* unsigned 32 */ \
unsigned char buf[5]; \ unsigned char buf[5]; \
buf[0] = 0xce; _msgpack_store32(&buf[1], d); \ buf[0] = 0xce; _msgpack_store32(&buf[1], (uint32_t)d); \
msgpack_pack_append_buffer(x, buf, 5); \ msgpack_pack_append_buffer(x, buf, 5); \
} else { \ } else { \
/* unsigned 64 */ \ /* unsigned 64 */ \
@ -149,7 +149,7 @@ do { \
if(d < -(1<<7)) { \ if(d < -(1<<7)) { \
/* signed 16 */ \ /* signed 16 */ \
unsigned char buf[3]; \ unsigned char buf[3]; \
buf[0] = 0xd1; _msgpack_store16(&buf[1], d); \ buf[0] = 0xd1; _msgpack_store16(&buf[1], (int16_t)d); \
msgpack_pack_append_buffer(x, buf, 3); \ msgpack_pack_append_buffer(x, buf, 3); \
} else { \ } else { \
/* signed 8 */ \ /* signed 8 */ \
@ -167,7 +167,7 @@ do { \
} else { \ } else { \
/* unsigned 16 */ \ /* unsigned 16 */ \
unsigned char buf[3]; \ unsigned char buf[3]; \
buf[0] = 0xcd; _msgpack_store16(&buf[1], d); \ buf[0] = 0xcd; _msgpack_store16(&buf[1], (uint16_t)d); \
msgpack_pack_append_buffer(x, buf, 3); \ msgpack_pack_append_buffer(x, buf, 3); \
} \ } \
} \ } \
@ -179,12 +179,12 @@ do { \
if(d < -(1<<15)) { \ if(d < -(1<<15)) { \
/* signed 32 */ \ /* signed 32 */ \
unsigned char buf[5]; \ unsigned char buf[5]; \
buf[0] = 0xd2; _msgpack_store32(&buf[1], d); \ buf[0] = 0xd2; _msgpack_store32(&buf[1], (int32_t)d); \
msgpack_pack_append_buffer(x, buf, 5); \ msgpack_pack_append_buffer(x, buf, 5); \
} else if(d < -(1<<7)) { \ } else if(d < -(1<<7)) { \
/* signed 16 */ \ /* signed 16 */ \
unsigned char buf[3]; \ unsigned char buf[3]; \
buf[0] = 0xd1; _msgpack_store16(&buf[1], d); \ buf[0] = 0xd1; _msgpack_store16(&buf[1], (int16_t)d); \
msgpack_pack_append_buffer(x, buf, 3); \ msgpack_pack_append_buffer(x, buf, 3); \
} else { \ } else { \
/* signed 8 */ \ /* signed 8 */ \
@ -202,12 +202,12 @@ do { \
} else if(d < (1<<16)) { \ } else if(d < (1<<16)) { \
/* unsigned 16 */ \ /* unsigned 16 */ \
unsigned char buf[3]; \ unsigned char buf[3]; \
buf[0] = 0xcd; _msgpack_store16(&buf[1], d); \ buf[0] = 0xcd; _msgpack_store16(&buf[1], (uint16_t)d); \
msgpack_pack_append_buffer(x, buf, 3); \ msgpack_pack_append_buffer(x, buf, 3); \
} else { \ } else { \
/* unsigned 32 */ \ /* unsigned 32 */ \
unsigned char buf[5]; \ unsigned char buf[5]; \
buf[0] = 0xce; _msgpack_store32(&buf[1], d); \ buf[0] = 0xce; _msgpack_store32(&buf[1], (uint32_t)d); \
msgpack_pack_append_buffer(x, buf, 5); \ msgpack_pack_append_buffer(x, buf, 5); \
} \ } \
} \ } \
@ -225,14 +225,14 @@ do { \
} else { \ } else { \
/* signed 32 */ \ /* signed 32 */ \
unsigned char buf[5]; \ unsigned char buf[5]; \
buf[0] = 0xd2; _msgpack_store32(&buf[1], d); \ buf[0] = 0xd2; _msgpack_store32(&buf[1], (int32_t)d); \
msgpack_pack_append_buffer(x, buf, 5); \ msgpack_pack_append_buffer(x, buf, 5); \
} \ } \
} else { \ } else { \
if(d < -(1<<7)) { \ if(d < -(1<<7)) { \
/* signed 16 */ \ /* signed 16 */ \
unsigned char buf[3]; \ unsigned char buf[3]; \
buf[0] = 0xd1; _msgpack_store16(&buf[1], d); \ buf[0] = 0xd1; _msgpack_store16(&buf[1], (int16_t)d); \
msgpack_pack_append_buffer(x, buf, 3); \ msgpack_pack_append_buffer(x, buf, 3); \
} else { \ } else { \
/* signed 8 */ \ /* signed 8 */ \
@ -252,14 +252,14 @@ do { \
} else { \ } else { \
/* unsigned 16 */ \ /* unsigned 16 */ \
unsigned char buf[3]; \ unsigned char buf[3]; \
buf[0] = 0xcd; _msgpack_store16(&buf[1], d); \ buf[0] = 0xcd; _msgpack_store16(&buf[1], (uint16_t)d); \
msgpack_pack_append_buffer(x, buf, 3); \ msgpack_pack_append_buffer(x, buf, 3); \
} \ } \
} else { \ } else { \
if(d < (1LL<<32)) { \ if(d < (1LL<<32)) { \
/* unsigned 32 */ \ /* unsigned 32 */ \
unsigned char buf[5]; \ unsigned char buf[5]; \
buf[0] = 0xce; _msgpack_store32(&buf[1], d); \ buf[0] = 0xce; _msgpack_store32(&buf[1], (uint32_t)d); \
msgpack_pack_append_buffer(x, buf, 5); \ msgpack_pack_append_buffer(x, buf, 5); \
} else { \ } else { \
/* unsigned 64 */ \ /* unsigned 64 */ \
@ -690,11 +690,11 @@ msgpack_pack_inline_func(_array)(msgpack_pack_user x, unsigned int n)
msgpack_pack_append_buffer(x, &d, 1); msgpack_pack_append_buffer(x, &d, 1);
} else if(n < 65536) { } else if(n < 65536) {
unsigned char buf[3]; unsigned char buf[3];
buf[0] = 0xdc; _msgpack_store16(&buf[1], n); buf[0] = 0xdc; _msgpack_store16(&buf[1], (uint16_t)n);
msgpack_pack_append_buffer(x, buf, 3); msgpack_pack_append_buffer(x, buf, 3);
} else { } else {
unsigned char buf[5]; unsigned char buf[5];
buf[0] = 0xdd; _msgpack_store32(&buf[1], n); buf[0] = 0xdd; _msgpack_store32(&buf[1], (uint32_t)n);
msgpack_pack_append_buffer(x, buf, 5); msgpack_pack_append_buffer(x, buf, 5);
} }
} }
@ -711,11 +711,11 @@ msgpack_pack_inline_func(_map)(msgpack_pack_user x, unsigned int n)
msgpack_pack_append_buffer(x, &TAKE8_8(d), 1); msgpack_pack_append_buffer(x, &TAKE8_8(d), 1);
} else if(n < 65536) { } else if(n < 65536) {
unsigned char buf[3]; unsigned char buf[3];
buf[0] = 0xde; _msgpack_store16(&buf[1], n); buf[0] = 0xde; _msgpack_store16(&buf[1], (uint16_t)n);
msgpack_pack_append_buffer(x, buf, 3); msgpack_pack_append_buffer(x, buf, 3);
} else { } else {
unsigned char buf[5]; unsigned char buf[5];
buf[0] = 0xdf; _msgpack_store32(&buf[1], n); buf[0] = 0xdf; _msgpack_store32(&buf[1], (uint32_t)n);
msgpack_pack_append_buffer(x, buf, 5); msgpack_pack_append_buffer(x, buf, 5);
} }
} }
@ -732,11 +732,11 @@ msgpack_pack_inline_func(_raw)(msgpack_pack_user x, size_t l)
msgpack_pack_append_buffer(x, &TAKE8_8(d), 1); msgpack_pack_append_buffer(x, &TAKE8_8(d), 1);
} else if(l < 65536) { } else if(l < 65536) {
unsigned char buf[3]; unsigned char buf[3];
buf[0] = 0xda; _msgpack_store16(&buf[1], l); buf[0] = 0xda; _msgpack_store16(&buf[1], (uint16_t)l);
msgpack_pack_append_buffer(x, buf, 3); msgpack_pack_append_buffer(x, buf, 3);
} else { } else {
unsigned char buf[5]; unsigned char buf[5];
buf[0] = 0xdb; _msgpack_store32(&buf[1], l); buf[0] = 0xdb; _msgpack_store32(&buf[1], (uint32_t)l);
msgpack_pack_append_buffer(x, buf, 5); msgpack_pack_append_buffer(x, buf, 5);
} }
} }