From 6d2dcc93669952be5dbb9907ad7cb2efba25df45 Mon Sep 17 00:00:00 2001 From: Alexey Melnichuk Date: Fri, 23 May 2014 15:25:57 +0500 Subject: [PATCH 1/4] Run tests on Travis. --- .travis.yml | 28 +++++++++++++++++++++++++++ .travis/setup_lua.sh | 45 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 .travis.yml create mode 100644 .travis/setup_lua.sh diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..b7953a4 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,28 @@ +language: erlang + +env: + global: + - PLATFORM=linux + - LUAROCKS_VER=2.1.0 + matrix: + - LUA=lua5.1 LUA_SFX= + - LUA=lua5.2 LUA_SFX= + - LUA=luajit LUA_SFX=jit + +before_install: + - bash .travis/setup_lua.sh + - sudo pip install cpp-coveralls + +install: + - sudo luarocks make rockspec/lua-cmsgpack-scm-1.rockspec CFLAGS="-O2 -fPIC -ftest-coverage -fprofile-arcs" LIBFLAG="-shared --coverage" + +script: + - lua$LUA_SFX test.lua + +after_success: + - coveralls + +notifications: + email: + on_success: change + on_failure: always diff --git a/.travis/setup_lua.sh b/.travis/setup_lua.sh new file mode 100644 index 0000000..8bcaca1 --- /dev/null +++ b/.travis/setup_lua.sh @@ -0,0 +1,45 @@ +# A script for setting up environment for travis-ci testing. +# Sets up Lua and Luarocks. +# LUA must be "lua5.1", "lua5.2" or "luajit". +# PLATFORM must be "linux" or "macosx". + +if [ "$LUA" == "luajit" ]; then + curl http://luajit.org/download/LuaJIT-2.0.2.tar.gz | tar xz + cd LuaJIT-2.0.2 + make && sudo make install + cd $TRAVIS_BUILD_DIR; +else + if [ "$LUA" == "lua5.1" ]; then + curl http://www.lua.org/ftp/lua-5.1.5.tar.gz | tar xz + cd lua-5.1.5; + elif [ "$LUA" == "lua5.2" ]; then + curl http://www.lua.org/ftp/lua-5.2.3.tar.gz | tar xz + cd lua-5.2.3; + fi + sudo make $PLATFORM install + cd $TRAVIS_BUILD_DIR; +fi + +LUAROCKS_BASE=luarocks-$LUAROCKS_VER +curl http://luarocks.org/releases/$LUAROCKS_BASE.tar.gz | tar xz +cd $LUAROCKS_BASE; + +if [ "$LUA" == "luajit" ]; then + ./configure --lua-suffix=jit --with-lua-include=/usr/local/include/luajit-2.0; +else + ./configure; +fi + +make && sudo make install + +cd $TRAVIS_BUILD_DIR + +rm -rf $LUAROCKS_BASE + +if [ "$LUA" == "luajit" ]; then + rm -rf LuaJIT-2.0.2; +elif [ "$LUA" == "lua5.1" ]; then + rm -rf lua-5.1.5; +elif [ "$LUA" == "lua5.2" ]; then + rm -rf lua-5.2.3; +fi From 40c071a495714d203b7784a697f55059bfaf272b Mon Sep 17 00:00:00 2001 From: Alexey Melnichuk Date: Fri, 23 May 2014 15:29:40 +0500 Subject: [PATCH 2/4] Fix. Redefine `LUACMSGPACK_MAX_NESTING` --- lua_cmsgpack.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lua_cmsgpack.c b/lua_cmsgpack.c index 6b9e9d1..0966d3b 100644 --- a/lua_cmsgpack.c +++ b/lua_cmsgpack.c @@ -13,11 +13,9 @@ #define LUACMSGPACK_COPYRIGHT "Copyright (C) 2012, Salvatore Sanfilippo" #define LUACMSGPACK_DESCRIPTION "MessagePack C implementation for Lua" -#define LUACMSGPACK_MAX_NESTING 16 /* Max tables nesting. */ - /* Allows a preprocessor directive to override MAX_NESTING */ #ifndef LUACMSGPACK_MAX_NESTING - #define LUACMSGPACK_MAX_NESTING 16 + #define LUACMSGPACK_MAX_NESTING 16 /* Max tables nesting. */ #endif #if (_XOPEN_SOURCE >= 600 || _ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L) From 55ce29b1d0a2736678bfdfbd5b760af189c1bc29 Mon Sep 17 00:00:00 2001 From: Alexey Melnichuk Date: Fri, 23 May 2014 16:09:01 +0500 Subject: [PATCH 3/4] Fix. Use `lua_pushnumber` to push int64 on Lua < 5.3 The problem occurs when lua_Number is double and lua_Integer is int32 In this case `mp.unpack(mp.pack(0xFFFFFFFF)) == -1` --- lua_cmsgpack.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/lua_cmsgpack.c b/lua_cmsgpack.c index 0966d3b..3a2d028 100644 --- a/lua_cmsgpack.c +++ b/lua_cmsgpack.c @@ -31,7 +31,7 @@ #define IS_INT_EQUIVALENT(x) IS_INT_TYPE_EQUIVALENT(x, int) #if LUA_VERSION_NUM < 503 - #define lua_pushunsigned(L, n) lua_pushinteger(L, n) + #define lua_pushunsigned(L, n) ((sizeof(lua_Integer) < 64) ? lua_pushnumber(L, n) : lua_pushinteger(L, n)) #endif /* ============================================================================= @@ -348,8 +348,17 @@ static void mp_encode_lua_bool(lua_State *L, mp_buf *buf) { /* Lua 5.3 has a built in 64-bit integer type */ static void mp_encode_lua_integer(lua_State *L, mp_buf *buf) { - lua_Integer i = lua_tointeger(L,-1); - mp_encode_int(buf, (int64_t)i); +#if LUA_VERSION_NUM < 503 + if(sizeof(lua_Integer) < 64){ + lua_Number i = lua_tonumber(L,-1); + mp_encode_int(buf, (int64_t)i); + } + else +#endif + { // MSVC + lua_Integer i = lua_tointeger(L,-1); + mp_encode_int(buf, (int64_t)i); + } } /* Lua 5.2 and lower only has 64-bit doubles, so we need to @@ -431,10 +440,11 @@ static int table_is_an_array(lua_State *L) { /* The <= 0 check is valid here because we're comparing indexes. */ #if LUA_VERSION_NUM < 503 if ((LUA_TNUMBER != lua_type(L,-1)) || (n = lua_tonumber(L, -1)) <= 0 || - !IS_INT_EQUIVALENT(n)) { + !IS_INT_EQUIVALENT(n)) #else - if (!lua_isinteger(L,-1) || (n = lua_tointeger(L, -1)) <= 0) { + if (!lua_isinteger(L,-1) || (n = lua_tointeger(L, -1)) <= 0) #endif + { lua_settop(L, stacktop); return 0; } @@ -628,7 +638,12 @@ void mp_decode_to_lua_type(lua_State *L, mp_cur *c) { break; case 0xd3: /* int 64 */ mp_cur_need(c,9); - lua_pushinteger(L, +#if LUA_VERSION_NUM < 503 + lua_pushnumber +#else + lua_pushinteger +#endif + (L, ((int64_t)c->p[1] << 56) | ((int64_t)c->p[2] << 48) | ((int64_t)c->p[3] << 40) | From bfa38b12ec32ea9700b59839e5ebe9f98c6a1b59 Mon Sep 17 00:00:00 2001 From: Alexey Melnichuk Date: Fri, 23 May 2014 16:29:52 +0500 Subject: [PATCH 4/4] Run test with Lua 5.3 work2 --- .travis.yml | 1 + .travis/setup_lua.sh | 5 +++++ test.lua | 4 ++++ 3 files changed, 10 insertions(+) diff --git a/.travis.yml b/.travis.yml index b7953a4..72661a9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,6 +8,7 @@ env: - LUA=lua5.1 LUA_SFX= - LUA=lua5.2 LUA_SFX= - LUA=luajit LUA_SFX=jit + - LUA=lua5.3 LUA_SFX= before_install: - bash .travis/setup_lua.sh diff --git a/.travis/setup_lua.sh b/.travis/setup_lua.sh index 8bcaca1..8514adf 100644 --- a/.travis/setup_lua.sh +++ b/.travis/setup_lua.sh @@ -15,6 +15,9 @@ else elif [ "$LUA" == "lua5.2" ]; then curl http://www.lua.org/ftp/lua-5.2.3.tar.gz | tar xz cd lua-5.2.3; + elif [ "$LUA" == "lua5.3" ]; then + curl http://www.lua.org/work/lua-5.3.0-work2.tar.gz | tar xz + cd lua-5.3.0-work2; fi sudo make $PLATFORM install cd $TRAVIS_BUILD_DIR; @@ -42,4 +45,6 @@ elif [ "$LUA" == "lua5.1" ]; then rm -rf lua-5.1.5; elif [ "$LUA" == "lua5.2" ]; then rm -rf lua-5.2.3; +elif [ "$LUA" == "lua5.3" ]; then + rm -rf lua-5.3.0-work2; fi diff --git a/test.lua b/test.lua index 000e9d4..1e52f21 100644 --- a/test.lua +++ b/test.lua @@ -6,6 +6,10 @@ local cmsgpack = require "cmsgpack" local ok, cmsgpack_safe = pcall(require, 'cmsgpack.safe') if not ok then cmsgpack_safe = nil end +print("------------------------------------") +print("Lua version: " .. (_G.jit and _G.jit.version or _G._VERSION)) +print("------------------------------------") + local unpack = unpack or table.unpack passed = 0