bugfix issue #185

This commit is contained in:
Cloud Wu
2014-10-22 20:32:23 +08:00
parent 9bdc36526e
commit fc8983227d

View File

@@ -120,37 +120,37 @@ rb_read(struct read_block *rb, void *buffer, int sz) {
static inline void static inline void
wb_nil(struct write_block *wb) { wb_nil(struct write_block *wb) {
int n = TYPE_NIL; uint8_t n = TYPE_NIL;
wb_push(wb, &n, 1); wb_push(wb, &n, 1);
} }
static inline void static inline void
wb_boolean(struct write_block *wb, int boolean) { wb_boolean(struct write_block *wb, int boolean) {
int n = COMBINE_TYPE(TYPE_BOOLEAN , boolean ? 1 : 0); uint8_t n = COMBINE_TYPE(TYPE_BOOLEAN , boolean ? 1 : 0);
wb_push(wb, &n, 1); wb_push(wb, &n, 1);
} }
static inline void static inline void
wb_integer(struct write_block *wb, int v, int type) { wb_integer(struct write_block *wb, int v, int type) {
if (v == 0) { if (v == 0) {
int n = COMBINE_TYPE(type , 0); uint8_t n = COMBINE_TYPE(type , 0);
wb_push(wb, &n, 1); wb_push(wb, &n, 1);
} else if (v<0) { } else if (v<0) {
int n = COMBINE_TYPE(type , 4); uint8_t n = COMBINE_TYPE(type , 4);
wb_push(wb, &n, 1); wb_push(wb, &n, 1);
wb_push(wb, &v, 4); wb_push(wb, &v, 4);
} else if (v<0x100) { } else if (v<0x100) {
int n = COMBINE_TYPE(type , 1); uint8_t n = COMBINE_TYPE(type , 1);
wb_push(wb, &n, 1); wb_push(wb, &n, 1);
uint8_t byte = (uint8_t)v; uint8_t byte = (uint8_t)v;
wb_push(wb, &byte, 1); wb_push(wb, &byte, 1);
} else if (v<0x10000) { } else if (v<0x10000) {
int n = COMBINE_TYPE(type , 2); uint8_t n = COMBINE_TYPE(type , 2);
wb_push(wb, &n, 1); wb_push(wb, &n, 1);
uint16_t word = (uint16_t)v; uint16_t word = (uint16_t)v;
wb_push(wb, &word, 2); wb_push(wb, &word, 2);
} else { } else {
int n = COMBINE_TYPE(type , 4); uint8_t n = COMBINE_TYPE(type , 4);
wb_push(wb, &n, 1); wb_push(wb, &n, 1);
wb_push(wb, &v, 4); wb_push(wb, &v, 4);
} }
@@ -158,14 +158,14 @@ wb_integer(struct write_block *wb, int v, int type) {
static inline void static inline void
wb_number(struct write_block *wb, double v) { wb_number(struct write_block *wb, double v) {
int n = COMBINE_TYPE(TYPE_NUMBER , 8); uint8_t n = COMBINE_TYPE(TYPE_NUMBER , 8);
wb_push(wb, &n, 1); wb_push(wb, &n, 1);
wb_push(wb, &v, 8); wb_push(wb, &v, 8);
} }
static inline void static inline void
wb_pointer(struct write_block *wb, void *v) { wb_pointer(struct write_block *wb, void *v) {
int n = TYPE_USERDATA; uint8_t n = TYPE_USERDATA;
wb_push(wb, &n, 1); wb_push(wb, &n, 1);
wb_push(wb, &v, sizeof(v)); wb_push(wb, &v, sizeof(v));
} }
@@ -173,7 +173,7 @@ wb_pointer(struct write_block *wb, void *v) {
static inline void static inline void
wb_string(struct write_block *wb, const char *str, int len) { wb_string(struct write_block *wb, const char *str, int len) {
if (len < MAX_COOKIE) { if (len < MAX_COOKIE) {
int n = COMBINE_TYPE(TYPE_SHORT_STRING, len); uint8_t n = COMBINE_TYPE(TYPE_SHORT_STRING, len);
wb_push(wb, &n, 1); wb_push(wb, &n, 1);
if (len > 0) { if (len > 0) {
wb_push(wb, str, len); wb_push(wb, str, len);
@@ -201,11 +201,11 @@ static int
wb_table_array(lua_State *L, struct write_block * wb, int index, int depth) { wb_table_array(lua_State *L, struct write_block * wb, int index, int depth) {
int array_size = lua_rawlen(L,index); int array_size = lua_rawlen(L,index);
if (array_size >= MAX_COOKIE-1) { if (array_size >= MAX_COOKIE-1) {
int n = COMBINE_TYPE(TYPE_TABLE, MAX_COOKIE-1); uint8_t n = COMBINE_TYPE(TYPE_TABLE, MAX_COOKIE-1);
wb_push(wb, &n, 1); wb_push(wb, &n, 1);
wb_integer(wb, array_size,TYPE_NUMBER); wb_integer(wb, array_size,TYPE_NUMBER);
} else { } else {
int n = COMBINE_TYPE(TYPE_TABLE, array_size); uint8_t n = COMBINE_TYPE(TYPE_TABLE, array_size);
wb_push(wb, &n, 1); wb_push(wb, &n, 1);
} }