Various fixes to the Lua int64 code

- add casts to pacify certain buildbots
- skip test if lua isn't available

Change-Id: I614c05dca40cb848c87b361e4b3d3c4e94aafb9e
Reviewed-on: https://code.wireshark.org/review/97
Reviewed-by: Evan Huus <eapache@gmail.com>
Tested-by: Evan Huus <eapache@gmail.com>
This commit is contained in:
Evan Huus 2014-02-03 19:56:49 -05:00
parent 2e7f771a18
commit 1cd7828527
3 changed files with 22 additions and 12 deletions

View File

@ -357,7 +357,7 @@ WSLUA_METHOD Int64_lshift(lua_State* L) {
/* Returns a Int64 of the bitwise logical left-shift operation, by the given number of bits. */
#define WSLUA_ARG_Int64_lshift_NUMBITS 2 /* The number of bits to left-shift by */
guint64 b = (guint64) getInt64(L,1);
guint32 n = luaL_checknumber(L,WSLUA_ARG_Int64_lshift_NUMBITS);
guint32 n = (guint32) luaL_checknumber(L,WSLUA_ARG_Int64_lshift_NUMBITS);
pushInt64(L,(gint64)(b << n));
WSLUA_RETURN(1); /* The Int64 object */
}
@ -366,7 +366,7 @@ WSLUA_METHOD Int64_rshift(lua_State* L) {
/* Returns a Int64 of the bitwise logical right-shift operation, by the given number of bits. */
#define WSLUA_ARG_Int64_rshift_NUMBITS 2 /* The number of bits to right-shift by */
guint64 b = (guint64) getInt64(L,1);
guint32 n = luaL_checknumber(L,WSLUA_ARG_Int64_rshift_NUMBITS);
guint32 n = (guint32) luaL_checknumber(L,WSLUA_ARG_Int64_rshift_NUMBITS);
pushInt64(L,(gint64)(b >> n));
WSLUA_RETURN(1); /* The Int64 object */
}
@ -375,7 +375,7 @@ WSLUA_METHOD Int64_arshift(lua_State* L) {
/* Returns a Int64 of the bitwise arithmetic right-shift operation, by the given number of bits. */
#define WSLUA_ARG_Int64_arshift_NUMBITS 2 /* The number of bits to right-shift by */
gint64 b = getInt64(L,1);
gint32 n = luaL_checknumber(L,WSLUA_ARG_Int64_arshift_NUMBITS);
gint32 n = (gint32) luaL_checknumber(L,WSLUA_ARG_Int64_arshift_NUMBITS);
pushInt64(L,(b >> n));
WSLUA_RETURN(1); /* The Int64 object */
}
@ -384,7 +384,7 @@ WSLUA_METHOD Int64_rol(lua_State* L) {
/* Returns a Int64 of the bitwise left rotation operation, by the given number of bits (up to 63). */
#define WSLUA_ARG_Int64_rol_NUMBITS 2 /* The number of bits to roll left by */
guint64 b = (guint64) getInt64(L,1);
guint32 n = luaL_checknumber(L,WSLUA_ARG_Int64_rol_NUMBITS);
guint32 n = (guint32) luaL_checknumber(L,WSLUA_ARG_Int64_rol_NUMBITS);
pushInt64(L,(gint64)((b << n) | (b >> (64-n))));
WSLUA_RETURN(1); /* The Int64 object */
}
@ -393,7 +393,7 @@ WSLUA_METHOD Int64_ror(lua_State* L) {
/* Returns a Int64 of the bitwise right rotation operation, by the given number of bits (up to 63). */
#define WSLUA_ARG_Int64_ror_NUMBITS 2 /* The number of bits to roll right by */
guint64 b = (guint64) getInt64(L,1);
guint32 n = luaL_checknumber(L,WSLUA_ARG_Int64_ror_NUMBITS);
guint32 n = (guint32) luaL_checknumber(L,WSLUA_ARG_Int64_ror_NUMBITS);
pushInt64(L,(gint64)((b << (64-n)) | (b >> n)));
WSLUA_RETURN(1); /* The Int64 object */
}
@ -475,7 +475,7 @@ static guint64 getUInt64(lua_State *L, int i)
switch (lua_type(L,i))
{
case LUA_TNUMBER:
return luaL_checknumber(L,i);
return (guint64) luaL_checknumber(L,i);
case LUA_TSTRING:
return g_ascii_strtoull(luaL_checkstring(L,i), &end, 10);
case LUA_TUSERDATA:
@ -769,7 +769,7 @@ WSLUA_METHOD UInt64_lshift(lua_State* L) {
/* Returns a UInt64 of the bitwise logical left-shift operation, by the given number of bits. */
#define WSLUA_ARG_UInt64_lshift_NUMBITS 2 /* The number of bits to left-shift by */
guint64 b = getUInt64(L,1);
guint32 n = luaL_checknumber(L,WSLUA_ARG_UInt64_lshift_NUMBITS);
guint32 n = (guint32) luaL_checknumber(L,WSLUA_ARG_UInt64_lshift_NUMBITS);
pushUInt64(L,(b << n));
WSLUA_RETURN(1); /* The UInt64 object */
}
@ -778,7 +778,7 @@ WSLUA_METHOD UInt64_rshift(lua_State* L) {
/* Returns a UInt64 of the bitwise logical right-shift operation, by the given number of bits. */
#define WSLUA_ARG_UInt64_rshift_NUMBITS 2 /* The number of bits to right-shift by */
guint64 b = getUInt64(L,1);
guint32 n = luaL_checknumber(L,WSLUA_ARG_UInt64_rshift_NUMBITS);
guint32 n = (guint32) luaL_checknumber(L,WSLUA_ARG_UInt64_rshift_NUMBITS);
pushUInt64(L,(b >> n));
WSLUA_RETURN(1); /* The UInt64 object */
}
@ -787,7 +787,7 @@ WSLUA_METHOD UInt64_arshift(lua_State* L) {
/* Returns a UInt64 of the bitwise arithmetic right-shift operation, by the given number of bits. */
#define WSLUA_ARG_UInt64_arshift_NUMBITS 2 /* The number of bits to right-shift by */
guint64 b = getUInt64(L,1);
guint32 n = luaL_checknumber(L,WSLUA_ARG_UInt64_arshift_NUMBITS);
guint32 n = (guint32) luaL_checknumber(L,WSLUA_ARG_UInt64_arshift_NUMBITS);
pushUInt64(L,(b >> n));
WSLUA_RETURN(1); /* The UInt64 object */
}
@ -796,7 +796,7 @@ WSLUA_METHOD UInt64_rol(lua_State* L) {
/* Returns a UInt64 of the bitwise left rotation operation, by the given number of bits (up to 63). */
#define WSLUA_ARG_UInt64_rol_NUMBITS 2 /* The number of bits to roll left by */
guint64 b = getUInt64(L,1);
guint32 n = luaL_checknumber(L,WSLUA_ARG_UInt64_rol_NUMBITS);
guint32 n = (guint32) luaL_checknumber(L,WSLUA_ARG_UInt64_rol_NUMBITS);
pushUInt64(L,((b << n) | (b >> (64-n))));
WSLUA_RETURN(1); /* The UInt64 object */
}
@ -805,7 +805,7 @@ WSLUA_METHOD UInt64_ror(lua_State* L) {
/* Returns a UInt64 of the bitwise right rotation operation, by the given number of bits (up to 63). */
#define WSLUA_ARG_UInt64_ror_NUMBITS 2 /* The number of bits to roll right by */
guint64 b = getUInt64(L,1);
guint32 n = luaL_checknumber(L,WSLUA_ARG_UInt64_ror_NUMBITS);
guint32 n = (guint32) luaL_checknumber(L,WSLUA_ARG_UInt64_ror_NUMBITS);
pushUInt64(L,((b << (64-n)) | (b >> n)));
WSLUA_RETURN(1); /* The UInt64 object */
}

View File

@ -99,6 +99,11 @@ export WIRESHARK_QUIT_AFTER_CAPTURE="True"
CAPTURE_DIR="$TESTS_DIR/captures/"
# Figure out if we were built with lua or not so we can skip the lua tests if we
# don't have it. Is there a better way to do this than grepping config.h?
grep -q "#define HAVE_LUA 1" $SOURCE_DIR/config.h
HAVE_LUA=$?
# Display our environment
##printf "\n ------- Info =-----------------\n"

View File

@ -70,8 +70,13 @@ unittests_step_exntest() {
}
unittests_step_lua_int64_test() {
$TSHARK -r $CAPTURE_DIR/dhcp.pcap -X lua_script:$TESTS_DIR/lua/int64.lua > testout.txt 2>&1
if [ $HAVE_LUA -ne 0 ]; then
test_step_skipped
return
fi
# Tshark catches lua script failures, so we have to parse the output.
$TSHARK -r $CAPTURE_DIR/dhcp.pcap -X lua_script:$TESTS_DIR/lua/int64.lua > testout.txt 2>&1
if grep -q "All tests passed!" testout.txt; then
test_step_ok
else