diff options
Diffstat (limited to '')
-rw-r--r-- | epan/wslua/init_wslua.c | 10 | ||||
-rw-r--r-- | epan/wslua/lrexlib/pcre2/lpcre2.c | 2 | ||||
-rw-r--r-- | epan/wslua/lua_bitop.c | 25 | ||||
-rwxr-xr-x | epan/wslua/make-taps.py | 24 | ||||
-rw-r--r-- | epan/wslua/wslua_byte_array.c | 12 | ||||
-rw-r--r-- | epan/wslua/wslua_dissector.c | 4 | ||||
-rw-r--r-- | epan/wslua/wslua_field.c | 12 | ||||
-rw-r--r-- | epan/wslua/wslua_file.c | 10 | ||||
-rw-r--r-- | epan/wslua/wslua_file_handler.c | 8 | ||||
-rw-r--r-- | epan/wslua/wslua_frame_info.c | 8 | ||||
-rw-r--r-- | epan/wslua/wslua_pinfo.c | 2 | ||||
-rw-r--r-- | epan/wslua/wslua_pref.c | 4 | ||||
-rw-r--r-- | epan/wslua/wslua_proto.c | 50 | ||||
-rw-r--r-- | epan/wslua/wslua_struct.c | 10 | ||||
-rw-r--r-- | epan/wslua/wslua_tree.c | 6 | ||||
-rw-r--r-- | epan/wslua/wslua_tvb.c | 58 | ||||
-rw-r--r-- | epan/wslua/wslua_wtap.c | 10 |
17 files changed, 160 insertions, 95 deletions
diff --git a/epan/wslua/init_wslua.c b/epan/wslua/init_wslua.c index 40093265..9217a4ab 100644 --- a/epan/wslua/init_wslua.c +++ b/epan/wslua/init_wslua.c @@ -969,7 +969,7 @@ add_table_symbol(const char *table, const char *name, int value) lua_getglobal(L, table); /* Set symbol in table. */ lua_pushstring(L, name); - lua_pushnumber(L, value); + lua_pushinteger(L, value); lua_settable(L, -3); /* Pop table from stack. */ lua_pop(L, 1); @@ -979,7 +979,7 @@ static void add_global_symbol(const char *name, int value) { /* Set symbol in global environment. */ - lua_pushnumber(L, value); + lua_pushinteger(L, value); lua_setglobal(L, name); } @@ -988,7 +988,7 @@ add_pi_severity_symbol(const char *name, int value) { lua_getglobal(L, WSLUA_EXPERT_TABLE); lua_getfield(L, -1, WSLUA_EXPERT_SEVERITY_TABLE); - lua_pushnumber(L, value); + lua_pushinteger(L, value); lua_setfield(L, -2, name); lua_pop(L, 2); } @@ -998,7 +998,7 @@ add_pi_group_symbol(const char *name, int value) { lua_getglobal(L, WSLUA_EXPERT_TABLE); lua_getfield(L, -1, WSLUA_EXPERT_GROUP_TABLE); - lua_pushnumber(L, value); + lua_pushinteger(L, value); lua_setfield(L, -2, name); lua_pop(L, 2); } @@ -1007,7 +1007,7 @@ static void add_menu_group_symbol(const char *name, int value) { /* Set symbol in global environment. */ - lua_pushnumber(L, value); + lua_pushinteger(L, value); char *str = g_strdup(name); char *s = strstr(str, "_GROUP_"); if (s == NULL) diff --git a/epan/wslua/lrexlib/pcre2/lpcre2.c b/epan/wslua/lrexlib/pcre2/lpcre2.c index f24cbec8..ee1926f8 100644 --- a/epan/wslua/lrexlib/pcre2/lpcre2.c +++ b/epan/wslua/lrexlib/pcre2/lpcre2.c @@ -432,7 +432,7 @@ static int Lpcre2_jit_compile (lua_State *L) { #define SET_INFO_FIELD(L,ud,what,name,valtype) { \ valtype val; \ if (0 == pcre2_pattern_info (ud->pr, what, &val)) { \ - lua_pushnumber (L, val); \ + lua_pushinteger (L, val); \ lua_setfield (L, -2, name); \ } \ } diff --git a/epan/wslua/lua_bitop.c b/epan/wslua/lua_bitop.c index 2f3c3eeb..52be189a 100644 --- a/epan/wslua/lua_bitop.c +++ b/epan/wslua/lua_bitop.c @@ -24,7 +24,7 @@ typedef uint32_t UBits; typedef union { lua_Number n; -#ifdef LUA_NUMBER_DOUBLE +#if defined(LUA_NUMBER_DOUBLE) || defined(LUA_FLOAT_DOUBLE) uint64_t b; #else UBits b; @@ -41,24 +41,25 @@ static UBits barg(lua_State *L, int idx) #else bn.n = luaL_checknumber(L, idx); #endif -#if defined(LUA_NUMBER_DOUBLE) +#if defined(LUA_NUMBER_DOUBLE) || defined(LUA_FLOAT_DOUBLE) bn.n += 6755399441055744.0; /* 2^52+2^51 */ #ifdef SWAPPED_DOUBLE b = (UBits)(bn.b >> 32); #else b = (UBits)bn.b; #endif -#elif defined(LUA_NUMBER_INT) || defined(LUA_NUMBER_LONG) || \ - defined(LUA_NUMBER_LONGLONG) || defined(LUA_NUMBER_LONG_LONG) || \ - defined(LUA_NUMBER_LLONG) +#elif defined(LUA_NUMBER_INT) || defined(LUA_INT_INT) || \ + defined(LUA_NUMBER_LONG) || defined(LUA_INT_LONG) || \ + defined(LUA_NUMBER_LONGLONG) || defined(LUA_INT_LONGLONG) || \ + defined(LUA_NUMBER_LONG_LONG) || defined(LUA_NUMBER_LLONG) if (sizeof(UBits) == sizeof(lua_Number)) b = bn.b; else b = (UBits)(SBits)bn.n; -#elif defined(LUA_NUMBER_FLOAT) +#elif defined(LUA_NUMBER_FLOAT) || defined(LUA_FLOAT_FLOAT) #error "A 'float' lua_Number type is incompatible with this library" #else -#error "Unknown number type, check LUA_NUMBER_* in luaconf.h" +#error "Unknown number type, check LUA_NUMBER_*, LUA_FLOAT_*, LUA_INT_* in luaconf.h" #endif #if LUA_VERSION_NUM < 502 if (b == 0 && !lua_isnumber(L, idx)) { @@ -69,7 +70,11 @@ static UBits barg(lua_State *L, int idx) } /* Return bit type. */ +#if LUA_VERSION_NUM < 503 #define BRET(b) lua_pushnumber(L, (lua_Number)(SBits)(b)); return 1; +#else +#define BRET(b) lua_pushinteger(L, (lua_Integer)(SBits)(b)); return 1; +#endif static int bit_tobit(lua_State *L) { BRET(barg(L, 1)) } static int bit_bnot(lua_State *L) { BRET(~barg(L, 1)) } @@ -141,11 +146,15 @@ static const struct luaL_Reg bit_funcs[] = { LUALIB_API int luaopen_bit(lua_State *L) { UBits b; +#if LUA_VERSION_NUM < 503 lua_pushnumber(L, (lua_Number)1437217655L); +#else + lua_pushinteger(L, (lua_Integer)1437217655L); +#endif b = barg(L, -1); if (b != (UBits)1437217655L || BAD_SAR) { /* Perform a simple self-test. */ const char *msg = "compiled with incompatible luaconf.h"; -#ifdef LUA_NUMBER_DOUBLE +#if defined(LUA_NUMBER_DOUBLE) || defined(LUA_FLOAT_DOUBLE) #ifdef _WIN32 if (b == (UBits)1610612736L) msg = "use D3DCREATE_FPU_PRESERVE with DirectX"; diff --git a/epan/wslua/make-taps.py b/epan/wslua/make-taps.py index 14c5a397..ed677ff5 100755 --- a/epan/wslua/make-taps.py +++ b/epan/wslua/make-taps.py @@ -34,18 +34,18 @@ def get_tap_info(tap_name, header_file, struct_name, enum_types): types = { 'gchar[]': 'lua_pushstring(L,(const char*)v->STR);', 'gchar*': 'lua_pushstring(L,(const char*)v->STR);', - 'guint': 'lua_pushnumber(L,(lua_Number)v->STR);', - 'guint8': 'lua_pushnumber(L,(lua_Number)v->STR);', - 'guint16': 'lua_pushnumber(L,(lua_Number)v->STR);', - 'guint32': 'lua_pushnumber(L,(lua_Number)v->STR);', - 'gint': 'lua_pushnumber(L,(lua_Number)v->STR);', - 'gint8': 'lua_pushnumber(L,(lua_Number)v->STR);', - 'gint16': 'lua_pushnumber(L,(lua_Number)v->STR);', - 'gint32': 'lua_pushnumber(L,(lua_Number)v->STR);', + 'guint': 'lua_pushinteger(L,(lua_Integer)v->STR);', + 'guint8': 'lua_pushinteger(L,(lua_Integer)v->STR);', + 'guint16': 'lua_pushinteger(L,(lua_Integer)v->STR);', + 'guint32': 'lua_pushinteger(L,(lua_Integer)v->STR);', + 'gint': 'lua_pushinteger(L,(lua_Integer)v->STR);', + 'gint8': 'lua_pushinteger(L,(lua_Integer)v->STR);', + 'gint16': 'lua_pushinteger(L,(lua_Integer)v->STR);', + 'gint32': 'lua_pushinteger(L,(lua_Integer)v->STR);', 'gboolean': 'lua_pushboolean(L,(int)v->STR);', 'address': '{ Address a = (Address)g_malloc(sizeof(address)); copy_address(a, &(v->STR)); pushAddress(L,a); }', 'address*': '{ Address a = (Address)g_malloc(sizeof(address)); copy_address(a, v->STR); pushAddress(L,a); }', - 'int': 'lua_pushnumber(L,(lua_Number)v->STR);', + 'int': 'lua_pushinteger(L,(lua_Integer)v->STR);', 'nstime_t': 'lua_pushnumber(L,(lua_Number)nstime_to_sec(&(v->STR)));', 'nstime_t*': 'lua_pushnumber(L,(lua_Number)nstime_to_sec(v->STR));', } @@ -79,7 +79,7 @@ def get_tap_info(tap_name, header_file, struct_name, enum_types): for enum in enum_types: m = re.search(fr'typedef\s+enum[^{{]*{{([^}}]*)}}[\s\n]*{enum}[\s\n]*;', buf, flags=re.DOTALL) if m: - types[enum] = f'lua_pushnumber(L,(lua_Number)v->STR); /* {enum} */' + types[enum] = f'lua_pushinteger(L,(lua_Integer)v->STR); /* {enum} */' econsts = m.group(1).splitlines() econsts = [re.sub(r'\s+', '', item) for item in econsts] econsts = [re.sub(',', '', item) for item in econsts] @@ -183,9 +183,9 @@ def main(): c_body += f'\n\t/*\n\t * {enum}\n\t */\n\tlua_newtable(L);\n' for econst in enums[enum]: c_body += f'''\ - lua_pushnumber(L,(lua_Number){econst}); + lua_pushinteger(L,(lua_Integer){econst}); lua_setglobal(L,"{econst}"); - lua_pushnumber(L,(lua_Number){econst}); + lua_pushinteger(L,(lua_Integer){econst}); lua_pushstring(L,"{econst}"); lua_settable(L,-3); ''' diff --git a/epan/wslua/wslua_byte_array.c b/epan/wslua/wslua_byte_array.c index 6e6ae304..b0449912 100644 --- a/epan/wslua/wslua_byte_array.c +++ b/epan/wslua/wslua_byte_array.c @@ -214,7 +214,7 @@ WSLUA_METHOD ByteArray_get_index(lua_State* L) { luaL_argerror(L,2,"index out of range"); return 0; } - lua_pushnumber(L,ba->data[idx]); + lua_pushinteger(L,ba->data[idx]); WSLUA_RETURN(1); /* The value [0-255] of the byte. */ } @@ -255,7 +255,7 @@ WSLUA_METHOD ByteArray_le_int(lua_State* L) { value |= (guint8)ba->data[offset + i]; } - lua_pushnumber(L, value); + lua_pushinteger(L, value); WSLUA_RETURN(1); /* The value of the little endian encoded signed integer beginning at given offset with given length. */ } @@ -337,7 +337,7 @@ WSLUA_METHOD ByteArray_le_uint(lua_State* L) { value |= (guint8)ba->data[offset + i]; } - lua_pushnumber(L, value); + lua_pushinteger(L, value); WSLUA_RETURN(1); /* The value of the little endian encoded unsigned integer beginning at given offset with given length. */ } @@ -419,7 +419,7 @@ WSLUA_METHOD ByteArray_int(lua_State* L) { value |= (guint8)ba->data[offset + i]; } - lua_pushnumber(L, value); + lua_pushinteger(L, value); WSLUA_RETURN(1); /* The value of the big endian encoded 32 bit signed integer beginning at given offset with given length. */ } @@ -501,7 +501,7 @@ WSLUA_METHOD ByteArray_uint(lua_State* L) { value |= (guint8)ba->data[offset + i]; } - lua_pushnumber(L, value); + lua_pushinteger(L, value); WSLUA_RETURN(1); /* The value of the big endian encoded 32 bit unsigned integer beginning at given offset with given length. */ } @@ -551,7 +551,7 @@ WSLUA_METHOD ByteArray_len(lua_State* L) { /* Obtain the length of a <<lua_class_ByteArray,`ByteArray`>>. */ ByteArray ba = checkByteArray(L,1); - lua_pushnumber(L,(lua_Number)ba->len); + lua_pushinteger(L,(lua_Integer)ba->len); WSLUA_RETURN(1); /* The length of the <<lua_class_ByteArray,`ByteArray`>>. */ } diff --git a/epan/wslua/wslua_dissector.c b/epan/wslua/wslua_dissector.c index 5b189308..6181ffbf 100644 --- a/epan/wslua/wslua_dissector.c +++ b/epan/wslua/wslua_dissector.c @@ -107,7 +107,7 @@ WSLUA_METHOD Dissector_call(lua_State* L) { are normal conditions and possibly don't need the Lua traceback. */ if (error) { WSLUA_ERROR(Dissector_call,error); } - lua_pushnumber(L,(lua_Number)len); + lua_pushinteger(L,(lua_Integer)len); WSLUA_RETURN(1); /* Number of bytes dissected. Note that some dissectors always return number of bytes in incoming buffer, so be aware. */ } @@ -618,7 +618,7 @@ WSLUA_METHOD DissectorTable_try (lua_State *L) { if (error) { WSLUA_ERROR(DissectorTable_try,error); } - lua_pushnumber(L,(lua_Number)len); + lua_pushinteger(L,(lua_Integer)len); WSLUA_RETURN(1); /* Number of bytes dissected. Note that some dissectors always return number of bytes in incoming buffer, so be aware. */ } diff --git a/epan/wslua/wslua_field.c b/epan/wslua/wslua_field.c index 17db1974..d7d3e9d7 100644 --- a/epan/wslua/wslua_field.c +++ b/epan/wslua/wslua_field.c @@ -50,7 +50,7 @@ WSLUA_METAMETHOD FieldInfo__len(lua_State* L) { */ FieldInfo fi = checkFieldInfo(L,1); - lua_pushnumber(L,fi->ws_fi->length); + lua_pushinteger(L,fi->ws_fi->length); return 1; } @@ -61,7 +61,7 @@ WSLUA_METAMETHOD FieldInfo__unm(lua_State* L) { */ FieldInfo fi = checkFieldInfo(L,1); - lua_pushnumber(L,fi->ws_fi->start); + lua_pushinteger(L,fi->ws_fi->start); return 1; } @@ -91,13 +91,13 @@ WSLUA_METAMETHOD FieldInfo__call(lua_State* L) { case FT_UINT24: case FT_UINT32: case FT_FRAMENUM: - lua_pushnumber(L,(lua_Number)(fvalue_get_uinteger(fi->ws_fi->value))); + lua_pushinteger(L,(lua_Integer)(fvalue_get_uinteger(fi->ws_fi->value))); return 1; case FT_INT8: case FT_INT16: case FT_INT24: case FT_INT32: - lua_pushnumber(L,(lua_Number)(fvalue_get_sinteger(fi->ws_fi->value))); + lua_pushinteger(L,(lua_Integer)(fvalue_get_sinteger(fi->ws_fi->value))); return 1; case FT_FLOAT: case FT_DOUBLE: @@ -268,7 +268,7 @@ static int FieldInfo_get_type(lua_State* L) { FieldInfo fi = checkFieldInfo(L,1); if (fi->ws_fi->hfinfo) { - lua_pushnumber(L, fi->ws_fi->hfinfo->type); + lua_pushinteger(L, fi->ws_fi->hfinfo->type); } else { lua_pushnil(L); @@ -710,7 +710,7 @@ static int Field_get_type(lua_State* L) { Field f = checkField(L,1); header_field_info* hfinfo = NULL; - GET_HFINFO_MEMBER(lua_pushnumber, type); + GET_HFINFO_MEMBER(lua_pushinteger, type); return 1; } diff --git a/epan/wslua/wslua_file.c b/epan/wslua/wslua_file.c index 2621a997..ff74760f 100644 --- a/epan/wslua/wslua_file.c +++ b/epan/wslua/wslua_file.c @@ -152,7 +152,7 @@ static int File_read_number (lua_State *L, FILE_T ft) { buff[buff_end] = '\0'; if (buff_end > 0 && num_digits > 0 && sscanf(buff, "%lf", &d) == 1) { - lua_pushnumber(L, d); + lua_pushinteger(L, d); return 1; } else { @@ -338,7 +338,11 @@ WSLUA_METHOD File_seek(lua_State* L) { static const char *const modenames[] = {"set", "cur", "end", NULL}; File f = checkFile(L,1); int op = luaL_checkoption(L, 2, "cur", modenames); +#if LUA_VERSION_NUM >= 503 + gint64 offset = (gint64)luaL_optinteger(L, 3, 0); +#else gint64 offset = (gint64) luaL_optlong(L, 3, 0); +#endif int err; @@ -351,7 +355,7 @@ WSLUA_METHOD File_seek(lua_State* L) { return 2; } - lua_pushnumber(L, (lua_Number)(file_tell(f->file))); + lua_pushinteger(L, (lua_Integer)(file_tell(f->file))); } else { offset = wtap_dump_file_seek(f->wdh, offset, mode[op], &err); @@ -370,7 +374,7 @@ WSLUA_METHOD File_seek(lua_State* L) { return 2; } - lua_pushnumber(L, (lua_Number)(offset)); + lua_pushinteger(L, (lua_Integer)(offset)); } WSLUA_RETURN(1); /* The current file cursor position as a number. */ diff --git a/epan/wslua/wslua_file_handler.c b/epan/wslua/wslua_file_handler.c index f0c9ad83..47f72d45 100644 --- a/epan/wslua/wslua_file_handler.c +++ b/epan/wslua/wslua_file_handler.c @@ -326,7 +326,7 @@ wslua_filehandler_seek_read_packet(wtap *wth, gint64 seek_off, wtap_rec *rec, Bu fp = push_File(L, wth->random_fh); fc = push_CaptureInfo(L, wth, FALSE); fi = push_FrameInfo(L, rec, buf); - lua_pushnumber(L, (lua_Number)seek_off); + lua_pushinteger(L, (lua_Integer)seek_off); switch ( lua_pcall(L,4,1,1) ) { case 0: @@ -474,7 +474,7 @@ wslua_filehandler_can_write_encap(int encap, void* data) INIT_FILEHANDLER_ROUTINE(can_write_encap,WTAP_ERR_UNWRITABLE_ENCAP,NULL,NULL); - lua_pushnumber(L, encap); + lua_pushinteger(L, encap); switch ( lua_pcall(L,1,1,1) ) { case 0: @@ -842,7 +842,7 @@ WSLUA_FUNCTION wslua_register_filehandler(lua_State* L) { fh->registered = TRUE; registered_file_handlers = g_slist_prepend(registered_file_handlers, fh); - lua_pushnumber(L, fh->file_type); + lua_pushinteger(L, fh->file_type); WSLUA_RETURN(1); /* the new type number for this file reader/write */ } @@ -1207,7 +1207,7 @@ WSLUA_ATTRIBUTE_GET(FileHandler,supported_comment_types,{ \ break;\ } \ } \ - lua_pushnumber(L, (lua_Number)supported_comment_types); \ + lua_pushinteger(L, (lua_Integer)supported_comment_types); \ }); WSLUA_ATTRIBUTE_SET(FileHandler,supported_comment_types, { \ guint supported_comment_types; \ diff --git a/epan/wslua/wslua_frame_info.c b/epan/wslua/wslua_frame_info.c index 401abd73..72701d6f 100644 --- a/epan/wslua/wslua_frame_info.c +++ b/epan/wslua/wslua_frame_info.c @@ -89,7 +89,7 @@ WSLUA_METHOD FrameInfo_read_data(lua_State* L) { g_free(err_info); /* is this right? */ } else lua_pushnil(L); - lua_pushnumber(L, err); + lua_pushinteger(L, err); return 3; } @@ -120,7 +120,7 @@ static int FrameInfo_get_comment (lua_State* L) { lua_createtable(L, n_comments, 0); for (i = 0; i < n_comments; i++) { comment = NULL; - lua_pushnumber(L, i+1); + lua_pushinteger(L, i+1); if (WTAP_OPTTYPE_SUCCESS == wtap_block_get_nth_string_option_value(block, OPT_COMMENT, i, &comment)) { lua_pushstring(L, comment); @@ -371,7 +371,7 @@ WSLUA_METHOD FrameInfoConst_write_data(lua_State* L) { if (!wtap_dump_file_write(fh->wdh, fi->pd, (size_t)(len), &err)) { lua_pushboolean(L, FALSE); lua_pushfstring(L, "FrameInfoConst write_data() error: %s", g_strerror(err)); - lua_pushnumber(L, err); + lua_pushinteger(L, err); return 3; } @@ -403,7 +403,7 @@ static int FrameInfoConst_get_comment (lua_State* L) { lua_createtable(L, n_comments, 0); for (i = 0; i < n_comments; i++) { comment = NULL; - lua_pushnumber(L, i+1); + lua_pushinteger(L, i+1); if (WTAP_OPTTYPE_SUCCESS == wtap_block_get_nth_string_option_value(block, OPT_COMMENT, i, &comment)) { lua_pushstring(L, comment); diff --git a/epan/wslua/wslua_pinfo.c b/epan/wslua/wslua_pinfo.c index a735d601..3e60715e 100644 --- a/epan/wslua/wslua_pinfo.c +++ b/epan/wslua/wslua_pinfo.c @@ -308,7 +308,7 @@ static int Pinfo_get_match(lua_State *L) { if (pinfo->ws_pinfo->match_string) { lua_pushstring(L,pinfo->ws_pinfo->match_string); } else { - lua_pushnumber(L,(lua_Number)(pinfo->ws_pinfo->match_uint)); + lua_pushinteger(L,(lua_Integer)(pinfo->ws_pinfo->match_uint)); } return 1; diff --git a/epan/wslua/wslua_pref.c b/epan/wslua/wslua_pref.c index 234170d3..3d6ed540 100644 --- a/epan/wslua/wslua_pref.c +++ b/epan/wslua/wslua_pref.c @@ -515,9 +515,9 @@ WSLUA_METAMETHOD Prefs__index(lua_State* L) { if ( g_str_equal(prefs_p->name,name) ) { switch (prefs_p->type) { case PREF_BOOL: lua_pushboolean(L, prefs_p->value.b); break; - case PREF_UINT: lua_pushnumber(L,(lua_Number)prefs_p->value.u); break; + case PREF_UINT: lua_pushinteger(L,(lua_Integer)prefs_p->value.u); break; case PREF_STRING: lua_pushstring(L,prefs_p->value.s); break; - case PREF_ENUM: lua_pushnumber(L,(lua_Number)prefs_p->value.e); break; + case PREF_ENUM: lua_pushinteger(L,(lua_Integer)prefs_p->value.e); break; case PREF_RANGE: { char *push_str = range_convert_range(NULL, prefs_p->value.r); diff --git a/epan/wslua/wslua_proto.c b/epan/wslua/wslua_proto.c index 363975b2..92a1d192 100644 --- a/epan/wslua/wslua_proto.c +++ b/epan/wslua/wslua_proto.c @@ -444,7 +444,33 @@ static int Proto_set_fields(lua_State* L) { if( lua_istable(L,NEW_TABLE)) { for (lua_pushnil(L); lua_next(L, NEW_TABLE); ) { if (isProtoField(L,5)) { - luaL_ref(L,FIELDS_TABLE); + /* luaL_ref returns a reference. lua_next will return not + * just occupied entries in the table, but also references + * used to store unused/deleted entries in the hash table + * so that they can be reused without reallocation. Those + * will have a lua_Number as their value. The values form + * a linked list of available indicies, starting with the + * head at index 3 (LUA_RIDX_LAST + 1) in Lua 5.4 and index + * 0 in earlier versions. (Since arrays are 1-indexed, this + * is mostly invisible in Lua 5.3 and earlier so long as + * nothing has been deleted.) + * + * Perhaps the assumption is that no one wants to use a + * hash table to store numbers anyway? This also means + * that for any table with 2 or more real entries, the + * length operator # *includes* the freelist and cannot + * be trusted. + * + * If we wanted to only check entries we knew were valid, + * we could save this reference. + * + * This also means that our checks below on registration + * and deregistration that the table entries are ProtoFields + * are less useful, because we do now expect some numbers + * in the table. Hopefully the check on insert here obviates + * needing to check there. + */ + /* int ref = */ luaL_ref(L,FIELDS_TABLE); } else if (! lua_isnil(L,5) ) { return luaL_error(L,"only ProtoFields should be in the table"); } @@ -457,6 +483,7 @@ static int Proto_set_fields(lua_State* L) { return luaL_error(L,"either a ProtoField or an array of protofields"); } + /* XXX - I don't think this is necessary. */ lua_pushvalue(L, 3); return 1; @@ -573,6 +600,11 @@ ProtoField wslua_is_field_available(lua_State* L, const char* field_abbr) { lua_pushnil(L); while (lua_next(L, -2)) { + if (lua_type(L, -1) == LUA_TNUMBER) { + /* part of free reference linked list, ignore */ + lua_pop(L, 1); /* table value */ + continue; + } ProtoField f = checkProtoField(L, -1); if (strcmp(field_abbr, f->abbrev) == 0) { /* found! */ @@ -632,6 +664,10 @@ int wslua_deregister_protocols(lua_State* L) { /* for each registered ProtoField do... */ lua_rawgeti(L, LUA_REGISTRYINDEX, proto->fields); for (lua_pushnil(L); lua_next(L, -2); lua_pop(L, 1)) { + if (lua_type(L, -1) == LUA_TNUMBER) { + /* part of free reference linked list, ignore */ + continue; + } ProtoField f = checkProtoField(L, -1); /* Memory ownership was previously transferred to epan in Proto_commit */ @@ -647,6 +683,10 @@ int wslua_deregister_protocols(lua_State* L) { /* for each registered ProtoExpert do... */ lua_rawgeti(L, LUA_REGISTRYINDEX, proto->expert_info_table_ref); for (lua_pushnil(L); lua_next(L, -2); lua_pop(L, 1)) { + if (lua_type(L, -1) == LUA_TNUMBER) { + /* part of free reference linked list, ignore */ + continue; + } ProtoExpert pe = checkProtoExpert(L,-1); /* Memory ownership was previously transferred to epan in Proto_commit */ @@ -708,6 +748,10 @@ int Proto_commit(lua_State* L) { /* for each ProtoField in the Lua table do... */ for (lua_pushnil(L); lua_next(L, 4); lua_pop(L, 1)) { + if (lua_type(L, -1) == LUA_TNUMBER) { + /* part of free reference linked list, ignore */ + continue; + } ProtoField f = checkProtoField(L,6); hf_register_info hfri = { NULL, { NULL, NULL, FT_NONE, 0, NULL, 0, NULL, HFILL } }; ettp = &(f->ett); @@ -744,6 +788,10 @@ int Proto_commit(lua_State* L) { /* for each ProtoExpert in the Lua table do... */ for (lua_pushnil(L); lua_next(L, 4); lua_pop(L, 1)) { + if (lua_type(L, -1) == LUA_TNUMBER) { + /* part of free reference linked list, ignore */ + continue; + } ProtoExpert e = checkProtoExpert(L,6); ei_register_info eiri = { NULL, { NULL, 0, 0, NULL, EXPFILL } }; diff --git a/epan/wslua/wslua_struct.c b/epan/wslua/wslua_struct.c index 7d62dc09..440a0900 100644 --- a/epan/wslua/wslua_struct.c +++ b/epan/wslua/wslua_struct.c @@ -410,7 +410,7 @@ WSLUA_CONSTRUCTOR Struct_pack (lua_State *L) { * given endianness and size. If the integer type is signed, this makes * the Lua number be +/- correctly as well. */ -static lua_Number getinteger (const gchar *buff, int endian, +static lua_Integer getinteger (const gchar *buff, int endian, int issigned, int size) { Uinttype l = 0; int i; @@ -427,12 +427,12 @@ static lua_Number getinteger (const gchar *buff, int endian, } } if (!issigned) - return (lua_Number)l; + return (lua_Integer)l; else { /* signed format */ Uinttype mask = (Uinttype)(~((Uinttype)0)) << (size*8 - 1); if (l & mask) /* negative value? */ l |= mask; /* signal extension */ - return (lua_Number)(Inttype)l; + return (lua_Integer)(Inttype)l; } } @@ -470,8 +470,8 @@ WSLUA_CONSTRUCTOR Struct_unpack (lua_State *L) { case 'b': case 'B': case 'h': case 'H': case 'l': case 'L': case 'T': case 'i': case 'I': { /* integer types */ int issigned = g_ascii_islower(opt); - lua_Number res = getinteger(data+pos, h.endian, issigned, (int)size); - lua_pushnumber(L, res); + lua_Integer res = getinteger(data+pos, h.endian, issigned, (int)size); + lua_pushinteger(L, res); break; } case 'e': { diff --git a/epan/wslua/wslua_tree.c b/epan/wslua/wslua_tree.c index 503b8b7b..5d8dc7c7 100644 --- a/epan/wslua/wslua_tree.c +++ b/epan/wslua/wslua_tree.c @@ -123,7 +123,7 @@ try_add_packet_field(lua_State *L, TreeItem tree_item, TvbRange tvbr, const int item = proto_tree_add_item_ret_int(tree_item->tree, hfid, tvbr->tvb->ws_tvb, tvbr->offset, tvbr->len, encoding, &ret); - lua_pushnumber(L, (lua_Number)ret); + lua_pushinteger(L, (lua_Integer)ret); lua_pushinteger(L, tvbr->offset + tvbr->len); } break; @@ -152,7 +152,7 @@ try_add_packet_field(lua_State *L, TreeItem tree_item, TvbRange tvbr, const int item = proto_tree_add_item_ret_uint(tree_item-> tree, hfid, tvbr->tvb->ws_tvb, tvbr->offset, tvbr->len, encoding, &ret); - lua_pushnumber(L, (lua_Number)ret); + lua_pushinteger(L, (lua_Integer)ret); lua_pushinteger(L, tvbr->offset + tvbr->len); } break; @@ -502,7 +502,7 @@ static int TreeItem_add_item_any(lua_State *L, gboolean little_endian) { switch(type) { case FT_PROTOCOL: item = proto_tree_add_item(tree_item->tree,hfid,tvbr->tvb->ws_tvb,tvbr->offset,tvbr->len,ENC_NA); - lua_pushnumber(L,0); + lua_pushinteger(L,0); lua_insert(L,1); break; case FT_BOOLEAN: diff --git a/epan/wslua/wslua_tvb.c b/epan/wslua/wslua_tvb.c index 7951c7d9..f315e83e 100644 --- a/epan/wslua/wslua_tvb.c +++ b/epan/wslua/wslua_tvb.c @@ -135,7 +135,7 @@ WSLUA_METHOD Tvb_reported_len(lua_State* L) { /* Obtain the reported length (length on the network) of a <<lua_class_Tvb,`Tvb`>>. */ Tvb tvb = checkTvb(L,1); - lua_pushnumber(L,tvb_reported_length(tvb->ws_tvb)); + lua_pushinteger(L,tvb_reported_length(tvb->ws_tvb)); WSLUA_RETURN(1); /* The reported length of the <<lua_class_Tvb,`Tvb`>>. */ } @@ -143,7 +143,7 @@ WSLUA_METHOD Tvb_captured_len(lua_State* L) { /* Obtain the captured length (amount saved in the capture process) of a <<lua_class_Tvb,`Tvb`>>. */ Tvb tvb = checkTvb(L,1); - lua_pushnumber(L,tvb_captured_length(tvb->ws_tvb)); + lua_pushinteger(L,tvb_captured_length(tvb->ws_tvb)); WSLUA_RETURN(1); /* The captured length of the <<lua_class_Tvb,`Tvb`>>. */ } @@ -152,7 +152,7 @@ WSLUA_METHOD Tvb_len(lua_State* L) { Same as captured_len; kept only for backwards compatibility */ Tvb tvb = checkTvb(L,1); - lua_pushnumber(L,tvb_captured_length(tvb->ws_tvb)); + lua_pushinteger(L,tvb_captured_length(tvb->ws_tvb)); WSLUA_RETURN(1); /* The captured length of the <<lua_class_Tvb,`Tvb`>>. */ } @@ -163,7 +163,7 @@ WSLUA_METHOD Tvb_reported_length_remaining(lua_State* L) { Tvb tvb = checkTvb(L,1); int offset = (int) luaL_optinteger(L, Tvb_reported_length_remaining_OFFSET, 0); - lua_pushnumber(L,tvb_reported_length_remaining(tvb->ws_tvb, offset)); + lua_pushinteger(L,tvb_reported_length_remaining(tvb->ws_tvb, offset)); WSLUA_RETURN(1); /* The captured length of the <<lua_class_Tvb,`Tvb`>>. */ } @@ -176,9 +176,13 @@ WSLUA_METHOD Tvb_bytes(lua_State* L) { #define WSLUA_OPTARG_Tvb_bytes_LENGTH 3 /* The length (in octets) of the range. Defaults to until the end of the <<lua_class_Tvb,`Tvb`>>. */ Tvb tvb = checkTvb(L,1); GByteArray* ba; +#if LUA_VERSION_NUM >= 503 + int offset = (int)luaL_optinteger(L, WSLUA_OPTARG_Tvb_bytes_OFFSET, 0); + int len = (int)luaL_optinteger(L, WSLUA_OPTARG_Tvb_bytes_LENGTH, -1); +#else int offset = luaL_optint(L, WSLUA_OPTARG_Tvb_bytes_OFFSET, 0); int len = luaL_optint(L,WSLUA_OPTARG_Tvb_bytes_LENGTH,-1); - +#endif if (tvb->expired) { luaL_error(L,"expired tvb"); return 0; @@ -206,7 +210,7 @@ WSLUA_METHOD Tvb_offset(lua_State* L) { /* Returns the raw offset (from the beginning of the source <<lua_class_Tvb,`Tvb`>>) of a sub <<lua_class_Tvb,`Tvb`>>. */ Tvb tvb = checkTvb(L,1); - lua_pushnumber(L,tvb_raw_offset(tvb->ws_tvb)); + lua_pushinteger(L,tvb_raw_offset(tvb->ws_tvb)); WSLUA_RETURN(1); /* The raw offset of the <<lua_class_Tvb,`Tvb`>>. */ } @@ -437,16 +441,16 @@ WSLUA_METHOD TvbRange_uint(lua_State* L) { switch (tvbr->len) { case 1: - lua_pushnumber(L,tvb_get_guint8(tvbr->tvb->ws_tvb,tvbr->offset)); + lua_pushinteger(L,tvb_get_guint8(tvbr->tvb->ws_tvb,tvbr->offset)); return 1; case 2: - lua_pushnumber(L,tvb_get_ntohs(tvbr->tvb->ws_tvb,tvbr->offset)); + lua_pushinteger(L,tvb_get_ntohs(tvbr->tvb->ws_tvb,tvbr->offset)); return 1; case 3: - lua_pushnumber(L,tvb_get_ntoh24(tvbr->tvb->ws_tvb,tvbr->offset)); + lua_pushinteger(L,tvb_get_ntoh24(tvbr->tvb->ws_tvb,tvbr->offset)); return 1; case 4: - lua_pushnumber(L,tvb_get_ntohl(tvbr->tvb->ws_tvb,tvbr->offset)); + lua_pushinteger(L,tvb_get_ntohl(tvbr->tvb->ws_tvb,tvbr->offset)); WSLUA_RETURN(1); /* The unsigned integer value. */ default: luaL_error(L,"TvbRange:uint() does not handle %d byte integers",tvbr->len); @@ -470,16 +474,16 @@ WSLUA_METHOD TvbRange_le_uint(lua_State* L) { switch (tvbr->len) { case 1: /* XXX unsigned anyway */ - lua_pushnumber(L,(lua_Number)(guint)tvb_get_guint8(tvbr->tvb->ws_tvb,tvbr->offset)); + lua_pushinteger(L,(lua_Integer)(guint)tvb_get_guint8(tvbr->tvb->ws_tvb,tvbr->offset)); return 1; case 2: - lua_pushnumber(L,tvb_get_letohs(tvbr->tvb->ws_tvb,tvbr->offset)); + lua_pushinteger(L,tvb_get_letohs(tvbr->tvb->ws_tvb,tvbr->offset)); return 1; case 3: - lua_pushnumber(L,tvb_get_letoh24(tvbr->tvb->ws_tvb,tvbr->offset)); + lua_pushinteger(L,tvb_get_letoh24(tvbr->tvb->ws_tvb,tvbr->offset)); return 1; case 4: - lua_pushnumber(L,tvb_get_letohl(tvbr->tvb->ws_tvb,tvbr->offset)); + lua_pushinteger(L,tvb_get_letohl(tvbr->tvb->ws_tvb,tvbr->offset)); WSLUA_RETURN(1); /* The unsigned integer value */ default: luaL_error(L,"TvbRange:le_uint() does not handle %d byte integers",tvbr->len); @@ -590,16 +594,16 @@ WSLUA_METHOD TvbRange_int(lua_State* L) { switch (tvbr->len) { case 1: - lua_pushnumber(L,tvb_get_gint8(tvbr->tvb->ws_tvb,tvbr->offset)); + lua_pushinteger(L,tvb_get_gint8(tvbr->tvb->ws_tvb,tvbr->offset)); return 1; case 2: - lua_pushnumber(L,tvb_get_ntohis(tvbr->tvb->ws_tvb,tvbr->offset)); + lua_pushinteger(L,tvb_get_ntohis(tvbr->tvb->ws_tvb,tvbr->offset)); return 1; case 3: - lua_pushnumber(L,tvb_get_ntohi24(tvbr->tvb->ws_tvb,tvbr->offset)); + lua_pushinteger(L,tvb_get_ntohi24(tvbr->tvb->ws_tvb,tvbr->offset)); return 1; case 4: - lua_pushnumber(L,tvb_get_ntohil(tvbr->tvb->ws_tvb,tvbr->offset)); + lua_pushinteger(L,tvb_get_ntohil(tvbr->tvb->ws_tvb,tvbr->offset)); WSLUA_RETURN(1); /* The signed integer value. */ /* * XXX: @@ -629,16 +633,16 @@ WSLUA_METHOD TvbRange_le_int(lua_State* L) { switch (tvbr->len) { case 1: - lua_pushnumber(L,tvb_get_gint8(tvbr->tvb->ws_tvb,tvbr->offset)); + lua_pushinteger(L,tvb_get_gint8(tvbr->tvb->ws_tvb,tvbr->offset)); return 1; case 2: - lua_pushnumber(L,tvb_get_letohis(tvbr->tvb->ws_tvb,tvbr->offset)); + lua_pushinteger(L,tvb_get_letohis(tvbr->tvb->ws_tvb,tvbr->offset)); return 1; case 3: - lua_pushnumber(L,tvb_get_letohi24(tvbr->tvb->ws_tvb,tvbr->offset)); + lua_pushinteger(L,tvb_get_letohi24(tvbr->tvb->ws_tvb,tvbr->offset)); return 1; case 4: - lua_pushnumber(L,tvb_get_letohil(tvbr->tvb->ws_tvb,tvbr->offset)); + lua_pushinteger(L,tvb_get_letohil(tvbr->tvb->ws_tvb,tvbr->offset)); WSLUA_RETURN(1); /* The signed integer value. */ default: luaL_error(L,"TvbRange:le_int() does not handle %d byte integers",tvbr->len); @@ -1233,13 +1237,13 @@ WSLUA_METHOD TvbRange_bitfield(lua_State* L) { } if (len <= 8) { - lua_pushnumber(L,(lua_Number)(guint)tvb_get_bits8(tvbr->tvb->ws_tvb,tvbr->offset*8 + pos, len)); + lua_pushinteger(L,(lua_Integer)(guint)tvb_get_bits8(tvbr->tvb->ws_tvb,tvbr->offset*8 + pos, len)); return 1; } else if (len <= 16) { - lua_pushnumber(L,tvb_get_bits16(tvbr->tvb->ws_tvb,tvbr->offset*8 + pos, len, FALSE)); + lua_pushinteger(L,tvb_get_bits16(tvbr->tvb->ws_tvb,tvbr->offset*8 + pos, len, FALSE)); return 1; } else if (len <= 32) { - lua_pushnumber(L,tvb_get_bits32(tvbr->tvb->ws_tvb,tvbr->offset*8 + pos, len, FALSE)); + lua_pushinteger(L,tvb_get_bits32(tvbr->tvb->ws_tvb,tvbr->offset*8 + pos, len, FALSE)); return 1; } else if (len <= 64) { pushUInt64(L,tvb_get_bits64(tvbr->tvb->ws_tvb,tvbr->offset*8 + pos, len, FALSE)); @@ -1330,7 +1334,7 @@ WSLUA_METHOD TvbRange_len(lua_State* L) { luaL_error(L,"expired tvb"); return 0; } - lua_pushnumber(L,(lua_Number)tvbr->len); + lua_pushinteger(L,(lua_Integer)tvbr->len); return 1; } @@ -1343,7 +1347,7 @@ WSLUA_METHOD TvbRange_offset(lua_State* L) { luaL_error(L,"expired tvb"); return 0; } - lua_pushnumber(L,(lua_Number)tvbr->offset); + lua_pushinteger(L,(lua_Integer)tvbr->offset); return 1; } diff --git a/epan/wslua/wslua_wtap.c b/epan/wslua/wslua_wtap.c index 524ed7c3..9fa27879 100644 --- a/epan/wslua/wslua_wtap.c +++ b/epan/wslua/wslua_wtap.c @@ -85,7 +85,7 @@ WSLUA_FUNCTION wslua_wtap_name_to_file_type_subtype(lua_State* LS) { if (filetype == -1) lua_pushnil(LS); else - lua_pushnumber(LS,filetype); + lua_pushinteger(LS,filetype); WSLUA_RETURN(1); /* The filetype value for the file type with that name, or nil if there is no such file type. */ } @@ -96,7 +96,7 @@ WSLUA_FUNCTION wslua_wtap_pcap_file_type_subtype(lua_State* LS) { @since 3.2.12, 3.4.4 */ lua_Number filetype = wtap_pcap_file_type_subtype(); - lua_pushnumber(LS,filetype); + lua_pushinteger(LS,filetype); WSLUA_RETURN(1); /* The filetype value for pcap files. */ } @@ -107,7 +107,7 @@ WSLUA_FUNCTION wslua_wtap_pcap_nsec_file_type_subtype(lua_State* LS) { @since 3.2.12, 3.4.4 */ lua_Number filetype = wtap_pcap_nsec_file_type_subtype(); - lua_pushnumber(LS,filetype); + lua_pushinteger(LS,filetype); WSLUA_RETURN(1); /* The filetype value for nanosecond-resolution pcap files. */ } @@ -118,7 +118,7 @@ WSLUA_FUNCTION wslua_wtap_pcapng_file_type_subtype(lua_State* LS) { @since 3.2.12, 3.4.4 */ lua_Number filetype = wtap_pcapng_file_type_subtype(); - lua_pushnumber(LS,filetype); + lua_pushinteger(LS,filetype); WSLUA_RETURN(1); /* The filetype value for pcapng files. */ } @@ -148,7 +148,7 @@ extern void wslua_init_wtap_filetypes(lua_State* LS) { * it. */ lua_pushstring(LS, entry->name); - lua_pushnumber(LS, entry->ft); + lua_pushinteger(LS, entry->ft); /* * The -3 is the index, relative to the top of the stack, of * the table; the two elements on top of it are the ft and |