Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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
50 changes: 50 additions & 0 deletions .travis/setup_lua.sh
Original file line number Diff line number Diff line change
@@ -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
31 changes: 22 additions & 9 deletions lua_cmsgpack.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

/* =============================================================================
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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) |
Expand Down
4 changes: 4 additions & 0 deletions test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down