lua.cfg: Add Lua C API library configuration with tests (#2119)

This commit is contained in:
Sebastian 2019-08-29 11:38:21 +02:00 committed by GitHub
parent 03fe6795bf
commit 8782a5f5e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 216 additions and 1 deletions

View File

@ -18,7 +18,7 @@ env:
before_install:
# install needed deps
- travis_retry sudo apt-get update -qq
- travis_retry sudo apt-get install -qq python-pygments qt5-default qt5-qmake qtbase5-dev qtcreator libxml2-utils libpcre3 gdb unzip wx-common xmlstarlet python3-dev
- travis_retry sudo apt-get install -qq python-pygments qt5-default qt5-qmake qtbase5-dev qtcreator libxml2-utils libpcre3 gdb unzip wx-common xmlstarlet python3-dev liblua5.3-dev
- travis_retry python2 -m pip install --user pytest==4.6.4
- travis_retry python2 -m pip install --user pylint
- travis_retry python2 -m pip install --user unittest2

156
cfg/lua.cfg Normal file
View File

@ -0,0 +1,156 @@
<?xml version="1.0"?>
<def format="2">
<!-- Lua C API. See https://www.lua.org/manual/5.3/manual.html#4 -->
<!-- The Lua C API is typically include by '#include <lua.h>' or '#include "lua.h"' -->
<!-- ########## Lua C API Types ########## -->
<!-- https://www.lua.org/manual/5.3/manual.html#lua_Number -->
<define name="lua_Number" value="double"/>
<!-- https://www.lua.org/manual/5.3/manual.html#lua_Integer -->
<podtype name="lua_Integer" sign="s"/>
<!-- https://www.lua.org/manual/5.3/manual.html#lua_Unsigned -->
<podtype name="lua_Unsigned" sign="u"/>
<!-- ########## Lua C API Functions ########## -->
<!-- int lua_error (lua_State *L); -->
<function name="lua_error">
<noreturn>true</noreturn>
<returnValue type="int"/>
<arg nr="1"/>
</function>
<!-- int lua_gettop (lua_State *L); -->
<function name="lua_gettop">
<noreturn>false</noreturn>
<returnValue type="int"/>
<use-retval/>
<arg nr="1"/>
</function>
<!-- int lua_isboolean (lua_State *L, int index); -->
<!-- int lua_iscfunction (lua_State *L, int index); -->
<!-- int lua_isfunction (lua_State *L, int index); -->
<!-- int lua_isinteger (lua_State *L, int index); -->
<!-- int lua_islightuserdata (lua_State *L, int index); -->
<!-- int lua_isnil (lua_State *L, int index); -->
<!-- int lua_isnone (lua_State *L, int index); -->
<!-- int lua_isnoneornil (lua_State *L, int index); -->
<!-- int lua_isnumber (lua_State *L, int index); -->
<!-- int lua_isstring (lua_State *L, int index); -->
<!-- int lua_istable (lua_State *L, int index); -->
<!-- int lua_isthread (lua_State *L, int index); -->
<!-- int lua_isuserdata (lua_State *L, int index); -->
<function name="lua_isboolean,lua_iscfunction,lua_isfunction,lua_isinteger,lua_islightuserdata,lua_isnil,lua_isnone,lua_isnoneornil,lua_isnumber,lua_isstring,lua_istable,lua_isthread,lua_isuserdata">
<noreturn>false</noreturn>
<returnValue type="int"/>
<use-retval/>
<arg nr="1"/>
<arg nr="2" direction="in">
<not-uninit/>
<not-bool/>
</arg>
</function>
<!-- int lua_isyieldable (lua_State *L); -->
<function name="lua_isyieldable">
<noreturn>false</noreturn>
<returnValue type="int"/>
<use-retval/>
<arg nr="1"/>
</function>
<!-- lua_State *lua_newstate (lua_Alloc f, void *ud); -->
<function name="lua_newstate">
<noreturn>false</noreturn>
<returnValue type="lua_State *"/>
<use-retval/>
<arg nr="1"/>
<arg nr="2"/>
</function>
<!-- void lua_pop (lua_State *L, int n); -->
<function name="lua_pop">
<noreturn>false</noreturn>
<returnValue type="void"/>
<arg nr="1"/>
<arg nr="2" direction="in">
<not-uninit/>
<valid>1:</valid>
</arg>
</function>
<!-- void lua_pushnil (lua_State *L); -->
<function name="lua_pushnil">
<noreturn>false</noreturn>
<returnValue type="void"/>
<arg nr="1"/>
</function>
<!-- void lua_pushnumber (lua_State *L, lua_Number n); -->
<function name="lua_pushnumber">
<noreturn>false</noreturn>
<returnValue type="void"/>
<arg nr="1"/>
<arg nr="2" direction="in">
<not-uninit/>
</arg>
</function>
<!-- void lua_pushvalue (lua_State *L, int index); -->
<function name="lua_pushvalue">
<noreturn>false</noreturn>
<returnValue type="void"/>
<arg nr="1"/>
<arg nr="2" direction="in">
<not-uninit/>
</arg>
</function>
<!-- const char *lua_tolstring (lua_State *L, int index, size_t *len); -->
<function name="lua_tolstring">
<noreturn>false</noreturn>
<returnValue type="const char *"/>
<arg nr="1"/>
<arg nr="2" direction="in">
<not-uninit/>
</arg>
<arg nr="3" direction="out">
<not-bool/>
</arg>
</function>
<!-- lua_Number lua_tonumber (lua_State *L, int index); -->
<function name="lua_tonumber">
<noreturn>false</noreturn>
<returnValue type="lua_Number"/>
<use-retval/>
<arg nr="1"/>
<arg nr="2" direction="in">
<not-uninit/>
<not-bool/>
</arg>
</function>
<!-- lua_Number lua_tonumberx (lua_State *L, int index, int *isnum); -->
<function name="lua_tonumberx">
<noreturn>false</noreturn>
<returnValue type="lua_Number"/>
<arg nr="1"/>
<arg nr="2" direction="in">
<not-uninit/>
</arg>
<arg nr="3" direction="out">
<not-bool/>
</arg>
</function>
<!-- const char *lua_tostring (lua_State *L, int index); -->
<function name="lua_tostring">
<noreturn>false</noreturn>
<returnValue type="const char *"/>
<use-retval/>
<arg nr="1"/>
<arg nr="2" direction="in">
<not-uninit/>
<not-bool/>
</arg>
</function>
<!-- int luaL_error (lua_State *L, const char *fmt, ...); -->
<function name="luaL_error">
<noreturn>true</noreturn>
<returnValue type="int"/>
<arg nr="1"/>
<arg nr="2" direction="in">
<not-uninit/>
</arg>
<arg nr="variadic" direction="in">
<not-uninit/>
</arg>
</function>
</def>

31
test/cfg/lua.c Normal file
View File

@ -0,0 +1,31 @@
// Test library configuration for lua.cfg
//
// Usage:
// $ cppcheck --check-library --library=lua --enable=information --error-exitcode=1 --inline-suppr --suppress=missingIncludeSystem test/cfg/lua.c
// =>
// No warnings about bad library configuration, unmatched suppressions, etc. exitcode=0
//
#include <lua.h>
#include <stdio.h>
void validCode(lua_State *L)
{
int a = lua_gettop(L);
printf("%d", a);
lua_pushnil(L);
lua_pop(L, 1);
}
void ignoredReturnValue(lua_State *L)
{
// cppcheck-suppress ignoredReturnValue
lua_tonumber(L, 1);
// cppcheck-suppress ignoredReturnValue
lua_tostring(L, 1);
// cppcheck-suppress ignoredReturnValue
lua_isboolean(L, 1);
// cppcheck-suppress ignoredReturnValue
lua_isnil(L, 1);
}

View File

@ -199,6 +199,33 @@ else
fi
${CPPCHECK} ${CPPCHECK_OPT} --library=python ${DIR}python.c
# lua.c
set +e
pkg-config --version
PKGCONFIG_RETURNCODE=$?
set -e
if [ $PKGCONFIG_RETURNCODE -ne 0 ]; then
echo "pkg-config needed to retrieve Lua configuration is not available, skipping syntax check."
else
set +e
LUACONFIG=$(pkg-config --cflags lua-5.3)
LUACONFIG_RETURNCODE=$?
set -e
if [ $LUACONFIG_RETURNCODE -eq 0 ]; then
set +e
echo -e "#include <lua.h>" | ${CC} ${CC_OPT} ${LUACONFIG} -x c -
LUACONFIG_RETURNCODE=$?
set -e
if [ $LUACONFIG_RETURNCODE -ne 0 ]; then
echo "Lua not completely present or not working, skipping syntax check with ${CC}."
else
echo "Lua found and working, checking syntax with ${CC} now."
${CC} ${CC_OPT} ${LUACONFIG} ${DIR}lua.c
fi
fi
fi
${CPPCHECK} ${CPPCHECK_OPT} --library=lua ${DIR}lua.c
# Check the syntax of the defines in the configuration files
set +e
xmlstarlet --version

View File

@ -273,6 +273,7 @@ def scan_package(work_path, cppcheck_path, jobs):
'googletest': ['<gtest/gtest.h>'],
'gtk': ['<gtk/gtk.h>', '<glib.h>', '<glib/', '<gnome.h>'],
'libcerror': ['<libcerror.h>'],
# 'lua': ['<lua.h>', '"lua.h"'], <= enable after release of version 1.89
'microsoft_sal': ['<sal.h>'],
'motif': ['<X11/', '<Xm/'],
'nspr': ['<prtypes.h>', '"prtypes.h"'],