diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..72661a9 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,29 @@ +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 + - LUA=lua5.3 LUA_SFX= + +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..8514adf --- /dev/null +++ b/.travis/setup_lua.sh @@ -0,0 +1,50 @@ +# 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; + 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; +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; +elif [ "$LUA" == "lua5.3" ]; then + rm -rf lua-5.3.0-work2; +fi diff --git a/lua_cmsgpack.c b/lua_cmsgpack.c index 6b9e9d1..3a2d028 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) @@ -33,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 /* ============================================================================= @@ -350,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 @@ -433,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; } @@ -630,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) | 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