update lua-bson to fix the 32bit signed int bug

This commit is contained in:
Cloud Wu
2014-05-21 11:21:01 +08:00
parent d6a4c5cc59
commit 1fbee1ac0b
2 changed files with 12 additions and 9 deletions

View File

@@ -1,3 +1,7 @@
Dev version
-----------
* Bugfix: update lua-bson (signed 32bit int bug)
v0.2.1 (2014-5-19)
-----------
* Bugfix: check all the events already read after socket close

View File

@@ -1,5 +1,3 @@
#include "skynet_malloc.h"
#include <lua.h>
#include <lauxlib.h>
@@ -73,7 +71,7 @@ struct bson_reader {
static inline void
bson_destroy(struct bson *b) {
if (b->ptr != b->buffer) {
skynet_free(b->ptr);
free(b->ptr);
}
}
@@ -93,10 +91,10 @@ bson_reserve(struct bson *b, int sz) {
} while (b->cap <= b->size + sz);
if (b->ptr == b->buffer) {
b->ptr = skynet_malloc(b->cap);
b->ptr = malloc(b->cap);
memcpy(b->ptr, b->buffer, b->size);
} else {
b->ptr = skynet_realloc(b->ptr, b->cap);
b->ptr = realloc(b->ptr, b->cap);
}
}
@@ -258,13 +256,13 @@ append_key(struct bson *bs, int type, const char *key, size_t sz) {
static void
append_number(struct bson *bs, lua_State *L, const char *key, size_t sz) {
lua_Integer i = lua_tointeger(L, -1);
int64_t i = lua_tointeger(L, -1);
lua_Number d = lua_tonumber(L,-1);
if (i != d) {
append_key(bs, BSON_REAL, key, sz);
write_double(bs, d);
} else {
int si = (int64_t)i >> 32;
int si = i >> 31;
if (si == 0 || si == -1) {
append_key(bs, BSON_INT32, key, sz);
write_int32(bs, i);
@@ -459,7 +457,7 @@ pack_dict(lua_State *L, struct bson *b, bool isarray) {
}
static void
pack_sorted_dict(lua_State *L, struct bson *b, int n) {
pack_ordered_dict(lua_State *L, struct bson *b, int n) {
int length = reserve_length(b);
int i;
for (i=0;i<n;i+=2) {
@@ -865,7 +863,7 @@ lencode_order(lua_State *L) {
if (n%2 != 0) {
return luaL_error(L, "Invalid ordered dict");
}
pack_sorted_dict(L, &b, n);
pack_ordered_dict(L, &b, n);
lua_settop(L,1);
void * ud = lua_newuserdata(L, b.size);
memcpy(ud, b.ptr, b.size);
@@ -1190,3 +1188,4 @@ luaopen_bson(lua_State *L) {
return 1;
}