From 072bb262595a52827b55b14730c68bf5ac0c1257 Mon Sep 17 00:00:00 2001 From: Matt Stancliff Date: Fri, 4 Apr 2014 15:28:32 -0400 Subject: [PATCH 1/4] Remove unused variable causing warning We don't need 'max' because 'idx' is monotonically increasing, so when we exit the loop, 'idx' is 'max' by definition. Removes compile-time warning of: lua_cmsgpack.c: In function 'table_is_an_array': lua_cmsgpack.c:370:21: warning: variable 'max' set but not used [-Wunused-but-set-variable] long count = 0, max = 0, idx = 0; ^ --- lua_cmsgpack.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lua_cmsgpack.c b/lua_cmsgpack.c index 0cce72d..6250a20 100644 --- a/lua_cmsgpack.c +++ b/lua_cmsgpack.c @@ -371,7 +371,7 @@ static void mp_encode_lua_table_as_map(lua_State *L, mp_buf *buf, int level) { * of keys from numerical keys from 1 up to N, with N being the total number * of elements, without any hole in the middle. */ static int table_is_an_array(lua_State *L) { - long count = 0, max = 0, idx = 0; + long count = 0, idx = 0; lua_Number n; lua_pushnil(L); @@ -383,7 +383,6 @@ static int table_is_an_array(lua_State *L) { idx = n; if (idx != n || idx < 1) goto not_array; count++; - max = idx; } /* We have the total number of elements in "count". Also we have * the max index encountered in "idx". We can't reach this code From b628c4d0a6cc3b00d8bcc2c6e94229b04af0e8f4 Mon Sep 17 00:00:00 2001 From: Matt Stancliff Date: Fri, 4 Apr 2014 15:37:26 -0400 Subject: [PATCH 2/4] Remove double free (discovered by scan-build) --- lua_cmsgpack.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lua_cmsgpack.c b/lua_cmsgpack.c index 6250a20..e0eafc0 100644 --- a/lua_cmsgpack.c +++ b/lua_cmsgpack.c @@ -683,8 +683,9 @@ static int mp_unpack(lua_State *L) { mp_cur_free(c); lua_pushstring(L,"Extra bytes in input."); lua_error(L); + } else { + mp_cur_free(c); } - mp_cur_free(c); return 1; } From dfbfd58bccc504d130d90d5e24338939059faf56 Mon Sep 17 00:00:00 2001 From: Matt Stancliff Date: Fri, 4 Apr 2014 15:48:01 -0400 Subject: [PATCH 3/4] Refactor 5.2 version checking Use a more forgiving version comparison for the future. This change future-proofs compatability against any potential upcoming versions 503, 504, 601, .... (assuming these API changes remain stable). --- lua_cmsgpack.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lua_cmsgpack.c b/lua_cmsgpack.c index e0eafc0..c0c9c1d 100644 --- a/lua_cmsgpack.c +++ b/lua_cmsgpack.c @@ -328,10 +328,10 @@ static void mp_encode_lua_type(lua_State *L, mp_buf *buf, int level); /* Convert a lua table into a message pack list. */ static void mp_encode_lua_table_as_array(lua_State *L, mp_buf *buf, int level) { -#if LUA_VERSION_NUM == 502 - size_t len = lua_rawlen(L,-1), j; -#else +#if LUA_VERSION_NUM < 502 size_t len = lua_objlen(L,-1), j; +#else + size_t len = lua_rawlen(L,-1), j; #endif mp_encode_array(buf,len); @@ -691,10 +691,10 @@ static int mp_unpack(lua_State *L) { /* ---------------------------------------------------------------------------- */ -#if LUA_VERSION_NUM == 502 -static const struct luaL_Reg thislib[] = { -#else +#if LUA_VERSION_NUM < 502 static const struct luaL_reg thislib[] = { +#else +static const struct luaL_Reg thislib[] = { #endif {"pack", mp_pack}, {"unpack", mp_unpack}, @@ -702,10 +702,10 @@ static const struct luaL_reg thislib[] = { }; LUALIB_API int luaopen_cmsgpack (lua_State *L) { -#if LUA_VERSION_NUM == 502 - luaL_newlib(L, thislib); -#else +#if LUA_VERSION_NUM < 502 luaL_register(L, "cmsgpack", thislib); +#else + luaL_newlib(L, thislib); #endif lua_pushliteral(L, LUACMSGPACK_VERSION); From c86287e9eb9142b4d01a5d1b4a91851093abe811 Mon Sep 17 00:00:00 2001 From: Matt Stancliff Date: Fri, 4 Apr 2014 15:54:14 -0400 Subject: [PATCH 4/4] Bump to version 0.3.1 It's been two years since 0.3.0 and there have been a few small changes since then (including 5.2 compat). Cutting a new version allows other projects (and rocks) to pull down additions easier. Also adding a rockspec for 0.3.1 (tag 0.3.1 should be made on the origin repo so rocks can pull properly). --- lua_cmsgpack.c | 3 ++- rockspec/lua-cmsgpack-0.3-1.rockspec | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 rockspec/lua-cmsgpack-0.3-1.rockspec diff --git a/lua_cmsgpack.c b/lua_cmsgpack.c index c0c9c1d..f7325e7 100644 --- a/lua_cmsgpack.c +++ b/lua_cmsgpack.c @@ -7,7 +7,7 @@ #include "lua.h" #include "lauxlib.h" -#define LUACMSGPACK_VERSION "lua-cmsgpack 0.3.0" +#define LUACMSGPACK_VERSION "lua-cmsgpack 0.3.1" #define LUACMSGPACK_COPYRIGHT "Copyright (C) 2012, Salvatore Sanfilippo" #define LUACMSGPACK_DESCRIPTION "MessagePack C implementation for Lua" @@ -29,6 +29,7 @@ * 20-Feb-2012 (ver 0.2.0): Tables encoding improved. * 20-Feb-2012 (ver 0.2.1): Minor bug fixing. * 20-Feb-2012 (ver 0.3.0): Module renamed lua-cmsgpack (was lua-msgpack). + * 04-Apr-2014 (ver 0.3.1): Lua 5.2 support and minor bug fix. * ============================================================================ */ /* --------------------------- Endian conversion -------------------------------- diff --git a/rockspec/lua-cmsgpack-0.3-1.rockspec b/rockspec/lua-cmsgpack-0.3-1.rockspec new file mode 100644 index 0000000..2062072 --- /dev/null +++ b/rockspec/lua-cmsgpack-0.3-1.rockspec @@ -0,0 +1,25 @@ +package = "lua-cmsgpack" +version = "0.3.1-0" +source = { + url = "git://github.com/antirez/lua-cmsgpack.git", + tag = "0.3.1" +} +description = { + summary = "MessagePack C implementation and bindings for Lua 5.1/5.2", + homepage = "http://github.com/antirez/lua-cmsgpack", + license = "Two-clause BSD", + maintainer = "Salvatore Sanfilippo " +} +dependencies = { + "lua >= 5.1" +} +build = { + type = "builtin", + modules = { + cmsgpack = { + sources = { + "lua_cmsgpack.c", + } + } + } +}